Skip to main content
Glama

n8n MCP Server

MIT License
133
1,377
  • Apple
  • Linux
base-handler.ts2.38 kB
/** * Base Workflow Tool Handler * * This module provides a base handler for workflow-related tools. */ import { ToolCallResult } from '../../types/index.js'; import { N8nApiError } from '../../errors/index.js'; import { createApiService } from '../../api/n8n-client.js'; import { getEnvConfig } from '../../config/environment.js'; /** * Base class for workflow tool handlers */ export abstract class BaseWorkflowToolHandler { protected apiService = createApiService(getEnvConfig()); /** * Validate and execute the tool * * @param args Arguments passed to the tool * @returns Tool call result */ abstract execute(args: Record<string, any>): Promise<ToolCallResult>; /** * Format a successful response * * @param data Response data * @param message Optional success message * @returns Formatted success response */ protected formatSuccess(data: any, message?: string): ToolCallResult { const formattedData = typeof data === 'object' ? JSON.stringify(data, null, 2) : String(data); return { content: [ { type: 'text', text: message ? `${message}\n\n${formattedData}` : formattedData, }, ], }; } /** * Format an error response * * @param error Error object or message * @returns Formatted error response */ protected formatError(error: Error | string): ToolCallResult { const errorMessage = error instanceof Error ? error.message : error; return { content: [ { type: 'text', text: errorMessage, }, ], isError: true, }; } /** * Handle tool execution errors * * @param handler Function to execute * @param args Arguments to pass to the handler * @returns Tool call result */ protected async handleExecution( handler: (args: Record<string, any>) => Promise<ToolCallResult>, args: Record<string, any> ): Promise<ToolCallResult> { try { return await handler(args); } catch (error) { if (error instanceof N8nApiError) { return this.formatError(error.message); } const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; return this.formatError(`Error executing workflow tool: ${errorMessage}`); } } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leonardsellem/n8n-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server