From c3863d845f1a065d70e5f6737e8bd46840e0cfe2 Mon Sep 17 00:00:00 2001 From: bipproduction Date: Tue, 18 Nov 2025 10:11:09 +0800 Subject: [PATCH] build --- src/nodes/OpenapiMcpServer.ts | 38 ++++++++++++++++------------------- x.json | 18 +++++++++++++++++ 2 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 x.json diff --git a/src/nodes/OpenapiMcpServer.ts b/src/nodes/OpenapiMcpServer.ts index 1f50202..1a52ced 100644 --- a/src/nodes/OpenapiMcpServer.ts +++ b/src/nodes/OpenapiMcpServer.ts @@ -19,7 +19,6 @@ const toolsCache = new Map(); async function loadTools(openapiUrl: string, filterTag: string, forceRefresh = false): Promise { const cacheKey = `${openapiUrl}::${filterTag}`; - // Jika tidak forceRefresh, gunakan cache if (!forceRefresh && toolsCache.has(cacheKey)) { return toolsCache.get(cacheKey)!; } @@ -27,12 +26,9 @@ async function loadTools(openapiUrl: string, filterTag: string, forceRefresh = f console.log(`[MCP] 🔄 Refreshing tools from ${openapiUrl} ...`); const fetched = await getMcpTools(openapiUrl, filterTag); - // 🟢 Log jumlah & daftar tools console.log(`[MCP] ✅ Loaded ${fetched.length} tools`); if (fetched.length > 0) { - console.log( - `[MCP] Tools: ${fetched.map((t: any) => t.name).join(", ")}` - ); + console.log(`[MCP] Tools: ${fetched.map((t: any) => t.name).join(", ")}`); } toolsCache.set(cacheKey, fetched); @@ -104,7 +100,7 @@ async function executeTool( } // ====================================================== -// JSON-RPC Handler (per node, per request) +// JSON-RPC Handler // ====================================================== async function handleMCPRequest( request: JSONRPCRequest, @@ -181,7 +177,7 @@ async function handleMCPRequest( result: { content: [ isObject - ? { type: "json", data: data } + ? { type: "json", data } : { type: "text", text: JSON.stringify(data || result.data || result) }, ], }, @@ -208,7 +204,7 @@ async function handleMCPRequest( } // ====================================================== -// NODE MCP TRIGGER +// MCP TRIGGER NODE // ====================================================== export class OpenapiMcpServer implements INodeType { description: INodeTypeDescription = { @@ -255,27 +251,25 @@ export class OpenapiMcpServer implements INodeType { default: "", placeholder: "mcp | tag", }, - // 🟢 Tambahan agar terlihat jumlah tools di UI { displayName: 'Available Tools (auto-refresh)', name: 'toolList', type: 'options', typeOptions: { loadOptionsMethod: 'refreshToolList', - refreshOnOpen: true, // setiap node dibuka auto refresh + refreshOnOpen: true, }, - default: '', + default: 'all', description: 'Daftar tools yang berhasil dimuat dari OpenAPI', }, ], }; // ================================================== - // LoadOptions untuk tampil di dropdown + // LoadOptions // ================================================== methods = { loadOptions: { - // 🟢 otomatis refetch setiap kali node dibuka async refreshToolList(this: ILoadOptionsFunctions): Promise { const openapiUrl = this.getNodeParameter("openapiUrl", 0) as string; const filterTag = this.getNodeParameter("defaultFilter", 0) as string; @@ -284,25 +278,27 @@ export class OpenapiMcpServer implements INodeType { return [{ name: "❌ No OpenAPI URL provided", value: "" }]; } - const tools = await loadTools(openapiUrl, filterTag, true); // force refresh + const tools = await loadTools(openapiUrl, filterTag, true); - return tools.map((t) => ({ - name: t.name, - value: t.name, - description: t.description, - })); + return [ + { name: "All Tools", value: "all" }, + ...tools.map((t) => ({ + name: t.name, + value: t.name, + description: t.description, + })), + ]; }, }, }; // ================================================== - // WEBHOOK HANDLER + // Webhook Handler // ================================================== async webhook(this: IWebhookFunctions): Promise { const openapiUrl = this.getNodeParameter("openapiUrl", 0) as string; const filterTag = this.getNodeParameter("defaultFilter", 0) as string; - // 🟢 selalu refresh (agar node terbaru) const tools = await loadTools(openapiUrl, filterTag, true); const creds = await this.getCredentials("openapiMcpServerCredentials") as { diff --git a/x.json b/x.json new file mode 100644 index 0000000..a1d3bfe --- /dev/null +++ b/x.json @@ -0,0 +1,18 @@ +{ + "model": "gpt-4.1", + "tools": [ + { + "type": "web_search_preview" + } + ], + "input": [ + { + "role": "system", + "content": "Kamu adalah AI agent yang hanya menjawab berdasarkan tools websearch preview berdasarkan tag [indonesia, bali, badung, abiansemal, darmasaba, 2025], jika tidak menggunakan , jangan menjawab selain hasil dari tools , dilarang percakapan basabasi , jika tidak ada hasil dari tool cukup jawab dengan \"\" jika ada hasil dari tool gunakan format berikut # LAPORAN WEB PREVIEW AGENT\n\n" + }, + { + "role": "user", + "content": "{{ $('map_data').item.json.message_text }}" + } + ] +}