Skip to main content
Glama

n8n_create_workflow

Create automation workflows by defining nodes and connections. Specify workflow name, node array, and connection object to build and optionally activate workflows.

Instructions

Create a new automation workflow with nodes and connections. Provide workflow name, node array, and connection object. Optionally activate immediately. Returns new workflow with assigned ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesDescriptive workflow name
nodesYesArray of node objects with type, parameters, position
connectionsYesConnection map linking node outputs to inputs
activeNoStart workflow immediately (default: false)

Implementation Reference

  • The createWorkflow method in N8nClient class that executes the tool logic. It makes a POST request to the n8n API endpoint /api/v1/workflows with the workflow data (name, nodes, connections, active) serialized as JSON.
    async createWorkflow(workflow: any) {
      return this.request(`${this.apiBase}/workflows`, {
        method: 'POST',
        body: JSON.stringify(workflow),
      });
    }
  • The tool definition/schema for n8n_create_workflow. Defines the tool name, description, inputSchema with required properties (name, nodes, connections) and optional 'active' property, plus annotations for MCP capabilities.
      name: 'n8n_create_workflow',
      description: 'Create a new automation workflow with nodes and connections. Provide workflow name, node array, and connection object. Optionally activate immediately. Returns new workflow with assigned ID.',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Descriptive workflow name' },
          nodes: { type: 'array', description: 'Array of node objects with type, parameters, position' },
          connections: { type: 'object', description: 'Connection map linking node outputs to inputs' },
          active: { type: 'boolean', description: 'Start workflow immediately (default: false)' },
        },
        required: ['name', 'nodes', 'connections'],
      },
      annotations: {
        title: 'Create Workflow',
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: false,
        openWorldHint: true,
      },
    },
  • src/server.ts:22-30 (registration)
    The handleToolCall function routes tool calls to appropriate handlers. Line 29-30 shows n8n_create_workflow case delegating to client.createWorkflow(args).
    export async function handleToolCall(toolName: string, args: any, client: N8nClient): Promise<any> {
      switch (toolName) {
        // Workflow operations
        case 'n8n_list_workflows':
          return client.listWorkflows(args);
        case 'n8n_get_workflow':
          return client.getWorkflow(args.id);
        case 'n8n_create_workflow':
          return client.createWorkflow(args);
  • The private request method that handles all HTTP requests to the n8n API. Includes authentication via X-N8N-API-KEY header, timeout handling, and error response handling.
    private async request<T>(
      endpoint: string,
      options: RequestInit = {}
    ): Promise<T> {
      const url = `${this.config.apiUrl}${endpoint}`;
    
      const response = await fetch(url, {
        ...options,
        signal: AbortSignal.timeout(this.timeout),
        headers: {
          'X-N8N-API-KEY': this.config.apiKey,
          'Content-Type': 'application/json',
          ...options.headers,
        },
      });
    
      if (!response.ok) {
        const error = await response.text();
        throw new Error(`n8n API Error (${response.status}): ${error}`);
      }
    
      return response.json() as Promise<T>;
    }

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/node2flow-th/n8n-management-mcp-community'

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