From db3561b6bf64d447d565ce25ff7381f6f9a4d149 Mon Sep 17 00:00:00 2001 From: bipproduction Date: Thu, 20 Nov 2025 10:17:18 +0800 Subject: [PATCH] build --- src/nodes/OpenapiMcpServer.ts | 61 +++++++++++++++++++++++++++++++---- src/package.json | 2 +- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/nodes/OpenapiMcpServer.ts b/src/nodes/OpenapiMcpServer.ts index f84e399..e98b571 100644 --- a/src/nodes/OpenapiMcpServer.ts +++ b/src/nodes/OpenapiMcpServer.ts @@ -205,6 +205,58 @@ async function handleMCPRequest( }; } + // Converter MCP content yang valid + function convertToMcpContent(data: any) { + // Jika string → text + if (typeof data === "string") { + return { + type: "text", + text: data, + }; + } + + // Jika kirim tipe khusus image + if (data?.__mcp_type === "image") { + return { + type: "image", + data: data.base64, + mimeType: data.mimeType || "image/png", + }; + } + + // Jika audio + if (data?.__mcp_type === "audio") { + return { + type: "audio", + data: data.base64, + mimeType: data.mimeType || "audio/mpeg", + }; + } + + // Jika resource link + if (data?.__mcp_type === "resource_link") { + return { + type: "resource_link", + name: data.name || "resource", + uri: data.uri, + }; + } + + // Jika object biasa → jadikan resource + if (typeof data === "object") { + return { + type: "resource", + resource: data, + }; + } + + // fallback → text stringified + return { + type: "text", + text: JSON.stringify(data, null, 2), + }; + } + try { const baseUrl = credentials?.baseUrl; const token = credentials?.token; @@ -216,17 +268,13 @@ async function handleMCPRequest( token ); - const content = result.data?.data ?? result.data; + const raw = result.data?.data ?? result.data; return { jsonrpc: "2.0", id, result: { - content: [ - typeof content === "object" - ? { type: "json", data: content } - : { type: "text", text: JSON.stringify(content) }, - ], + content: [convertToMcpContent(raw)], }, }; } catch (err: any) { @@ -238,6 +286,7 @@ async function handleMCPRequest( } } + case "ping": return { jsonrpc: "2.0", id, result: {} }; diff --git a/src/package.json b/src/package.json index 193e6bc..2946e11 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "n8n-nodes-openapi-mcp-server", - "version": "1.1.25", + "version": "1.1.26", "keywords": [ "n8n", "n8n-nodes"