Skip to content

maithanhduyan/memory-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Memory Graph MCP Server

Rust MCP Build Release License Stars

πŸš€ A blazing-fast Knowledge Graph server for AI Agents

Give your AI perfect memory. Forever.

Features β€’ Quick Start β€’ API Reference β€’ Architecture


⚠️ DISCLAIMER: ALL SOURCE CODE IS AI-GENERATED. THE AUTHOR ASSUMES NO LIABILITY FOR PATENT, INTELLECTUAL PROPERTY, OR LEGAL COMPLIANCE ISSUES IN ANY JURISDICTION.


🎯 The Problem

AI Agents forget everything between sessions. They hallucinate facts. They lose context.

Memory Graph fixes this.

Before: "Sorry, I don't have information about your project structure..."
After:  "Based on your Auth Module which implements JWT, I suggest..."

✨ Features

πŸ› οΈ 15 Powerful Tools

Category Tools Description
Memory create_entities, create_relations, add_observations, delete_entities, delete_observations, delete_relations, read_graph, search_nodes, open_nodes Full CRUD for knowledge graph
Query get_related, traverse, summarize Advanced graph traversal
Temporal get_relations_at_time, get_relation_history Time-travel queries
Utility get_current_time Timestamp helper

πŸ”₯ Why Memory Graph?

Feature Description
⚑ Blazing Fast In-memory cache with file persistence. Nanosecond reads.
πŸ”’ Thread-Safe Production-ready with Mutex-based concurrency control
πŸ” Semantic Search Built-in synonym matching (developer ↔ coder ↔ engineer)
⏰ Time Travel Query historical state with validFrom/validTo
πŸ“ Pagination Handle massive graphs with limit/offset
βœ… Type Validation Soft warnings for non-standard types
πŸ¦€ Pure Rust Single binary, ~3MB. Only depends on serde

πŸš€ Quick Start

Option 1: Build from Source

git clone https://github.com/maithanhduyan/memory-graph.git
cd memory-graph
cargo build --release

Option 2: Docker

docker run -v $(pwd)/data:/data ghcr.io/maithanhduyan/memory-graph

Configure VS Code

Create .vscode/mcp.json:

{
    "servers": {
        "memory": {
            "type": "stdio",
            "command": "${workspaceFolder}/target/release/memory-server.exe",
            "env": {
                "MEMORY_FILE_PATH": "${workspaceFolder}/memory.jsonl"
            }
        }
    }
}

Configure Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "memory": {
      "command": "/path/to/memory-server",
      "env": {
        "MEMORY_FILE_PATH": "/path/to/memory.jsonl"
      }
    }
  }
}

πŸ“– API Reference

Memory Tools

create_entities

{
  "entities": [{
    "name": "Auth Module",
    "entityType": "Module",
    "observations": ["Implements JWT", "Uses bcrypt"]
  }]
}

create_relations

{
  "relations": [{
    "from": "Auth Module",
    "to": "User Service",
    "relationType": "depends_on"
  }]
}

search_nodes (with Semantic Search)

{
  "query": "developer",  // Also matches: coder, programmer, engineer
  "limit": 10,
  "includeRelations": true
}

read_graph (with Pagination)

{
  "limit": 50,
  "offset": 0
}

Temporal Queries

get_relations_at_time

{
  "timestamp": 1704067200,
  "entityName": "Alice"
}
// Returns: Relations valid at that specific point in time

get_relation_history

{
  "entityName": "Alice"
}
// Returns: All relations (current + expired) with isCurrent flag

Graph Traversal

traverse

{
  "startNode": "Project: MyApp",
  "path": [
    {"relationType": "contains", "direction": "out"},
    {"relationType": "implements", "direction": "out", "targetType": "Feature"}
  ],
  "maxResults": 50
}

get_related

{
  "entityName": "Auth Module",
  "direction": "both",
  "relationType": "depends_on"
}

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    AI Agent (Claude, etc.)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚ JSON-RPC 2.0 (stdio)
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Memory Graph MCP Server                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                  MCP Protocol Layer                    β”‚ β”‚
β”‚  β”‚          (initialize, tools/list, tools/call)         β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                              β”‚                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                    Tool Registry                       β”‚ β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚ β”‚
β”‚  β”‚  β”‚ Memory   β”‚  β”‚  Query   β”‚  β”‚ Temporal β”‚            β”‚ β”‚
β”‚  β”‚  β”‚ Tools(9) β”‚  β”‚ Tools(3) β”‚  β”‚ Tools(2) β”‚            β”‚ β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                              β”‚                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚            KnowledgeBase (Thread-Safe)                 β”‚ β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚  β”‚  β”‚  Mutex<Graph>       β”‚  β”‚   Synonym Dictionary    β”‚ β”‚ β”‚
β”‚  β”‚  β”‚  (In-Memory Cache)  β”‚  β”‚   (Semantic Search)     β”‚ β”‚ β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚   memory.jsonl     β”‚
                   β”‚  (JSONL Storage)   β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Model

Entity:

{
  "name": "Auth Module",
  "entityType": "Module",
  "observations": ["Implements JWT", "Uses bcrypt"],
  "createdAt": 1704067200,
  "updatedAt": 1704153600
}

Relation (with Temporal Support):

{
  "from": "Alice",
  "to": "NYC",
  "relationType": "lives_in",
  "createdAt": 1704067200,
  "validFrom": 1704067200,
  "validTo": 1735689599
}

πŸ“Š Standard Types

Entity Types (11)

Project Module Feature Bug Decision Requirement Milestone Risk Convention Schema Person

Relation Types (12)

contains implements fixes caused_by depends_on blocked_by assigned_to part_of relates_to supersedes affects requires

⚠️ Custom types are allowed with soft warnings.


πŸ§ͺ Testing

cargo test

# Output:
# test tests::test_create_entities ... ok
# test tests::test_create_relations ... ok
# test tests::test_search_nodes ... ok
# test tests::test_delete_entities ... ok
# test tests::test_concurrent_access ... ok      # 10 threads
# test tests::test_concurrent_read_write ... ok  # 5 readers + 3 writers
#
# test result: ok. 6 passed; 0 failed

πŸ”§ Configuration

Environment Variable Default Description
MEMORY_FILE_PATH ./memory.jsonl Path to knowledge graph storage

πŸ—ΊοΈ Roadmap

  • Core CRUD operations (9 tools)
  • Advanced query tools (3 tools)
  • Semantic search with synonyms
  • Temporal relations (time-travel)
  • Pagination support
  • Thread-safe in-memory cache
  • Type validation with warnings
  • Vector embeddings for true semantic search
  • Web UI for graph visualization
  • Multi-tenant support
  • WAL (Write-Ahead Log) for large graphs

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md first.

# Fork the repo, then:
git checkout -b feature/amazing-feature
cargo test
git commit -m "Add amazing feature"
git push origin feature/amazing-feature
# Open a Pull Request

πŸ“„ License

MIT License - see LICENSE for details.


Built with πŸ¦€ Rust and ❀️ for AI Agents

If this project helps you, please ⭐ star the repo!

Report Bug Β· Request Feature