UNPKG

n8n-mcp-server

Version:

Model Context Protocol (MCP) server for n8n workflow automation

61 lines (54 loc) 1.58 kB
/** * Execution Tools Handler * * This module handles calls to execution-related tools. */ import { ToolCallResult } from '../../types/index.js'; import { McpError } from '@modelcontextprotocol/sdk/types.js'; import { ErrorCode } from '../../errors/error-codes.js'; import { N8nApiError, getErrorMessage } from '../../errors/index.js'; import { ListExecutionsHandler, GetExecutionHandler, DeleteExecutionHandler } from './index.js'; /** * Handle execution tool calls * * @param toolName Name of the tool being called * @param args Arguments passed to the tool * @returns Tool call result */ export default async function executionHandler( toolName: string, args: Record<string, any> ): Promise<ToolCallResult> { try { // Route to the appropriate handler based on tool name switch (toolName) { case 'list_executions': return await new ListExecutionsHandler().execute(args); case 'get_execution': return await new GetExecutionHandler().execute(args); case 'delete_execution': return await new DeleteExecutionHandler().execute(args); default: throw new McpError( ErrorCode.NotImplemented, `Unknown execution tool: '${toolName}'` ); } } catch (error) { // Get appropriate error message const errorMessage = getErrorMessage(error); return { content: [ { type: 'text', text: `Error executing execution tool: ${errorMessage}`, }, ], isError: true, }; } }