UNPKG

n8n

Version:

n8n Workflow Automation Tool

63 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findMcpSupportedTrigger = exports.getToolArguments = exports.getToolName = exports.getProtocolVersion = exports.getClientInfo = void 0; const is_record_1 = require("@n8n/utils/is-record"); const mcp_constants_1 = require("./mcp.constants"); const mcp_typeguards_1 = require("./mcp.typeguards"); const getRequestMetaValue = (params, key) => { const meta = params?._meta; return (0, is_record_1.isRecord)(meta) ? meta[key] : undefined; }; const getClientInfo = (req) => { if (!(0, mcp_typeguards_1.isJSONRPCRequest)(req.body)) return undefined; const params = req.body.params; const metaClientInfo = getRequestMetaValue(params, mcp_constants_1.MCP_CLIENT_INFO_META_KEY); if ((0, is_record_1.isRecord)(metaClientInfo)) { return { name: typeof metaClientInfo.name === 'string' ? metaClientInfo.name : undefined, version: typeof metaClientInfo.version === 'string' ? metaClientInfo.version : undefined, }; } return params?.clientInfo; }; exports.getClientInfo = getClientInfo; const getProtocolVersion = (req) => { if (!(0, mcp_typeguards_1.isJSONRPCRequest)(req.body)) return undefined; const version = getRequestMetaValue(req.body.params, mcp_constants_1.MCP_PROTOCOL_VERSION_META_KEY); return typeof version === 'string' ? version : undefined; }; exports.getProtocolVersion = getProtocolVersion; const getToolName = (body) => { if (!(0, mcp_typeguards_1.isJSONRPCRequest)(body)) return 'unknown'; if (!body.params) return 'unknown'; const { name } = body.params; if (typeof name === 'string') { return name; } return 'unknown'; }; exports.getToolName = getToolName; const getToolArguments = (body) => { if (!(0, mcp_typeguards_1.isJSONRPCRequest)(body)) return {}; if (!body.params) return {}; const args = body.params.arguments; if ((0, is_record_1.isRecord)(args)) { return args; } return {}; }; exports.getToolArguments = getToolArguments; const findMcpSupportedTrigger = (nodes, mode = 'production') => { const triggerNodeTypes = mode === 'production' ? Object.keys(mcp_constants_1.SUPPORTED_PRODUCTION_MCP_TRIGGERS) : Object.keys(mcp_constants_1.SUPPORTED_MCP_TRIGGERS); return nodes.find((node) => triggerNodeTypes.includes(node.type) && !node.disabled); }; exports.findMcpSupportedTrigger = findMcpSupportedTrigger; //# sourceMappingURL=mcp.utils.js.map