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
| Name | Required | Description | Default |
|---|---|---|---|
| workflow | Yes |
Implementation Reference
- src/n8n-client.ts:98-107 (handler)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'], }, }, - src/index.ts:222-226 (handler)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) }] }; } - src/n8n-client.ts:4-10 (helper)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, }; }