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