n8n-nodes-browser-smart-automation 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/McpClient/McpClient.node.js +333 -0
- package/dist/McpClient/McpClient.node.js.map +1 -0
- package/dist/McpClient/listSearch.js +58 -0
- package/dist/McpClient/listSearch.js.map +1 -0
- package/dist/McpClient/resourceMapping.js +61 -0
- package/dist/McpClient/resourceMapping.js.map +1 -0
- package/dist/McpClient/utils.js +248 -0
- package/dist/McpClient/utils.js.map +1 -0
- package/dist/McpClientTool/McpClientTool.node.js +417 -0
- package/dist/McpClientTool/McpClientTool.node.js.map +1 -0
- package/dist/McpClientTool/loadOptions.js +61 -0
- package/dist/McpClientTool/loadOptions.js.map +1 -0
- package/dist/McpClientTool/types.js +17 -0
- package/dist/McpClientTool/types.js.map +1 -0
- package/dist/McpClientTool/utils.js +120 -0
- package/dist/McpClientTool/utils.js.map +1 -0
- package/dist/McpTrigger/FlushingTransport.js +61 -0
- package/dist/McpTrigger/FlushingTransport.js.map +1 -0
- package/dist/McpTrigger/McpServer.js +246 -0
- package/dist/McpTrigger/McpServer.js.map +1 -0
- package/dist/McpTrigger/McpTrigger.node.js +196 -0
- package/dist/McpTrigger/McpTrigger.node.js.map +1 -0
- package/dist/shared/descriptions.js +89 -0
- package/dist/shared/descriptions.js.map +1 -0
- package/dist/shared/helpers.js +47 -0
- package/dist/shared/helpers.js.map +1 -0
- package/dist/shared/httpProxyAgent.js +31 -0
- package/dist/shared/httpProxyAgent.js.map +1 -0
- package/dist/shared/logWrapper.js +31 -0
- package/dist/shared/logWrapper.js.map +1 -0
- package/dist/shared/schemaParsing.js +32 -0
- package/dist/shared/schemaParsing.js.map +1 -0
- package/dist/shared/sharedFields.js +41 -0
- package/dist/shared/sharedFields.js.map +1 -0
- package/dist/shared/types.js +17 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/utils.js +231 -0
- package/dist/shared/utils.js.map +1 -0
- package/jest.config.js +24 -0
- package/nodes/McpClient/McpClient.node.ts +327 -0
- package/nodes/McpClient/__test__/McpClient.node.test.ts +221 -0
- package/nodes/McpClient/__test__/utils.test.ts +302 -0
- package/nodes/McpClient/listSearch.ts +48 -0
- package/nodes/McpClient/resourceMapping.ts +48 -0
- package/nodes/McpClient/utils.ts +281 -0
- package/nodes/McpClientTool/McpClientTool.node.ts +468 -0
- package/nodes/McpClientTool/__test__/McpClientTool.node.test.ts +730 -0
- package/nodes/McpClientTool/loadOptions.ts +45 -0
- package/nodes/McpClientTool/types.ts +1 -0
- package/nodes/McpClientTool/utils.ts +116 -0
- package/nodes/McpTrigger/FlushingTransport.ts +61 -0
- package/nodes/McpTrigger/McpServer.ts +317 -0
- package/nodes/McpTrigger/McpTrigger.node.ts +204 -0
- package/nodes/McpTrigger/__test__/FlushingTransport.test.ts +102 -0
- package/nodes/McpTrigger/__test__/McpServer.test.ts +532 -0
- package/nodes/McpTrigger/__test__/McpTrigger.node.test.ts +171 -0
- package/nodes/mcp.dark.svg +7 -0
- package/nodes/mcp.svg +7 -0
- package/nodes/shared/__test__/utils.test.ts +318 -0
- package/nodes/shared/descriptions.ts +65 -0
- package/nodes/shared/helpers.ts +31 -0
- package/nodes/shared/httpProxyAgent.ts +11 -0
- package/nodes/shared/logWrapper.ts +13 -0
- package/nodes/shared/schemaParsing.ts +9 -0
- package/nodes/shared/sharedFields.ts +20 -0
- package/nodes/shared/types.ts +12 -0
- package/nodes/shared/utils.ts +296 -0
- package/officail/package.json +255 -0
- package/package.json +46 -0
- package/tsconfig.json +32 -0
- package/tsup.config.ts +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpClientTool/McpClientTool.node.ts"],"sourcesContent":["import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport {\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { getTools } from './loadOptions';\nimport type { McpToolIncludeMode } from './types';\nimport { createCallTool, getSelectedTools, McpToolkit, mcpToolToDynamicTool } from './utils';\nimport { credentials, transportSelect } from '../shared/descriptions';\nimport type { McpAuthenticationOption, McpServerTransport } from '../shared/types';\nimport {\n\tconnectMcpClient,\n\tgetAllTools,\n\tgetAuthHeaders,\n\tmapToNodeOperationError,\n\ttryRefreshOAuth2Token,\n} from '../shared/utils';\n\n/**\n * Get node parameters for MCP client configuration\n */\nfunction getNodeConfig(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): {\n\tauthentication: McpAuthenticationOption;\n\ttimeout: number;\n\tserverTransport: McpServerTransport;\n\tendpointUrl: string;\n\tcdp_endpointUrl?: string;\n\tmode: McpToolIncludeMode;\n\tincludeTools: string[];\n\texcludeTools: string[];\n} {\n\tconst node = ctx.getNode();\n\tconst authentication = ctx.getNodeParameter(\n\t\t'authentication',\n\t\titemIndex,\n\t) as McpAuthenticationOption;\n\tconst timeout = ctx.getNodeParameter('options.timeout', itemIndex, 60000) as number;\n\n\tlet serverTransport: McpServerTransport;\n\tlet endpointUrl: string;\n\tif (node.typeVersion === 1) {\n\t\tserverTransport = 'sse';\n\t\tendpointUrl = ctx.getNodeParameter('sseEndpoint', itemIndex) as string;\n\t} else {\n\t\tserverTransport = ctx.getNodeParameter('serverTransport', itemIndex) as McpServerTransport;\n\t\tendpointUrl = ctx.getNodeParameter('endpointUrl', itemIndex) as string;\n\t}\n\n\tconst mode = ctx.getNodeParameter('include', itemIndex) as McpToolIncludeMode;\n\tconst includeTools = ctx.getNodeParameter('includeTools', itemIndex, []) as string[];\n\tconst excludeTools = ctx.getNodeParameter('excludeTools', itemIndex, []) as string[];\n\n\treturn {\n\t\tauthentication,\n\t\ttimeout,\n\t\tserverTransport,\n\t\tendpointUrl,\n\t\tmode,\n\t\tincludeTools,\n\t\texcludeTools,\n\t};\n}\n\n/**\n * Connect to MCP server and get filtered tools\n */\nasync function connectAndGetTools(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tconfig: ReturnType<typeof getNodeConfig>,\n) {\n\tconst node = ctx.getNode();\n\tconst { headers } = await getAuthHeaders(ctx, config.authentication);\n\n\tconst client = await connectMcpClient({\n\t\tserverTransport: config.serverTransport,\n\t\tendpointUrl: config.endpointUrl,\n\t\theaders,\n\t\tname: node.type,\n\t\tversion: node.typeVersion,\n\t\tonUnauthorized: async (headers) =>\n\t\t\tawait tryRefreshOAuth2Token(ctx, config.authentication, headers),\n\t});\n\n\tif (!client.ok) {\n\t\treturn { client, mcpTools: null, error: client.error };\n\t}\n\n\tconst allTools = await getAllTools(client.result);\n\tconst mcpTools = getSelectedTools({\n\t\ttools: allTools,\n\t\tmode: config.mode,\n\t\tincludeTools: config.includeTools,\n\t\texcludeTools: config.excludeTools,\n\t});\n\n\treturn { client: client.result, mcpTools, error: null };\n}\n\nexport class McpClientTool implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MCP Client Tool',\n\t\tname: 'mcpClientTool',\n\t\ticon: {\n\t\t\tlight: 'file:../mcp.svg',\n\t\t\tdark: 'file:../mcp.dark.svg',\n\t\t},\n\t\tgroup: ['output'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdescription: 'Connect tools from an MCP Server',\n\t\tdefaults: {\n\t\t\tname: 'MCP Client',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Model Context Protocol', 'Tools'],\n\t\t\t},\n\t\t\talias: ['Model Context Protocol', 'MCP Client'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolmcp/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [{ type: NodeConnectionTypes.AiTool, displayName: 'Tools' }],\n\t\tcredentials,\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'SSE Endpoint',\n\t\t\t\tname: 'sseEndpoint',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'SSE Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/sse',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Endpoint',\n\t\t\t\tname: 'endpointUrl',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/mcp',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'sse',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'httpStreamable',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'MCP OAuth2',\n\t\t\t\t\t\tvalue: 'mcpOAuth2Api',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Multiple Headers Auth',\n\t\t\t\t\t\tvalue: 'multipleHeadersAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Credentials',\n\t\t\t\tname: 'credentials',\n\t\t\t\ttype: 'credentials',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth', 'bearerAuth', 'mcpOAuth2Api', 'multipleHeadersAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'include',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How to select the tools you want to be exposed to the AI Agent',\n\t\t\t\tdefault: 'all',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Also include all unchanged fields from the input',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Selected',\n\t\t\t\t\t\tvalue: 'selected',\n\t\t\t\t\t\tdescription: 'Also include the tools listed in the parameter \"Tools to Include\"',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Except',\n\t\t\t\t\t\tvalue: 'except',\n\t\t\t\t\t\tdescription: 'Exclude the tools listed in the parameter \"Tools to Exclude\"',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'includeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t\tloadOptionsDependsOn: ['sseEndpoint'],\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['selected'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Exclude',\n\t\t\t\tname: 'excludeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['except'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'cdp_endpointUrl',\n\t\t\t\t\t\tname: 'cdp_endpointUrl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tminValue: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: 60000,\n\t\t\t\t\t\tdescription: 'Time in ms to wait for tool calls to finish',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tminValue: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: 60000,\n\t\t\t\t\t\tdescription: 'Time in ms to wait for tool calls to finish',\n\t\t\t\t\t}\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tloadOptions: {\n\t\t\tgetTools,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst node = this.getNode();\n\t\tconst config = getNodeConfig(this, itemIndex);\n\t\tconst setError = (error: NodeOperationError): SupplyData => {\n\t\t\tthis.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\tthrow error;\n\t\t};\n\n\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\n\t\tif (error) {\n\t\t\tthis.logger.error('McpClientTool: Failed to connect to MCP Server', { error });\n\t\t\treturn setError(mapToNodeOperationError(node, error));\n\t\t}\n\n\t\tthis.logger.debug('McpClientTool: Successfully connected to MCP Server');\n\n\t\tif (!mcpTools?.length) {\n\t\t\treturn setError(\n\t\t\t\tnew NodeOperationError(node, 'MCP Server returned no tools', {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Connected successfully to your MCP server but it returned an empty list of tools.',\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst tools = mcpTools.map((tool) =>\n\t\t\tlogWrapper(\n\t\t\t\tmcpToolToDynamicTool(\n\t\t\t\t\ttool,\n\t\t\t\t\tcreateCallTool(tool.name, client, config.timeout, (errorMessage) => {\n\t\t\t\t\t\tconst error = new NodeOperationError(node, errorMessage, { itemIndex });\n\t\t\t\t\t\tvoid this.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\t\t\t\tthis.logger.error(`McpClientTool: Tool \"${tool.name}\" failed to execute`, { error });\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tthis,\n\t\t\t),\n\t\t);\n\n\t\tthis.logger.debug(`McpClientTool: Connected to MCP Server with ${tools.length} tools`);\n\n\t\tconst toolkit = new McpToolkit(tools);\n\n\t\treturn { response: toolkit, closeFunction: async () => await client.close() };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst node = this.getNode();\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst config = getNodeConfig(this, itemIndex);\n\n\t\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\t\t\t\n\t\t\tif (error) {\n\t\t\t\tthrow new NodeOperationError(node, error.error, { itemIndex });\n\t\t\t}\n\n\t\t\tif (!mcpTools?.length) {\n\t\t\t\tthrow new NodeOperationError(node, 'MCP Server returned no tools', { itemIndex });\n\t\t\t}\n\t\t\tawait client.callTool({name:\"browser_cdp_endpoint\",arguments:{endpoint:config.cdp_endpointUrl}},CallToolResultSchema,{timeout:config.timeout});\n\n\t\t\tfor (const tool of mcpTools) {\n\t\t\t\t// Check for tool name in item.json.tool (for toolkit execution from agent)\n\t\t\t\t// or item.tool (for direct execution)\n\t\t\t\tif (!item.json.tool || typeof item.json.tool !== 'string') {\n\t\t\t\t\tthrow new NodeOperationError(node, 'Tool name not found in item.json.tool or item.tool', {\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst toolName = item.json.tool;\n\t\t\t\tif (toolName === tool.name) {\n\t\t\t\t\t// Extract the tool name from arguments before passing to MCP\n\t\t\t\t\tconst { tool: _, ...toolArguments } = item.json;\n\t\t\t\t\tconst params: {\n\t\t\t\t\t\tname: string;\n\t\t\t\t\t\targuments: IDataObject;\n\t\t\t\t\t} = {\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\targuments: toolArguments,\n\t\t\t\t};\n\t\t\t\tconst result = await client.callTool(params, CallToolResultSchema, {\n\t\t\t\t\ttimeout: config.timeout,\n\t\t\t\t});\n\t\t\t\treturnData.push({\n\t\t\t\t\tjson: {\n\t\t\t\t\t\tresponse: (result.content || result) as IDataObject,\n\t\t\t\t\t},\n\t\t\t\t\tpairedItem: {\n\t\t\t\t\t\titem: itemIndex,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn [returnData];\n}\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,0BAUO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,yBAAyB;AAEzB,mBAAmF;AACnF,0BAA6C;AAE7C,IAAAA,gBAMO;AAKP,SAAS,cACR,KACA,WAUC;AACD,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,iBAAiB,IAAI;AAAA,IAC1B;AAAA,IACA;AAAA,EACD;AACA,QAAM,UAAU,IAAI,iBAAiB,mBAAmB,WAAW,GAAK;AAExE,MAAI;AACJ,MAAI;AACJ,MAAI,KAAK,gBAAgB,GAAG;AAC3B,sBAAkB;AAClB,kBAAc,IAAI,iBAAiB,eAAe,SAAS;AAAA,EAC5D,OAAO;AACN,sBAAkB,IAAI,iBAAiB,mBAAmB,SAAS;AACnE,kBAAc,IAAI,iBAAiB,eAAe,SAAS;AAAA,EAC5D;AAEA,QAAM,OAAO,IAAI,iBAAiB,WAAW,SAAS;AACtD,QAAM,eAAe,IAAI,iBAAiB,gBAAgB,WAAW,CAAC,CAAC;AACvE,QAAM,eAAe,IAAI,iBAAiB,gBAAgB,WAAW,CAAC,CAAC;AAEvE,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAKA,eAAe,mBACd,KACA,QACC;AACD,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,QAAQ,IAAI,UAAM,8BAAe,KAAK,OAAO,cAAc;AAEnE,QAAM,SAAS,UAAM,gC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AAM,mBAAmB,MAAM,MAAM;AAEzE,UAAI,OAAO;AACV,cAAM,IAAI,uCAAmB,MAAM,MAAM,OAAO,EAAE,UAAU,CAAC;AAAA,MAC9D;AAEA,UAAI,CAAC,UAAU,QAAQ;AACtB,cAAM,IAAI,uCAAmB,MAAM,gCAAgC,EAAE,UAAU,CAAC;AAAA,MACjF;AACA,YAAM,OAAO,SAAS,EAAC,MAAK,wBAAuB,WAAU,EAAC,UAAS,OAAO,gBAAe,EAAC,GAAE,mCAAqB,EAAC,SAAQ,OAAO,QAAO,CAAC;AAE7I,iBAAW,QAAQ,UAAU;AAG5B,YAAI,CAAC,KAAK,KAAK,QAAQ,OAAO,KAAK,KAAK,SAAS,UAAU;AAC1D,gBAAM,IAAI,uCAAmB,MAAM,sDAAsD;AAAA,YACxF;AAAA,UACD,CAAC;AAAA,QACF;AAEA,cAAM,WAAW,KAAK,KAAK;AAC3B,YAAI,aAAa,KAAK,MAAM;AAE3B,gBAAM,EAAE,MAAM,GAAG,GAAG,cAAc,IAAI,KAAK;AAC3C,gBAAM,SAGF;AAAA,YACH,MAAM,KAAK;AAAA,YACX,WAAW;AAAA,UACb;AACA,gBAAM,SAAS,MAAM,OAAO,SAAS,QAAQ,mCAAsB;AAAA,YAClE,SAAS,OAAO;AAAA,UACjB,CAAC;AACD,qBAAW,KAAK;AAAA,YACf,MAAM;AAAA,cACL,UAAW,OAAO,WAAW;AAAA,YAC9B;AAAA,YACA,YAAY;AAAA,cACX,MAAM;AAAA,YACP;AAAA,UACD,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACA;","names":["import_utils","headers","error"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var loadOptions_exports = {};
|
|
20
|
+
__export(loadOptions_exports, {
|
|
21
|
+
getTools: () => getTools
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(loadOptions_exports);
|
|
24
|
+
var import_utils = require("../shared/utils");
|
|
25
|
+
async function getTools() {
|
|
26
|
+
const authentication = this.getNodeParameter("authentication");
|
|
27
|
+
const node = this.getNode();
|
|
28
|
+
let serverTransport;
|
|
29
|
+
let endpointUrl;
|
|
30
|
+
if (node.typeVersion === 1) {
|
|
31
|
+
serverTransport = "sse";
|
|
32
|
+
endpointUrl = this.getNodeParameter("sseEndpoint");
|
|
33
|
+
} else {
|
|
34
|
+
serverTransport = this.getNodeParameter("serverTransport");
|
|
35
|
+
endpointUrl = this.getNodeParameter("endpointUrl");
|
|
36
|
+
}
|
|
37
|
+
const { headers } = await (0, import_utils.getAuthHeaders)(this, authentication);
|
|
38
|
+
const client = await (0, import_utils.connectMcpClient)({
|
|
39
|
+
serverTransport,
|
|
40
|
+
endpointUrl,
|
|
41
|
+
headers,
|
|
42
|
+
name: node.type,
|
|
43
|
+
version: node.typeVersion,
|
|
44
|
+
onUnauthorized: async (headers2) => await (0, import_utils.tryRefreshOAuth2Token)(this, authentication, headers2)
|
|
45
|
+
});
|
|
46
|
+
if (!client.ok) {
|
|
47
|
+
throw (0, import_utils.mapToNodeOperationError)(node, client.error);
|
|
48
|
+
}
|
|
49
|
+
const tools = await (0, import_utils.getAllTools)(client.result);
|
|
50
|
+
return tools.map((tool) => ({
|
|
51
|
+
name: tool.name,
|
|
52
|
+
value: tool.name,
|
|
53
|
+
description: tool.description,
|
|
54
|
+
inputSchema: tool.inputSchema
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
getTools
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=loadOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpClientTool/loadOptions.ts"],"sourcesContent":["import { type ILoadOptionsFunctions, type INodePropertyOptions } from 'n8n-workflow';\n\nimport type { McpAuthenticationOption, McpServerTransport } from '../shared/types';\nimport {\n\tconnectMcpClient,\n\tgetAllTools,\n\tgetAuthHeaders,\n\tmapToNodeOperationError,\n\ttryRefreshOAuth2Token,\n} from '../shared/utils';\n\nexport async function getTools(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {\n\tconst authentication = this.getNodeParameter('authentication') as McpAuthenticationOption;\n\tconst node = this.getNode();\n\tlet serverTransport: McpServerTransport;\n\tlet endpointUrl: string;\n\tif (node.typeVersion === 1) {\n\t\tserverTransport = 'sse';\n\t\tendpointUrl = this.getNodeParameter('sseEndpoint') as string;\n\t} else {\n\t\tserverTransport = this.getNodeParameter('serverTransport') as McpServerTransport;\n\t\tendpointUrl = this.getNodeParameter('endpointUrl') as string;\n\t}\n\tconst { headers } = await getAuthHeaders(this, authentication);\n\tconst client = await connectMcpClient({\n\t\tserverTransport,\n\t\tendpointUrl,\n\t\theaders,\n\t\tname: node.type,\n\t\tversion: node.typeVersion,\n\t\tonUnauthorized: async (headers) => await tryRefreshOAuth2Token(this, authentication, headers),\n\t});\n\n\tif (!client.ok) {\n\t\tthrow mapToNodeOperationError(node, client.error);\n\t}\n\n\tconst tools = await getAllTools(client.result);\n\treturn tools.map((tool) => ({\n\t\tname: tool.name,\n\t\tvalue: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.inputSchema,\n\t}));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAMO;AAEP,eAAsB,WAAuE;AAC5F,QAAM,iBAAiB,KAAK,iBAAiB,gBAAgB;AAC7D,QAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI;AACJ,MAAI;AACJ,MAAI,KAAK,gBAAgB,GAAG;AAC3B,sBAAkB;AAClB,kBAAc,KAAK,iBAAiB,aAAa;AAAA,EAClD,OAAO;AACN,sBAAkB,KAAK,iBAAiB,iBAAiB;AACzD,kBAAc,KAAK,iBAAiB,aAAa;AAAA,EAClD;AACA,QAAM,EAAE,QAAQ,IAAI,UAAM,6BAAe,MAAM,cAAc;AAC7D,QAAM,SAAS,UAAM,+BAAiB;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,IACd,gBAAgB,OAAOA,aAAY,UAAM,oCAAsB,MAAM,gBAAgBA,QAAO;AAAA,EAC7F,CAAC;AAED,MAAI,CAAC,OAAO,IAAI;AACf,cAAM,sCAAwB,MAAM,OAAO,KAAK;AAAA,EACjD;AAEA,QAAM,QAAQ,UAAM,0BAAY,OAAO,MAAM;AAC7C,SAAO,MAAM,IAAI,CAAC,UAAU;AAAA,IAC3B,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,IAClB,aAAa,KAAK;AAAA,EACnB,EAAE;AACH;","names":["headers"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpClientTool/types.ts"],"sourcesContent":["export type McpToolIncludeMode = 'all' | 'selected' | 'except';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
McpToolkit: () => McpToolkit,
|
|
22
|
+
createCallTool: () => createCallTool,
|
|
23
|
+
getErrorDescriptionFromToolCall: () => getErrorDescriptionFromToolCall,
|
|
24
|
+
getSelectedTools: () => getSelectedTools,
|
|
25
|
+
mcpToolToDynamicTool: () => mcpToolToDynamicTool
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
var import_tools = require("@langchain/core/tools");
|
|
29
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
30
|
+
var import_agents = require("@langchain/classic/agents");
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var import_schemaParsing = require("@utils/schemaParsing");
|
|
33
|
+
function getSelectedTools({
|
|
34
|
+
mode,
|
|
35
|
+
includeTools,
|
|
36
|
+
excludeTools,
|
|
37
|
+
tools
|
|
38
|
+
}) {
|
|
39
|
+
switch (mode) {
|
|
40
|
+
case "selected": {
|
|
41
|
+
if (!includeTools?.length) return tools;
|
|
42
|
+
const include = new Set(includeTools);
|
|
43
|
+
return tools.filter((tool) => include.has(tool.name));
|
|
44
|
+
}
|
|
45
|
+
case "except": {
|
|
46
|
+
const except = new Set(excludeTools ?? []);
|
|
47
|
+
return tools.filter((tool) => !except.has(tool.name));
|
|
48
|
+
}
|
|
49
|
+
case "all":
|
|
50
|
+
default:
|
|
51
|
+
return tools;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const getErrorDescriptionFromToolCall = (result) => {
|
|
55
|
+
if (result && typeof result === "object") {
|
|
56
|
+
if ("content" in result && Array.isArray(result.content)) {
|
|
57
|
+
const errorMessage = result.content.find(
|
|
58
|
+
(content) => content && typeof content === "object" && typeof content.text === "string"
|
|
59
|
+
)?.text;
|
|
60
|
+
return errorMessage;
|
|
61
|
+
} else if ("toolResult" in result && typeof result.toolResult === "string") {
|
|
62
|
+
return result.toolResult;
|
|
63
|
+
}
|
|
64
|
+
if ("message" in result && typeof result.message === "string") {
|
|
65
|
+
return result.message;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return void 0;
|
|
69
|
+
};
|
|
70
|
+
const createCallTool = (name, client, timeout, onError) => async (args) => {
|
|
71
|
+
let result;
|
|
72
|
+
function handleError(error) {
|
|
73
|
+
const errorDescription = getErrorDescriptionFromToolCall(error) ?? `Failed to execute tool "${name}"`;
|
|
74
|
+
onError(errorDescription);
|
|
75
|
+
return errorDescription;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
result = await client.callTool({ name, arguments: args }, import_types.CompatibilityCallToolResultSchema, {
|
|
79
|
+
timeout
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return handleError(error);
|
|
83
|
+
}
|
|
84
|
+
if (result.isError) {
|
|
85
|
+
return handleError(result);
|
|
86
|
+
}
|
|
87
|
+
if (result.toolResult !== void 0) {
|
|
88
|
+
return result.toolResult;
|
|
89
|
+
}
|
|
90
|
+
if (result.content !== void 0) {
|
|
91
|
+
return result.content;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
function mcpToolToDynamicTool(tool, onCallTool) {
|
|
96
|
+
const rawSchema = (0, import_schemaParsing.convertJsonSchemaToZod)(tool.inputSchema);
|
|
97
|
+
const objectSchema = rawSchema instanceof import_zod.z.ZodObject ? rawSchema : import_zod.z.object({ value: rawSchema });
|
|
98
|
+
return new import_tools.DynamicStructuredTool({
|
|
99
|
+
name: tool.name,
|
|
100
|
+
description: tool.description ?? "",
|
|
101
|
+
schema: objectSchema,
|
|
102
|
+
func: onCallTool,
|
|
103
|
+
metadata: { isFromToolkit: true }
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
class McpToolkit extends import_agents.Toolkit {
|
|
107
|
+
constructor(tools) {
|
|
108
|
+
super();
|
|
109
|
+
this.tools = tools;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
McpToolkit,
|
|
115
|
+
createCallTool,
|
|
116
|
+
getErrorDescriptionFromToolCall,
|
|
117
|
+
getSelectedTools,
|
|
118
|
+
mcpToolToDynamicTool
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpClientTool/utils.ts"],"sourcesContent":["import { DynamicStructuredTool, type DynamicStructuredToolInput } from '@langchain/core/tools';\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Toolkit } from '@langchain/classic/agents';\nimport { type IDataObject } from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport type { McpToolIncludeMode } from './types';\nimport type { McpTool } from '../shared/types';\n\nexport function getSelectedTools({\n\tmode,\n\tincludeTools,\n\texcludeTools,\n\ttools,\n}: {\n\tmode: McpToolIncludeMode;\n\tincludeTools?: string[];\n\texcludeTools?: string[];\n\ttools: McpTool[];\n}) {\n\tswitch (mode) {\n\t\tcase 'selected': {\n\t\t\tif (!includeTools?.length) return tools;\n\t\t\tconst include = new Set(includeTools);\n\t\t\treturn tools.filter((tool) => include.has(tool.name));\n\t\t}\n\t\tcase 'except': {\n\t\t\tconst except = new Set(excludeTools ?? []);\n\t\t\treturn tools.filter((tool) => !except.has(tool.name));\n\t\t}\n\t\tcase 'all':\n\t\tdefault:\n\t\t\treturn tools;\n\t}\n}\n\nexport const getErrorDescriptionFromToolCall = (result: unknown): string | undefined => {\n\tif (result && typeof result === 'object') {\n\t\tif ('content' in result && Array.isArray(result.content)) {\n\t\t\tconst errorMessage = (result.content as Array<{ type: 'text'; text: string }>).find(\n\t\t\t\t(content) => content && typeof content === 'object' && typeof content.text === 'string',\n\t\t\t)?.text;\n\t\t\treturn errorMessage;\n\t\t} else if ('toolResult' in result && typeof result.toolResult === 'string') {\n\t\t\treturn result.toolResult;\n\t\t}\n\t\tif ('message' in result && typeof result.message === 'string') {\n\t\t\treturn result.message;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nexport const createCallTool =\n\t(name: string, client: Client, timeout: number, onError: (error: string) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\n\t\tfunction handleError(error: unknown) {\n\t\t\tconst errorDescription =\n\t\t\t\tgetErrorDescriptionFromToolCall(error) ?? `Failed to execute tool \"${name}\"`;\n\t\t\tonError(errorDescription);\n\t\t\treturn errorDescription;\n\t\t}\n\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema, {\n\t\t\t\ttimeout,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn handleError(error);\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn handleError(result);\n\t\t}\n\n\t\tif (result.toolResult !== undefined) {\n\t\t\treturn result.toolResult;\n\t\t}\n\n\t\tif (result.content !== undefined) {\n\t\t\treturn result.content;\n\t\t}\n\n\t\treturn result;\n\t};\n\nexport function mcpToolToDynamicTool(\n\ttool: McpTool,\n\tonCallTool: DynamicStructuredToolInput['func'],\n): DynamicStructuredTool {\n\tconst rawSchema = convertJsonSchemaToZod(tool.inputSchema);\n\n\t// Ensure we always have an object schema for structured tools\n\tconst objectSchema =\n\t\trawSchema instanceof z.ZodObject ? rawSchema : z.object({ value: rawSchema });\n\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: objectSchema,\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpTo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AAEJ,WAAS,YAAY,OAAgB;AACpC,UAAM,mBACL,gCAAgC,KAAK,KAAK,2BAA2B,IAAI;AAC1E,YAAQ,gBAAgB;AACxB,WAAO;AAAA,EACR;AAEA,MAAI;AACH,aAAS,MAAM,OAAO,SAAS,EAAE,MAAM,WAAW,KAAK,GAAG,gDAAmC;AAAA,MAC5F;AAAA,IACD,CAAC;AAAA,EACF,SAAS,OAAO;AACf,WAAO,YAAY,KAAK;AAAA,EACzB;AAEA,MAAI,OAAO,SAAS;AACnB,WAAO,YAAY,MAAM;AAAA,EAC1B;AAEA,MAAI,OAAO,eAAe,QAAW;AACpC,WAAO,OAAO;AAAA,EACf;AAEA,MAAI,OAAO,YAAY,QAAW;AACjC,WAAO,OAAO;AAAA,EACf;AAEA,SAAO;AACR;AAEM,SAAS,qBACf,MACA,YACwB;AACxB,QAAM,gBAAY,6CAAuB,KAAK,WAAW;AAGzD,QAAM,eACL,qBAAqB,aAAE,YAAY,YAAY,aAAE,OAAO,EAAE,OAAO,UAAU,CAAC;AAE7E,SAAO,IAAI,mCAAsB;AAAA,IAChC,MAAM,KAAK;AAAA,IACX,aAAa,KAAK,eAAe;AAAA,IACjC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU,EAAE,eAAe,KAAK;AAAA,EACjC,CAAC;AACF;AAEO,MAAM,mBAAmB,sBAAQ;AAAA,EACvC,YAAmB,OAAgC;AAClD,UAAM;AADY;AAAA,EAEnB;AACD;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FlushingTransport_exports = {};
|
|
20
|
+
__export(FlushingTransport_exports, {
|
|
21
|
+
FlushingSSEServerTransport: () => FlushingSSEServerTransport,
|
|
22
|
+
FlushingStreamableHTTPTransport: () => FlushingStreamableHTTPTransport
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(FlushingTransport_exports);
|
|
25
|
+
var import_sse = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
26
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
27
|
+
class FlushingSSEServerTransport extends import_sse.SSEServerTransport {
|
|
28
|
+
constructor(_endpoint, response) {
|
|
29
|
+
super(_endpoint, response);
|
|
30
|
+
this.response = response;
|
|
31
|
+
}
|
|
32
|
+
async send(message) {
|
|
33
|
+
await super.send(message);
|
|
34
|
+
this.response.flush();
|
|
35
|
+
}
|
|
36
|
+
async handleRequest(req, resp, message) {
|
|
37
|
+
await super.handlePostMessage(req, resp, message);
|
|
38
|
+
this.response.flush();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class FlushingStreamableHTTPTransport extends import_streamableHttp.StreamableHTTPServerTransport {
|
|
42
|
+
response;
|
|
43
|
+
constructor(options, response) {
|
|
44
|
+
super(options);
|
|
45
|
+
this.response = response;
|
|
46
|
+
}
|
|
47
|
+
async send(message) {
|
|
48
|
+
await super.send(message);
|
|
49
|
+
this.response.flush();
|
|
50
|
+
}
|
|
51
|
+
async handleRequest(req, resp, parsedBody) {
|
|
52
|
+
await super.handleRequest(req, resp, parsedBody);
|
|
53
|
+
this.response.flush();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
FlushingSSEServerTransport,
|
|
59
|
+
FlushingStreamableHTTPTransport
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=FlushingTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpTrigger/FlushingTransport.ts"],"sourcesContent":["import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport type { StreamableHTTPServerTransportOptions } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';\nimport type { Response } from 'express';\nimport type { IncomingMessage, ServerResponse } from 'http';\n\nexport type CompressionResponse = Response & {\n\t/**\n\t * `flush()` is defined in the compression middleware.\n\t * This is necessary because the compression middleware sometimes waits\n\t * for a certain amount of data before sending the data to the client\n\t */\n\tflush: () => void;\n};\n\nexport class FlushingSSEServerTransport extends SSEServerTransport {\n\tconstructor(\n\t\t_endpoint: string,\n\t\tprivate response: CompressionResponse,\n\t) {\n\t\tsuper(_endpoint, response);\n\t}\n\n\tasync send(message: JSONRPCMessage): Promise<void> {\n\t\tawait super.send(message);\n\t\tthis.response.flush();\n\t}\n\n\tasync handleRequest(\n\t\treq: IncomingMessage,\n\t\tresp: ServerResponse,\n\t\tmessage: IncomingMessage,\n\t): Promise<void> {\n\t\tawait super.handlePostMessage(req, resp, message);\n\t\tthis.response.flush();\n\t}\n}\n\nexport class FlushingStreamableHTTPTransport extends StreamableHTTPServerTransport {\n\tprivate response: CompressionResponse;\n\n\tconstructor(options: StreamableHTTPServerTransportOptions, response: CompressionResponse) {\n\t\tsuper(options);\n\t\tthis.response = response;\n\t}\n\n\tasync send(message: JSONRPCMessage): Promise<void> {\n\t\tawait super.send(message);\n\t\tthis.response.flush();\n\t}\n\n\tasync handleRequest(\n\t\treq: IncomingMessage,\n\t\tresp: ServerResponse,\n\t\tparsedBody?: unknown,\n\t): Promise<void> {\n\t\tawait super.handleRequest(req, resp, parsedBody);\n\t\tthis.response.flush();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAmC;AACnC,4BAA8C;AAevC,MAAM,mCAAmC,8BAAmB;AAAA,EAClE,YACC,WACQ,UACP;AACD,UAAM,WAAW,QAAQ;AAFjB;AAAA,EAGT;AAAA,EAEA,MAAM,KAAK,SAAwC;AAClD,UAAM,MAAM,KAAK,OAAO;AACxB,SAAK,SAAS,MAAM;AAAA,EACrB;AAAA,EAEA,MAAM,cACL,KACA,MACA,SACgB;AAChB,UAAM,MAAM,kBAAkB,KAAK,MAAM,OAAO;AAChD,SAAK,SAAS,MAAM;AAAA,EACrB;AACD;AAEO,MAAM,wCAAwC,oDAA8B;AAAA,EAC1E;AAAA,EAER,YAAY,SAA+C,UAA+B;AACzF,UAAM,OAAO;AACb,SAAK,WAAW;AAAA,EACjB;AAAA,EAEA,MAAM,KAAK,SAAwC;AAClD,UAAM,MAAM,KAAK,OAAO;AACxB,SAAK,SAAS,MAAM;AAAA,EACrB;AAAA,EAEA,MAAM,cACL,KACA,MACA,YACgB;AAChB,UAAM,MAAM,cAAc,KAAK,MAAM,UAAU;AAC/C,SAAK,SAAS,MAAM;AAAA,EACrB;AACD;","names":[]}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var McpServer_exports = {};
|
|
20
|
+
__export(McpServer_exports, {
|
|
21
|
+
McpServerManager: () => McpServerManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(McpServer_exports);
|
|
24
|
+
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
25
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
26
|
+
var import_crypto = require("crypto");
|
|
27
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
28
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
29
|
+
var import_FlushingTransport = require("./FlushingTransport");
|
|
30
|
+
function wasToolCall(body) {
|
|
31
|
+
try {
|
|
32
|
+
const message = JSON.parse(body);
|
|
33
|
+
const parsedMessage = import_types.JSONRPCMessageSchema.parse(message);
|
|
34
|
+
return "method" in parsedMessage && "id" in parsedMessage && parsedMessage?.method === import_types.CallToolRequestSchema.shape.method.value;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getRequestId(message) {
|
|
40
|
+
try {
|
|
41
|
+
const parsedMessage = import_types.JSONRPCMessageSchema.parse(message);
|
|
42
|
+
return "id" in parsedMessage ? String(parsedMessage.id) : void 0;
|
|
43
|
+
} catch {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class McpServerManager {
|
|
48
|
+
static #instance;
|
|
49
|
+
servers = {};
|
|
50
|
+
transports = {};
|
|
51
|
+
tools = {};
|
|
52
|
+
resolveFunctions = {};
|
|
53
|
+
logger;
|
|
54
|
+
constructor(logger) {
|
|
55
|
+
this.logger = logger;
|
|
56
|
+
this.logger.debug("MCP Server created");
|
|
57
|
+
}
|
|
58
|
+
static instance(logger) {
|
|
59
|
+
if (!McpServerManager.#instance) {
|
|
60
|
+
McpServerManager.#instance = new McpServerManager(logger);
|
|
61
|
+
logger.debug("Created singleton MCP manager");
|
|
62
|
+
}
|
|
63
|
+
return McpServerManager.#instance;
|
|
64
|
+
}
|
|
65
|
+
async createServerWithSSETransport(serverName, postUrl, resp) {
|
|
66
|
+
const server = new import_server.Server(
|
|
67
|
+
{
|
|
68
|
+
name: serverName,
|
|
69
|
+
version: "0.1.0"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
capabilities: {
|
|
73
|
+
tools: {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
const transport = new import_FlushingTransport.FlushingSSEServerTransport(postUrl, resp);
|
|
78
|
+
this.setUpHandlers(server);
|
|
79
|
+
const sessionId = transport.sessionId;
|
|
80
|
+
this.transports[sessionId] = transport;
|
|
81
|
+
this.servers[sessionId] = server;
|
|
82
|
+
resp.on("close", async () => {
|
|
83
|
+
this.logger.debug(`Deleting transport for ${sessionId}`);
|
|
84
|
+
delete this.tools[sessionId];
|
|
85
|
+
delete this.transports[sessionId];
|
|
86
|
+
delete this.servers[sessionId];
|
|
87
|
+
});
|
|
88
|
+
await server.connect(transport);
|
|
89
|
+
if (resp.flush) {
|
|
90
|
+
resp.flush();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
getSessionId(req) {
|
|
94
|
+
return req.query.sessionId ?? req.headers["mcp-session-id"];
|
|
95
|
+
}
|
|
96
|
+
getTransport(sessionId) {
|
|
97
|
+
return this.transports[sessionId];
|
|
98
|
+
}
|
|
99
|
+
async createServerWithStreamableHTTPTransport(serverName, resp, req) {
|
|
100
|
+
const server = new import_server.Server(
|
|
101
|
+
{
|
|
102
|
+
name: serverName,
|
|
103
|
+
version: "0.1.0"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
capabilities: {
|
|
107
|
+
tools: {}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
const transport = new import_FlushingTransport.FlushingStreamableHTTPTransport(
|
|
112
|
+
{
|
|
113
|
+
sessionIdGenerator: () => (0, import_crypto.randomUUID)(),
|
|
114
|
+
onsessioninitialized: (sessionId) => {
|
|
115
|
+
this.logger.debug(`New session initialized: ${sessionId}`);
|
|
116
|
+
transport.onclose = () => {
|
|
117
|
+
this.logger.debug(`Deleting transport for ${sessionId}`);
|
|
118
|
+
delete this.tools[sessionId];
|
|
119
|
+
delete this.transports[sessionId];
|
|
120
|
+
delete this.servers[sessionId];
|
|
121
|
+
};
|
|
122
|
+
this.transports[sessionId] = transport;
|
|
123
|
+
this.servers[sessionId] = server;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
resp
|
|
127
|
+
);
|
|
128
|
+
this.setUpHandlers(server);
|
|
129
|
+
await server.connect(transport);
|
|
130
|
+
await transport.handleRequest(req, resp, req?.body);
|
|
131
|
+
if (resp.flush) {
|
|
132
|
+
resp.flush();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async handlePostMessage(req, resp, connectedTools) {
|
|
136
|
+
const sessionId = this.getSessionId(req);
|
|
137
|
+
const transport = this.getTransport(sessionId);
|
|
138
|
+
if (sessionId && transport) {
|
|
139
|
+
const message = (0, import_n8n_workflow.jsonParse)(req.rawBody.toString());
|
|
140
|
+
const messageId = getRequestId(message);
|
|
141
|
+
const callId = messageId ? `${sessionId}_${messageId}` : sessionId;
|
|
142
|
+
this.tools[sessionId] = connectedTools;
|
|
143
|
+
try {
|
|
144
|
+
await new Promise(async (resolve) => {
|
|
145
|
+
this.resolveFunctions[callId] = resolve;
|
|
146
|
+
await transport.handleRequest(req, resp, message);
|
|
147
|
+
});
|
|
148
|
+
} finally {
|
|
149
|
+
delete this.resolveFunctions[callId];
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
this.logger.warn(`No transport found for session ${sessionId}`);
|
|
153
|
+
resp.status(401).send("No transport found for sessionId");
|
|
154
|
+
}
|
|
155
|
+
if (resp.flush) {
|
|
156
|
+
resp.flush();
|
|
157
|
+
}
|
|
158
|
+
return wasToolCall(req.rawBody.toString());
|
|
159
|
+
}
|
|
160
|
+
async handleDeleteRequest(req, resp) {
|
|
161
|
+
const sessionId = this.getSessionId(req);
|
|
162
|
+
if (!sessionId) {
|
|
163
|
+
resp.status(400).send("No sessionId provided");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const transport = this.getTransport(sessionId);
|
|
167
|
+
if (transport) {
|
|
168
|
+
if (transport instanceof import_FlushingTransport.FlushingStreamableHTTPTransport) {
|
|
169
|
+
await transport.handleRequest(req, resp);
|
|
170
|
+
return;
|
|
171
|
+
} else {
|
|
172
|
+
resp.status(405).send("Method Not Allowed");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
resp.status(404).send("Session not found");
|
|
177
|
+
}
|
|
178
|
+
setUpHandlers(server) {
|
|
179
|
+
server.setRequestHandler(
|
|
180
|
+
import_types.ListToolsRequestSchema,
|
|
181
|
+
async (_, extra) => {
|
|
182
|
+
if (!extra.sessionId) {
|
|
183
|
+
throw new import_n8n_workflow.OperationalError("Require a sessionId for the listing of tools");
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
tools: this.tools[extra.sessionId].map((tool) => {
|
|
187
|
+
return {
|
|
188
|
+
name: tool.name,
|
|
189
|
+
description: tool.description,
|
|
190
|
+
// Allow additional properties on tool call input
|
|
191
|
+
inputSchema: (0, import_zod_to_json_schema.zodToJsonSchema)(tool.schema, { removeAdditionalStrategy: "strict" })
|
|
192
|
+
};
|
|
193
|
+
})
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
server.setRequestHandler(
|
|
198
|
+
import_types.CallToolRequestSchema,
|
|
199
|
+
async (request, extra) => {
|
|
200
|
+
if (!request.params?.name || !request.params?.arguments) {
|
|
201
|
+
throw new import_n8n_workflow.OperationalError("Require a name and arguments for the tool call");
|
|
202
|
+
}
|
|
203
|
+
if (!extra.sessionId) {
|
|
204
|
+
throw new import_n8n_workflow.OperationalError("Require a sessionId for the tool call");
|
|
205
|
+
}
|
|
206
|
+
const callId = extra.requestId ? `${extra.sessionId}_${extra.requestId}` : extra.sessionId;
|
|
207
|
+
const requestedTool = this.tools[extra.sessionId].find(
|
|
208
|
+
(tool) => tool.name === request.params.name
|
|
209
|
+
);
|
|
210
|
+
if (!requestedTool) {
|
|
211
|
+
throw new import_n8n_workflow.OperationalError("Tool not found");
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const result = await requestedTool.invoke(request.params.arguments);
|
|
215
|
+
if (this.resolveFunctions[callId]) {
|
|
216
|
+
this.resolveFunctions[callId]();
|
|
217
|
+
} else {
|
|
218
|
+
this.logger.warn(`No resolve function found for ${callId}`);
|
|
219
|
+
}
|
|
220
|
+
this.logger.debug(`Got request for ${requestedTool.name}, and executed it.`);
|
|
221
|
+
if (typeof result === "object") {
|
|
222
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
223
|
+
}
|
|
224
|
+
if (typeof result === "string") {
|
|
225
|
+
return { content: [{ type: "text", text: result }] };
|
|
226
|
+
}
|
|
227
|
+
return { content: [{ type: "text", text: String(result) }] };
|
|
228
|
+
} catch (error) {
|
|
229
|
+
this.logger.error(`Error while executing Tool ${requestedTool.name}: ${error}`);
|
|
230
|
+
return { isError: true, content: [{ type: "text", text: `Error: ${error.message}` }] };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
server.onclose = () => {
|
|
235
|
+
this.logger.debug("Closing MCP Server");
|
|
236
|
+
};
|
|
237
|
+
server.onerror = (error) => {
|
|
238
|
+
this.logger.error(`MCP Error: ${error}`);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
243
|
+
0 && (module.exports = {
|
|
244
|
+
McpServerManager
|
|
245
|
+
});
|
|
246
|
+
//# sourceMappingURL=McpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nodes/McpTrigger/McpServer.ts"],"sourcesContent":["import type { Tool } from '@langchain/core/tools';\nimport { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type {\n\tJSONRPCMessage,\n\tServerRequest,\n\tServerNotification,\n} from '@modelcontextprotocol/sdk/types.js';\nimport {\n\tJSONRPCMessageSchema,\n\tListToolsRequestSchema,\n\tCallToolRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { randomUUID } from 'crypto';\nimport type * as express from 'express';\nimport type { IncomingMessage } from 'http';\nimport { jsonParse, OperationalError, type Logger } from 'n8n-workflow';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\nimport { FlushingSSEServerTransport, FlushingStreamableHTTPTransport } from './FlushingTransport';\nimport type { CompressionResponse } from './FlushingTransport';\n\n/**\n * Parses the JSONRPC message and checks whether the method used was a tool\n * call. This is necessary in order to not have executions for listing tools\n * and other commands sent by the MCP client\n */\nfunction wasToolCall(body: string) {\n\ttry {\n\t\tconst message: unknown = JSON.parse(body);\n\t\tconst parsedMessage: JSONRPCMessage = JSONRPCMessageSchema.parse(message);\n\t\treturn (\n\t\t\t'method' in parsedMessage &&\n\t\t\t'id' in parsedMessage &&\n\t\t\tparsedMessage?.method === CallToolRequestSchema.shape.method.value\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Extracts the request ID from a JSONRPC message (for example for tool calls).\n * Returns undefined if the message doesn't have an ID (for example on a tool list request)\n *\n */\nfunction getRequestId(message: unknown): string | undefined {\n\ttry {\n\t\tconst parsedMessage: JSONRPCMessage = JSONRPCMessageSchema.parse(message);\n\t\treturn 'id' in parsedMessage ? String(parsedMessage.id) : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * This singleton is shared across the instance, making sure it is the one\n * keeping account of MCP servers.\n * It needs to stay in memory to keep track of the long-lived connections.\n * It requires a logger at first creation to set everything up.\n */\nexport class McpServerManager {\n\tstatic #instance: McpServerManager;\n\n\tservers: { [sessionId: string]: Server } = {};\n\n\ttransports: {\n\t\t[sessionId: string]: FlushingSSEServerTransport | FlushingStreamableHTTPTransport;\n\t} = {};\n\n\tprivate tools: { [sessionId: string]: Tool[] } = {};\n\n\tprivate resolveFunctions: { [callId: string]: CallableFunction } = {};\n\n\tlogger: Logger;\n\n\tprivate constructor(logger: Logger) {\n\t\tthis.logger = logger;\n\t\tthis.logger.debug('MCP Server created');\n\t}\n\n\tstatic instance(logger: Logger): McpServerManager {\n\t\tif (!McpServerManager.#instance) {\n\t\t\tMcpServerManager.#instance = new McpServerManager(logger);\n\t\t\tlogger.debug('Created singleton MCP manager');\n\t\t}\n\n\t\treturn McpServerManager.#instance;\n\t}\n\n\tasync createServerWithSSETransport(\n\t\tserverName: string,\n\t\tpostUrl: string,\n\t\tresp: CompressionResponse,\n\t): Promise<void> {\n\t\tconst server = new Server(\n\t\t\t{\n\t\t\t\tname: serverName,\n\t\t\t\tversion: '0.1.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tcapabilities: {\n\t\t\t\t\ttools: {},\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tconst transport = new FlushingSSEServerTransport(postUrl, resp);\n\n\t\tthis.setUpHandlers(server);\n\n\t\tconst sessionId = transport.sessionId;\n\t\tthis.transports[sessionId] = transport;\n\t\tthis.servers[sessionId] = server;\n\n\t\tresp.on('close', async () => {\n\t\t\tthis.logger.debug(`Deleting transport for ${sessionId}`);\n\t\t\tdelete this.tools[sessionId];\n\t\t\tdelete this.transports[sessionId];\n\t\t\tdelete this.servers[sessionId];\n\t\t});\n\t\tawait server.connect(transport);\n\n\t\t// Make sure we flush the compression middleware, so that it's not waiting for more content to be added to the buffer\n\t\tif (resp.flush) {\n\t\t\tresp.flush();\n\t\t}\n\t}\n\n\tgetSessionId(req: express.Request): string | undefined {\n\t\t// Session ID can be passed either as a query parameter (SSE transport)\n\t\t// or in the header (StreamableHTTP transport).\n\t\treturn (req.query.sessionId ?? req.headers['mcp-session-id']) as string | undefined;\n\t}\n\n\tgetTransport(\n\t\tsessionId: string,\n\t): FlushingSSEServerTransport | FlushingStreamableHTTPTransport | undefined {\n\t\treturn this.transports[sessionId];\n\t}\n\n\tasync createServerWithStreamableHTTPTransport(\n\t\tserverName: string,\n\t\tresp: CompressionResponse,\n\t\treq?: express.Request,\n\t): Promise<void> {\n\t\tconst server = new Server(\n\t\t\t{\n\t\t\t\tname: serverName,\n\t\t\t\tversion: '0.1.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tcapabilities: {\n\t\t\t\t\ttools: {},\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tconst transport = new FlushingStreamableHTTPTransport(\n\t\t\t{\n\t\t\t\tsessionIdGenerator: () => randomUUID(),\n\t\t\t\tonsessioninitialized: (sessionId) => {\n\t\t\t\t\tthis.logger.debug(`New session initialized: ${sessionId}`);\n\t\t\t\t\ttransport.onclose = () => {\n\t\t\t\t\t\tthis.logger.debug(`Deleting transport for ${sessionId}`);\n\t\t\t\t\t\tdelete this.tools[sessionId];\n\t\t\t\t\t\tdelete this.transports[sessionId];\n\t\t\t\t\t\tdelete this.servers[sessionId];\n\t\t\t\t\t};\n\t\t\t\t\tthis.transports[sessionId] = transport;\n\t\t\t\t\tthis.servers[sessionId] = server;\n\t\t\t\t},\n\t\t\t},\n\t\t\tresp,\n\t\t);\n\n\t\tthis.setUpHandlers(server);\n\n\t\tawait server.connect(transport);\n\n\t\tawait transport.handleRequest(req as IncomingMessage, resp, req?.body);\n\t\tif (resp.flush) {\n\t\t\tresp.flush();\n\t\t}\n\t}\n\n\tasync handlePostMessage(req: express.Request, resp: CompressionResponse, connectedTools: Tool[]) {\n\t\t// Session ID can be passed either as a query parameter (SSE transport)\n\t\t// or in the header (StreamableHTTP transport).\n\t\tconst sessionId = this.getSessionId(req);\n\t\tconst transport = this.getTransport(sessionId as string);\n\t\tif (sessionId && transport) {\n\t\t\t// We need to add a promise here because the `handlePostMessage` will send something to the\n\t\t\t// MCP Server, that will run in a different context. This means that the return will happen\n\t\t\t// almost immediately, and will lead to marking the sub-node as \"running\" in the final execution\n\t\t\tconst message = jsonParse(req.rawBody.toString());\n\t\t\tconst messageId = getRequestId(message);\n\t\t\t// Use session & message ID if available, otherwise fall back to sessionId\n\t\t\tconst callId = messageId ? `${sessionId}_${messageId}` : sessionId;\n\t\t\tthis.tools[sessionId] = connectedTools;\n\n\t\t\ttry {\n\t\t\t\tawait new Promise(async (resolve) => {\n\t\t\t\t\tthis.resolveFunctions[callId] = resolve;\n\t\t\t\t\tawait transport.handleRequest(req, resp, message as IncomingMessage);\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tdelete this.resolveFunctions[callId];\n\t\t\t}\n\t\t} else {\n\t\t\tthis.logger.warn(`No transport found for session ${sessionId}`);\n\t\t\tresp.status(401).send('No transport found for sessionId');\n\t\t}\n\n\t\tif (resp.flush) {\n\t\t\tresp.flush();\n\t\t}\n\n\t\treturn wasToolCall(req.rawBody.toString());\n\t}\n\n\tasync handleDeleteRequest(req: express.Request, resp: CompressionResponse) {\n\t\tconst sessionId = this.getSessionId(req);\n\n\t\tif (!sessionId) {\n\t\t\tresp.status(400).send('No sessionId provided');\n\t\t\treturn;\n\t\t}\n\n\t\tconst transport = this.getTransport(sessionId);\n\n\t\tif (transport) {\n\t\t\tif (transport instanceof FlushingStreamableHTTPTransport) {\n\t\t\t\tawait transport.handleRequest(req, resp);\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t// For SSE transport, we don't support DELETE requests\n\t\t\t\tresp.status(405).send('Method Not Allowed');\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tresp.status(404).send('Session not found');\n\t}\n\n\tsetUpHandlers(server: Server) {\n\t\tserver.setRequestHandler(\n\t\t\tListToolsRequestSchema,\n\t\t\tasync (_, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {\n\t\t\t\tif (!extra.sessionId) {\n\t\t\t\t\tthrow new OperationalError('Require a sessionId for the listing of tools');\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\ttools: this.tools[extra.sessionId].map((tool) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t// Allow additional properties on tool call input\n\t\t\t\t\t\t\tinputSchema: zodToJsonSchema(tool.schema, { removeAdditionalStrategy: 'strict' }),\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t},\n\t\t);\n\n\t\tserver.setRequestHandler(\n\t\t\tCallToolRequestSchema,\n\t\t\tasync (request, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {\n\t\t\t\tif (!request.params?.name || !request.params?.arguments) {\n\t\t\t\t\tthrow new OperationalError('Require a name and arguments for the tool call');\n\t\t\t\t}\n\t\t\t\tif (!extra.sessionId) {\n\t\t\t\t\tthrow new OperationalError('Require a sessionId for the tool call');\n\t\t\t\t}\n\n\t\t\t\tconst callId = extra.requestId ? `${extra.sessionId}_${extra.requestId}` : extra.sessionId;\n\n\t\t\t\tconst requestedTool: Tool | undefined = this.tools[extra.sessionId].find(\n\t\t\t\t\t(tool) => tool.name === request.params.name,\n\t\t\t\t);\n\t\t\t\tif (!requestedTool) {\n\t\t\t\t\tthrow new OperationalError('Tool not found');\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await requestedTool.invoke(request.params.arguments);\n\t\t\t\t\tif (this.resolveFunctions[callId]) {\n\t\t\t\t\t\tthis.resolveFunctions[callId]();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.logger.warn(`No resolve function found for ${callId}`);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.logger.debug(`Got request for ${requestedTool.name}, and executed it.`);\n\n\t\t\t\t\tif (typeof result === 'object') {\n\t\t\t\t\t\treturn { content: [{ type: 'text', text: JSON.stringify(result) }] };\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof result === 'string') {\n\t\t\t\t\t\treturn { content: [{ type: 'text', text: result }] };\n\t\t\t\t\t}\n\t\t\t\t\treturn { content: [{ type: 'text', text: String(result) }] };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error(`Error while executing Tool ${requestedTool.name}: ${error}`);\n\t\t\t\t\treturn { isError: true, content: [{ type: 'text', text: `Error: ${error.message}` }] };\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tserver.onclose = () => {\n\t\t\tthis.logger.debug('Closing MCP Server');\n\t\t};\n\t\tserver.onerror = (error: unknown) => {\n\t\t\tthis.logger.error(`MCP Error: ${error}`);\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAOvB,mBAIO;AACP,oBAA2B;AAG3B,0BAAyD;AACzD,gCAAgC;AAEhC,+BAA4E;AAQ5E,SAAS,YAAY,MAAc;AAClC,MAAI;AACH,UAAM,UAAmB,KAAK,MAAM,IAAI;AACxC,UAAM,gBAAgC,kCAAqB,MAAM,OAAO;AACxE,WACC,YAAY,iBACZ,QAAQ,iBACR,eAAe,WAAW,mCAAsB,MAAM,OAAO;AAAA,EAE/D,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAO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