MCP Memory Server - Python Implementation

by jason-c-dev

Not rated
GitHub

About

A Python implementation of the MCP memory server for knowledge graph storage and retrieval, using JSONL files for persistence.

Details

Author
jason-c-dev
Categories
Database, Knowledge Base, Other, File Management

Setup

Install MCP Memory Server - Python Implementation in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/jason-c-dev/memory-mcp-server-py

Follow the installation instructions in the repository README, then restart your MCP client.

MCP Memory Server - Python Implementation

A Python implementation of the MCP memory server for knowledge graph storage and retrieval, using JSONL files for persistence.

MCP Memory Server - Python Implementation

A complete Python port of the officialTypeScript 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)

Set up the virtual environment(see above)

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"}

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.

{ "entities": [ { "name": "John Doe", "entityType": "person", "observations": ["Software engineer", "Lives in San Francisco"] } ] }
{ "relations": [ { "from": "John Doe", "to": "Acme Corp", "relationType": "works_at" } ] }

Add new observations to existing entities.

{ "additions": [ { "entityName": "John Doe", "observations": ["Enjoys hiking", "Plays guitar"] } ] }

Delete entities and their associated relations.

{ "names": ["John Doe", "Jane Smith"] }
{ "relations": [ { "from": "John Doe", "to": "Acme Corp", "relationType": "works_at" } ] }

Remove specific observations from entities.

{ "deletions": [ { "entityName": "John Doe", "observations": ["Old observation to remove"] } ] }

Output:Complete graph with all entities and relations.

{ "query": "software engineer" }

Output:Entities matching the query and their interconnections.

Get specific entities and their connections.

{ "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:

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

- 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

- 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

- 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.

Neo4j graph database server (schema + read/write-cypher) and separate graph database backed memory

Query a hybrid graph (Neo4j) and vector (Qdrant) database for powerful semantic and graph-based document retrieval.

Connects to Neo4j graph databases with ability to use GDS functions ( when available), a read only mode , and set the sample size for schema detection

Integrate the Neo4j graph database with clients through natural language interactions.

MCP server for Neo4j — run Cypher queries, explore schema, and inspect database info over stdio

A read-only query service for Neo4j graph databases.

Interact with and explore graph data in a Neo4j database.

Persistent shared memory for AI agents. Hybrid search (pgvector + tsvector), knowledge graph, cognitive scoring - 97.2% Recall@10 on LongMemEval

Cognitive memory for AI agents - persistent semantic memory with knowledge graph and adaptive recall

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.