A complete Python port of the official TypeScript MCP memory server. This server provides knowledge graph storage and retrieval capabilities via the Model Context Protocol (MCP).
This implementation was developed and tested exclusively on macOS. While it should work on other Unix-like systems, no testing has been performed on Windows, Linux, or other platforms. Use on other platforms is at your own risk.
- Complete Knowledge Graph Management: Store and manage entities, relations, and observations
- JSONL File Format: Compatible with the TypeScript version's file format
- 9 MCP Tools: Full feature parity with the original TypeScript implementation
- Search Capabilities: Query entities by name, type, or observation content
- Graph Traversal: Explore entity connections and relationships
- Environment Configuration: Customizable storage location
- Python 3.8 or higher
- macOS (tested platform)
-
Create a virtual environment:
python3 -m venv .venv
-
Activate the virtual environment:
source .venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Deactivate when done:
deactivate
-
Clone or download this repository
-
Set up the virtual environment (see above)
-
Test the installation:
source .venv/bin/activate python mcp_memory_server.py
The server should start and wait for MCP protocol messages via stdin/stdout.
MEMORY_FILE_PATH
: Path to the memory storage file (default:./memory.json
)
export MEMORY_FILE_PATH="/path/to/my/memory.json"
source .venv/bin/activate
python mcp_memory_server.py
Add this configuration to your Claude Desktop settings:
{
"mcpServers": {
"memory": {
"command": "python",
"args": ["/path/to/mcp_memory_server.py"],
"env": {
"MEMORY_FILE_PATH": "/path/to/memory.json"
}
}
}
}
Note: Make sure to activate your virtual environment before running, or use the full path to the Python interpreter in your virtual environment.
- Open Cursor IDE settings
- Navigate to MCP Servers configuration
- Add a new server with:
- Name:
memory
- Command:
python
- Args:
["/path/to/mcp_memory_server.py"]
- Environment:
{"MEMORY_FILE_PATH": "/path/to/memory.json"}
- Name:
Configure the memory server in your AWS Q CLI MCP settings:
{
"mcp_servers": {
"memory": {
"command": ["python", "/path/to/mcp_memory_server.py"],
"env": {
"MEMORY_FILE_PATH": "/path/to/memory.json"
}
}
}
}
For any MCP client that supports stdio-based servers:
{
"servers": {
"memory": {
"command": "python",
"args": ["/path/to/mcp_memory_server.py"],
"cwd": "/path/to/server/directory",
"env": {
"MEMORY_FILE_PATH": "/path/to/memory.json"
}
}
}
}
To get the most out of the memory server, add this system prompt to Claude:
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
c) Store facts about them as observations
The server provides 9 MCP tools with exact compatibility to the TypeScript version:
Create new entities in the knowledge graph.
Input:
{
"entities": [
{
"name": "John Doe",
"entityType": "person",
"observations": ["Software engineer", "Lives in San Francisco"]
}
]
}
Create relationships between entities.
Input:
{
"relations": [
{
"from": "John Doe",
"to": "Acme Corp",
"relationType": "works_at"
}
]
}
Add new observations to existing entities.
Input:
{
"additions": [
{
"entityName": "John Doe",
"observations": ["Enjoys hiking", "Plays guitar"]
}
]
}
Delete entities and their associated relations.
Input:
{
"names": ["John Doe", "Jane Smith"]
}
Delete specific relations.
Input:
{
"relations": [
{
"from": "John Doe",
"to": "Acme Corp",
"relationType": "works_at"
}
]
}
Remove specific observations from entities.
Input:
{
"deletions": [
{
"entityName": "John Doe",
"observations": ["Old observation to remove"]
}
]
}
Retrieve the entire knowledge graph.
Input: None
Output: Complete graph with all entities and relations.
Search for entities by query string.
Input:
{
"query": "software engineer"
}
Output: Entities matching the query and their interconnections.
Get specific entities and their connections.
Input:
{
"names": ["John Doe", "Acme Corp"]
}
Output: Requested entities plus any connected entities and all relevant relations.
The server uses JSONL (JSON Lines) format for storage, with each line containing either an entity or relation:
{"type": "entity", "name": "John Doe", "entityType": "person", "observations": ["Software engineer"]}
{"type": "relation", "from": "John Doe", "to": "Acme Corp", "relationType": "works_at"}
This format is fully compatible with the TypeScript version, allowing you to migrate existing memory files.
You can test the server directly without an MCP client:
-
Start the server:
source .venv/bin/activate python mcp_memory_server.py
-
Send MCP protocol messages via stdin. The server expects JSON-RPC 2.0 messages following the MCP specification.
The server includes comprehensive error handling for:
- Malformed JSON in memory files
- Missing required fields
- File I/O errors
- Invalid tool parameters
- Concurrent access protection
The server is optimized for:
- Graphs with hundreds of entities
- Efficient search across entity names, types, and observations
- Fast file I/O with minimal memory usage
- Concurrent access safety
The server logs important events to help with debugging:
- Server startup and configuration
- Graph loading and saving operations
- Error conditions and warnings
- Tool execution results
This Python implementation provides:
- Functional compatibility: Works with existing memory.json files from the TypeScript version
- Tool compatibility: All 9 tools work identically to the TypeScript version
- File format compatibility: Can read/write the same JSONL format
- Client compatibility: Works with Claude Desktop, Cursor IDE, AWS Q CLI, and other MCP clients
mcp-memory-server-py/
├── mcp_memory_server.py # Main server implementation
├── requirements.txt # Python dependencies
├── README.md # This documentation
When contributing to this project:
- Maintain compatibility with the TypeScript version
- Follow Python best practices and PEP 8
- Add comprehensive error handling
- Update documentation for any changes
- Test on macOS (primary supported platform)
This implementation follows the same licensing as the original TypeScript MCP memory server.
For issues, bugs, or feature requests, please refer to the original MCP memory server documentation and adapt solutions for this Python implementation.
Remember: This implementation was developed and tested only on macOS. Use on other platforms may require additional testing and modifications.