From e33e7a2a87d82b66414c25f078d537715ca997da Mon Sep 17 00:00:00 2001 From: bipproduction Date: Mon, 27 Oct 2025 02:37:51 +0800 Subject: [PATCH] tambahan --- src/server/routes/mcp_route.ts | 74 ++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/server/routes/mcp_route.ts b/src/server/routes/mcp_route.ts index 6fb017d..c5bc1f8 100644 --- a/src/server/routes/mcp_route.ts +++ b/src/server/routes/mcp_route.ts @@ -1,42 +1,48 @@ import { Elysia } from "elysia"; -const tools = [ - { - name: "pengajuan-pembuatan-ktp", - value: "pengajuan-pembuatan-ktp", - description: "untuk melakukan pengajuan pembuatan ktp\nmembutuhkan :\n- jenis\n- name\n- deskripsi", - inputSchema: { - type: "object", - properties: { JSON: {} }, - required: ["JSON"], - additionalProperties: true, - $schema: "http://json-schema.org/draft-07/schema#" - } - }, - { - name: "list-layanan-desa-darmasaba", - value: "list-layanan-desa-darmasaba", - description: "mendapatkan list layanan desa darmasaba", - inputSchema: { - type: "object", - properties: {}, - additionalProperties: true, - $schema: "http://json-schema.org/draft-07/schema#" - } - } -]; - const MCPRoute = new Elysia() - .post("/mcp", async ({ body, set }) => { - set.headers["Content-Type"] = "application/json; charset=utf-8"; + .get("/mcp", ({ set }) => { + set.headers["Content-Type"] = "application/json; charset=utf-8"; + return { + jsonrpc: "2.0", + id: null, + result: { + protocol: "2024-11-05", + capabilities: { + "tools/list": true, + "tools/call": true, + }, + status: "MCP Server Ready", + }, + }; + }) + .post("/mcp", async ({ body, set }) => { + set.headers["Content-Type"] = "application/json; charset=utf-8"; - const { methodName } = body as { methodName: string }; + const { id, method, params } = body as { id: string; method: string; params: any }; - if (methodName === "getTools") { - return { data: tools }; // ✅ sesuai format yang n8n minta - } + if (method === "getTools") { + return { + jsonrpc: "2.0", + id, + result: { + tools: [ + { name: "sayHello", description: "Returns a greeting" }, + { name: "getTime", description: "Current server time" }, + ], + }, + }; + } - return { error: "Unsupported method" }; - }); + // Default jika method salah + return { + jsonrpc: "2.0", + id, + error: { + code: -32601, + message: `Method ${method} not found`, + }, + }; + }); export default MCPRoute; \ No newline at end of file