create-variable
Generate and manage variables in n8n workflows to store and share data. Requires n8n Enterprise license with variable management enabled. Input data must be in compact JSON format.
Instructions
Create a new variable in n8n. NOTE: Requires n8n Enterprise license with variable management features enabled. Variables can be used across workflows to store and share data. IMPORTANT: Arguments must be provided as compact, single-line JSON without whitespace or newlines.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clientId | Yes | ||
| key | Yes | ||
| value | Yes |
Implementation Reference
- src/index.ts:1425-1455 (handler)The main handler for the 'create-variable' tool within the CallToolRequestSchema switch statement. It retrieves the N8nClient by clientId, calls the client's createVariable method, and returns success or error response.case "create-variable": { const { clientId, key, value } = args as { clientId: string; key: string; value: string }; const client = clients.get(clientId); if (!client) { return { content: [{ type: "text", text: "Client not initialized. Please run init-n8n first.", }], isError: true }; } try { await client.createVariable(key, value); return { content: [{ type: "text", text: `Successfully created variable with key: ${key}`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error occurred", }], isError: true }; } }
- src/index.ts:627-638 (schema)The input schema definition for the 'create-variable' tool, registered in the listTools response.name: "create-variable", description: "Create a new variable in n8n. NOTE: Requires n8n Enterprise license with variable management features enabled. Variables can be used across workflows to store and share data. IMPORTANT: Arguments must be provided as compact, single-line JSON without whitespace or newlines.", inputSchema: { type: "object", properties: { clientId: { type: "string" }, key: { type: "string" }, value: { type: "string" } }, required: ["clientId", "key", "value"] } },
- src/index.ts:256-261 (helper)The N8nClient helper method that performs the actual API call to create a variable in n8n by POSTing to /variables endpoint.async createVariable(key: string, value: string): Promise<void> { return this.makeRequest<void>('/variables', { method: 'POST', body: JSON.stringify({ key, value }), }); }