Skip to main content
Glama

create_workflow

Build n8n workflows from JSON to test automation processes in a secure environment without credential exposure.

Instructions

Create a new n8n workflow from JSON.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowYes

Implementation Reference

  • The core handler function that creates a new n8n workflow by making a POST request to the n8n API with the workflow JSON payload.
    export async function createWorkflow(workflow: Record<string, unknown>) {
      const { baseUrl } = getEnv();
      const response = await fetch(`${baseUrl}/api/v1/workflows`, {
        method: 'POST',
        headers: buildHeaders(),
        body: JSON.stringify(workflow),
      });
      if (!response.ok) throw new Error(`n8n API returned ${response.status}`);
      return (await response.json()) as any;
    }
  • src/index.ts:49-57 (registration)
    Tool registration defining the 'create_workflow' tool with its name, description, and JSON Schema for input validation.
    {
      name: 'create_workflow',
      description: 'Create a new n8n workflow from JSON.',
      inputSchema: {
        type: 'object',
        properties: { workflow: { type: 'object' } },
        required: ['workflow'],
      },
    },
  • Request handler that dispatches 'create_workflow' tool calls, validates input using Zod schema, invokes the createWorkflow function, and returns the result.
    if (name === 'create_workflow') {
      const { workflow } = z.object({ workflow: z.record(z.unknown()) }).parse(args);
      const created = await createWorkflow(workflow);
      return { content: [{ type: 'text', text: JSON.stringify(created, null, 2) }] };
    }
  • Helper function that builds HTTP headers including the n8n API key for authentication when making API requests.
    function buildHeaders() {
      const { apiKey } = getEnv();
      return {
        'Content-Type': 'application/json',
        'X-N8N-API-KEY': apiKey,
      };
    }

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/Souzix76/n8n-workflow-tester-safe'

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