Skip to main content
Glama

get_template

Read-onlyIdempotent

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
NameRequiredDescriptionDefault
templateIdYesThe template ID to retrieve
modeNoResponse detail level. nodes_only: just node list, structure: nodes+connections, full: complete workflow JSON.full

Implementation Reference

  • 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'],
    },
  • 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']
      }
    };
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and idempotentHint=true, indicating safe, repeatable reads. The description adds valuable behavioral context by explaining the 'mode' parameter's impact on response size and content, which goes beyond annotations. No contradictions exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose ('Get template by ID') and efficiently follows with essential usage details for the 'mode' parameter. Every sentence adds value without redundancy, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity, rich annotations (readOnlyHint, idempotentHint), and full schema coverage, the description is largely complete. It explains the key behavioral aspect (mode control) but lacks output details (no output schema provided), leaving some ambiguity about return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters. The description adds semantic meaning by explaining what each 'mode' value does (e.g., 'nodes_only: minimal', 'full: complete workflow'), enhancing understanding beyond the schema's enum and descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get template by ID') and resource ('template'), distinguishing it from siblings like 'search_templates' (which searches) or 'n8n_get_workflow' (which targets workflows). It's precise and avoids tautology.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool (to retrieve a template by ID) and includes usage guidance for the 'mode' parameter to control response size. However, it does not explicitly state when not to use it or name alternatives like 'search_templates' for broader queries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/czlonkowski/n8n-mcp'

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