{"version":3,"sources":["jsdelivr-header.js","/npm/n8n-nodes-mcp-client@0.2.12/dist/nodes/McpClient.node.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aACA,IAAI,gBAAmB,MAAQ,KAAK,iBAAoB,SAAU,GAC9D,OAAQ,GAAO,EAAI,WAAc,EAAM,CAAE,QAAW,EACxD,EACA,OAAO,eAAe,QAAS,aAAc,CAAE,OAAO,IACtD,QAAQ,eAAY,EAEpB,MAAM,eAAiB,QAAQ,gBACzB,QAAU,gBAAgB,QAAQ,UAElC,YAAc,QAAQ,eAC5B,MAAM,UACF,WAAA,GACI,KAAK,YAAc,CACf,YAAa,mBACb,KAAM,YACN,MAAO,CAAC,SACR,QAAS,EACT,YAAa,qHACb,SAAU,CACN,KAAM,mBACN,MAAO,WAEX,OAAQ,GACR,QAAS,CAAC,QACV,KAAM,2BACN,cAAc,EACd,YAAa,CACT,CACI,KAAM,eACN,UAAU,EACV,YAAa,qBAGrB,WAAY,CACR,CACI,YAAa,YACb,KAAM,WACN,KAAM,UACN,QAAS,CACL,CACI,KAAM,iBACN,MAAO,WACP,YAAa,uDAEjB,CACI,KAAM,eACN,MAAO,UACP,YAAa,qCAGrB,QAAS,WACT,YAAa,sDAEjB,CACI,YAAa,YACb,KAAM,WACN,KAAM,SACN,QAAS,GACT,YAAa,4DACb,UAAU,EACV,eAAgB,CACZ,KAAM,CACF,SAAU,CAAC,aAGnB,YAAa,CACT,iBAAiB,IAGzB,CACI,YAAa,kBACb,KAAM,iBACN,KAAM,OACN,QAAS,KACT,YAAa,6CACb,UAAU,EACV,eAAgB,CACZ,KAAM,CACF,SAAU,CAAC,aAGnB,YAAa,CACT,iBAAiB,IAGzB,CACI,YAAa,+BACb,KAAM,kBACN,KAAM,OACN,QAAS,KACT,YAAa,0GACb,UAAU,IAI1B,CACA,aAAM,GACF,MAAM,QAAoB,KAAK,eAAe,iBACxC,OAAE,EAAM,WAAE,EAAU,QAAE,EAAO,gBAA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EZ,EAAS,IACpB,CACA,MAAO,GACH,QAAQ,MAAM,gCAAiC,CAC3C,MAAO,EAAM,QACb,SAAU,EAAM,UAAU,KAC1B,OAAQ,EAAM,UAAU,OACxB,WAAY,EAAM,UAAU,aAEhC,IAAI,EAAe,qBAUnB,MATI,EAAM,UAAU,MAAM,QACtB,GAAgB,EAAM,SAAS,KAAK,QAE/B,EAAM,UAAU,WACrB,GAAgB,GAAG,EAAM,SAAS,UAAU,EAAM,SAAS,aAG3D,GAAgB,EAAM,QAEpB,IAAI,eAAe,mBAAmB,EAAQ,UAAW,EACnE,CACJ,EAEJ,QAAQ,UAAY","file":"/npm/n8n-nodes-mcp-client@0.2.12/dist/nodes/McpClient.node.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/n8n-nodes-mcp-client@0.2.12/dist/nodes/McpClient.node.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.McpClient = void 0;\n// n8n types are resolved at runtime in the n8n environment\nconst n8n_workflow_1 = require(\"n8n-workflow\");\nconst axios_1 = __importDefault(require(\"axios\"));\n// Use require for EventSource for compatibility\nconst EventSource = require('eventsource');\nclass McpClient {\n    constructor() {\n        this.description = {\n            displayName: '4Runr MCP Client',\n            name: 'mcpClient',\n            group: ['input'],\n            version: 1,\n            description: 'Streams tool definitions from a 4Runr MCP Server via SSE. Built to power dynamic AI agents using the MCP protocol.',\n            defaults: {\n                name: '4Runr MCP Client',\n                color: '#00b894',\n            },\n            inputs: [],\n            outputs: [\"main\" /* NodeConnectionType.Main */],\n            icon: 'file:images/n8n4Runr.svg',\n            usableAsTool: true,\n            credentials: [\n                {\n                    name: 'McpClientApi',\n                    required: true,\n                    displayName: '4Runr MCP Access',\n                },\n            ],\n            properties: [\n                {\n                    displayName: 'Node Mode',\n                    name: 'nodeMode',\n                    type: 'options',\n                    options: [\n                        {\n                            name: 'Discover Tools',\n                            value: 'discover',\n                            description: 'Stream and list available tools from the MCP server',\n                        },\n                        {\n                            name: 'Execute Tool',\n                            value: 'execute',\n                            description: 'Execute a tool on the MCP server',\n                        },\n                    ],\n                    default: 'discover',\n                    description: 'Choose whether to discover tools or execute a tool',\n                },\n                {\n                    displayName: 'Tool Name',\n                    name: 'toolName',\n                    type: 'string',\n                    default: '',\n                    description: 'Name of the tool to execute (as received from the server)',\n                    required: false,\n                    displayOptions: {\n                        show: {\n                            nodeMode: ['execute'],\n                        },\n                    },\n                    typeOptions: {\n                        allowExpression: true,\n                    },\n                },\n                {\n                    displayName: 'Tool Parameters',\n                    name: 'toolParameters',\n                    type: 'json',\n                    default: '{}',\n                    description: 'Parameters for the selected tool (as JSON)',\n                    required: false,\n                    displayOptions: {\n                        show: {\n                            nodeMode: ['execute'],\n                        },\n                    },\n                    typeOptions: {\n                        allowExpression: true,\n                    },\n                },\n                {\n                    displayName: 'Tool Name Mapping (Optional)',\n                    name: 'toolNameMapping',\n                    type: 'json',\n                    default: '{}',\n                    description: 'Optional mapping of tool names to aliases (e.g., {\"calendar.check_availability\": \"Check Availability\"})',\n                    required: false,\n                },\n            ],\n        };\n    }\n    async execute() {\n        const credentials = await this.getCredentials('McpClientApi');\n        const { sseUrl, sseTimeout, headers, messageEndpoint } = credentials;\n        const nodeMode = this.getNodeParameter('nodeMode', 0);\n        console.log(`[McpClient] Starting execution with config:`, {\n            sseUrl,\n            sseTimeout,\n            messageEndpoint,\n            nodeMode,\n            hasHeaders: !!headers\n        });\n        if (nodeMode === 'discover') {\n            return new Promise((resolve, reject) => {\n                const eventSourceOptions = {};\n                if (headers) {\n                    try {\n                        const parsedHeaders = typeof headers === 'string' ? JSON.parse(headers) : headers;\n                        eventSourceOptions.headers = parsedHeaders;\n                        console.log('[McpClient] Using headers:', parsedHeaders);\n                    }\n                    catch (err) {\n                        console.error('[McpClient] Failed to parse headers:', err);\n                        throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to parse headers: ' + err.message);\n                    }\n                }\n                console.log(`[McpClient] Connecting to SSE: ${sseUrl}`);\n                const eventSource = new EventSource(sseUrl, eventSourceOptions);\n                let timeoutId;\n                if (sseTimeout) {\n                    timeoutId = setTimeout(() => {\n                        console.error('[McpClient] SSE connection timed out after', sseTimeout, 'ms');\n                        eventSource.close();\n                        reject(new n8n_workflow_1.NodeOperationError(this.getNode(), `SSE connection timed out after ${sseTimeout}ms`));\n                    }, sseTimeout);\n                }\n                eventSource.onopen = () => {\n                    if (timeoutId)\n                        clearTimeout(timeoutId);\n                    console.log('[McpClient] SSE connection opened successfully');\n                };\n                eventSource.onerror = (err) => {\n                    console.error('[McpClient] SSE connection error:', err);\n                    eventSource.close();\n                    reject(new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to connect to SSE endpoint: ' + err.message));\n                };\n                eventSource.onmessage = (event) => {\n                    console.log('[McpClient] Received message event:', {\n                        type: event.type,\n                        data: event.data,\n                        lastEventId: event.lastEventId\n                    });\n                };\n                eventSource.addEventListener('tools', (event) => {\n                    console.log('[McpClient] Received tools event:', {\n                        data: event.data,\n                        lastEventId: event.lastEventId\n                    });\n                    try {\n                        const parsed = JSON.parse(event.data);\n                        console.log('[McpClient] Parsed tools data:', parsed);\n                        if (!parsed.tools || !Array.isArray(parsed.tools)) {\n                            throw new Error('Invalid tools data: missing or invalid tools array');\n                        }\n                        let tools = parsed.tools.map((tool) => {\n                            console.log('[McpClient] Processing tool:', tool);\n                            return {\n                                name: tool.name,\n                                description: tool.description,\n                                parameters: tool.parameters || {},\n                            };\n                        });\n                        console.log(`[McpClient] Emitting ${tools.length} tools:`, tools);\n                        eventSource.close();\n                        resolve([this.helpers.returnJsonArray(tools)]);\n                    }\n                    catch (err) {\n                        console.error('[McpClient] Failed to process tools event:', err);\n                        eventSource.close();\n                        reject(new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to process tools event: ' + err.message));\n                    }\n                });\n            });\n        }\n        else if (nodeMode === 'execute') {\n            const toolName = this.getNodeParameter('toolName', 0);\n            const toolParameters = this.getNodeParameter('toolParameters', 0);\n            console.log('[McpClient] Executing tool:', { toolName, toolParameters });\n            const result = await McpClient.executeToolCall(this, toolName, toolParameters, credentials);\n            return [this.helpers.returnJsonArray([result])];\n        }\n        else {\n            throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown node mode: ${nodeMode}`);\n        }\n    }\n    // --- Tool Execution Logic ---\n    /**\n     * Executes a tool call by POSTing to the MCP server's message endpoint.\n     * Throws a clear error if toolName or parameters are missing/invalid.\n     */\n    static async executeToolCall(context, toolName, parameters, credentials) {\n        const { messageEndpoint, headers } = credentials;\n        console.log('[McpClient] Executing tool call:', {\n            toolName,\n            parameters,\n            messageEndpoint,\n            hasHeaders: !!headers\n        });\n        if (!toolName || typeof toolName !== 'string') {\n            throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'Tool name is required and must be a string.');\n        }\n        if (!parameters || typeof parameters !== 'object') {\n            throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'Tool parameters are required and must be an object.');\n        }\n        const payload = {\n            toolCall: {\n                toolName,\n                parameters,\n            },\n        };\n        console.log('[McpClient] Preparing POST request:', {\n            url: messageEndpoint,\n            payload\n        });\n        const axiosConfig = {\n            headers: {\n                'Content-Type': 'application/json',\n                ...(headers ? (typeof headers === 'string' ? JSON.parse(headers) : headers) : {}),\n            },\n        };\n        try {\n            console.log('[McpClient] Sending POST request...');\n            const response = await axios_1.default.post(messageEndpoint, payload, axiosConfig);\n            console.log('[McpClient] Received response:', {\n                status: response.status,\n                statusText: response.statusText,\n                data: response.data\n            });\n            return response.data;\n        }\n        catch (error) {\n            console.error('[McpClient] Tool call failed:', {\n                error: error.message,\n                response: error.response?.data,\n                status: error.response?.status,\n                statusText: error.response?.statusText\n            });\n            let errorMessage = 'Tool call failed: ';\n            if (error.response?.data?.message) {\n                errorMessage += error.response.data.message;\n            }\n            else if (error.response?.statusText) {\n                errorMessage += `${error.response.status} ${error.response.statusText}`;\n            }\n            else {\n                errorMessage += error.message;\n            }\n            throw new n8n_workflow_1.NodeOperationError(context.getNode(), errorMessage);\n        }\n    }\n}\nexports.McpClient = McpClient;\n"]}