mem0-mcp-server 1.0.2 → 1.0.3
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 +42 -172
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1,205 +1,75 @@
|
|
|
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 = process.env.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";
|
|
26
7
|
|
|
27
8
|
const server = new Server(
|
|
28
|
-
{ name: "mem0-mcp-server", version: "1.0.
|
|
9
|
+
{ name: "mem0-mcp-server", version: "1.0.3" },
|
|
29
10
|
{ capabilities: { tools: {} } }
|
|
30
11
|
);
|
|
31
12
|
|
|
32
13
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
33
14
|
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
|
-
],
|
|
15
|
+
{ 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"] } },
|
|
16
|
+
{ 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"] } },
|
|
17
|
+
{ name: "get_all_memories", description: "获取用户的所有记忆", inputSchema: { type: "object", properties: { user_id: { type: "string" }, agent_id: { type: "string" }, run_id: { type: "string" } } } },
|
|
18
|
+
{ name: "get_memory", description: "根据ID获取单条记忆", inputSchema: { type: "object", properties: { memory_id: { type: "string" } }, required: ["memory_id"] } },
|
|
19
|
+
{ name: "update_memory", description: "更新指定记忆内容", inputSchema: { type: "object", properties: { memory_id: { type: "string" }, data: { type: "string" } }, required: ["memory_id", "data"] } },
|
|
20
|
+
{ name: "delete_memory", description: "删除指定记忆", inputSchema: { type: "object", properties: { memory_id: { type: "string" } }, required: ["memory_id"] } },
|
|
21
|
+
{ name: "delete_all_memories", description: "删除用户的所有记忆", inputSchema: { type: "object", properties: { user_id: { type: "string" }, agent_id: { type: "string" }, run_id: { type: "string" } } } }
|
|
22
|
+
]
|
|
129
23
|
}));
|
|
130
24
|
|
|
131
25
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
132
26
|
const { name, arguments: args } = request.params;
|
|
133
|
-
|
|
134
27
|
try {
|
|
28
|
+
let res, data;
|
|
135
29
|
switch (name) {
|
|
136
|
-
case "add_memory":
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
body: JSON.stringify(args),
|
|
140
|
-
});
|
|
30
|
+
case "add_memory":
|
|
31
|
+
res = await fetch(`${MEM0_API_URL}/memory/add`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(args) });
|
|
32
|
+
data = await res.json();
|
|
141
33
|
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
|
-
});
|
|
34
|
+
case "search_memory":
|
|
35
|
+
res = await fetch(`${MEM0_API_URL}/memory/search`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(args) });
|
|
36
|
+
data = await res.json();
|
|
149
37
|
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}`);
|
|
38
|
+
case "get_all_memories":
|
|
39
|
+
const params1 = new URLSearchParams();
|
|
40
|
+
if (args.user_id) params1.append("user_id", args.user_id);
|
|
41
|
+
if (args.agent_id) params1.append("agent_id", args.agent_id);
|
|
42
|
+
if (args.run_id) params1.append("run_id", args.run_id);
|
|
43
|
+
res = await fetch(`${MEM0_API_URL}/memory/all?${params1}`);
|
|
44
|
+
data = await res.json();
|
|
158
45
|
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const data = await apiRequest(`/memory/${args.memory_id}`);
|
|
46
|
+
case "get_memory":
|
|
47
|
+
res = await fetch(`${MEM0_API_URL}/memory/${args.memory_id}`);
|
|
48
|
+
data = await res.json();
|
|
163
49
|
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
|
-
});
|
|
50
|
+
case "update_memory":
|
|
51
|
+
res = await fetch(`${MEM0_API_URL}/memory/update`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(args) });
|
|
52
|
+
data = await res.json();
|
|
171
53
|
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
|
-
});
|
|
54
|
+
case "delete_memory":
|
|
55
|
+
res = await fetch(`${MEM0_API_URL}/memory/delete`, { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify(args) });
|
|
56
|
+
data = await res.json();
|
|
179
57
|
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
|
-
});
|
|
58
|
+
case "delete_all_memories":
|
|
59
|
+
const params2 = new URLSearchParams();
|
|
60
|
+
if (args.user_id) params2.append("user_id", args.user_id);
|
|
61
|
+
if (args.agent_id) params2.append("agent_id", args.agent_id);
|
|
62
|
+
if (args.run_id) params2.append("run_id", args.run_id);
|
|
63
|
+
res = await fetch(`${MEM0_API_URL}/memory/delete_all?${params2}`, { method: "DELETE" });
|
|
64
|
+
data = await res.json();
|
|
190
65
|
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
66
|
default:
|
|
194
67
|
throw new Error(`Unknown tool: ${name}`);
|
|
195
68
|
}
|
|
196
69
|
} catch (error) {
|
|
197
|
-
return {
|
|
198
|
-
content: [{ type: "text", text: `Error: ${error.message}` }],
|
|
199
|
-
isError: true,
|
|
200
|
-
};
|
|
70
|
+
return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true };
|
|
201
71
|
}
|
|
202
72
|
});
|
|
203
73
|
|
|
204
74
|
const transport = new StdioServerTransport();
|
|
205
|
-
await server.connect(transport);
|
|
75
|
+
await server.connect(transport);
|