Refactor MCP resources to tools, add chat deletion
This commit implements two main changes based on your feedback:
1. Refactors all Model Context Protocol (MCP) resources into tools:
- In `whatsappIntegration.js`:
- `whatsapp.chat` (resource) -> `whatsapp.list-chats` (tool) & `whatsapp.get-chat-details` (tool)
- `whatsapp.contact` (resource) -> `whatsapp.get-contact-details` (tool)
- `whatsapp.blocklist` (resource) -> `whatsapp.get-blocklist` (tool)
- In `conversationIntegration.js`:
- `conversation` (resource) -> `conversation.list-conversations` (tool) & `conversation.get-conversation-details` (tool)
This change aligns with current Gemini SDK capabilities for MCP.
2. Implements chat deletion functionality:
- In `whatsapp-router`:
- Added `deleteChat` function to `whatsappClient.ts`. This function calls an assumed OpenWA endpoint (`POST /deleteChat`) and will require verification against the actual OpenWA API.
- Added a `DELETE /chats/:chatId` route to `whatsappActions.ts` that utilizes the new `deleteChat` client function.
- In `conversation-layer-mcp`:
- Added a new `whatsapp.delete-chat` tool to `whatsappIntegration.js`. This tool calls the new `DELETE /chats/:chatId` endpoint in `whatsapp-router`.
Additionally, the existing `conversation.delete` MCP tool was verified to be correctly implemented.
This commit is contained in:
69
mcp/modules/conversationIntegration.js
Normal file
69
mcp/modules/conversationIntegration.js
Normal file
@@ -0,0 +1,69 @@
|
||||
// mcp/modules/conversationIntegration.js
|
||||
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { z } from "zod";
|
||||
import { fetchJSON } from "../lib/api.js";
|
||||
|
||||
const log = (...args) => console.log("[MCP ConversationIntegration]", ...args); // Changed log prefix
|
||||
|
||||
export default function registerConversationIntegration(server) {
|
||||
// --- Conversation Actions ---
|
||||
|
||||
// Tool: conversation.list-conversations
|
||||
server.tool(
|
||||
"conversation.list-conversations",
|
||||
"Retrieves a list of all conversations.",
|
||||
{}, // No input parameters
|
||||
async () => {
|
||||
log("Tool invoked", "conversation.list-conversations");
|
||||
const result = await fetchJSON("/conversations");
|
||||
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
||||
}
|
||||
);
|
||||
|
||||
// Tool: conversation.get-conversation-details
|
||||
server.tool(
|
||||
"conversation.get-conversation-details",
|
||||
"Retrieves details for a specific conversation by its ID.",
|
||||
{
|
||||
id: z.string().describe("ID of the conversation"),
|
||||
},
|
||||
async (params) => {
|
||||
log("Tool invoked", "conversation.get-conversation-details", params);
|
||||
const result = await fetchJSON(`/conversations/${params.id}`);
|
||||
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
||||
}
|
||||
);
|
||||
|
||||
// Tool: conversation.update
|
||||
server.tool(
|
||||
"conversation.update",
|
||||
"Updates/rebuilds a conversation by its ID.",
|
||||
{
|
||||
id: z.string().describe("ID of the conversation to update"),
|
||||
},
|
||||
async (params) => {
|
||||
log("Tool invoked", "conversation.update", params);
|
||||
const result = await fetchJSON(`/conversations/${params.id}/update`, {
|
||||
method: "POST",
|
||||
// No body needed for this specific route as per analysis
|
||||
});
|
||||
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
||||
}
|
||||
);
|
||||
|
||||
// Tool: conversation.delete
|
||||
server.tool(
|
||||
"conversation.delete",
|
||||
"Deletes a conversation by its ID.",
|
||||
{
|
||||
id: z.string().describe("ID of the conversation to delete"),
|
||||
},
|
||||
async (params) => {
|
||||
log("Tool invoked", "conversation.delete", params);
|
||||
const result = await fetchJSON(`/conversations/${params.id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user