Initial commit of n8n MCP Server
A Model Context Protocol (MCP) server that integrates with n8n, providing tools for workflow and execution management via the n8n API.
This commit is contained in:
60
src/tools/execution/handler.ts
Normal file
60
src/tools/execution/handler.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user