n8n-mcp 2.102.0 → 2.103.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -1
- package/README.md +51 -14
- package/dist/mcp/handlers-n8n-manager.d.ts +5 -0
- package/dist/mcp/handlers-n8n-manager.d.ts.map +1 -1
- package/dist/mcp/handlers-n8n-manager.js +249 -0
- package/dist/mcp/handlers-n8n-manager.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +16 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-docs/index.d.ts.map +1 -1
- package/dist/mcp/tool-docs/index.js +1 -0
- package/dist/mcp/tool-docs/index.js.map +1 -1
- package/dist/mcp/tool-docs/workflow_management/index.d.ts +1 -0
- package/dist/mcp/tool-docs/workflow_management/index.d.ts.map +1 -1
- package/dist/mcp/tool-docs/workflow_management/index.js +3 -1
- package/dist/mcp/tool-docs/workflow_management/index.js.map +1 -1
- package/dist/mcp/tool-docs/workflow_management/n8n-manage-variables.d.ts +3 -0
- package/dist/mcp/tool-docs/workflow_management/n8n-manage-variables.d.ts.map +1 -0
- package/dist/mcp/tool-docs/workflow_management/n8n-manage-variables.js +84 -0
- package/dist/mcp/tool-docs/workflow_management/n8n-manage-variables.js.map +1 -0
- package/dist/mcp/tool-policy.d.ts +1 -0
- package/dist/mcp/tool-policy.d.ts.map +1 -1
- package/dist/mcp/tool-policy.js +29 -6
- package/dist/mcp/tool-policy.js.map +1 -1
- package/dist/mcp/tools-documentation.d.ts.map +1 -1
- package/dist/mcp/tools-documentation.js +1 -0
- package/dist/mcp/tools-documentation.js.map +1 -1
- package/dist/mcp/tools-n8n-manager.d.ts +1 -0
- package/dist/mcp/tools-n8n-manager.d.ts.map +1 -1
- package/dist/mcp/tools-n8n-manager.js +36 -1
- package/dist/mcp/tools-n8n-manager.js.map +1 -1
- package/dist/services/n8n-api-client.d.ts +4 -4
- package/dist/services/n8n-api-client.d.ts.map +1 -1
- package/dist/services/n8n-api-client.js +8 -10
- package/dist/services/n8n-api-client.js.map +1 -1
- package/dist/types/n8n-api.d.ts +27 -2
- package/dist/types/n8n-api.d.ts.map +1 -1
- package/package.json +2 -2
package/.env.example
CHANGED
|
@@ -120,6 +120,13 @@ AUTH_TOKEN=your-secure-token-here
|
|
|
120
120
|
# Default: (empty - all tools enabled)
|
|
121
121
|
# DISABLED_TOOLS=
|
|
122
122
|
|
|
123
|
+
# Enterprise Tools
|
|
124
|
+
# Set to true to remove the tools whose every action needs a paid n8n license
|
|
125
|
+
# feature (currently n8n_manage_variables). Use it when your n8n instances run
|
|
126
|
+
# the free Community edition. Combines with DISABLED_TOOLS.
|
|
127
|
+
# Default: false
|
|
128
|
+
# DISABLE_ENTERPRISE_TOOLS=false
|
|
129
|
+
|
|
123
130
|
# Per-Operation Tool Filtering
|
|
124
131
|
# Disable specific operations within a tool without losing its read paths.
|
|
125
132
|
# Useful for sensitive deployments that need read-only access
|
|
@@ -132,10 +139,11 @@ AUTH_TOKEN=your-secure-token-here
|
|
|
132
139
|
# n8n_executions — action: get, list, delete
|
|
133
140
|
# n8n_evaluations — action: list_runs, get_run, list_cases, run, cancel
|
|
134
141
|
# n8n_manage_folders — action: create, list, get, rename, move, delete
|
|
142
|
+
# n8n_manage_variables — action: list, get, create, update, delete
|
|
135
143
|
# n8n_workflow_versions — mode: list, get, rollback, delete, prune
|
|
136
144
|
#
|
|
137
145
|
# Read-only deployment recipe (blocks all destructive operations):
|
|
138
|
-
# DISABLED_TOOL_OPERATIONS=n8n_workflow_versions:delete,rollback,prune;n8n_executions:delete;n8n_evaluations:run,cancel;n8n_manage_folders:create,rename,move,delete
|
|
146
|
+
# DISABLED_TOOL_OPERATIONS=n8n_workflow_versions:delete,rollback,prune;n8n_executions:delete;n8n_evaluations:run,cancel;n8n_manage_folders:create,rename,move,delete;n8n_manage_variables:create,update,delete
|
|
139
147
|
#
|
|
140
148
|
# Combine with n8n API key RBAC for defence in depth.
|
|
141
149
|
# Default: (empty - all operations enabled)
|
package/README.md
CHANGED
|
@@ -7,13 +7,44 @@
|
|
|
7
7
|
[](https://github.com/czlonkowski/n8n-mcp/actions)
|
|
8
8
|
[](https://github.com/n8n-io/n8n)
|
|
9
9
|
[](https://github.com/czlonkowski/n8n-mcp/pkgs/container/n8n-mcp)
|
|
10
|
+
[](https://www.bestpractices.dev/projects/16495)
|
|
10
11
|
[](https://railway.com/deploy/n8n-mcp?referralCode=n8n-mcp)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
n8n-MCP is an open-source MCP server that lets Claude, ChatGPT, Cursor, and other AI assistants operate n8n: read failed executions, edit workflows in place, validate and test them, manage credentials, and build new workflows. It works with any n8n instance that has the Public API enabled, and can use n8n's built-in MCP server as a second backend.
|
|
13
14
|
|
|
14
|
-
##
|
|
15
|
+
## What You Can Do With It
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
- **Debug failing workflows** - `n8n_executions` reads an execution and, with `mode: "error"`, returns the error, the failing node, and sample items from the node before it.
|
|
18
|
+
- **Edit workflows in place** - `n8n_update_partial_workflow` applies targeted operations to the nodes and connections named in the request, so the assistant does not resend the whole workflow. This includes find-and-replace inside one large field such as a Code node (`patchNodeField`). By default n8n-MCP saves a snapshot before it changes a workflow's nodes or connections, and `n8n_workflow_versions` can diff and roll back.
|
|
19
|
+
- **Validate and fix before going live** - `validate_node`, `validate_workflow`, and `n8n_validate_workflow` report unknown nodes, invalid node versions, missing required fields, and broken connections or expressions. `n8n_autofix_workflow` repairs the common ones.
|
|
20
|
+
- **Test** - `n8n_test_workflow` runs a workflow through its webhook, form, or chat trigger, or, through n8n's built-in MCP server, with pinned data when it has no such trigger.
|
|
21
|
+
- **Manage the instance** - create, update, and delete credentials, work with data tables, folders and variables, and run a security audit (`n8n_audit_instance`).
|
|
22
|
+
- **Build new workflows** - bundled knowledge of 3,501 nodes and 2,352 templates, so the assistant configures real nodes instead of guessing.
|
|
23
|
+
- **Work across several n8n instances** - on the [hosted service](https://www.n8n-mcp.com/docs/multi-instance), register production, staging, and client instances once and name the target on each call. Self-hosted HTTP mode can serve several instances with [per-request instance headers](./docs/HTTP_DEPLOYMENT.md#per-request-instance-headers-multi-tenant).
|
|
24
|
+
|
|
25
|
+
## n8n-MCP and n8n's Built-In MCP Server
|
|
26
|
+
|
|
27
|
+
n8n ships its own instance-level MCP server, and it covers a lot: building and editing workflows, executions, version history, data tables, and Agents. n8n-MCP does not replace it. The two differ in how they are built:
|
|
28
|
+
|
|
29
|
+
| | n8n's built-in MCP server | n8n-MCP |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| Runs | Inside one n8n instance | As a separate server that talks to n8n |
|
|
32
|
+
| Instances per connection | One | Several (hosted service, or multi-tenant HTTP mode) |
|
|
33
|
+
| Credentials | Lists credentials and edits their descriptions | Creates, updates, and deletes credentials |
|
|
34
|
+
| n8n versions | Present since late n8n 1.x; most tools need n8n 2.12 or later, and each tool has its own minimum version | Workflow and execution tools work through the Public API on older versions too, including the 1.x line. Credential actions depend on what that version's API exposes, and newer tools state the version they need |
|
|
35
|
+
| Workflow access | Most operations need the workflow's "Available in MCP" setting, which is off by default | Every workflow the API key can reach |
|
|
36
|
+
|
|
37
|
+
**The built-in server is enough when** you work with a single instance on a recent n8n 2.x, build and edit workflows on that instance, and set up credentials yourself in the n8n UI.
|
|
38
|
+
|
|
39
|
+
**Add n8n-MCP when** you run more than one instance, want the assistant to create and update credentials, are on an older n8n version that predates the built-in tools you need, or want autofix, execution error analysis, templates, and a security audit.
|
|
40
|
+
|
|
41
|
+
**Or use both through one connection.** Set `N8N_MCP_ACCESS_TOKEN` and n8n-MCP routes the operations the Public API cannot perform to n8n's own server: test runs with pinned data, n8n's native version history, live dropdown values, n8n Agents, and data-table column changes. The assistant still sees one MCP server. See [Official MCP Setup](./docs/OFFICIAL_MCP_SETUP.md).
|
|
42
|
+
|
|
43
|
+
> **Naming note:** n8n's documentation uses `n8n-mcp` as the example connection name for its built-in server in some client configurations (for example `claude mcp add --transport http n8n-mcp https://<your-n8n-domain>/mcp-server/http`). That name points at n8n's own server. This project is a separate open-source server: `github.com/czlonkowski/n8n-mcp`, published on npm as `n8n-mcp`.
|
|
44
|
+
|
|
45
|
+
## Node and Template Coverage
|
|
46
|
+
|
|
47
|
+
The documentation and validation tools work without an n8n connection, against a bundled database:
|
|
17
48
|
|
|
18
49
|
- **3,501 n8n nodes** - 842 core nodes + 2,659 community nodes (2,228 verified)
|
|
19
50
|
- **Node properties** - 99% coverage with detailed schemas
|
|
@@ -36,15 +67,15 @@ n8n-MCP serves as a bridge between n8n's workflow automation platform and AI mod
|
|
|
36
67
|
|
|
37
68
|
> 💼 **Need it built for you?** Work with [AiAdvisors — n8n automation audits, builds, and operations](https://aiadvisors.pl/en), run by the author of n8n-mcp and n8n-skills.
|
|
38
69
|
|
|
39
|
-
##
|
|
70
|
+
## Working Safely on Live Workflows
|
|
40
71
|
|
|
41
|
-
**
|
|
42
|
-
- Make a copy of your workflow before using AI tools
|
|
43
|
-
- Test in development environment first
|
|
44
|
-
- Export backups of important workflows
|
|
45
|
-
- Validate changes before deploying to production
|
|
72
|
+
AI results can be unpredictable, and n8n-MCP can change real workflows. **Try changes to important production workflows on a copy or a staging instance first.**
|
|
46
73
|
|
|
47
|
-
|
|
74
|
+
- **Snapshots and rollback** - by default n8n-MCP saves a version of a workflow before it changes its nodes or connections, and keeps up to 10 per workflow. `n8n_workflow_versions` lists, diffs, and rolls back those versions. A snapshot that fails to save does not stop the edit, so check that a version exists before relying on rollback for an important change.
|
|
75
|
+
- **One editor at a time** - n8n-MCP reads a workflow, applies the change, and writes the whole workflow back, because n8n's Public API has no conditional write. An edit made in the n8n UI in between is overwritten, so do not edit a workflow in the UI while the assistant is working on it.
|
|
76
|
+
- **Validate before deploying** - run `validate_workflow` on the change, and `n8n_validate_workflow` once it is in n8n.
|
|
77
|
+
- **Keep exports** of workflows you cannot afford to lose.
|
|
78
|
+
- **Limit what the assistant can do** - [Read-Only Deployment](#read-only-deployment) disables write operations.
|
|
48
79
|
|
|
49
80
|
## Quick Start
|
|
50
81
|
|
|
@@ -53,11 +84,14 @@ AI results can be unpredictable. Protect your work!
|
|
|
53
84
|
**[dashboard.n8n-mcp.com](https://dashboard.n8n-mcp.com)**
|
|
54
85
|
|
|
55
86
|
- Free tier: 100 tool calls/day
|
|
56
|
-
- Instant access:
|
|
87
|
+
- Instant access: Connect your n8n instance and start working on your workflows
|
|
88
|
+
- Several n8n instances through one connection, on every plan ([multi-instance guide](https://www.n8n-mcp.com/docs/multi-instance))
|
|
89
|
+
- OAuth sign-in for claude.ai and ChatGPT, API keys for IDEs and other MCP clients
|
|
90
|
+
- Your n8n API key is stored encrypted and is never returned to the AI client
|
|
57
91
|
- Always up-to-date: Latest n8n nodes and templates
|
|
58
92
|
- No infrastructure: We handle everything
|
|
59
93
|
|
|
60
|
-
Just sign up,
|
|
94
|
+
The hosted service is run by the author of this project. Just sign up, connect your n8n instance, and connect your MCP client.
|
|
61
95
|
|
|
62
96
|
**Want to self-host?** See the [Self-Hosting Guide](./docs/SELF_HOSTING.md) for npx, Docker, Railway, and local installation options.
|
|
63
97
|
|
|
@@ -381,7 +415,7 @@ Save these instructions in your Claude Project for optimal n8n workflow assistan
|
|
|
381
415
|
- `searchMode: 'by_metadata'` - Filter by `complexity`, `requiredService`, `targetAudience`
|
|
382
416
|
- **`get_template`** - Get complete workflow JSON (modes: nodes_only, structure, full)
|
|
383
417
|
|
|
384
|
-
### n8n Management Tools (
|
|
418
|
+
### n8n Management Tools (22 tools - Requires API Configuration)
|
|
385
419
|
These tools require `N8N_API_URL` and `N8N_API_KEY` in your configuration.
|
|
386
420
|
|
|
387
421
|
#### Workflow Management
|
|
@@ -407,6 +441,9 @@ These tools require `N8N_API_URL` and `N8N_API_KEY` in your configuration.
|
|
|
407
441
|
#### Folder Management
|
|
408
442
|
- **`n8n_manage_folders`** - Manage workflow folders (create, list, get, rename, move, delete; n8n 2.19+). Place workflows into folders via `n8n_create_workflow`'s `parentFolderId` or `n8n_update_partial_workflow`'s `moveToFolder` operation (n8n 2.32+)
|
|
409
443
|
|
|
444
|
+
#### Variable Management
|
|
445
|
+
- **`n8n_manage_variables`** - Manage instance variables that workflows read as `{{ $vars.KEY }}` (list, get, create, update, delete; global or project-scoped). Needs an n8n license that includes Variables; set `DISABLE_ENTERPRISE_TOOLS=true` to hide it on Community-edition instances
|
|
446
|
+
|
|
410
447
|
#### Data Table Management
|
|
411
448
|
- **`n8n_manage_datatable`** - Manage n8n data tables, rows and columns (list, get, create, update, delete; `addColumn`/`deleteColumn`/`renameColumn` change an existing table's columns through n8n's own MCP server and need `N8N_MCP_ACCESS_TOKEN`)
|
|
412
449
|
|
|
@@ -434,7 +471,7 @@ DISABLED_TOOLS=n8n_create_workflow,n8n_update_full_workflow,n8n_update_partial_w
|
|
|
434
471
|
For tools that bundle read and write operations under one name, block only the destructive operations while keeping `list` and `get`. Use this instead of a full `DISABLED_TOOLS` entry where the tool's read operations are acceptable — the `n8n_manage_datatable` and `n8n_test_workflow` entries below are the alternative to removing those tools entirely as above. The example names every write operation of every tool that has one:
|
|
435
472
|
|
|
436
473
|
```bash
|
|
437
|
-
DISABLED_TOOL_OPERATIONS=n8n_executions:delete;n8n_test_workflow:auto,trigger,pinned,direct,expose;n8n_evaluations:run,cancel;n8n_manage_folders:create,rename,move,delete;n8n_workflow_versions:delete,rollback,prune,expose;n8n_manage_agents:create,mutate,call,publish,unpublish,revert,delete,update_integration;n8n_manage_datatable:createTable,updateTable,deleteTable,insertRows,updateRows,upsertRows,deleteRows,addColumn,deleteColumn,renameColumn
|
|
474
|
+
DISABLED_TOOL_OPERATIONS=n8n_executions:delete;n8n_test_workflow:auto,trigger,pinned,direct,expose;n8n_evaluations:run,cancel;n8n_manage_folders:create,rename,move,delete;n8n_manage_variables:create,update,delete;n8n_workflow_versions:delete,rollback,prune,expose;n8n_manage_agents:create,mutate,call,publish,unpublish,revert,delete,update_integration;n8n_manage_datatable:createTable,updateTable,deleteTable,insertRows,updateRows,upsertRows,deleteRows,addColumn,deleteColumn,renameColumn
|
|
438
475
|
```
|
|
439
476
|
|
|
440
477
|
Two details are easy to miss when writing your own list. For `n8n_test_workflow`, all four of `auto`, `trigger`, `pinned` and `direct` run the workflow (an omitted or blank `method` counts as `auto`), leaving only the read-only `prepare`. And `expose` is not a value of any operation parameter: it is the `exposeToMcp` consent write of `n8n_test_workflow` and `n8n_workflow_versions`, which enables a workflow's "Available in MCP" setting. Omitting `expose` leaves that write reachable.
|
|
@@ -59,5 +59,10 @@ export declare function handleGetFolder(args: unknown, context?: InstanceContext
|
|
|
59
59
|
export declare function handleRenameFolder(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
60
60
|
export declare function handleMoveFolder(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
61
61
|
export declare function handleDeleteFolder(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
62
|
+
export declare function handleListVariables(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
63
|
+
export declare function handleGetVariable(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
64
|
+
export declare function handleCreateVariable(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
65
|
+
export declare function handleUpdateVariable(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
66
|
+
export declare function handleDeleteVariable(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
62
67
|
export declare function handleAuditInstance(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
|
|
63
68
|
//# sourceMappingURL=handlers-n8n-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers-n8n-manager.d.ts","sourceRoot":"","sources":["../../src/mcp/handlers-n8n-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI1D,OAAO,EAML,eAAe,
|
|
1
|
+
{"version":3,"file":"handlers-n8n-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GAAG,OAAO,CAAC,eAAe,CAAC,CAUxG;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAc3G;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBzG;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAgB3G;AA+ID,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAsB5G;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CA2C1G;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CA8B7G;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAqD7G;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAa7G;AAeD,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAwG5G"}
|
|
@@ -89,6 +89,11 @@ exports.handleGetFolder = handleGetFolder;
|
|
|
89
89
|
exports.handleRenameFolder = handleRenameFolder;
|
|
90
90
|
exports.handleMoveFolder = handleMoveFolder;
|
|
91
91
|
exports.handleDeleteFolder = handleDeleteFolder;
|
|
92
|
+
exports.handleListVariables = handleListVariables;
|
|
93
|
+
exports.handleGetVariable = handleGetVariable;
|
|
94
|
+
exports.handleCreateVariable = handleCreateVariable;
|
|
95
|
+
exports.handleUpdateVariable = handleUpdateVariable;
|
|
96
|
+
exports.handleDeleteVariable = handleDeleteVariable;
|
|
92
97
|
exports.handleAuditInstance = handleAuditInstance;
|
|
93
98
|
const crypto_1 = require("crypto");
|
|
94
99
|
const n8n_api_client_1 = require("../services/n8n-api-client");
|
|
@@ -3751,6 +3756,250 @@ async function handleDeleteFolder(args, context) {
|
|
|
3751
3756
|
return handleFolderError(error);
|
|
3752
3757
|
}
|
|
3753
3758
|
}
|
|
3759
|
+
const VARIABLE_GLOBAL_FILTER = 'null';
|
|
3760
|
+
const VARIABLE_PAGE_LIMIT = 250;
|
|
3761
|
+
const VARIABLE_MAX_PAGES = 40;
|
|
3762
|
+
const variableValueSchema = zod_1.z.string().max(1000, 'value cannot be longer than 1000 characters');
|
|
3763
|
+
const variableKeySchema = zod_1.z.string().trim().min(1).max(50).regex(/^[A-Za-z_][A-Za-z0-9_]*$/, 'key may contain only letters, digits and underscores, and must not start with a digit');
|
|
3764
|
+
const optionalVariableProjectId = zod_1.z.preprocess(nullOrEmptyToUndefined, zod_1.z.string().trim().min(1).max(36).optional());
|
|
3765
|
+
const listVariablesSchema = zod_1.z.object({
|
|
3766
|
+
projectId: optionalVariableProjectId,
|
|
3767
|
+
state: optionalEmptyAware(zod_1.z.literal('empty')),
|
|
3768
|
+
limit: optionalEmptyAware(zod_1.z.number().int().min(1).max(VARIABLE_PAGE_LIMIT)),
|
|
3769
|
+
cursor: optionalEmptyAware(zod_1.z.string().trim().min(1)),
|
|
3770
|
+
});
|
|
3771
|
+
const getVariableSchema = zod_1.z.object({
|
|
3772
|
+
id: optionalEmptyAware(zod_1.z.string().trim().min(1)),
|
|
3773
|
+
key: optionalEmptyAware(zod_1.z.string().trim().min(1)),
|
|
3774
|
+
projectId: optionalVariableProjectId,
|
|
3775
|
+
}).refine((v) => v.id || v.key, { message: 'id or key is required', path: ['id'] });
|
|
3776
|
+
const createVariableSchema = zod_1.z.object({
|
|
3777
|
+
key: variableKeySchema,
|
|
3778
|
+
value: variableValueSchema,
|
|
3779
|
+
projectId: optionalVariableProjectId,
|
|
3780
|
+
});
|
|
3781
|
+
const updateVariableSchema = zod_1.z.object({
|
|
3782
|
+
id: zod_1.z.string().trim().min(1),
|
|
3783
|
+
key: optionalEmptyAware(variableKeySchema),
|
|
3784
|
+
value: zod_1.z.preprocess((v) => (v === '' ? undefined : v), variableValueSchema.optional()),
|
|
3785
|
+
clearValue: optionalEmptyAware(zod_1.z.boolean()),
|
|
3786
|
+
projectId: zod_1.z.preprocess(emptyToUndefined, zod_1.z.string().trim().min(1).max(36).nullable().optional()),
|
|
3787
|
+
}).refine((v) => v.key !== undefined || v.value !== undefined || v.projectId !== undefined || v.clearValue, {
|
|
3788
|
+
message: 'update needs at least one of key, value, clearValue or projectId',
|
|
3789
|
+
path: ['value'],
|
|
3790
|
+
}).refine((v) => !(v.clearValue && v.value !== undefined), {
|
|
3791
|
+
message: 'pass either value or clearValue, not both',
|
|
3792
|
+
path: ['clearValue'],
|
|
3793
|
+
});
|
|
3794
|
+
const deleteVariableSchema = zod_1.z.object({
|
|
3795
|
+
id: zod_1.z.string().trim().min(1),
|
|
3796
|
+
});
|
|
3797
|
+
function isGlobalAlias(projectId) {
|
|
3798
|
+
return projectId === null || (typeof projectId === 'string' && projectId.toLowerCase() === 'global');
|
|
3799
|
+
}
|
|
3800
|
+
function toVariableListScope(projectId) {
|
|
3801
|
+
return projectId && isGlobalAlias(projectId) ? VARIABLE_GLOBAL_FILTER : projectId;
|
|
3802
|
+
}
|
|
3803
|
+
function toProjectSummary(project) {
|
|
3804
|
+
return project ? { id: project.id, name: project.name } : null;
|
|
3805
|
+
}
|
|
3806
|
+
function toVariableSummary(variable) {
|
|
3807
|
+
return {
|
|
3808
|
+
id: variable.id,
|
|
3809
|
+
key: variable.key,
|
|
3810
|
+
value: variable.value,
|
|
3811
|
+
type: variable.type,
|
|
3812
|
+
project: toProjectSummary(variable.project),
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
async function listAllVariables(client, projectId, stopAt) {
|
|
3816
|
+
const variables = [];
|
|
3817
|
+
let cursor;
|
|
3818
|
+
for (let page = 0; page < VARIABLE_MAX_PAGES; page++) {
|
|
3819
|
+
const result = await client.listVariables({
|
|
3820
|
+
limit: VARIABLE_PAGE_LIMIT,
|
|
3821
|
+
...(cursor ? { cursor } : {}),
|
|
3822
|
+
...(projectId ? { projectId } : {}),
|
|
3823
|
+
});
|
|
3824
|
+
variables.push(...result.data);
|
|
3825
|
+
if (!result.nextCursor || (stopAt && result.data.some(stopAt)))
|
|
3826
|
+
return { variables, truncated: false };
|
|
3827
|
+
cursor = result.nextCursor;
|
|
3828
|
+
}
|
|
3829
|
+
return { variables, truncated: true };
|
|
3830
|
+
}
|
|
3831
|
+
const VARIABLE_LICENSE_HINT = 'Variables need an n8n license that includes the Variables feature (feat:variables; it is not part of the free Community edition) and an API key with variable:* scopes.';
|
|
3832
|
+
function handleVariableError(error) {
|
|
3833
|
+
const response = handleCrudError(error);
|
|
3834
|
+
if (error instanceof n8n_errors_1.N8nApiError) {
|
|
3835
|
+
const base = (response.error ?? '').trimEnd();
|
|
3836
|
+
const append = (hint) => {
|
|
3837
|
+
response.error = `${base}${/[.!?]$/.test(base) ? '' : '.'} ${hint}`;
|
|
3838
|
+
};
|
|
3839
|
+
if (error.statusCode === 403) {
|
|
3840
|
+
append(VARIABLE_LICENSE_HINT);
|
|
3841
|
+
}
|
|
3842
|
+
else if (error.statusCode === 404) {
|
|
3843
|
+
append('Check the variable id (find it with action=list); on n8n versions without the variables API the route itself is missing.');
|
|
3844
|
+
}
|
|
3845
|
+
else if (/already exists/i.test(base)) {
|
|
3846
|
+
append('Keys are unique per scope (global, or per project): update the existing variable instead.');
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
return response;
|
|
3850
|
+
}
|
|
3851
|
+
async function handleListVariables(args, context) {
|
|
3852
|
+
try {
|
|
3853
|
+
const client = ensureApiConfigured(context);
|
|
3854
|
+
const input = listVariablesSchema.parse(args || {});
|
|
3855
|
+
const projectId = toVariableListScope(input.projectId);
|
|
3856
|
+
const result = await client.listVariables({
|
|
3857
|
+
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
|
3858
|
+
...(input.cursor ? { cursor: input.cursor } : {}),
|
|
3859
|
+
...(projectId ? { projectId } : {}),
|
|
3860
|
+
...(input.state ? { state: input.state } : {}),
|
|
3861
|
+
});
|
|
3862
|
+
return {
|
|
3863
|
+
success: true,
|
|
3864
|
+
data: {
|
|
3865
|
+
variables: result.data.map(toVariableSummary),
|
|
3866
|
+
returned: result.data.length,
|
|
3867
|
+
...(result.nextCursor ? { nextCursor: result.nextCursor } : {}),
|
|
3868
|
+
},
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
catch (error) {
|
|
3872
|
+
return handleVariableError(error);
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
async function handleGetVariable(args, context) {
|
|
3876
|
+
try {
|
|
3877
|
+
const client = ensureApiConfigured(context);
|
|
3878
|
+
const input = getVariableSchema.parse(args || {});
|
|
3879
|
+
const isMatch = (v) => (input.id === undefined || v.id === input.id) && (input.key === undefined || v.key === input.key);
|
|
3880
|
+
const unique = input.id !== undefined || input.projectId !== undefined;
|
|
3881
|
+
const { variables, truncated } = await listAllVariables(client, toVariableListScope(input.projectId), unique ? isMatch : undefined);
|
|
3882
|
+
const matches = variables.filter(isMatch);
|
|
3883
|
+
const label = [input.id ? `id ${input.id}` : '', input.key ? `key "${input.key}"` : ''].filter(Boolean).join(' and ');
|
|
3884
|
+
if (matches.length === 0) {
|
|
3885
|
+
return {
|
|
3886
|
+
success: false,
|
|
3887
|
+
error: `No variable with ${label} is visible to this API key${input.projectId ? ' in that scope' : ''}.${truncated ? ` Only the first ${VARIABLE_PAGE_LIMIT * VARIABLE_MAX_PAGES} variables were searched.` : ''}`,
|
|
3888
|
+
code: 'NOT_FOUND',
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
if (matches.length > 1) {
|
|
3892
|
+
return {
|
|
3893
|
+
success: false,
|
|
3894
|
+
error: `${matches.length} variables share ${label}. Pass projectId ('global' for the global one) or the id.`,
|
|
3895
|
+
details: { matches: matches.map(toVariableSummary) },
|
|
3896
|
+
};
|
|
3897
|
+
}
|
|
3898
|
+
if (truncated && !unique) {
|
|
3899
|
+
return {
|
|
3900
|
+
success: false,
|
|
3901
|
+
error: `Only the first ${VARIABLE_PAGE_LIMIT * VARIABLE_MAX_PAGES} variables were searched, so another variable with key "${input.key}" may exist in a different scope. Pass projectId ('global' for the global one) or the id.`,
|
|
3902
|
+
code: 'INCOMPLETE_SEARCH',
|
|
3903
|
+
details: { matches: matches.map(toVariableSummary) },
|
|
3904
|
+
};
|
|
3905
|
+
}
|
|
3906
|
+
return { success: true, data: toVariableSummary(matches[0]) };
|
|
3907
|
+
}
|
|
3908
|
+
catch (error) {
|
|
3909
|
+
return handleVariableError(error);
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
async function handleCreateVariable(args, context) {
|
|
3913
|
+
try {
|
|
3914
|
+
const client = ensureApiConfigured(context);
|
|
3915
|
+
const input = createVariableSchema.parse(args);
|
|
3916
|
+
const projectId = input.projectId && !isGlobalAlias(input.projectId) ? input.projectId : undefined;
|
|
3917
|
+
await client.createVariable({ key: input.key, value: input.value, ...(projectId ? { projectId } : {}) });
|
|
3918
|
+
let created;
|
|
3919
|
+
try {
|
|
3920
|
+
const isCreated = (v) => v.key === input.key;
|
|
3921
|
+
const { variables } = await listAllVariables(client, projectId ?? VARIABLE_GLOBAL_FILTER, isCreated);
|
|
3922
|
+
created = variables.find(isCreated);
|
|
3923
|
+
}
|
|
3924
|
+
catch (lookupError) {
|
|
3925
|
+
logger_1.logger.debug('Variable created but the ID lookup failed', lookupError instanceof Error ? lookupError.message : lookupError);
|
|
3926
|
+
}
|
|
3927
|
+
const scopeLabel = projectId ? `project ${projectId}` : 'the global scope';
|
|
3928
|
+
return {
|
|
3929
|
+
success: true,
|
|
3930
|
+
data: created
|
|
3931
|
+
? toVariableSummary(created)
|
|
3932
|
+
: { key: input.key, value: input.value, project: projectId ? { id: projectId } : null },
|
|
3933
|
+
message: created
|
|
3934
|
+
? `Variable "${input.key}" created in ${scopeLabel} with ID: ${created.id}. Reference it in expressions as {{ $vars.${input.key} }}.`
|
|
3935
|
+
: `Variable "${input.key}" created in ${scopeLabel}, but its ID could not be read back - run action=list to find it.`,
|
|
3936
|
+
};
|
|
3937
|
+
}
|
|
3938
|
+
catch (error) {
|
|
3939
|
+
return handleVariableError(error);
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
async function handleUpdateVariable(args, context) {
|
|
3943
|
+
try {
|
|
3944
|
+
const client = ensureApiConfigured(context);
|
|
3945
|
+
const input = updateVariableSchema.parse(args);
|
|
3946
|
+
let key = input.key;
|
|
3947
|
+
let value = input.clearValue ? '' : input.value;
|
|
3948
|
+
let project;
|
|
3949
|
+
if (key === undefined || value === undefined) {
|
|
3950
|
+
const isTarget = (v) => v.id === input.id;
|
|
3951
|
+
const { variables, truncated } = await listAllVariables(client, undefined, isTarget);
|
|
3952
|
+
const current = variables.find(isTarget);
|
|
3953
|
+
if (!current) {
|
|
3954
|
+
return {
|
|
3955
|
+
success: false,
|
|
3956
|
+
error: truncated
|
|
3957
|
+
? `Variable ${input.id} is not among the first ${VARIABLE_PAGE_LIMIT * VARIABLE_MAX_PAGES} variables. Pass both key and value so the update needs no lookup.`
|
|
3958
|
+
: `No variable with id ${input.id} is visible to this API key. Find the id with action=list.`,
|
|
3959
|
+
code: 'NOT_FOUND',
|
|
3960
|
+
};
|
|
3961
|
+
}
|
|
3962
|
+
key = key ?? current.key;
|
|
3963
|
+
value = value ?? current.value;
|
|
3964
|
+
project = toProjectSummary(current.project);
|
|
3965
|
+
}
|
|
3966
|
+
let projectId;
|
|
3967
|
+
let scopeNote = '';
|
|
3968
|
+
if (input.projectId !== undefined) {
|
|
3969
|
+
projectId = isGlobalAlias(input.projectId) ? null : input.projectId;
|
|
3970
|
+
project = projectId ? { id: projectId } : null;
|
|
3971
|
+
scopeNote = projectId ? ` and moved to project ${projectId}` : ' and moved to the global scope';
|
|
3972
|
+
}
|
|
3973
|
+
await client.updateVariable(input.id, {
|
|
3974
|
+
key: key,
|
|
3975
|
+
value: value,
|
|
3976
|
+
...(projectId !== undefined ? { projectId } : {}),
|
|
3977
|
+
});
|
|
3978
|
+
return {
|
|
3979
|
+
success: true,
|
|
3980
|
+
data: { id: input.id, key, value, ...(project !== undefined ? { project } : {}) },
|
|
3981
|
+
message: `Variable ${input.id} updated${scopeNote}.`,
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
catch (error) {
|
|
3985
|
+
return handleVariableError(error);
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
async function handleDeleteVariable(args, context) {
|
|
3989
|
+
try {
|
|
3990
|
+
const client = ensureApiConfigured(context);
|
|
3991
|
+
const input = deleteVariableSchema.parse(args);
|
|
3992
|
+
await client.deleteVariable(input.id);
|
|
3993
|
+
return {
|
|
3994
|
+
success: true,
|
|
3995
|
+
data: { id: input.id, deleted: true },
|
|
3996
|
+
message: `Variable ${input.id} deleted. Expressions that read it now resolve to undefined.`,
|
|
3997
|
+
};
|
|
3998
|
+
}
|
|
3999
|
+
catch (error) {
|
|
4000
|
+
return handleVariableError(error);
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
3754
4003
|
const auditInstanceSchema = zod_1.z.object({
|
|
3755
4004
|
categories: zod_1.z.array(zod_1.z.enum([
|
|
3756
4005
|
'credentials', 'database', 'nodes', 'instance', 'filesystem',
|