get_workflow
Retrieve detailed workflow information by ID, including nodes, connections, and settings, to analyze structure or prepare for updates in the n8n workflow system.
Instructions
Retrieves complete details of a specific workflow by its ID, including all nodes, connections, settings, and metadata. Use this tool when you need to examine a workflow's structure before updating it or to understand how it works.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the workflow to retrieve - can be obtained from list_workflows | |
| verbosity | No | Output verbosity level (concise or full). Default is concise which preserves context window space. Use full when you need complete workflow details including all nodes and connections. |
Implementation Reference
- The primary handler function for the 'get_workflow' tool. Validates the workflow ID, fetches the full workflow data using the N8nApiClient, computes summary statistics (status, node counts, trigger nodes, tags), formats the output according to verbosity (concise summary or full JSON), and returns structured MCP content or error response./** * Handles the get_workflow tool */ export async function handle_get_workflow( api_client: N8nApiClient, args: any, ) { if (!args.id) { throw new McpError( ErrorCode.InvalidParams, 'Workflow ID is required', ); } try { const workflow = await api_client.get_workflow(args.id); // Format a summary of the workflow const activation_status = workflow.active ? 'Active' : 'Inactive'; const node_count = workflow.nodes.length; const trigger_nodes = workflow.nodes.filter( (node: { type: string }) => node.type.toLowerCase().includes('trigger'), ).length; const summary = `Workflow: "${workflow.name}" (ID: ${args.id}) Status: ${activation_status} Created: ${new Date(workflow.created_at).toLocaleString()} Updated: ${new Date(workflow.updated_at).toLocaleString()} Nodes: ${node_count} (including ${trigger_nodes} trigger nodes) Tags: ${ workflow.tags ?.map((tag: { name: string }) => tag.name) .join(', ') || 'None' }`; return { content: [ { type: 'text', text: format_output(summary, workflow, args.verbosity), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error retrieving workflow: ${ error.message || String(error) }`, }, ], isError: true, }; } }
- src/tool-handlers/index.ts:134-155 (registration)Tool registration in MCP listTools handler: defines 'get_workflow' with detailed description and inputSchema (required 'id': string, optional 'verbosity': 'concise'|'full').{ name: 'get_workflow', description: "Retrieves complete details of a specific workflow by its ID, including all nodes, connections, settings, and metadata. Use this tool when you need to examine a workflow's structure before updating it or to understand how it works.", inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'ID of the workflow to retrieve - can be obtained from list_workflows', }, verbosity: { type: 'string', description: 'Output verbosity level (concise or full). Default is concise which preserves context window space. Use full when you need complete workflow details including all nodes and connections.', enum: ['concise', 'full'], }, }, required: ['id'], }, },
- src/tool-handlers/index.ts:324-325 (registration)Dispatch logic in MCP callTool handler: routes 'get_workflow' tool calls to the handle_get_workflow function with api_client and parsed arguments.case 'get_workflow': return await handle_get_workflow(api_client, args);
- Utility helper function used by get_workflow handler to conditionally include full JSON details or just summary based on verbosity parameter (overrides global config)./** * Helper function to format output based on verbosity setting * @param summary The human-readable summary text * @param details The full JSON details * @param verbosity The verbosity level (concise or full) * @returns Formatted text based on verbosity setting */ function format_output( summary: string, details: any, verbosity?: string, ): string { // Use the provided verbosity parameter if available, otherwise fall back to config const output_verbosity = verbosity || config.output_verbosity; if (output_verbosity === 'full') { return ( summary + '\n\nFull details:\n' + JSON.stringify(details, null, 2) ); } else { // Default to concise mode return summary; } }
- src/n8n-api-client.ts:137-141 (helper)N8nApiClient method invoked by the handler: performs authenticated GET request to n8n REST API endpoint /api/v1/workflows/{id} to retrieve raw workflow data.* Get a workflow by ID */ async get_workflow(id: string): Promise<any> { return this.request<any>('GET', `/workflows/${id}`); }