Skip to main content

情景+实体记忆 MCP 服务

Project description

Memory MCP Service

PyPI version Python License: MIT

English | 中文

A persistent memory MCP service for Claude Code. Automatically saves conversations and retrieves relevant history across sessions.

What it does: Every time you chat with Claude Code, your conversation context (decisions, preferences, key discussions) is saved and automatically recalled in future sessions — so Claude always has the background it needs.

Quick Start

1. Install

pip install chenxiaofie-memory-mcp

Requires Python 3.10 - 3.13 (chromadb is not compatible with Python 3.14+).

2. Add MCP Server to Claude Code

claude mcp add memory-mcp -s user -- memory-mcp

3. Configure Hooks (Recommended)

Hooks enable fully automatic message saving. Without hooks, you need to manually call memory tools.

Add the following to ~/.claude/settings.json:

{
  "hooks": {
    "SessionStart": [{
      "matcher": ".*",
      "hooks": [{ "type": "command", "command": "memory-mcp-session-start" }]
    }],
    "UserPromptSubmit": [{
      "matcher": ".*",
      "hooks": [{ "type": "command", "command": "memory-mcp-auto-save" }]
    }],
    "Stop": [{
      "matcher": ".*",
      "hooks": [{ "type": "command", "command": "memory-mcp-save-response" }]
    }],
    "SessionEnd": [{
      "matcher": ".*",
      "hooks": [{ "type": "command", "command": "memory-mcp-session-end" }]
    }]
  }
}

4. Verify

claude mcp list

You should see memory-mcp: ... - ✓ Connected.

That's it! Start a new Claude Code session and your conversations will be automatically saved and recalled.

How It Works

Session Start ──► Create Episode ──► Monitor Process (background)
                                          │
User Message  ──► Save Message ──► Recall Related Memories ──► Inject Context
                                          │
Claude Reply  ──► Save Response           │
                                          │
Session End   ──► Close Signal ──► Archive Episode + Generate Summary
  • Episodes: Each conversation session is an "episode" with auto-generated summaries
  • Entities: Key knowledge extracted from conversations (decisions, preferences, concepts)
  • Dual-layer storage: User-level (shared across projects) + Project-level (isolated per project)
  • Semantic search: Vector-based retrieval finds relevant past context

Usage

Automatic Mode (With Hooks)

Once hooks are configured, everything is automatic. Claude will see relevant history from past sessions as context.

Manual Mode

You can also call memory tools directly in Claude Code:

# Start a new episode
memory_start_episode("Login Feature Development", ["auth"])

# Record a decision
memory_add_entity("Decision", "Use JWT + Redis", "For distributed deployment")

# Search history
memory_recall("login implementation")

# Close episode
memory_close_episode("Completed JWT login feature")

Hooks Reference

Hook What it does Timing
SessionStart Creates a new episode ~50ms
UserPromptSubmit Saves user message + retrieves related memories ~1-2s
Stop Saves assistant response ~1s
SessionEnd Signals episode closure ~50ms

Tools Reference

Tool Description
memory_start_episode Start a new episode
memory_close_episode Close and archive current episode
memory_get_current_episode Get current active episode
memory_add_entity Add a knowledge entity
memory_confirm_entity Confirm a detected entity candidate
memory_reject_candidate Reject a false detection
memory_deprecate_entity Mark an entity as outdated
memory_get_pending List pending entity candidates
memory_recall Semantic search across episodes and entities
memory_search_by_type Search entities by type
memory_get_episode_detail Get full episode details
memory_list_episodes List all episodes chronologically
memory_stats Get system statistics
memory_encoder_status Check vector encoder status
memory_cache_message Manually cache a message
memory_clear_cache Clear message cache
memory_cleanup_messages Clean up old cached messages

Entity Types

Type Level Description
Decision Project Technical decisions for this project
Architecture Project Architecture designs
File Project Important file descriptions
Preference User Personal preferences (shared across projects)
Concept User General concepts
Habit User Work habits

Storage Locations

  • User-level: ~/.claude-memory/
  • Project-level: {project-root}/.claude/memory/
Alternative: Install from source

If you need to run from source (e.g., for development):

git clone https://github.com/chenxiaofie/memory-mcp.git
cd memory-mcp
# Windows:
install.bat
# Mac/Linux:
chmod +x install.sh && ./install.sh

Then configure MCP server with the venv Python:

# Windows:
claude mcp add memory-mcp -s user -- "C:\path\to\memory-mcp\venv310\Scripts\python.exe" -m src.server

# Mac/Linux:
claude mcp add memory-mcp -s user -- /path/to/memory-mcp/venv310/bin/python -m src.server

License

MIT License - see LICENSE file for details.

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

chenxiaofie_memory_mcp-0.2.1.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

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

chenxiaofie_memory_mcp-0.2.1-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file chenxiaofie_memory_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: chenxiaofie_memory_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chenxiaofie_memory_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 25ca1d43e2f2898888c065526bcca34097899508027ac1a889265d0ee331b264
MD5 15f921be202d363a524cffe6c224e92d
BLAKE2b-256 9654f563de4692787aa2148f474de3fe52a20e92484bd45aa6f453e816b90ea5

See more details on using hashes here.

File details

Details for the file chenxiaofie_memory_mcp-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for chenxiaofie_memory_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1338279da9e34ecea57defc23dfd19c4929a8ac7f85749cc95bbef6ecbf5a558
MD5 57389db42bef61400289c4f0f156699f
BLAKE2b-256 a1528b63d332643b94133ed673e7bb8b10399d8ef6d68ba40d0fed68d2ed6929

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