memories with lessons mcp server
Enhances user interaction through a persistent memory system that remembers information across chats and learns from past errors by utilizing a local knowledge graph and lesson management.
Enhances user interaction through a persistent memory system that remembers information across chats and learns from past errors by utilizing a local knowledge graph and lesson management.
A basic implementation of persistent memory using a local knowledge graph. This lets Claude remember information about the user across chats and learn from past errors through a lesson system.
Entities are the primary nodes in the knowledge graph. Each entity has: - A unique name (identifier) - An entity type (e.g., "person", "organization", "event") - A list of observations
Example:
{
"name": "John_Smith",
"entityType": "person",
"observations": ["Speaks fluent Spanish"]
}
Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other.
Example:
{
"from": "John_Smith",
"to": "Anthropic",
"relationType": "works_at"
}
Observations are discrete pieces of information about an entity. They are:
Example:
{
"entityName": "John_Smith",
"observations": [
"Speaks fluent Spanish",
"Graduated in 2019",
"Prefers morning meetings"
]
}
Lessons are special entities that capture knowledge about errors and their solutions. Each lesson has: - A unique name (identifier) - Error pattern information (type, message, context) - Solution steps and verification - Success rate tracking - Environmental context - Metadata (severity, timestamps, frequency)
Example:
{
"name": "NPM_VERSION_MISMATCH_01",
"entityType": "lesson",
"observations": [
"Error occurs when using incompatible package versions",
"Affects Windows environments specifically",
"Resolution requires version pinning"
],
"errorPattern": {
"type": "dependency",
"message": "Cannot find package @shadcn/ui",
"context": "package installation"
},
"metadata": {
"severity": "high",
"environment": {
"os": "windows",
"nodeVersion": "18.x"
},
"createdAt": "2025-02-13T13:21:58.523Z",
"updatedAt": "2025-02-13T13:22:21.336Z",
"frequency": 1,
"successRate": 1.0
},
"verificationSteps": [
{
"command": "pnpm add shadcn@latest",
"expectedOutput": "Successfully installed shadcn",
"successIndicators": ["added shadcn"]
}
]
}
entities
(array of objects)name
(string): Entity identifierentityType
(string): Type classificationobservations
(string[]): Associated observationsIgnores entities with existing names
create_relations
relations
(array of objects)from
(string): Source entity nameto
(string): Target entity namerelationType
(string): Relationship type in active voiceSkips duplicate relations
add_observations
observations
(array of objects)entityName
(string): Target entitycontents
(string[]): New observations to addFails if entity doesn't exist
delete_entities
entityNames
(string[])Silent operation if entity doesn't exist
delete_observations
deletions
(array of objects)entityName
(string): Target entityobservations
(string[]): Observations to removeSilent operation if observation doesn't exist
delete_relations
relations
(array of objects)from
(string): Source entity nameto
(string): Target entity namerelationType
(string): Relationship typeSilent operation if relation doesn't exist
read_graph
Returns complete graph structure with all entities and relations
search_nodes
query
(string)Returns matching entities and their relations
open_nodes
names
(string[])lesson
(object)name
(string): Unique identifierentityType
(string): Must be "lesson"observations
(string[]): Notes about the error and solutionerrorPattern
(object): Error detailstype
(string): Category of errormessage
(string): Error messagecontext
(string): Where error occurredstackTrace
(string, optional): Stack tracemetadata
(object): Additional informationseverity
("low" | "medium" | "high" | "critical")environment
(object): System detailsfrequency
(number): Times encounteredsuccessRate
(number): Solution success rateverificationSteps
(array): Solution verificationcommand
(string): Action to takeexpectedOutput
(string): Expected resultsuccessIndicators
(string[]): Success markersValidates all required fields
find_similar_errors
errorPattern
(object)type
(string): Error categorymessage
(string): Error messagecontext
(string): Error contextUses fuzzy matching for error messages
update_lesson_success
lessonName
(string): Lesson to updatesuccess
(boolean): Whether solution workedUpdates:
get_lesson_recommendations
context
(string)The server now handles two types of files:
- memory.json
: Stores basic entities and relations
- lesson.json
: Stores lesson entities with error patterns
Files are automatically split if they exceed 1000 lines to maintain performance.
To integrate this memory server with Cursor MCP client, follow these steps:
Clone the Repository:
git clone [repository-url]
cd [repository-name]
Install Dependencies:
pnpm install
Build the Project:
pnpm build
Configure the Server:
/path/to/the/dist/index.js
Start the server using Node.js: node /path/to/the/dist/index.js
Activate in Cursor:
Ctrl+Shift+P
The memory server should now be integrated with your Cursor MCP client and ready to use.
Add this to your claude_desktop_config.json:
{
"mcpServers": {
"memory": {
"command": "docker",
"args": ["run", "-i", "-v", "claude-memory:/app/dist", "--rm", "mcp/memory"]
}
}
}
{
"mcpServers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
The server can be configured using the following environment variables:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
],
"env": {
"MEMORY_FILE_PATH": "/path/to/custom/memory.json"
}
}
}
}
MEMORY_FILE_PATH
: Path to the memory storage JSON file (default: memory.json
in the server directory)The prompt for utilizing memory depends on the use case. Changing the prompt will help the model determine the frequency and types of memories created.
Here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a Claude.ai Project.
Follow these steps for each interaction:
1. User Identification:
- You should assume that you are interacting with default_user
- If you have not identified default_user, proactively try to do so.
2. Memory Retrieval:
- Always begin your chat by saying only "Remembering..." and retrieve all relevant information from your knowledge graph
- Always refer to your knowledge graph as your "memory"
3. Memory
- While conversing with the user, be attentive to any new information that falls into these categories:
a) Basic Identity (age, gender, location, job title, education level, etc.)
b) Behaviors (interests, habits, etc.)
c) Preferences (communication style, preferred language, etc.)
d) Goals (goals, targets, aspirations, etc.)
e) Relationships (personal and professional relationships up to 3 degrees of separation)
4. Memory Update:
- If any new information was gathered during the interaction, update your memory as follows:
a) Create entities for recurring organizations, people, and significant events
b) Connect them to the current entities using relations
b) Store facts about them as observations
Docker:
docker build -t mcp/memory -f src/memory/Dockerfile .
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
Input: lesson
(object)
find_similar_errors
Input: errorPattern
(object)
update_lesson_success
lessonName
(string): Lesson to updatesuccess
(boolean): Whether solution workedUpdates success rate and frequency metrics
get_lesson_recommendations
context
(string)Big thanks! https://github.com/modelcontextprotocol/servers jerome3o-anthropic https://github.com/modelcontextprotocol/servers/tree/main/src/memory
[
{
"description": "Create multiple new entities in the knowledge graph",
"inputSchema": {
"properties": {
"entities": {
"items": {
"properties": {
"entityType": {
"description": "The type of the entity",
"type": "string"
},
"name": {
"description": "The name of the entity",
"type": "string"
},
"observations": {
"description": "An array of observation contents associated with the entity",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"name",
"entityType",
"observations"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"entities"
],
"type": "object"
},
"name": "create_entities"
},
{
"description": "Create multiple new relations between entities in the knowledge graph. Relations should be in active voice",
"inputSchema": {
"properties": {
"relations": {
"items": {
"properties": {
"from": {
"description": "The name of the entity where the relation starts",
"type": "string"
},
"relationType": {
"description": "The type of the relation",
"type": "string"
},
"to": {
"description": "The name of the entity where the relation ends",
"type": "string"
}
},
"required": [
"from",
"to",
"relationType"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"relations"
],
"type": "object"
},
"name": "create_relations"
},
{
"description": "Add new observations to existing entities in the knowledge graph",
"inputSchema": {
"properties": {
"observations": {
"items": {
"properties": {
"contents": {
"description": "An array of observation contents to add",
"items": {
"type": "string"
},
"type": "array"
},
"entityName": {
"description": "The name of the entity to add the observations to",
"type": "string"
}
},
"required": [
"entityName",
"contents"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"observations"
],
"type": "object"
},
"name": "add_observations"
},
{
"description": "Delete multiple entities and their associated relations from the knowledge graph",
"inputSchema": {
"properties": {
"entityNames": {
"description": "An array of entity names to delete",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"entityNames"
],
"type": "object"
},
"name": "delete_entities"
},
{
"description": "Delete specific observations from entities in the knowledge graph",
"inputSchema": {
"properties": {
"deletions": {
"items": {
"properties": {
"entityName": {
"description": "The name of the entity containing the observations",
"type": "string"
},
"observations": {
"description": "An array of observations to delete",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"entityName",
"observations"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"deletions"
],
"type": "object"
},
"name": "delete_observations"
},
{
"description": "Delete multiple relations from the knowledge graph",
"inputSchema": {
"properties": {
"relations": {
"description": "An array of relations to delete",
"items": {
"properties": {
"from": {
"description": "The name of the entity where the relation starts",
"type": "string"
},
"relationType": {
"description": "The type of the relation",
"type": "string"
},
"to": {
"description": "The name of the entity where the relation ends",
"type": "string"
}
},
"required": [
"from",
"to",
"relationType"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"relations"
],
"type": "object"
},
"name": "delete_relations"
},
{
"description": "Read the entire knowledge graph",
"inputSchema": {
"properties": {},
"type": "object"
},
"name": "read_graph"
},
{
"description": "Search for nodes in the knowledge graph based on a query",
"inputSchema": {
"properties": {
"query": {
"description": "The search query to match against entity names, types, and observation content",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
},
"name": "search_nodes"
},
{
"description": "Open specific nodes in the knowledge graph by their names",
"inputSchema": {
"properties": {
"names": {
"description": "An array of entity names to retrieve",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"names"
],
"type": "object"
},
"name": "open_nodes"
},
{
"description": "Create a new lesson from an error and its solution",
"inputSchema": {
"properties": {
"lesson": {
"properties": {
"entityType": {
"description": "Must be 'lesson'",
"enum": [
"lesson"
],
"type": "string"
},
"errorPattern": {
"properties": {
"context": {
"description": "Where the error occurred",
"type": "string"
},
"message": {
"description": "The error message",
"type": "string"
},
"stackTrace": {
"description": "Optional stack trace",
"type": "string"
},
"type": {
"description": "Category of the error",
"type": "string"
}
},
"required": [
"type",
"message",
"context"
],
"type": "object"
},
"metadata": {
"properties": {
"environment": {
"properties": {
"dependencies": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"nodeVersion": {
"type": "string"
},
"os": {
"type": "string"
}
},
"type": "object"
},
"severity": {
"description": "Severity level of the error",
"enum": [
"low",
"medium",
"high",
"critical"
],
"type": "string"
}
},
"type": "object"
},
"name": {
"description": "Unique identifier for the lesson",
"type": "string"
},
"observations": {
"description": "List of observations about the error and solution",
"items": {
"type": "string"
},
"type": "array"
},
"verificationSteps": {
"items": {
"properties": {
"command": {
"description": "Command to run",
"type": "string"
},
"expectedOutput": {
"description": "Expected output",
"type": "string"
},
"successIndicators": {
"description": "Indicators of success",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"command",
"expectedOutput",
"successIndicators"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"name",
"entityType",
"observations",
"errorPattern",
"verificationSteps"
],
"type": "object"
}
},
"required": [
"lesson"
],
"type": "object"
},
"name": "create_lesson"
},
{
"description": "Find similar errors and their solutions in the knowledge graph",
"inputSchema": {
"properties": {
"errorPattern": {
"properties": {
"context": {
"description": "Where the error occurred",
"type": "string"
},
"message": {
"description": "The error message",
"type": "string"
},
"type": {
"description": "Category of the error",
"type": "string"
}
},
"required": [
"type",
"message",
"context"
],
"type": "object"
}
},
"required": [
"errorPattern"
],
"type": "object"
},
"name": "find_similar_errors"
},
{
"description": "Update the success rate of a lesson after applying its solution",
"inputSchema": {
"properties": {
"lessonName": {
"description": "Name of the lesson to update",
"type": "string"
},
"success": {
"description": "Whether the solution was successful",
"type": "boolean"
}
},
"required": [
"lessonName",
"success"
],
"type": "object"
},
"name": "update_lesson_success"
},
{
"description": "Get relevant lessons based on the current context",
"inputSchema": {
"properties": {
"context": {
"description": "The current context to find relevant lessons for",
"type": "string"
}
},
"required": [
"context"
],
"type": "object"
},
"name": "get_lesson_recommendations"
}
]