// 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) }] }; } ); }