From e0bef23eab9e44c3809495b5984d418de0200af0 Mon Sep 17 00:00:00 2001 From: bipproduction Date: Fri, 14 Nov 2025 10:19:44 +0800 Subject: [PATCH] tambahannnya --- src/server/routes/mcp_route.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/routes/mcp_route.ts b/src/server/routes/mcp_route.ts index 4dcec4b..eaf2a1b 100644 --- a/src/server/routes/mcp_route.ts +++ b/src/server/routes/mcp_route.ts @@ -2,7 +2,7 @@ import { Elysia } from "elysia"; import { getMcpTools } from "../lib/mcp_tool_convert"; var tools = [] as any[]; -const OPENAPI_URL = process.env.BUN_PUBLIC_BASE_URL+"/docs/json"; +const OPENAPI_URL = process.env.BUN_PUBLIC_BASE_URL + "/docs/json"; const FILTER_TAG = "mcp"; if (!process.env.BUN_PUBLIC_BASE_URL) { @@ -118,16 +118,16 @@ async function handleMCPRequestAsync( const baseUrl = process.env.BUN_PUBLIC_BASE_URL || "http://localhost:3000"; const result = await executeTool(tool, params?.arguments || {}, baseUrl); + const isObject = typeof result === "object" && result !== null; return { jsonrpc: "2.0", id, result: { content: [ - { - type: "text", - text: JSON.stringify(result, null, 2), - }, + isObject + ? { type: "json", data: result } // prefer JSON jika client support + : { type: "text", text: String(result) }, ], }, }; @@ -194,7 +194,7 @@ export const MCPRoute = new Elysia({ // Tools list (debug) .get("/mcp/tools", async ({ set }) => { if (!tools.length) { - + tools = await getMcpTools(OPENAPI_URL, FILTER_TAG); } set.headers["Access-Control-Allow-Origin"] = "*";