get_template
Retrieve workflow templates from n8n by ID with customizable detail levels: nodes only, structure with connections, or complete workflow JSON for automation setup.
Instructions
Get template by ID. Use mode to control response size: nodes_only (minimal), structure (nodes+connections), full (complete workflow).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| templateId | Yes | The template ID to retrieve | |
| mode | No | Response detail level. nodes_only: just node list, structure: nodes+connections, full: complete workflow JSON. | full |
Implementation Reference
- src/mcp/tools.ts:193-210 (schema)Tool schema definition for 'get_template' - defines name, description, inputSchema with templateId (required number) and mode enum (nodes_only, structure, full). This is used for MCP tool registration.name: 'get_template', description: `Get template by ID. Use mode to control response size: nodes_only (minimal), structure (nodes+connections), full (complete workflow).`, inputSchema: { type: 'object', properties: { templateId: { type: 'number', description: 'The template ID to retrieve', }, mode: { type: 'string', enum: ['nodes_only', 'structure', 'full'], description: 'Response detail level. nodes_only: just node list, structure: nodes+connections, full: complete workflow JSON.', default: 'full', }, }, required: ['templateId'], },
- src/templates/template-service.ts:87-125 (handler)Primary handler implementation for get_template tool. Fetches template from repository, parses/decompresses workflow JSON, and returns structured response based on mode parameter matching tool schema exactly. This executes the core tool logic.async getTemplate(templateId: number, mode: 'nodes_only' | 'structure' | 'full' = 'full'): Promise<any> { const template = this.repository.getTemplate(templateId); if (!template) { return null; } const workflow = JSON.parse(template.workflow_json || '{}'); if (mode === 'nodes_only') { return { id: template.id, name: template.name, nodes: workflow.nodes?.map((n: any) => ({ type: n.type, name: n.name })) || [] }; } if (mode === 'structure') { return { id: template.id, name: template.name, nodes: workflow.nodes?.map((n: any) => ({ id: n.id, type: n.type, name: n.name, position: n.position })) || [], connections: workflow.connections || {} }; } // Full mode return { ...this.formatTemplateInfo(template), workflow }; }
- Database access helper called by templateService.getTemplate. Retrieves raw template row from SQLite 'templates' table and handles decompression of gzipped workflow_json_compressed field.getTemplate(templateId: number): StoredTemplate | null { const row = this.db.prepare(` SELECT * FROM templates WHERE id = ? `).get(templateId) as StoredTemplate | undefined; if (!row) return null; // Decompress workflow JSON if compressed if (row.workflow_json_compressed && !row.workflow_json) { try { const compressed = Buffer.from(row.workflow_json_compressed, 'base64'); const decompressed = zlib.gunzipSync(compressed); row.workflow_json = decompressed.toString(); } catch (error) { logger.error(`Failed to decompress workflow for template ${templateId}:`, error); return null; } } return row; }
- Comprehensive tool documentation including full parameter descriptions, return structure, examples, performance metrics, best practices, pitfalls, and related tools.export const getTemplateDoc: ToolDocumentation = { name: 'get_template', category: 'templates', essentials: { description: 'Get workflow template by ID with configurable detail level. Ready to import. IDs from search_templates.', keyParameters: ['templateId', 'mode'], example: 'get_template({templateId: 1234, mode: "full"})', performance: 'Fast (<100ms) - single database lookup', tips: [ 'Get template IDs from search_templates first', 'Use mode="nodes_only" for quick overview, "structure" for topology, "full" for import', 'Returns complete workflow JSON ready for import into n8n' ] }, full: { description: `Retrieves the complete workflow JSON for a specific template by its ID. The returned workflow can be directly imported into n8n through the UI or API. This tool fetches pre-built workflows from the community template library containing 2,700+ curated workflows.`, parameters: { templateId: { type: 'number', required: true, description: 'The numeric ID of the template to retrieve. Get IDs from search_templates' }, mode: { type: 'string', required: false, description: 'Response detail level: "nodes_only" (minimal - just node list), "structure" (nodes + connections), "full" (complete workflow JSON, default)', default: 'full', enum: ['nodes_only', 'structure', 'full'] } }, returns: `Returns an object containing: - template: Complete template information including workflow JSON - id: Template ID - name: Template name - description: What the workflow does - author: Creator information (name, username, verified status) - nodes: Array of node types used - views: Number of times viewed - created: Creation date - url: Link to template on n8n.io - workflow: Complete workflow JSON with structure: - nodes: Array of node objects (id, name, type, typeVersion, position, parameters) - connections: Object mapping source nodes to targets - settings: Workflow configuration (timezone, error handling, etc.) - usage: Instructions for using the workflow`, examples: [ 'get_template({templateId: 1234}) - Get complete workflow (default mode="full")', 'get_template({templateId: 1234, mode: "nodes_only"}) - Get just the node list', 'get_template({templateId: 1234, mode: "structure"}) - Get nodes and connections', 'get_template({templateId: 5678, mode: "full"}) - Get complete workflow JSON for import' ], useCases: [ 'Download workflows for direct import into n8n', 'Study workflow patterns and best practices', 'Get complete workflow JSON for customization', 'Clone popular workflows for your use case', 'Learn how complex automations are built' ], performance: `Fast performance with single database lookup: - Query time: <10ms for template retrieval - Workflow JSON parsing: <50ms - Total response time: <100ms - No network calls (uses local cache)`, bestPractices: [ 'Always check if template exists before attempting modifications', 'Review workflow nodes before importing to ensure compatibility', 'Save template JSON locally if planning multiple customizations', 'Check template creation date for most recent patterns', 'Verify all required credentials are configured before import' ], pitfalls: [ 'Template IDs change when database is refreshed', 'Some templates may use deprecated node versions', 'Credentials in templates are placeholders - configure your own', 'Not all templates work with all n8n versions', 'Template may reference external services you don\'t have access to' ], relatedTools: ['search_templates', 'n8n_create_workflow'] } };