Skip to main content

A specialized MCP server that tracks your Python development sessions, errors, fixes, and coding patterns using a persistent knowledge graph. This helps you build a searchable database of your development learnings, solutions, and insights.

Project description

Memory Graph MCP Server for Python Development

A specialized MCP server that tracks your Python development sessions, errors, fixes, and coding patterns using a persistent knowledge graph. This helps you build a searchable database of your development learnings, solutions, and insights.

Core Concepts

Entities

Entities represent the building blocks of your development knowledge:

  • Features: Projects or tasks you're working on
  • Sessions: Individual development work periods
  • Errors: Persistent error tracking with fingerprinting
  • Patterns: Reusable solutions and coding patterns
  • Modules/Classes/Functions: Code structure elements

Example:

{
  "name": "user-authentication",
  "entityType": "Feature",
  "tags": ["backend", "security"],
  "description": "JWT-based user authentication system"
}

Relations

Relations connect your development knowledge to show how different pieces relate:

  • implements: A session implements a feature
  • encounters: A feature encounters an error
  • fixed_by: An error is fixed by a pattern
  • depends_on: Dependencies between modules/features

Example:

{
  "from": "session:abc123",
  "to": "user-authentication",
  "relationType": "implements"
}

Observations

Observations store your actual development insights and knowledge:

  • note: General observations and learnings
  • snippet: Code examples and implementations
  • error: Exception details and stack traces
  • command: CLI commands and scripts
  • qa: Questions, answers, and troubleshooting

Example:

{
  "kind": "snippet",
  "text": "JWT token validation middleware",
  "code": "def validate_jwt(token: str) -> dict:
    return jwt.decode(token, SECRET_KEY)",
  "language": "python",
  "tags": ["jwt", "middleware", "auth"]
}

API Tools

Core Knowledge Management

  • upsert_entity: Create or update entities (features, patterns, concepts)
  • create_relations: Establish connections between entities
  • add_insights: Store observations and code snippets
  • read_graph: Retrieve the complete knowledge graph
  • search_insights: Search through insights by text, tags, kind, or language

Development Session Tracking

  • start_session: Begin a tracked development session for a feature
  • log_event: Record development activities, decisions, and code during a session
  • end_session: Complete a session with a summary of outcomes

Error and Solution Management

  • record_error: Create persistent error entities with automatic fingerprinting
  • record_fix: Attach solutions to errors and create reusable patterns

Export and Maintenance

  • export_markdown: Generate comprehensive documentation from your knowledge graph
  • compact_store: Optimize storage by creating snapshots and clearing logs

Usage with Claude Desktop

Setup

Add this to your claude_desktop_config.json:

UV Script (Recommended)

{
  "mcpServers": {
    "memory-graph": {
      "command": "uv",
      "args": [
        "run",
        "--script",
        "/path/to/your/init.py"
      ],
      "env": {
        "MEMORY_FILE_PATH": "~/.mcp/"
      }
    }
  }
}

Python Direct

{
  "mcpServers": {
    "memory-graph": {
      "command": "python",
      "args": ["/path/to/your/init.py"],
      "env": {
        "MEMORY_FILE_PATH": "~/.mcp/"
      }
    }
  }
}

Configuration

The server supports the following environment variable:

  • MEMORY_FILE_PATH: Directory for storing memory files (default: ~/.mcp/)

The server creates two files in the specified directory:

  • agentmemory.json: Snapshot of the current knowledge graph
  • agentmemory.log.jsonl: Append-only event log for durability

Development Workflow Example

# Start a development session
start_session(
    feature="payment-processing",
    description="Implementing Stripe payment integration",
    tags=["backend", "payments", "stripe"]
)

# Log your development activities
log_event(
    session_id="session-uuid",
    kind="snippet",
    text="Payment intent creation",
    code="stripe.PaymentIntent.create(amount=1000, currency='usd')",
    tags=["stripe", "payment-intent"]
)

# Record errors you encounter
record_error(
    feature="payment-processing",
    exception_type="StripeError",
    message="Invalid API key",
    traceback="...",
    tags=["stripe", "api-key"]
)

# Document the solution
record_fix(
    error_entity="error:abc123",
    description="API key must be set in environment variables",
    code="os.environ['STRIPE_SECRET_KEY'] = 'sk_test_...'",
    tags=["configuration", "environment"]
)

# End the session
end_session(
    session_id="session-uuid",
    success=True,
    summary="Successfully integrated Stripe payments with error handling"
)

System Prompt for Development

Use this prompt to optimize the memory server for development work:

You are a development assistant with persistent memory. Follow these steps:

1. Session Management:
   - Start sessions when beginning focused development work
   - Log significant code changes, decisions, and learnings
   - Record errors and their solutions for future reference

2. Knowledge Capture:
   - Store useful code snippets with proper tagging
   - Document architectural decisions and trade-offs
   - Record debugging approaches and troubleshooting steps
   - Capture CLI commands and development workflows

3. Pattern Recognition:
   - Identify recurring solutions and create reusable patterns
   - Link related errors to their fixes
   - Build connections between similar technical concepts

4. Search and Retrieval:
   - Search previous solutions when encountering similar problems
   - Reference past sessions for context on ongoing features
   - Use tags and entity relationships to find relevant knowledge

Building and Installation

Requirements

  • Python 3.12+
  • Dependencies: fastmcp, pydantic, click

UV Script Setup

The project includes a UV script configuration in init.py for easy dependency management:

# Make the script executable
chmod +x init.py

# Run with UV (handles dependencies automatically)
uv run --script init.py

Manual Installation

# Install dependencies
pip install fastmcp pydantic click

# Run the server
python init.py --memory-file-path ~/.mcp/

Storage and Persistence

The server uses a dual storage approach:

  • Snapshot file: Complete knowledge graph state for fast loading
  • Event log: Append-only log of all changes for durability and replay

Use compact_store periodically to optimize storage by creating fresh snapshots and clearing the event log.

License

This MCP server is licensed under the MIT License. You are free to use, modify, and distribute the software under the terms of the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_agentmemory-0.1.4.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_agentmemory-0.1.4-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_agentmemory-0.1.4.tar.gz.

File metadata

  • Download URL: mcp_agentmemory-0.1.4.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for mcp_agentmemory-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0d0e7d0c79fcbe7bd1f0251e3d6901513b71d4a21f19f72c074eab07ae9903da
MD5 2b973251a0ba8bbb5ad9fa0bcce7cc67
BLAKE2b-256 ed086f3fd12355750305831ee06ff71018ad7859fde8b3dc9cbd7a05170cfbfc

See more details on using hashes here.

File details

Details for the file mcp_agentmemory-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_agentmemory-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3f687c7cb21d9e142e0c040475f0b769f6d08e71afece632c918a758aa8927a3
MD5 0e86a1a6685d46604524d995b634b26f
BLAKE2b-256 bee39462da3ae0adc97c892c03cb2d93d6e8d93d656229cd13b286baba70ea16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page