@codespar/mcp-evolution-api 0.1.2 → 0.2.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.
- package/dist/index.js +189 -2
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/index.ts +187 -2
package/dist/index.js
CHANGED
|
@@ -18,6 +18,16 @@
|
|
|
18
18
|
* - update_profile: Update instance profile (name, picture, status)
|
|
19
19
|
* - set_presence: Set online/offline presence for an instance
|
|
20
20
|
* - get_chat_history: Get full chat history with pagination
|
|
21
|
+
* - logout_instance: Logout an instance (disconnects WhatsApp session)
|
|
22
|
+
* - restart_instance: Restart an instance
|
|
23
|
+
* - delete_instance: Delete an instance permanently
|
|
24
|
+
* - connection_state: Get connection state of an instance
|
|
25
|
+
* - leave_group: Leave a WhatsApp group
|
|
26
|
+
* - update_group_participants: Add/remove/promote/demote participants in a group
|
|
27
|
+
* - fetch_group_invite_code: Fetch invite code/link for a group
|
|
28
|
+
* - mark_message_as_read: Mark messages in a chat as read
|
|
29
|
+
* - archive_chat: Archive or unarchive a chat
|
|
30
|
+
* - delete_message: Delete a message (for me or for everyone)
|
|
21
31
|
*
|
|
22
32
|
* Environment:
|
|
23
33
|
* EVOLUTION_API_URL — Base URL of self-hosted Evolution API
|
|
@@ -45,7 +55,7 @@ async function evolutionRequest(method, path, body) {
|
|
|
45
55
|
}
|
|
46
56
|
return res.json();
|
|
47
57
|
}
|
|
48
|
-
const server = new Server({ name: "mcp-evolution-api", version: "0.
|
|
58
|
+
const server = new Server({ name: "mcp-evolution-api", version: "0.2.0" }, { capabilities: { tools: {} } });
|
|
49
59
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
50
60
|
tools: [
|
|
51
61
|
{
|
|
@@ -249,6 +259,148 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
249
259
|
required: ["instance", "remoteJid"],
|
|
250
260
|
},
|
|
251
261
|
},
|
|
262
|
+
{
|
|
263
|
+
name: "logout_instance",
|
|
264
|
+
description: "Logout an instance (disconnects the WhatsApp session without deleting the instance)",
|
|
265
|
+
inputSchema: {
|
|
266
|
+
type: "object",
|
|
267
|
+
properties: {
|
|
268
|
+
instance: { type: "string", description: "Instance name" },
|
|
269
|
+
},
|
|
270
|
+
required: ["instance"],
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "restart_instance",
|
|
275
|
+
description: "Restart an instance",
|
|
276
|
+
inputSchema: {
|
|
277
|
+
type: "object",
|
|
278
|
+
properties: {
|
|
279
|
+
instance: { type: "string", description: "Instance name" },
|
|
280
|
+
},
|
|
281
|
+
required: ["instance"],
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "delete_instance",
|
|
286
|
+
description: "Delete an instance permanently",
|
|
287
|
+
inputSchema: {
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
instance: { type: "string", description: "Instance name" },
|
|
291
|
+
},
|
|
292
|
+
required: ["instance"],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
name: "connection_state",
|
|
297
|
+
description: "Get the connection state of an instance (open, connecting, close)",
|
|
298
|
+
inputSchema: {
|
|
299
|
+
type: "object",
|
|
300
|
+
properties: {
|
|
301
|
+
instance: { type: "string", description: "Instance name" },
|
|
302
|
+
},
|
|
303
|
+
required: ["instance"],
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: "leave_group",
|
|
308
|
+
description: "Leave a WhatsApp group",
|
|
309
|
+
inputSchema: {
|
|
310
|
+
type: "object",
|
|
311
|
+
properties: {
|
|
312
|
+
instance: { type: "string", description: "Instance name" },
|
|
313
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
314
|
+
},
|
|
315
|
+
required: ["instance", "groupJid"],
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "update_group_participants",
|
|
320
|
+
description: "Add, remove, promote, or demote participants in a WhatsApp group",
|
|
321
|
+
inputSchema: {
|
|
322
|
+
type: "object",
|
|
323
|
+
properties: {
|
|
324
|
+
instance: { type: "string", description: "Instance name" },
|
|
325
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
326
|
+
action: { type: "string", enum: ["add", "remove", "promote", "demote"], description: "Action to take on participants" },
|
|
327
|
+
participants: {
|
|
328
|
+
type: "array",
|
|
329
|
+
items: { type: "string" },
|
|
330
|
+
description: "Array of phone numbers (with country code)",
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
required: ["instance", "groupJid", "action", "participants"],
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: "fetch_group_invite_code",
|
|
338
|
+
description: "Fetch the invite code/link for a WhatsApp group",
|
|
339
|
+
inputSchema: {
|
|
340
|
+
type: "object",
|
|
341
|
+
properties: {
|
|
342
|
+
instance: { type: "string", description: "Instance name" },
|
|
343
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
344
|
+
},
|
|
345
|
+
required: ["instance", "groupJid"],
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "mark_message_as_read",
|
|
350
|
+
description: "Mark one or more messages in a chat as read",
|
|
351
|
+
inputSchema: {
|
|
352
|
+
type: "object",
|
|
353
|
+
properties: {
|
|
354
|
+
instance: { type: "string", description: "Instance name" },
|
|
355
|
+
readMessages: {
|
|
356
|
+
type: "array",
|
|
357
|
+
items: {
|
|
358
|
+
type: "object",
|
|
359
|
+
properties: {
|
|
360
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
361
|
+
fromMe: { type: "boolean", description: "Whether the message was sent by the instance" },
|
|
362
|
+
id: { type: "string", description: "Message ID" },
|
|
363
|
+
},
|
|
364
|
+
required: ["remoteJid", "fromMe", "id"],
|
|
365
|
+
},
|
|
366
|
+
description: "List of messages to mark as read",
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
required: ["instance", "readMessages"],
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "archive_chat",
|
|
374
|
+
description: "Archive or unarchive a chat",
|
|
375
|
+
inputSchema: {
|
|
376
|
+
type: "object",
|
|
377
|
+
properties: {
|
|
378
|
+
instance: { type: "string", description: "Instance name" },
|
|
379
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
380
|
+
archive: { type: "boolean", description: "true to archive, false to unarchive" },
|
|
381
|
+
lastMessage: {
|
|
382
|
+
type: "object",
|
|
383
|
+
description: "Last message key reference (optional)",
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
required: ["instance", "remoteJid", "archive"],
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
name: "delete_message",
|
|
391
|
+
description: "Delete a message for me or for everyone in a chat",
|
|
392
|
+
inputSchema: {
|
|
393
|
+
type: "object",
|
|
394
|
+
properties: {
|
|
395
|
+
instance: { type: "string", description: "Instance name" },
|
|
396
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
397
|
+
id: { type: "string", description: "Message ID" },
|
|
398
|
+
fromMe: { type: "boolean", description: "Whether the message was sent by the instance" },
|
|
399
|
+
participant: { type: "string", description: "Participant JID (required for group messages)" },
|
|
400
|
+
},
|
|
401
|
+
required: ["instance", "remoteJid", "id", "fromMe"],
|
|
402
|
+
},
|
|
403
|
+
},
|
|
252
404
|
],
|
|
253
405
|
}));
|
|
254
406
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
@@ -307,6 +459,41 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
307
459
|
body.where = { ...body.where, key: { remoteJid: args?.remoteJid, fromMe: args.fromMe } };
|
|
308
460
|
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/findMessages/${args?.instance}`, body), null, 2) }] };
|
|
309
461
|
}
|
|
462
|
+
case "logout_instance":
|
|
463
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/instance/logout/${args?.instance}`), null, 2) }] };
|
|
464
|
+
case "restart_instance":
|
|
465
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/instance/restart/${args?.instance}`), null, 2) }] };
|
|
466
|
+
case "delete_instance":
|
|
467
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/instance/delete/${args?.instance}`), null, 2) }] };
|
|
468
|
+
case "connection_state":
|
|
469
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("GET", `/instance/connectionState/${args?.instance}`), null, 2) }] };
|
|
470
|
+
case "leave_group":
|
|
471
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/group/leaveGroup/${args?.instance}?groupJid=${args?.groupJid}`), null, 2) }] };
|
|
472
|
+
case "update_group_participants":
|
|
473
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/group/updateParticipant/${args?.instance}?groupJid=${args?.groupJid}`, { action: args?.action, participants: args?.participants }), null, 2) }] };
|
|
474
|
+
case "fetch_group_invite_code":
|
|
475
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("GET", `/group/inviteCode/${args?.instance}?groupJid=${args?.groupJid}`), null, 2) }] };
|
|
476
|
+
case "mark_message_as_read":
|
|
477
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/markMessageAsRead/${args?.instance}`, { readMessages: args?.readMessages }), null, 2) }] };
|
|
478
|
+
case "archive_chat": {
|
|
479
|
+
const body = {
|
|
480
|
+
chat: args?.remoteJid,
|
|
481
|
+
archive: args?.archive,
|
|
482
|
+
};
|
|
483
|
+
if (args?.lastMessage)
|
|
484
|
+
body.lastMessage = args.lastMessage;
|
|
485
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/archiveChat/${args?.instance}`, body), null, 2) }] };
|
|
486
|
+
}
|
|
487
|
+
case "delete_message": {
|
|
488
|
+
const body = {
|
|
489
|
+
id: args?.id,
|
|
490
|
+
remoteJid: args?.remoteJid,
|
|
491
|
+
fromMe: args?.fromMe,
|
|
492
|
+
};
|
|
493
|
+
if (args?.participant)
|
|
494
|
+
body.participant = args.participant;
|
|
495
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/chat/deleteMessageForEveryone/${args?.instance}`, body), null, 2) }] };
|
|
496
|
+
}
|
|
310
497
|
default:
|
|
311
498
|
return { content: [{ type: "text", text: `Unknown tool: ${name}` }], isError: true };
|
|
312
499
|
}
|
|
@@ -333,7 +520,7 @@ async function main() {
|
|
|
333
520
|
const t = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID(), onsessioninitialized: (id) => { transports.set(id, t); } });
|
|
334
521
|
t.onclose = () => { if (t.sessionId)
|
|
335
522
|
transports.delete(t.sessionId); };
|
|
336
|
-
const s = new Server({ name: "mcp-evolution-api", version: "0.
|
|
523
|
+
const s = new Server({ name: "mcp-evolution-api", version: "0.2.0" }, { capabilities: { tools: {} } });
|
|
337
524
|
server._requestHandlers.forEach((v, k) => s._requestHandlers.set(k, v));
|
|
338
525
|
server._notificationHandlers?.forEach((v, k) => s._notificationHandlers.set(k, v));
|
|
339
526
|
await s.connect(t);
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"source": "github",
|
|
8
8
|
"subfolder": "packages/communication/evolution-api"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.2.0",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "@codespar/mcp-evolution-api",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.2.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
* - update_profile: Update instance profile (name, picture, status)
|
|
20
20
|
* - set_presence: Set online/offline presence for an instance
|
|
21
21
|
* - get_chat_history: Get full chat history with pagination
|
|
22
|
+
* - logout_instance: Logout an instance (disconnects WhatsApp session)
|
|
23
|
+
* - restart_instance: Restart an instance
|
|
24
|
+
* - delete_instance: Delete an instance permanently
|
|
25
|
+
* - connection_state: Get connection state of an instance
|
|
26
|
+
* - leave_group: Leave a WhatsApp group
|
|
27
|
+
* - update_group_participants: Add/remove/promote/demote participants in a group
|
|
28
|
+
* - fetch_group_invite_code: Fetch invite code/link for a group
|
|
29
|
+
* - mark_message_as_read: Mark messages in a chat as read
|
|
30
|
+
* - archive_chat: Archive or unarchive a chat
|
|
31
|
+
* - delete_message: Delete a message (for me or for everyone)
|
|
22
32
|
*
|
|
23
33
|
* Environment:
|
|
24
34
|
* EVOLUTION_API_URL — Base URL of self-hosted Evolution API
|
|
@@ -54,7 +64,7 @@ async function evolutionRequest(method: string, path: string, body?: unknown): P
|
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
const server = new Server(
|
|
57
|
-
{ name: "mcp-evolution-api", version: "0.
|
|
67
|
+
{ name: "mcp-evolution-api", version: "0.2.0" },
|
|
58
68
|
{ capabilities: { tools: {} } }
|
|
59
69
|
);
|
|
60
70
|
|
|
@@ -261,6 +271,148 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
261
271
|
required: ["instance", "remoteJid"],
|
|
262
272
|
},
|
|
263
273
|
},
|
|
274
|
+
{
|
|
275
|
+
name: "logout_instance",
|
|
276
|
+
description: "Logout an instance (disconnects the WhatsApp session without deleting the instance)",
|
|
277
|
+
inputSchema: {
|
|
278
|
+
type: "object",
|
|
279
|
+
properties: {
|
|
280
|
+
instance: { type: "string", description: "Instance name" },
|
|
281
|
+
},
|
|
282
|
+
required: ["instance"],
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: "restart_instance",
|
|
287
|
+
description: "Restart an instance",
|
|
288
|
+
inputSchema: {
|
|
289
|
+
type: "object",
|
|
290
|
+
properties: {
|
|
291
|
+
instance: { type: "string", description: "Instance name" },
|
|
292
|
+
},
|
|
293
|
+
required: ["instance"],
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: "delete_instance",
|
|
298
|
+
description: "Delete an instance permanently",
|
|
299
|
+
inputSchema: {
|
|
300
|
+
type: "object",
|
|
301
|
+
properties: {
|
|
302
|
+
instance: { type: "string", description: "Instance name" },
|
|
303
|
+
},
|
|
304
|
+
required: ["instance"],
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: "connection_state",
|
|
309
|
+
description: "Get the connection state of an instance (open, connecting, close)",
|
|
310
|
+
inputSchema: {
|
|
311
|
+
type: "object",
|
|
312
|
+
properties: {
|
|
313
|
+
instance: { type: "string", description: "Instance name" },
|
|
314
|
+
},
|
|
315
|
+
required: ["instance"],
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "leave_group",
|
|
320
|
+
description: "Leave a WhatsApp group",
|
|
321
|
+
inputSchema: {
|
|
322
|
+
type: "object",
|
|
323
|
+
properties: {
|
|
324
|
+
instance: { type: "string", description: "Instance name" },
|
|
325
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
326
|
+
},
|
|
327
|
+
required: ["instance", "groupJid"],
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
name: "update_group_participants",
|
|
332
|
+
description: "Add, remove, promote, or demote participants in a WhatsApp group",
|
|
333
|
+
inputSchema: {
|
|
334
|
+
type: "object",
|
|
335
|
+
properties: {
|
|
336
|
+
instance: { type: "string", description: "Instance name" },
|
|
337
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
338
|
+
action: { type: "string", enum: ["add", "remove", "promote", "demote"], description: "Action to take on participants" },
|
|
339
|
+
participants: {
|
|
340
|
+
type: "array",
|
|
341
|
+
items: { type: "string" },
|
|
342
|
+
description: "Array of phone numbers (with country code)",
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
required: ["instance", "groupJid", "action", "participants"],
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "fetch_group_invite_code",
|
|
350
|
+
description: "Fetch the invite code/link for a WhatsApp group",
|
|
351
|
+
inputSchema: {
|
|
352
|
+
type: "object",
|
|
353
|
+
properties: {
|
|
354
|
+
instance: { type: "string", description: "Instance name" },
|
|
355
|
+
groupJid: { type: "string", description: "Group JID (e.g. 120363000000000000@g.us)" },
|
|
356
|
+
},
|
|
357
|
+
required: ["instance", "groupJid"],
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: "mark_message_as_read",
|
|
362
|
+
description: "Mark one or more messages in a chat as read",
|
|
363
|
+
inputSchema: {
|
|
364
|
+
type: "object",
|
|
365
|
+
properties: {
|
|
366
|
+
instance: { type: "string", description: "Instance name" },
|
|
367
|
+
readMessages: {
|
|
368
|
+
type: "array",
|
|
369
|
+
items: {
|
|
370
|
+
type: "object",
|
|
371
|
+
properties: {
|
|
372
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
373
|
+
fromMe: { type: "boolean", description: "Whether the message was sent by the instance" },
|
|
374
|
+
id: { type: "string", description: "Message ID" },
|
|
375
|
+
},
|
|
376
|
+
required: ["remoteJid", "fromMe", "id"],
|
|
377
|
+
},
|
|
378
|
+
description: "List of messages to mark as read",
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
required: ["instance", "readMessages"],
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: "archive_chat",
|
|
386
|
+
description: "Archive or unarchive a chat",
|
|
387
|
+
inputSchema: {
|
|
388
|
+
type: "object",
|
|
389
|
+
properties: {
|
|
390
|
+
instance: { type: "string", description: "Instance name" },
|
|
391
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
392
|
+
archive: { type: "boolean", description: "true to archive, false to unarchive" },
|
|
393
|
+
lastMessage: {
|
|
394
|
+
type: "object",
|
|
395
|
+
description: "Last message key reference (optional)",
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
required: ["instance", "remoteJid", "archive"],
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
name: "delete_message",
|
|
403
|
+
description: "Delete a message for me or for everyone in a chat",
|
|
404
|
+
inputSchema: {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: {
|
|
407
|
+
instance: { type: "string", description: "Instance name" },
|
|
408
|
+
remoteJid: { type: "string", description: "Chat JID" },
|
|
409
|
+
id: { type: "string", description: "Message ID" },
|
|
410
|
+
fromMe: { type: "boolean", description: "Whether the message was sent by the instance" },
|
|
411
|
+
participant: { type: "string", description: "Participant JID (required for group messages)" },
|
|
412
|
+
},
|
|
413
|
+
required: ["instance", "remoteJid", "id", "fromMe"],
|
|
414
|
+
},
|
|
415
|
+
},
|
|
264
416
|
],
|
|
265
417
|
}));
|
|
266
418
|
|
|
@@ -314,6 +466,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
314
466
|
if (args?.fromMe !== undefined) body.where = { ...(body.where as Record<string, unknown>), key: { remoteJid: args?.remoteJid, fromMe: args.fromMe } };
|
|
315
467
|
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/findMessages/${args?.instance}`, body), null, 2) }] };
|
|
316
468
|
}
|
|
469
|
+
case "logout_instance":
|
|
470
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/instance/logout/${args?.instance}`), null, 2) }] };
|
|
471
|
+
case "restart_instance":
|
|
472
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/instance/restart/${args?.instance}`), null, 2) }] };
|
|
473
|
+
case "delete_instance":
|
|
474
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/instance/delete/${args?.instance}`), null, 2) }] };
|
|
475
|
+
case "connection_state":
|
|
476
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("GET", `/instance/connectionState/${args?.instance}`), null, 2) }] };
|
|
477
|
+
case "leave_group":
|
|
478
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/group/leaveGroup/${args?.instance}?groupJid=${args?.groupJid}`), null, 2) }] };
|
|
479
|
+
case "update_group_participants":
|
|
480
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/group/updateParticipant/${args?.instance}?groupJid=${args?.groupJid}`, { action: args?.action, participants: args?.participants }), null, 2) }] };
|
|
481
|
+
case "fetch_group_invite_code":
|
|
482
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("GET", `/group/inviteCode/${args?.instance}?groupJid=${args?.groupJid}`), null, 2) }] };
|
|
483
|
+
case "mark_message_as_read":
|
|
484
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/markMessageAsRead/${args?.instance}`, { readMessages: args?.readMessages }), null, 2) }] };
|
|
485
|
+
case "archive_chat": {
|
|
486
|
+
const body: Record<string, unknown> = {
|
|
487
|
+
chat: args?.remoteJid,
|
|
488
|
+
archive: args?.archive,
|
|
489
|
+
};
|
|
490
|
+
if (args?.lastMessage) body.lastMessage = args.lastMessage;
|
|
491
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("POST", `/chat/archiveChat/${args?.instance}`, body), null, 2) }] };
|
|
492
|
+
}
|
|
493
|
+
case "delete_message": {
|
|
494
|
+
const body: Record<string, unknown> = {
|
|
495
|
+
id: args?.id,
|
|
496
|
+
remoteJid: args?.remoteJid,
|
|
497
|
+
fromMe: args?.fromMe,
|
|
498
|
+
};
|
|
499
|
+
if (args?.participant) body.participant = args.participant;
|
|
500
|
+
return { content: [{ type: "text", text: JSON.stringify(await evolutionRequest("DELETE", `/chat/deleteMessageForEveryone/${args?.instance}`, body), null, 2) }] };
|
|
501
|
+
}
|
|
317
502
|
default:
|
|
318
503
|
return { content: [{ type: "text", text: `Unknown tool: ${name}` }], isError: true };
|
|
319
504
|
}
|
|
@@ -336,7 +521,7 @@ async function main() {
|
|
|
336
521
|
if (!sid && isInitializeRequest(req.body)) {
|
|
337
522
|
const t = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID(), onsessioninitialized: (id) => { transports.set(id, t); } });
|
|
338
523
|
t.onclose = () => { if (t.sessionId) transports.delete(t.sessionId); };
|
|
339
|
-
const s = new Server({ name: "mcp-evolution-api", version: "0.
|
|
524
|
+
const s = new Server({ name: "mcp-evolution-api", version: "0.2.0" }, { capabilities: { tools: {} } }); (server as any)._requestHandlers.forEach((v: any, k: any) => (s as any)._requestHandlers.set(k, v)); (server as any)._notificationHandlers?.forEach((v: any, k: any) => (s as any)._notificationHandlers.set(k, v)); await s.connect(t);
|
|
340
525
|
await t.handleRequest(req, res, req.body); return;
|
|
341
526
|
}
|
|
342
527
|
res.status(400).json({ jsonrpc: "2.0", error: { code: -32000, message: "Bad Request" }, id: null });
|