Skip to main content
Glama

create_workflow

Create a new n8n workflow by defining nodes, connections, and configuration to automate business processes and data flows.

Instructions

Create a new n8n workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activeNo
connectionsYes
nameYes
nodesYes
tagsNo

Implementation Reference

  • src/index.ts:71-71 (registration)
    Tool registration in list_tools response, including name, description, and input schema definition
    { name: 'create_workflow', description: 'Create a new n8n workflow', inputSchema: { type: 'object', properties: { name: { type: 'string' }, nodes: { type: 'array', items: { type: 'object' } }, connections: { type: 'object' }, active: { type: 'boolean', default: false }, tags: { type: 'array', items: { type: 'string' } } }, required: ['name', 'nodes', 'connections'] } },
  • Handler dispatch in CallToolRequestSchema switch statement routing create_workflow calls
    case 'create_workflow': return await this.handleCreateWorkflow(request.params.arguments as Omit<N8nWorkflow, 'id'>);
  • Primary MCP tool handler function that delegates to n8nClient.createWorkflow and formats response with alias and JSON success wrapper
    private async handleCreateWorkflow(args: Omit<N8nWorkflow, 'id'>) { const workflow = await this.n8nClient.createWorkflow(args); this.withAlias(workflow); return { content: [{ type: 'text', text: JSON.stringify(jsonSuccess(workflow), null, 2) }] };
  • Core implementation in N8nClient that preprocesses workflow (credentials, settings, tags, active), calls n8n /workflows POST API, and normalizes response
    async createWorkflow(workflow: Omit<N8nWorkflow, 'id'>): Promise<N8nWorkflow> { // Resolve credential aliases before creating the workflow await this.resolveCredentialsInWorkflow(workflow); // Ensure required fields expected by n8n API if ((workflow as any).settings == null) { (workflow as any).settings = {}; } // Some n8n deployments may not accept non-numeric tag values on create. // If tags are provided as strings (names), omit them here; users can set numeric tag IDs via setWorkflowTags. if (Array.isArray((workflow as any).tags) && (workflow as any).tags.some((t: any) => typeof t !== 'number')) { delete (workflow as any).tags; } // 'active' is managed via dedicated activate/deactivate endpoints; omit on create if ('active' in (workflow as any)) { delete (workflow as any).active; } const response = await this.api.post<N8nApiResponse<N8nWorkflow> | N8nWorkflow>('/workflows', workflow); const payload: any = response.data as any; return (payload && typeof payload === 'object' && 'data' in payload) ? payload.data : payload; }
  • Supporting helper that resolves credential aliases in workflow nodes before API submission
    async resolveCredentialsInWorkflow(workflow: Omit<N8nWorkflow, 'id'> | Partial<N8nWorkflow>): Promise<void> { if (!workflow.nodes) return; for (const node of workflow.nodes) { if (node.credentials) { for (const [credType, credValue] of Object.entries(node.credentials)) { // If the value doesn't look like an ID (not all digits), try to resolve as alias if (credValue && !/^\d+$/.test(credValue)) { try { node.credentials[credType] = await this.resolveCredentialAlias(credValue); } catch (error) { throw new Error(`Failed to resolve credential alias '${credValue}' for node '${node.name}': ${error instanceof Error ? error.message : String(error)}`); } } } } } }

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

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