This commit is contained in:
bipproduction
2025-11-20 10:17:18 +08:00
parent 69eed4d73a
commit db3561b6bf
2 changed files with 56 additions and 7 deletions

View File

@@ -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 { try {
const baseUrl = credentials?.baseUrl; const baseUrl = credentials?.baseUrl;
const token = credentials?.token; const token = credentials?.token;
@@ -216,17 +268,13 @@ async function handleMCPRequest(
token token
); );
const content = result.data?.data ?? result.data; const raw = result.data?.data ?? result.data;
return { return {
jsonrpc: "2.0", jsonrpc: "2.0",
id, id,
result: { result: {
content: [ content: [convertToMcpContent(raw)],
typeof content === "object"
? { type: "json", data: content }
: { type: "text", text: JSON.stringify(content) },
],
}, },
}; };
} catch (err: any) { } catch (err: any) {
@@ -238,6 +286,7 @@ async function handleMCPRequest(
} }
} }
case "ping": case "ping":
return { jsonrpc: "2.0", id, result: {} }; return { jsonrpc: "2.0", id, result: {} };

View File

@@ -1,6 +1,6 @@
{ {
"name": "n8n-nodes-openapi-mcp-server", "name": "n8n-nodes-openapi-mcp-server",
"version": "1.1.25", "version": "1.1.26",
"keywords": [ "keywords": [
"n8n", "n8n",
"n8n-nodes" "n8n-nodes"