mem0-mcp-server 1.0.0

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.
Files changed (2) hide show
  1. package/package.json +17 -0
  2. package/server.js +204 -0
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "mem0-mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for mem0 memory service",
5
+ "type": "module",
6
+ "bin": {
7
+ "mem0-mcp-server": "server.js"
8
+ },
9
+ "files": [
10
+ "server.js"
11
+ ],
12
+ "dependencies": {
13
+ "@modelcontextprotocol/sdk": "^1.0.0"
14
+ },
15
+ "keywords": ["mcp", "mem0", "memory"],
16
+ "license": "MIT"
17
+ }
package/server.js ADDED
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+
6
+ const MEM0_API_URL = process.env.MEM0_API_URL || "http://localhost:8001/mem0";
7
+ const MEM0_API_TOKEN = process.env.MEM0_API_TOKEN || "";
8
+
9
+ function authHeaders() {
10
+ const headers = { "Content-Type": "application/json" };
11
+ if (MEM0_API_TOKEN) {
12
+ headers["Authorization"] = `Bearer ${MEM0_API_TOKEN}`;
13
+ }
14
+ return headers;
15
+ }
16
+
17
+ async function apiRequest(path, options = {}) {
18
+ const url = `${MEM0_API_URL}${path}`;
19
+ const res = await fetch(url, {
20
+ ...options,
21
+ headers: { ...authHeaders(), ...options.headers },
22
+ });
23
+ return res.json();
24
+ }
25
+
26
+ const server = new Server(
27
+ { name: "mem0-mcp-server", version: "1.0.0" },
28
+ { capabilities: { tools: {} } }
29
+ );
30
+
31
+ server.setRequestHandler("tools/list", async () => ({
32
+ tools: [
33
+ {
34
+ name: "add_memory",
35
+ description: "Add new memory to mem0",
36
+ inputSchema: {
37
+ type: "object",
38
+ properties: {
39
+ messages: {
40
+ type: "array",
41
+ items: {
42
+ type: "object",
43
+ properties: {
44
+ role: { type: "string" },
45
+ content: { type: "string" },
46
+ },
47
+ required: ["role", "content"],
48
+ },
49
+ },
50
+ user_id: { type: "string" },
51
+ agent_id: { type: "string" },
52
+ run_id: { type: "string" },
53
+ metadata: { type: "object" },
54
+ },
55
+ required: ["messages"],
56
+ },
57
+ },
58
+ {
59
+ name: "search_memory",
60
+ description: "Search related memories",
61
+ inputSchema: {
62
+ type: "object",
63
+ properties: {
64
+ query: { type: "string" },
65
+ user_id: { type: "string" },
66
+ agent_id: { type: "string" },
67
+ run_id: { type: "string" },
68
+ limit: { type: "number" },
69
+ },
70
+ required: ["query"],
71
+ },
72
+ },
73
+ {
74
+ name: "get_all_memories",
75
+ description: "Get all memories for a user",
76
+ inputSchema: {
77
+ type: "object",
78
+ properties: {
79
+ user_id: { type: "string" },
80
+ agent_id: { type: "string" },
81
+ run_id: { type: "string" },
82
+ },
83
+ },
84
+ },
85
+ {
86
+ name: "get_memory",
87
+ description: "Get a single memory by ID",
88
+ inputSchema: {
89
+ type: "object",
90
+ properties: { memory_id: { type: "string" } },
91
+ required: ["memory_id"],
92
+ },
93
+ },
94
+ {
95
+ name: "update_memory",
96
+ description: "Update a memory by ID",
97
+ inputSchema: {
98
+ type: "object",
99
+ properties: {
100
+ memory_id: { type: "string" },
101
+ data: { type: "string" },
102
+ },
103
+ required: ["memory_id", "data"],
104
+ },
105
+ },
106
+ {
107
+ name: "delete_memory",
108
+ description: "Delete a memory by ID",
109
+ inputSchema: {
110
+ type: "object",
111
+ properties: { memory_id: { type: "string" } },
112
+ required: ["memory_id"],
113
+ },
114
+ },
115
+ {
116
+ name: "delete_all_memories",
117
+ description: "Delete all memories for a user",
118
+ inputSchema: {
119
+ type: "object",
120
+ properties: {
121
+ user_id: { type: "string" },
122
+ agent_id: { type: "string" },
123
+ run_id: { type: "string" },
124
+ },
125
+ },
126
+ },
127
+ ],
128
+ }));
129
+
130
+ server.setRequestHandler("tools/call", async (request) => {
131
+ const { name, arguments: args } = request.params;
132
+
133
+ try {
134
+ switch (name) {
135
+ case "add_memory": {
136
+ const data = await apiRequest("/memory/add", {
137
+ method: "POST",
138
+ body: JSON.stringify(args),
139
+ });
140
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
141
+ }
142
+
143
+ case "search_memory": {
144
+ const data = await apiRequest("/memory/search", {
145
+ method: "POST",
146
+ body: JSON.stringify(args),
147
+ });
148
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
149
+ }
150
+
151
+ case "get_all_memories": {
152
+ const params = new URLSearchParams();
153
+ if (args.user_id) params.append("user_id", args.user_id);
154
+ if (args.agent_id) params.append("agent_id", args.agent_id);
155
+ if (args.run_id) params.append("run_id", args.run_id);
156
+ const data = await apiRequest(`/memory/all?${params}`);
157
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
158
+ }
159
+
160
+ case "get_memory": {
161
+ const data = await apiRequest(`/memory/${args.memory_id}`);
162
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
163
+ }
164
+
165
+ case "update_memory": {
166
+ const data = await apiRequest("/memory/update", {
167
+ method: "PUT",
168
+ body: JSON.stringify(args),
169
+ });
170
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
171
+ }
172
+
173
+ case "delete_memory": {
174
+ const data = await apiRequest("/memory/delete", {
175
+ method: "DELETE",
176
+ body: JSON.stringify(args),
177
+ });
178
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
179
+ }
180
+
181
+ case "delete_all_memories": {
182
+ const params = new URLSearchParams();
183
+ if (args.user_id) params.append("user_id", args.user_id);
184
+ if (args.agent_id) params.append("agent_id", args.agent_id);
185
+ if (args.run_id) params.append("run_id", args.run_id);
186
+ const data = await apiRequest(`/memory/delete_all?${params}`, {
187
+ method: "DELETE",
188
+ });
189
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
190
+ }
191
+
192
+ default:
193
+ throw new Error(`Unknown tool: ${name}`);
194
+ }
195
+ } catch (error) {
196
+ return {
197
+ content: [{ type: "text", text: `Error: ${error.message}` }],
198
+ isError: true,
199
+ };
200
+ }
201
+ });
202
+
203
+ const transport = new StdioServerTransport();
204
+ await server.connect(transport);