memory-v2-mcp 2.1.0a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ # MCP server
2
+
3
+ Memory v2 exposes its API to any MCP-speaking agent through a small stdio
4
+ server. Works with Claude Desktop, Claude Code, Cursor and other MCP clients.
5
+
6
+ ## Tools
7
+
8
+ | Tool | Purpose |
9
+ |---|---|
10
+ | `memory_health` | Check API availability |
11
+ | `memory_list_projects` | List projects |
12
+ | `memory_project_context` | Restore a project and its branches |
13
+ | `memory_search` | Search memories and messages |
14
+ | `memory_archive_conversation` | Archive a branch idempotently |
15
+ | `memory_upsert` | Store a fact, decision, constraint or preference |
16
+ | `memory_deprecate` | Retire an old memory, optionally with a replacement |
17
+
18
+ ## Install
19
+
20
+ The project targets MCP SDK v2 (`MCPServer`, formerly `FastMCP`). The
21
+ requirement is `mcp>=2,<3`; `server.py` keeps a v1 fallback for older
22
+ environments.
23
+
24
+ ```sh
25
+ python3 -m venv .venv-mcp
26
+ . .venv-mcp/bin/activate
27
+ pip install -r mcp/requirements.txt
28
+ ```
29
+
30
+ Windows PowerShell:
31
+
32
+ ```powershell
33
+ python -m venv .venv-mcp
34
+ .venv-mcp\Scripts\Activate.ps1
35
+ pip install -r mcp\requirements.txt
36
+ ```
37
+
38
+ Environment:
39
+
40
+ | Variable | Default |
41
+ |---|---|
42
+ | `MEMORY_API` | `http://127.0.0.1:8002` |
43
+ | `MEMORY_API_TOKEN` | empty (local-only) |
44
+
45
+ ## Claude Desktop
46
+
47
+ Config file:
48
+
49
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
50
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
51
+ - Linux: `~/.config/Claude/claude_desktop_config.json`
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "memory-v2": {
57
+ "command": "C:\\path\\to\\memory_v2.0\\.venv-mcp\\Scripts\\python.exe",
58
+ "args": ["C:\\path\\to\\memory_v2.0\\mcp\\server.py"],
59
+ "env": {
60
+ "MEMORY_API": "http://127.0.0.1:8002"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ Restart Claude Desktop after editing the file. A `memory-v2` tool group should
68
+ appear.
69
+
70
+ ## Claude Code
71
+
72
+ ```sh
73
+ claude mcp add memory-v2 -- python /path/to/memory_v2.0/mcp/server.py
74
+ ```
75
+
76
+ ## Cursor
77
+
78
+ Put this in `~/.cursor/mcp.json` (or `.cursor/mcp.json` inside a project):
79
+
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "memory-v2": {
84
+ "command": "python",
85
+ "args": ["/path/to/memory_v2.0/mcp/server.py"],
86
+ "env": {
87
+ "MEMORY_API": "http://127.0.0.1:8002"
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## Docker-only option (no local Python)
95
+
96
+ If the Memory stack is running under Docker, the same image can host the MCP
97
+ server:
98
+
99
+ ```sh
100
+ docker run -i --rm --network memory-v2_default \
101
+ -e MEMORY_API=http://memory:8002 \
102
+ memory-v2:latest python /app/mcp/server.py
103
+ ```
104
+
105
+ On Linux, `--network host` with `MEMORY_API=http://127.0.0.1:8002` also works.
106
+ On Docker Desktop for Windows, host networking differs; running the MCP server
107
+ natively in a Python venv is usually simpler.
108
+
109
+ ## Testing
110
+
111
+ Run the stdio smoke test against a **dev/test** Memory API:
112
+
113
+ ```sh
114
+ MEMORY_API=http://127.0.0.1:8103 python mcp/test_server.py
115
+ ```
116
+
117
+ Or inside the Docker image (no local Python):
118
+
119
+ ```sh
120
+ docker run --rm --network host \
121
+ -e MEMORY_API=http://127.0.0.1:8103 \
122
+ -v "$PWD/mcp:/app/mcp:ro" \
123
+ --entrypoint python memory-v2:latest /app/mcp/test_server.py
124
+ ```
125
+
126
+ The test refuses to run against a non-loopback API, so a dev run cannot touch a
127
+ shared database. It checks `initialize`, `tools/list`, every tool, archive
128
+ idempotency, and error responses, then removes the test conversation and test
129
+ memory it created.
130
+
131
+ Point it at any project you don't mind writing to:
132
+
133
+ ```sh
134
+ MEMORY_API=http://127.0.0.1:8002 MEMORY_PROJECT_ID=2 python mcp/test_server.py
135
+ ```
136
+
137
+ `MEMORY_PROJECT_ID` defaults to `1`. The server itself has no model or client
138
+ dependency: any MCP-capable app works. See `docs/integrations.md` for Claude
139
+ Desktop, Cursor, Cline, Continue, Windsurf, Zed and plain REST/OpenAI/Anthropic
140
+ tool schemas.
141
+
142
+ Run the server as a script (`python mcp/server.py`), not as
143
+ `python -m mcp.server` from the repository root: the project's `mcp/`
144
+ directory can otherwise shadow the installed SDK.
145
+
146
+ ## Example prompts
147
+
148
+ - “Search my Memory for `AsyncSession` and show the source branch.”
149
+ - “Restore project 1 and summarize its open decisions.”
150
+ - “Archive this dialog as a branch in project 1 with external id
151
+ `demo:fastapi:async-session:003`.”
152
+ - “Save a decision: schema changes go through Alembic.”
153
+
154
+ ## Security
155
+
156
+ - The MCP server only talks to the Memory API; it does not open the database.
157
+ - Point `MEMORY_API` at a dev/test instance while developing. Never point the
158
+ MCP server at a shared or production address by accident.
159
+ - Keep the API bound to `127.0.0.1` for local use.
160
+ - If you expose the API to a LAN, set `MEMORY_API_TOKEN` and pass it to the
161
+ MCP server through the environment.
162
+ - Tool results may contain conversation text. Do not paste secrets into
163
+ prompts.
@@ -0,0 +1,98 @@
1
+ """Small standard-library client for the Memory v2 REST API."""
2
+
3
+ import json
4
+ import os
5
+ import urllib.error
6
+ import urllib.parse
7
+ import urllib.request
8
+
9
+
10
+ class MemoryError(RuntimeError):
11
+ """Raised when the Memory API returns an error."""
12
+
13
+
14
+ class MemoryClient:
15
+ def __init__(self, api=None, token=None, timeout=30):
16
+ self.api = (api or os.environ.get("MEMORY_API", "http://127.0.0.1:8002")).rstrip("/")
17
+ if token is None:
18
+ token = os.environ.get("MEMORY_API_TOKEN", "")
19
+ self.token = token.strip()
20
+ self.timeout = timeout
21
+
22
+ def _request(self, method, path, payload=None):
23
+ body = None
24
+ headers = {}
25
+ if payload is not None:
26
+ body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
27
+ headers["Content-Type"] = "application/json"
28
+ if self.token:
29
+ headers["Authorization"] = "Bearer " + self.token
30
+
31
+ request = urllib.request.Request(self.api + path, data=body, headers=headers, method=method)
32
+ try:
33
+ with urllib.request.urlopen(request, timeout=self.timeout) as response:
34
+ text = response.read().decode("utf-8")
35
+ return json.loads(text) if text else {}
36
+ except urllib.error.HTTPError as error:
37
+ text = error.read().decode("utf-8", "replace")
38
+ raise MemoryError("HTTP %s: %s" % (error.code, text[:800])) from error
39
+ except urllib.error.URLError as error:
40
+ raise MemoryError("cannot reach Memory API at %s: %s" % (self.api, error)) from error
41
+
42
+ def health(self):
43
+ return self._request("GET", "/health")
44
+
45
+ def list_projects(self):
46
+ return self._request("GET", "/projects")
47
+
48
+ def create_project(self, name, description=None):
49
+ payload = {"name": name}
50
+ if description:
51
+ payload["description"] = description
52
+ return self._request("POST", "/projects", payload)
53
+
54
+ def project_context(self, project_id):
55
+ return self._request("GET", "/projects/%s/context" % int(project_id))
56
+
57
+ def search(self, query, project_id=None, include_messages=True, limit=10, status=None):
58
+ params = {
59
+ "q": query,
60
+ "limit": str(max(1, min(int(limit), 100))),
61
+ "include_messages": "true" if include_messages else "false",
62
+ }
63
+ if project_id is not None:
64
+ params["project_id"] = str(int(project_id))
65
+ if status:
66
+ params["status"] = status
67
+ return self._request("GET", "/memories/search?" + urllib.parse.urlencode(params))
68
+
69
+ def archive(self, project_id, title, messages, external_id=None, source="mcp"):
70
+ payload = {
71
+ "project_id": int(project_id),
72
+ "title": title,
73
+ "source": source,
74
+ "messages": messages,
75
+ }
76
+ if external_id:
77
+ payload["external_id"] = external_id
78
+ return self._request("POST", "/conversations/archive", payload)
79
+
80
+ def upsert(self, project_id, memory_type, content, source="mcp", importance=5, confidence=10):
81
+ return self._request(
82
+ "POST",
83
+ "/memories/upsert",
84
+ {
85
+ "project_id": int(project_id),
86
+ "type": memory_type,
87
+ "content": content,
88
+ "source": source,
89
+ "importance": int(importance),
90
+ "confidence": int(confidence),
91
+ },
92
+ )
93
+
94
+ def deprecate(self, memory_id, superseded_by=None):
95
+ payload = {}
96
+ if superseded_by is not None:
97
+ payload["superseded_by"] = int(superseded_by)
98
+ return self._request("POST", "/memories/%s/deprecate" % int(memory_id), payload)
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "memory-v2": {
4
+ "command": "C:\\path\\to\\memory_v2.0\\.venv-mcp\\Scripts\\python.exe",
5
+ "args": ["C:\\path\\to\\memory_v2.0\\mcp\\server.py"],
6
+ "env": {
7
+ "MEMORY_API": "http://127.0.0.1:8002"
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "memory-v2": {
4
+ "command": "python",
5
+ "args": ["/path/to/memory_v2.0/mcp/server.py"],
6
+ "env": {
7
+ "MEMORY_API": "http://127.0.0.1:8002"
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "mcpServers": {
3
+ "memory-v2": {
4
+ "command": "docker",
5
+ "args": [
6
+ "run",
7
+ "-i",
8
+ "--rm",
9
+ "--network",
10
+ "memory-v2_default",
11
+ "-e",
12
+ "MEMORY_API=http://memory:8002",
13
+ "memory-v2:latest",
14
+ "python",
15
+ "/app/mcp/server.py"
16
+ ]
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,3 @@
1
+ # MCP SDK v2 provides MCPServer (formerly FastMCP).
2
+ # server.py also has a v1 fallback for older environments.
3
+ mcp>=2,<3
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env python3
2
+ """MCP server for Memory v2.
3
+
4
+ Run with stdio transport:
5
+
6
+ python mcp/server.py
7
+
8
+ Environment:
9
+ MEMORY_API default http://127.0.0.1:8002
10
+ MEMORY_API_TOKEN optional bearer token
11
+ """
12
+
13
+ import sys
14
+
15
+ try:
16
+ from mcp.server.mcpserver import MCPServer
17
+ except ImportError: # MCP SDK v1 compatibility
18
+ from mcp.server.fastmcp import FastMCP as MCPServer
19
+
20
+ try:
21
+ from .client import MemoryClient, MemoryError
22
+ except ImportError:
23
+ from client import MemoryClient, MemoryError
24
+
25
+ mcp = MCPServer(
26
+ "memory-v2",
27
+ instructions=(
28
+ "Long-term project memory for agents. Search projects, restore dialog "
29
+ "branches and persist durable facts. Prefer memory_search before "
30
+ "memory_upsert to avoid duplicates."
31
+ ),
32
+ )
33
+
34
+ client = MemoryClient()
35
+
36
+
37
+ def _safe(call):
38
+ try:
39
+ return call()
40
+ except MemoryError as error:
41
+ return {"error": str(error)}
42
+
43
+
44
+ @mcp.tool()
45
+ def memory_health() -> dict:
46
+ """Check whether the Memory API is reachable and healthy."""
47
+ return _safe(lambda: client.health())
48
+
49
+
50
+ @mcp.tool()
51
+ def memory_list_projects() -> dict:
52
+ """List all projects with ids and descriptions."""
53
+ return _safe(lambda: client.list_projects())
54
+
55
+
56
+ @mcp.tool()
57
+ def memory_project_context(project_id: int) -> dict:
58
+ """Restore a project: metadata, memories, events and conversation branches."""
59
+ return _safe(lambda: client.project_context(project_id))
60
+
61
+
62
+ @mcp.tool()
63
+ def memory_search(
64
+ query: str,
65
+ project_id: int | None = None,
66
+ include_messages: bool = True,
67
+ limit: int = 10,
68
+ status: str | None = None,
69
+ ) -> dict:
70
+ """Full-text search across durable memories and conversation messages."""
71
+ return _safe(
72
+ lambda: client.search(
73
+ query,
74
+ project_id=project_id,
75
+ include_messages=include_messages,
76
+ limit=limit,
77
+ status=status,
78
+ )
79
+ )
80
+
81
+
82
+ @mcp.tool()
83
+ def memory_archive_conversation(
84
+ project_id: int,
85
+ title: str,
86
+ messages: list[dict[str, str]],
87
+ external_id: str | None = None,
88
+ ) -> dict:
89
+ """Archive a dialog branch. Idempotent: repeated calls append only new messages."""
90
+ return _safe(
91
+ lambda: client.archive(
92
+ project_id,
93
+ title,
94
+ messages,
95
+ external_id=external_id,
96
+ )
97
+ )
98
+
99
+
100
+ @mcp.tool()
101
+ def memory_upsert(
102
+ project_id: int,
103
+ memory_type: str,
104
+ content: str,
105
+ importance: int = 5,
106
+ confidence: int = 10,
107
+ ) -> dict:
108
+ """Store a durable fact, decision, constraint or preference."""
109
+ return _safe(
110
+ lambda: client.upsert(
111
+ project_id,
112
+ memory_type,
113
+ content,
114
+ importance=importance,
115
+ confidence=confidence,
116
+ )
117
+ )
118
+
119
+
120
+ @mcp.tool()
121
+ def memory_deprecate(memory_id: int, superseded_by: int | None = None) -> dict:
122
+ """Retire an outdated memory and optionally link its replacement."""
123
+ return _safe(lambda: client.deprecate(memory_id, superseded_by=superseded_by))
124
+
125
+
126
+ def main() -> None:
127
+ """Run the MCP server over stdio."""
128
+ try:
129
+ mcp.run(transport="stdio")
130
+ except KeyboardInterrupt:
131
+ sys.exit(0)
132
+
133
+
134
+ if __name__ == "__main__":
135
+ main()
@@ -0,0 +1,294 @@
1
+ #!/usr/bin/env python3
2
+ """End-to-end stdio smoke test for the Memory v2 MCP server.
3
+
4
+ Run inside the dev Docker image (or a Python env with the MCP SDK):
5
+
6
+ MEMORY_API=http://127.0.0.1:8103 python mcp/test_server.py
7
+
8
+ The test refuses to run against a non-loopback API.
9
+ """
10
+
11
+ import json
12
+ import os
13
+ import queue
14
+ import subprocess
15
+ import sys
16
+ import threading
17
+ import time
18
+ import urllib.parse
19
+ import urllib.request
20
+
21
+ API = os.environ.get("MEMORY_API", "http://127.0.0.1:8103").rstrip("/")
22
+
23
+ # Local-only: prevents a dev/test run from writing into a shared database.
24
+ LOOPBACK_HOSTS = {"127.0.0.1", "localhost", "::1"}
25
+ _host = urllib.parse.urlsplit(API).hostname or ""
26
+ if _host not in LOOPBACK_HOSTS:
27
+ print(
28
+ f"REFUSING: MEMORY_API host {_host!r} is not loopback; tests are local-only",
29
+ file=sys.stderr,
30
+ )
31
+ sys.exit(2)
32
+
33
+ SERVER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "server.py")
34
+ TEST_EXTERNAL_ID = "demo:mcp:stdio:001"
35
+ TEST_FACT = "MCP stdio test fact: the client can write a unique dev memory."
36
+ PROJECT_ID = int(os.environ.get("MEMORY_PROJECT_ID", "1"))
37
+
38
+
39
+ def send(process, payload):
40
+ process.stdin.write(json.dumps(payload, ensure_ascii=False) + "\n")
41
+ process.stdin.flush()
42
+
43
+
44
+ RESPONSES = queue.Queue()
45
+
46
+
47
+ def _reader(process):
48
+ if process.stdout is None:
49
+ RESPONSES.put(None)
50
+ return
51
+ for line in process.stdout:
52
+ RESPONSES.put(line)
53
+ RESPONSES.put(None)
54
+
55
+
56
+ def read_response(request_id, timeout=20):
57
+ deadline = time.time() + timeout
58
+ while time.time() < deadline:
59
+ try:
60
+ line = RESPONSES.get(timeout=max(0.1, deadline - time.time()))
61
+ except queue.Empty:
62
+ break
63
+ if line is None:
64
+ raise RuntimeError("MCP server closed stdout")
65
+ line = line.strip()
66
+ if not line:
67
+ continue
68
+ try:
69
+ message = json.loads(line)
70
+ except json.JSONDecodeError:
71
+ continue
72
+ if message.get("id") == request_id:
73
+ return message
74
+ raise TimeoutError("no response for id %s" % request_id)
75
+
76
+
77
+ def rpc(process, request_id, method, params=None):
78
+ payload = {"jsonrpc": "2.0", "id": request_id, "method": method}
79
+ if params is not None:
80
+ payload["params"] = params
81
+ send(process, payload)
82
+ return read_response(request_id)
83
+
84
+
85
+ def result_text(result):
86
+ pieces = []
87
+ for item in result.get("content") or []:
88
+ if item.get("type") == "text":
89
+ pieces.append(item.get("text", ""))
90
+ if not pieces:
91
+ structured = result.get("structuredContent") or result.get("structured_content")
92
+ if structured is not None:
93
+ pieces.append(json.dumps(structured, ensure_ascii=False))
94
+ return "\n".join(pieces)
95
+
96
+
97
+ def call_tool(process, request_id, name, arguments):
98
+ response = rpc(process, request_id, "tools/call", {"name": name, "arguments": arguments})
99
+ if "error" in response:
100
+ return None, response
101
+ return response.get("result", {}), response
102
+
103
+
104
+ def check(condition, label, detail=""):
105
+ if condition:
106
+ print("PASS", label)
107
+ return True
108
+ print("FAIL", label, detail)
109
+ return False
110
+
111
+
112
+ def rest(path, method="GET"):
113
+ request = urllib.request.Request(API + path, method=method)
114
+ with urllib.request.urlopen(request, timeout=30) as response:
115
+ return json.loads(response.read().decode("utf-8"))
116
+
117
+
118
+ def cleanup(memory_id):
119
+ """Remove the artifacts this smoke test creates, so the DB stays clean."""
120
+ try:
121
+ listing = rest("/conversations?project_id=%s" % PROJECT_ID)
122
+ for conversation in listing.get("conversations") or []:
123
+ if conversation.get("title") == "MCP stdio smoke test":
124
+ rest("/conversations/%s" % conversation["id"], "DELETE")
125
+ except Exception:
126
+ pass
127
+ if memory_id:
128
+ try:
129
+ rest("/memories/%s" % memory_id, "DELETE")
130
+ except Exception:
131
+ pass
132
+
133
+
134
+ def main():
135
+ env = dict(os.environ)
136
+ env["MEMORY_API"] = API
137
+ env.setdefault("PYTHONUTF8", "1")
138
+ env.setdefault("PYTHONIOENCODING", "utf-8")
139
+ process = subprocess.Popen(
140
+ [sys.executable, SERVER],
141
+ stdin=subprocess.PIPE,
142
+ stdout=subprocess.PIPE,
143
+ stderr=subprocess.PIPE,
144
+ text=True,
145
+ encoding="utf-8",
146
+ errors="replace",
147
+ bufsize=1,
148
+ env=env,
149
+ )
150
+ threading.Thread(target=_reader, args=(process,), daemon=True).start()
151
+ failures = 0
152
+ memory_id = None
153
+ try:
154
+ init = rpc(
155
+ process,
156
+ 1,
157
+ "initialize",
158
+ {
159
+ "protocolVersion": "2025-06-18",
160
+ "capabilities": {},
161
+ "clientInfo": {"name": "memory-v2-stdio-test", "version": "1.0"},
162
+ },
163
+ )
164
+ server_info = (init.get("result") or {}).get("serverInfo") or (init.get("result") or {}).get("server_info") or {}
165
+ failures += 0 if check(init.get("result") is not None, "initialize", str(init)) else 1
166
+ failures += 0 if check(server_info.get("name") == "memory-v2", "serverInfo name", str(server_info)) else 1
167
+
168
+ send(process, {"jsonrpc": "2.0", "method": "notifications/initialized"})
169
+
170
+ listing = rpc(process, 2, "tools/list", {})
171
+ tools = (listing.get("result") or {}).get("tools") or []
172
+ names = {tool.get("name") for tool in tools}
173
+ expected = {
174
+ "memory_health",
175
+ "memory_list_projects",
176
+ "memory_project_context",
177
+ "memory_search",
178
+ "memory_archive_conversation",
179
+ "memory_upsert",
180
+ "memory_deprecate",
181
+ }
182
+ failures += 0 if check(expected <= names, "tools/list", str(sorted(names))) else 1
183
+
184
+ health, raw = call_tool(process, 3, "memory_health", {})
185
+ failures += 0 if check(health and "healthy" in result_text(health), "memory_health", str(raw)) else 1
186
+
187
+ projects, raw = call_tool(process, 4, "memory_list_projects", {})
188
+ projects_text = result_text(projects) if projects else ""
189
+ failures += 0 if check(projects and '"id"' in projects_text, "memory_list_projects", str(raw)) else 1
190
+
191
+ context, raw = call_tool(process, 5, "memory_project_context", {"project_id": PROJECT_ID})
192
+ context_text = result_text(context) if context else ""
193
+ failures += 0 if check(context and "conversations" in context_text, "memory_project_context", str(raw)) else 1
194
+
195
+ search, raw = call_tool(
196
+ process,
197
+ 6,
198
+ "memory_search",
199
+ {"query": "memory", "project_id": PROJECT_ID, "include_messages": True, "limit": 5},
200
+ )
201
+ search_text = result_text(search) if search else ""
202
+ failures += 0 if check(search and ("messages" in search_text or "count" in search_text), "memory_search", str(raw)) else 1
203
+
204
+ upsert, raw = call_tool(
205
+ process,
206
+ 7,
207
+ "memory_upsert",
208
+ {
209
+ "project_id": PROJECT_ID,
210
+ "memory_type": "fact",
211
+ "content": TEST_FACT,
212
+ "importance": 1,
213
+ "confidence": 1,
214
+ },
215
+ )
216
+ failures += 0 if check(upsert and ("created" in result_text(upsert) or "duplicate" in result_text(upsert)), "memory_upsert", str(raw)) else 1
217
+
218
+ memory_id = None
219
+ try:
220
+ data = json.loads(result_text(upsert))
221
+ memory_id = (data.get("memory") or {}).get("id") or data.get("id")
222
+ except (TypeError, ValueError):
223
+ pass
224
+
225
+ archive, raw = call_tool(
226
+ process,
227
+ 8,
228
+ "memory_archive_conversation",
229
+ {
230
+ "project_id": PROJECT_ID,
231
+ "title": "MCP stdio smoke test",
232
+ "external_id": TEST_EXTERNAL_ID,
233
+ "messages": [
234
+ {"role": "user", "content": "MCP test user message."},
235
+ {"role": "assistant", "content": "MCP test assistant message."},
236
+ ],
237
+ },
238
+ )
239
+ archive_text = result_text(archive) if archive else ""
240
+ failures += 0 if check(archive and ("created" in archive_text or "unchanged" in archive_text or "appended" in archive_text), "memory_archive_conversation", str(raw)) else 1
241
+
242
+ archive2, raw = call_tool(
243
+ process,
244
+ 9,
245
+ "memory_archive_conversation",
246
+ {
247
+ "project_id": PROJECT_ID,
248
+ "title": "MCP stdio smoke test",
249
+ "external_id": TEST_EXTERNAL_ID,
250
+ "messages": [
251
+ {"role": "user", "content": "MCP test user message."},
252
+ {"role": "assistant", "content": "MCP test assistant message."},
253
+ ],
254
+ },
255
+ )
256
+ second_text = result_text(archive2) if archive2 else ""
257
+ failures += 0 if check(archive2 and "unchanged" in second_text, "archive idempotency", str(raw)) else 1
258
+
259
+ deprecated, raw = call_tool(
260
+ process,
261
+ 10,
262
+ "memory_deprecate",
263
+ {"memory_id": memory_id} if memory_id else {"memory_id": 0},
264
+ )
265
+ deprecated_text = result_text(deprecated) if deprecated else ""
266
+ failures += 0 if check(deprecated and "deprecated" in deprecated_text, "memory_deprecate", str(raw)) else 1
267
+
268
+ bad, raw = call_tool(process, 11, "no_such_tool", {})
269
+ bad_text = result_text(bad) if bad else ""
270
+ bad_is_error = bool(bad and (bad.get("isError") or bad.get("is_error")))
271
+ failures += 0 if check(bad_is_error and "unknown tool" in bad_text.lower(), "unknown tool error", str(raw)) else 1
272
+
273
+ missing, raw = call_tool(process, 12, "memory_project_context", {"project_id": 999999})
274
+ missing_text = result_text(missing) if missing else ""
275
+ failures += 0 if check(missing is not None and "error" in missing_text.lower(), "missing project error", str(raw)) else 1
276
+
277
+ finally:
278
+ process.terminate()
279
+ try:
280
+ process.wait(timeout=5)
281
+ except subprocess.TimeoutExpired:
282
+ process.kill()
283
+ stderr = process.stderr.read() if process.stderr else ""
284
+ if stderr.strip():
285
+ print("--- server stderr ---", file=sys.stderr)
286
+ print(stderr[-4000:], file=sys.stderr)
287
+ cleanup(memory_id)
288
+
289
+ print("RESULT", "PASS" if failures == 0 else "FAIL", "failures=%s" % failures)
290
+ return 0 if failures == 0 else 1
291
+
292
+
293
+ if __name__ == "__main__":
294
+ sys.exit(main())
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: memory-v2-mcp
3
+ Version: 2.1.0a2
4
+ Summary: MCP server for Memory v2: local-first long-term memory for AI agents
5
+ Author: DonParalon85
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/DonParalon85/memory-v.2-alpha
8
+ Project-URL: Repository, https://github.com/DonParalon85/memory-v.2-alpha
9
+ Project-URL: Issues, https://github.com/DonParalon85/memory-v.2-alpha/issues
10
+ Keywords: mcp,model-context-protocol,memory,ai-agents,local-first,sqlite
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ License-File: NOTICE
20
+ Requires-Dist: mcp<3,>=2
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest>=8; extra == "test"
23
+ Dynamic: license-file
24
+
25
+ # MCP server
26
+
27
+ Memory v2 exposes its API to any MCP-speaking agent through a small stdio
28
+ server. Works with Claude Desktop, Claude Code, Cursor and other MCP clients.
29
+
30
+ ## Tools
31
+
32
+ | Tool | Purpose |
33
+ |---|---|
34
+ | `memory_health` | Check API availability |
35
+ | `memory_list_projects` | List projects |
36
+ | `memory_project_context` | Restore a project and its branches |
37
+ | `memory_search` | Search memories and messages |
38
+ | `memory_archive_conversation` | Archive a branch idempotently |
39
+ | `memory_upsert` | Store a fact, decision, constraint or preference |
40
+ | `memory_deprecate` | Retire an old memory, optionally with a replacement |
41
+
42
+ ## Install
43
+
44
+ The project targets MCP SDK v2 (`MCPServer`, formerly `FastMCP`). The
45
+ requirement is `mcp>=2,<3`; `server.py` keeps a v1 fallback for older
46
+ environments.
47
+
48
+ ```sh
49
+ python3 -m venv .venv-mcp
50
+ . .venv-mcp/bin/activate
51
+ pip install -r mcp/requirements.txt
52
+ ```
53
+
54
+ Windows PowerShell:
55
+
56
+ ```powershell
57
+ python -m venv .venv-mcp
58
+ .venv-mcp\Scripts\Activate.ps1
59
+ pip install -r mcp\requirements.txt
60
+ ```
61
+
62
+ Environment:
63
+
64
+ | Variable | Default |
65
+ |---|---|
66
+ | `MEMORY_API` | `http://127.0.0.1:8002` |
67
+ | `MEMORY_API_TOKEN` | empty (local-only) |
68
+
69
+ ## Claude Desktop
70
+
71
+ Config file:
72
+
73
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
74
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
75
+ - Linux: `~/.config/Claude/claude_desktop_config.json`
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "memory-v2": {
81
+ "command": "C:\\path\\to\\memory_v2.0\\.venv-mcp\\Scripts\\python.exe",
82
+ "args": ["C:\\path\\to\\memory_v2.0\\mcp\\server.py"],
83
+ "env": {
84
+ "MEMORY_API": "http://127.0.0.1:8002"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Restart Claude Desktop after editing the file. A `memory-v2` tool group should
92
+ appear.
93
+
94
+ ## Claude Code
95
+
96
+ ```sh
97
+ claude mcp add memory-v2 -- python /path/to/memory_v2.0/mcp/server.py
98
+ ```
99
+
100
+ ## Cursor
101
+
102
+ Put this in `~/.cursor/mcp.json` (or `.cursor/mcp.json` inside a project):
103
+
104
+ ```json
105
+ {
106
+ "mcpServers": {
107
+ "memory-v2": {
108
+ "command": "python",
109
+ "args": ["/path/to/memory_v2.0/mcp/server.py"],
110
+ "env": {
111
+ "MEMORY_API": "http://127.0.0.1:8002"
112
+ }
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ ## Docker-only option (no local Python)
119
+
120
+ If the Memory stack is running under Docker, the same image can host the MCP
121
+ server:
122
+
123
+ ```sh
124
+ docker run -i --rm --network memory-v2_default \
125
+ -e MEMORY_API=http://memory:8002 \
126
+ memory-v2:latest python /app/mcp/server.py
127
+ ```
128
+
129
+ On Linux, `--network host` with `MEMORY_API=http://127.0.0.1:8002` also works.
130
+ On Docker Desktop for Windows, host networking differs; running the MCP server
131
+ natively in a Python venv is usually simpler.
132
+
133
+ ## Testing
134
+
135
+ Run the stdio smoke test against a **dev/test** Memory API:
136
+
137
+ ```sh
138
+ MEMORY_API=http://127.0.0.1:8103 python mcp/test_server.py
139
+ ```
140
+
141
+ Or inside the Docker image (no local Python):
142
+
143
+ ```sh
144
+ docker run --rm --network host \
145
+ -e MEMORY_API=http://127.0.0.1:8103 \
146
+ -v "$PWD/mcp:/app/mcp:ro" \
147
+ --entrypoint python memory-v2:latest /app/mcp/test_server.py
148
+ ```
149
+
150
+ The test refuses to run against a non-loopback API, so a dev run cannot touch a
151
+ shared database. It checks `initialize`, `tools/list`, every tool, archive
152
+ idempotency, and error responses, then removes the test conversation and test
153
+ memory it created.
154
+
155
+ Point it at any project you don't mind writing to:
156
+
157
+ ```sh
158
+ MEMORY_API=http://127.0.0.1:8002 MEMORY_PROJECT_ID=2 python mcp/test_server.py
159
+ ```
160
+
161
+ `MEMORY_PROJECT_ID` defaults to `1`. The server itself has no model or client
162
+ dependency: any MCP-capable app works. See `docs/integrations.md` for Claude
163
+ Desktop, Cursor, Cline, Continue, Windsurf, Zed and plain REST/OpenAI/Anthropic
164
+ tool schemas.
165
+
166
+ Run the server as a script (`python mcp/server.py`), not as
167
+ `python -m mcp.server` from the repository root: the project's `mcp/`
168
+ directory can otherwise shadow the installed SDK.
169
+
170
+ ## Example prompts
171
+
172
+ - “Search my Memory for `AsyncSession` and show the source branch.”
173
+ - “Restore project 1 and summarize its open decisions.”
174
+ - “Archive this dialog as a branch in project 1 with external id
175
+ `demo:fastapi:async-session:003`.”
176
+ - “Save a decision: schema changes go through Alembic.”
177
+
178
+ ## Security
179
+
180
+ - The MCP server only talks to the Memory API; it does not open the database.
181
+ - Point `MEMORY_API` at a dev/test instance while developing. Never point the
182
+ MCP server at a shared or production address by accident.
183
+ - Keep the API bound to `127.0.0.1` for local use.
184
+ - If you expose the API to a LAN, set `MEMORY_API_TOKEN` and pass it to the
185
+ MCP server through the environment.
186
+ - Tool results may contain conversation text. Do not paste secrets into
187
+ prompts.
@@ -0,0 +1,15 @@
1
+ memory_v2_mcp/README.md,sha256=bhnXQ10Mko4zD11JXAhMAHVfqYQ9uJ4lk-tOlArvUvg,4600
2
+ memory_v2_mcp/client.py,sha256=-gEfpJH4N0ubktU_Y9QcXSvA3lS8C0iUf5ALvA6LMl4,3683
3
+ memory_v2_mcp/requirements.txt,sha256=V5uZQQ0_NfAWzqFhZn-6DTwouiknEmSsVKIoigwIvMI,121
4
+ memory_v2_mcp/server.py,sha256=TaR63f9z5Ienj7lwgJntiJIMeGwnEH6LmVZy-R4JIOc,3215
5
+ memory_v2_mcp/test_server.py,sha256=bYfHhgWbG3y9k7YRGxTbvpY7aXu6J_NkSSRYPC_XXgA,10486
6
+ memory_v2_mcp/examples/claude_desktop_config.json,sha256=gpnK3iFevQBNqilg887J77kF6mPEi9Ppym7meY0eZgM,259
7
+ memory_v2_mcp/examples/cursor_mcp.json,sha256=uR1LxwDvNOuITDkeVNqr4wIsbVr4L0OxSWxmC-fYYvo,201
8
+ memory_v2_mcp/examples/docker_claude_config.json,sha256=RIPEqIqT1sFqUagNb1Ojp8jY2x0I5ExyEP3MBINmVN0,327
9
+ memory_v2_mcp-2.1.0a2.dist-info/licenses/LICENSE,sha256=wlX3KM4VkrYr_bHsPlXh7rsHkhXkaeHz-ZRAMPJ1qWQ,1081
10
+ memory_v2_mcp-2.1.0a2.dist-info/licenses/NOTICE,sha256=WvndWR8hU2s6ZzxZ-JnIxY7FRAewhcdl4-NjABcMCs8,195
11
+ memory_v2_mcp-2.1.0a2.dist-info/METADATA,sha256=IWsYMBt7ZyJlXy1Vz_-EdUqds1dmZEKVNaRLbU_iqbw,5527
12
+ memory_v2_mcp-2.1.0a2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ memory_v2_mcp-2.1.0a2.dist-info/entry_points.txt,sha256=CmSY1F3mUxWoHwHAc0W1wvXWDcG3dRqYlC6QzKahxM4,60
14
+ memory_v2_mcp-2.1.0a2.dist-info/top_level.txt,sha256=4PiUPCs2nDwLwSIk2NvHCIiUdrM21ByzXBT7ygfCJXU,14
15
+ memory_v2_mcp-2.1.0a2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ memory-v2-mcp = memory_v2_mcp.server:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Memory v2.0 contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ Memory v2.0
2
+ Copyright 2026 Memory v2.0 contributors
3
+
4
+ This product includes software developed by third parties. See the dependency
5
+ metadata in api/requirements.txt for their respective licenses.
@@ -0,0 +1 @@
1
+ memory_v2_mcp