Skip to content

Commit eaa1f0e

Browse files
PeterZZZjealous
andauthored
Claude code Integration document (MemMachine#530)
* Doc: Claude Code integrate with MemMachine MCP * Doc: Claude Code integrate with MemMachine MCP--content --------- Co-authored-by: Cedric Zhuang <[email protected]>
1 parent d06564b commit eaa1f0e

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

docs/examples/claude_code_mcp.mdx

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
---
2+
title: "Claude Code"
3+
description: "Setting up MemMachine with Claude Code"
4+
icon: "terminal"
5+
---
6+
7+
# Claude Code Integration
8+
9+
## Getting Started with MemMachine in Claude Code
10+
11+
This guide will help you integrate MemMachine into Claude Code, Anthropic's official CLI tool for software engineering tasks. With MemMachine, Claude Code can remember context across sessions, making it more helpful for ongoing projects.
12+
13+
### What is Claude Code?
14+
15+
Claude Code is a command-line interface that provides Claude with powerful tools for software development, including file operations, code execution, and now—with MemMachine—persistent memory across conversations.
16+
17+
### Prerequisites
18+
19+
Before you begin, ensure you have:
20+
21+
1. Claude Code installed and configured
22+
2. MemMachine running (either via Docker or as a Python package)
23+
3. A MemMachine configuration file (`config.yml`)
24+
25+
**Starting Your Docker Container:**
26+
27+
Make sure your MemMachine Docker container is running:
28+
29+
```bash
30+
docker compose up -d
31+
```
32+
33+
Or if you're using the provided script:
34+
35+
```bash
36+
./memmachine-compose.sh
37+
```
38+
39+
<Steps>
40+
<Step title="Choose Your Setup Method">
41+
42+
MemMachine can be integrated with Claude Code in two ways:
43+
44+
**Option A: Using Docker (Recommended)**
45+
- Best for isolated, reproducible environments
46+
- MemMachine runs in a container
47+
- Requires Docker installed and running
48+
49+
**Option B: Direct Command**
50+
- Simpler setup if you have MemMachine installed locally
51+
- Uses your system Python environment
52+
- Requires MemMachine installed via pip or uv
53+
54+
Choose the method that best fits your workflow.
55+
56+
</Step>
57+
58+
<Step title="Option A: Configure with Docker">
59+
60+
If you're running MemMachine in Docker, create or edit the `.mcp.json` file in your project root:
61+
62+
```json
63+
{
64+
"mcpServers": {
65+
"memmachine": {
66+
"command": "docker",
67+
"args": [
68+
"exec",
69+
"-i",
70+
"memmachine-app",
71+
"/app/.venv/bin/memmachine-mcp-stdio"
72+
],
73+
"env": {
74+
"MEMORY_CONFIG": "/app/configuration.yml",
75+
"MM_USER_ID": "your-username",
76+
"PYTHONUNBUFFERED": "1"
77+
}
78+
}
79+
}
80+
}
81+
```
82+
83+
**Configuration Details:**
84+
- `memmachine-app`: The name of your Docker container (adjust if different)
85+
- `MEMORY_CONFIG`: Path to your config file inside the container
86+
- `MM_USER_ID`: Your user identifier for memory sessions (customize this)
87+
- `PYTHONUNBUFFERED`: Ensures immediate output from Python
88+
89+
90+
</Step>
91+
92+
<Step title="Option B: Configure with Direct Command">
93+
94+
<Note>
95+
**Reference Implementation**: This method has not been fully tested with Claude Code. It follows the standard MCP stdio pattern and should work, but if you encounter issues, please use Option A (Docker) or report your findings.
96+
</Note>
97+
98+
If you have MemMachine installed locally, create or edit the `.mcp.json` file in your project root:
99+
100+
```json
101+
{
102+
"mcpServers": {
103+
"memmachine": {
104+
"command": "memmachine-mcp-stdio",
105+
"env": {
106+
"MEMORY_CONFIG": "/absolute/path/to/config.yml",
107+
"MM_USER_ID": "your-username",
108+
"PYTHONUNBUFFERED": "1"
109+
}
110+
}
111+
}
112+
}
113+
```
114+
115+
Or if you're using uv:
116+
117+
```json
118+
{
119+
"mcpServers": {
120+
"memmachine": {
121+
"command": "uv",
122+
"args": ["run", "memmachine-mcp-stdio"],
123+
"env": {
124+
"MEMORY_CONFIG": "/absolute/path/to/config.yml",
125+
"MM_USER_ID": "your-username",
126+
"PYTHONUNBUFFERED": "1"
127+
}
128+
}
129+
}
130+
}
131+
```
132+
133+
**Important:** Use absolute paths for `MEMORY_CONFIG` to avoid path resolution issues.
134+
135+
</Step>
136+
137+
<Step title="Test the Integration">
138+
139+
Once configured, start Claude Code in your project directory:
140+
141+
```bash
142+
claude
143+
```
144+
145+
Claude Code will automatically detect the `.mcp.json` file and connect to MemMachine.
146+
147+
**Verify the connection** by checking /mcp or asking Claude to store something in memory:
148+
149+
```
150+
You: Remember that I prefer using TypeScript for new projects
151+
```
152+
153+
Claude should use the `add_memory` tool to store this preference.
154+
155+
**Test memory recall** by starting a new conversation and asking:
156+
157+
```
158+
You: What programming language do I prefer?
159+
```
160+
161+
Claude should search memory and recall your TypeScript preference.
162+
163+
</Step>
164+
165+
<Step title="Using Memory with Claude Code">
166+
167+
MemMachine provides two main tools that Claude Code can use:
168+
169+
**add_memory**: Stores new information
170+
- Called automatically when you share facts, preferences, or important context
171+
- Stores both episodic (conversation) and profile (long-term) memory
172+
173+
**search_memory**: Retrieves relevant context
174+
- Called automatically when context from previous sessions might be helpful
175+
- Searches both conversation history and user profile
176+
177+
You don't need to explicitly ask Claude to use these tools—they're integrated into the workflow automatically.
178+
179+
</Step>
180+
181+
<Step title="Troubleshooting">
182+
183+
**Claude Code can't connect to MemMachine:**
184+
- Verify your Docker container is running: `docker ps | grep memmachine`
185+
- Check the container name matches your config
186+
- Review Claude Code logs for connection errors
187+
188+
**Memory not persisting:**
189+
- Ensure `MEMORY_CONFIG` points to a valid configuration file
190+
- Check that your Neo4j and PostgreSQL databases are running
191+
- Verify `MM_USER_ID` is consistent across sessions
192+
193+
**Permission errors:**
194+
- If using Docker, ensure the container has proper volume mounts
195+
- Check file permissions on your configuration file
196+
- Verify the path to `memmachine-mcp-stdio` is correct
197+
198+
**Getting logs:**
199+
You can check the MCP server output by viewing:
200+
```bash
201+
docker logs memmachine-app
202+
```
203+
204+
Or if running directly, check the stderr output in your terminal.
205+
206+
</Step>
207+
</Steps>

0 commit comments

Comments
 (0)