n8n-ops-mcp 0.1.2 → 0.3.0
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/README.md +118 -82
- package/dist/mcp-server.js +328 -49
- package/index.ts +4 -0
- package/openclaw.plugin.json +2 -2
- package/package.json +19 -5
- package/src/client.ts +13 -0
- package/src/tools/cancel-execution.ts +54 -0
- package/src/tools/search-executions.ts +249 -0
package/README.md
CHANGED
|
@@ -1,87 +1,86 @@
|
|
|
1
1
|
# n8n-ops-mcp
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/n8n-ops-mcp)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://modelcontextprotocol.io)
|
|
6
|
+
|
|
3
7
|
Ops-focused n8n tools for Claude-compatible clients. List, inspect, trigger, validate, and safely edit n8n workflows from any MCP host — with first-class [OpenClaw](https://github.com/openclaw/openclaw) support.
|
|
4
8
|
|
|
5
9
|
Works with Claude Desktop, Claude Code, OpenClaw, Hermes Agent, Codex CLI, and any other MCP-compatible client.
|
|
6
10
|
|
|
7
11
|
## Why
|
|
8
12
|
|
|
9
|
-
Your AI agent has no native awareness of your n8n footprint.
|
|
13
|
+
Your AI agent has no native awareness of your n8n footprint. With this package, it can answer "what's broken in my n8n?" and trigger workflows from chat without you leaving your client.
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
For a catalog/docs tool that indexes n8n's node library, see [n8n-mcp](https://www.npmjs.com/package/n8n-mcp). This one is ops-focused — list, trigger, validate, edit.
|
|
12
16
|
|
|
13
17
|
## Tools
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
| Tool | Purpose | Write |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `n8n_list_workflows` | List workflows, filter by `active` / `tags` / `name` | |
|
|
22
|
+
| `n8n_get_workflow` | Fetch one workflow, optionally with full node graph | |
|
|
23
|
+
| `n8n_list_executions` | List recent executions, filter by workflow / status | |
|
|
24
|
+
| `n8n_get_execution` | Fetch an execution with per-node run log + raw error | |
|
|
25
|
+
| `n8n_search_executions` | Text-search recent executions for an error fragment | |
|
|
26
|
+
| `n8n_list_webhooks` | Enumerate webhook + form-trigger URLs | |
|
|
27
|
+
| `n8n_validate_workflow` | Static checks: deprecated nodes, legacy Code-node API, orphans | |
|
|
28
|
+
| `n8n_trigger` | Run a workflow via webhook (reliable) or workflow-id | |
|
|
29
|
+
| `n8n_activate` | Enable a workflow's triggers | ✓ |
|
|
30
|
+
| `n8n_deactivate` | Disable a workflow's triggers | ✓ |
|
|
31
|
+
| `n8n_save_workflow` | Overwrite a workflow with auto-backup + validation + confirm gate | ✓ |
|
|
32
|
+
| `n8n_cancel_execution` | Stop a running or waiting execution by id | ✓ |
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
<details>
|
|
37
|
+
<summary><b>Detailed tool reference</b></summary>
|
|
20
38
|
|
|
21
|
-
**`
|
|
39
|
+
**`n8n_list_workflows`** — filter by `active`, `tags`, `name` (substring), `limit`. Returns id, name, active state, tags, updatedAt.
|
|
22
40
|
|
|
23
|
-
**`
|
|
41
|
+
**`n8n_get_workflow`** — fetch one by id. Returns metadata by default. Pass `includeDefinition: true` for the full node graph + connections.
|
|
24
42
|
|
|
25
|
-
**`
|
|
43
|
+
**`n8n_list_executions`** — filter by `workflowId`, `status` (success/error/running/waiting/canceled), `limit`. Returns id, workflowId, workflowName, status, mode, startedAt, stoppedAt.
|
|
26
44
|
|
|
27
|
-
|
|
45
|
+
**`n8n_get_execution`** — includes per-node run log (truncated to `maxExecutionLogBytes`, default 64 KB) and the raw error object verbatim when status is `error`. Pass `includeRunData: false` to skip the run log.
|
|
28
46
|
|
|
29
|
-
**`
|
|
47
|
+
**`n8n_search_executions`** — defaults to scanning `status=error` executions for a `query` fragment (e.g. `ECONNREFUSED`) and returning matches with workflow context + a snippet around each hit. `scope: "error"` (default) greps the error payload only; `scope: "all"` also greps full per-node run data (slower, may return node outputs — treat snippets as sensitive). Optional `workflowId`, `status`, `limit` (default 50, max 250), `maxMatches` (default 20), `snippetChars` (default 160). Returns `matches` plus a `skipped` array for any execution that failed to fetch.
|
|
30
48
|
|
|
31
|
-
**`
|
|
49
|
+
**`n8n_list_webhooks`** — scans workflows for webhook and form-trigger nodes and returns their paths + fully-formed `triggerUrl`. Pairs with `n8n_trigger` mode='webhook'. Optional `workflowId`, `activeOnly` (default true), `limit` (default 50).
|
|
32
50
|
|
|
33
|
-
**`
|
|
51
|
+
**`n8n_validate_workflow`** — checks for deprecated node types (function → code), legacy Code-node API (`$node[]`, `items` global, `require()`), orphan nodes, disabled nodes, missing trigger. Returns issues with severity (error/warning/info) plus a summary count.
|
|
34
52
|
|
|
35
|
-
**`n8n_trigger`**
|
|
36
|
-
- `mode: "webhook"` + `webhookPath`
|
|
37
|
-
- `mode: "workflow"` + `workflowId`
|
|
53
|
+
**`n8n_trigger`** — two modes:
|
|
54
|
+
- `mode: "webhook"` + `webhookPath` — POST (or GET/PUT/DELETE) to the configured base URL + path, with an optional JSON `payload`. This is the reliable path.
|
|
55
|
+
- `mode: "workflow"` + `workflowId` — attempts `POST /api/v1/workflows/:id/execute`. Pre-checks that the workflow is active and has a webhook/manual/form trigger. Most n8n builds don't expose this endpoint on the Public API and will 405; the tool surfaces a hint to switch to webhook mode.
|
|
38
56
|
|
|
39
|
-
|
|
57
|
+
**`n8n_activate`** / **`n8n_deactivate`** — idempotent. Deactivating does not cancel running executions.
|
|
40
58
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
**`n8n_save_workflow`** — before writing: fetches the current version, snapshots it to `backupDir` as `<id>-<timestamp>.json` (mode 0600), runs `validateWorkflow` on the proposed state, and aborts on error-severity issues (pass `skipValidation: true` to bypass). Requires `confirm: true` to actually PUT. Response includes the backup path and a `restoreHint`.
|
|
60
|
+
|
|
61
|
+
**`n8n_cancel_execution`** — `POST /executions/{id}/stop`. Closes the triage loop after `n8n_search_executions` locates a stuck run. Returns a success summary with the execution's final status, or `ok: false` with `reason: "not_found_or_finished"` if the id no longer matches a running execution (404).
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
## Install
|
|
46
66
|
|
|
47
67
|
```bash
|
|
48
|
-
|
|
49
|
-
cd n8n-ops-mcp
|
|
50
|
-
npm install
|
|
51
|
-
npm run build
|
|
68
|
+
npm install -g n8n-ops-mcp
|
|
52
69
|
```
|
|
53
70
|
|
|
54
71
|
## Configuration
|
|
55
72
|
|
|
56
|
-
Generate an API key in n8n under Settings
|
|
73
|
+
Generate an API key in n8n under **Settings → API**, then set these env vars in your MCP client config:
|
|
57
74
|
|
|
58
75
|
| Variable | Required | Default | Description |
|
|
59
76
|
|---|---|---|---|
|
|
60
77
|
| `N8N_BASE_URL` | yes | — | n8n base URL, e.g. `http://localhost:5678` |
|
|
61
78
|
| `N8N_API_KEY` | yes | — | n8n Public API key (`X-N8N-API-KEY`) |
|
|
62
|
-
| `N8N_ENABLE_EDIT` | no | `false` |
|
|
79
|
+
| `N8N_ENABLE_EDIT` | no | `false` | Expose write tools |
|
|
63
80
|
| `N8N_BACKUP_DIR` | no | `~/.n8n-backups` | Where `n8n_save_workflow` writes pre-save snapshots |
|
|
64
81
|
| `N8N_MAX_EXECUTION_LOG_BYTES` | no | `65536` | Cap on inline execution log bytes |
|
|
65
82
|
| `N8N_REQUEST_TIMEOUT_MS` | no | `15000` | HTTP timeout for n8n API calls |
|
|
66
83
|
|
|
67
|
-
### Claude Desktop
|
|
68
|
-
|
|
69
|
-
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
70
|
-
|
|
71
|
-
```json
|
|
72
|
-
{
|
|
73
|
-
"mcpServers": {
|
|
74
|
-
"n8n": {
|
|
75
|
-
"command": "n8n-ops-mcp",
|
|
76
|
-
"env": {
|
|
77
|
-
"N8N_BASE_URL": "http://localhost:5678",
|
|
78
|
-
"N8N_API_KEY": "your-api-key-here"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
84
|
### Claude Code
|
|
86
85
|
|
|
87
86
|
```bash
|
|
@@ -93,17 +92,19 @@ claude mcp add n8n \
|
|
|
93
92
|
|
|
94
93
|
Add `--scope user` to make it available from any directory instead of only the current project.
|
|
95
94
|
|
|
96
|
-
### OpenClaw
|
|
95
|
+
### OpenClaw
|
|
96
|
+
|
|
97
|
+
n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — so it shares the gateway's process, auth profiles, and hooks.
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
```bash
|
|
100
|
+
openclaw plugins install clawhub:n8n-ops-mcp
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Add the config block to `~/.openclaw/openclaw.json`:
|
|
99
104
|
|
|
100
105
|
```json
|
|
101
106
|
{
|
|
102
107
|
"plugins": {
|
|
103
|
-
"allow": ["n8n"],
|
|
104
|
-
"load": {
|
|
105
|
-
"paths": ["/absolute/path/to/n8n-ops-mcp"]
|
|
106
|
-
},
|
|
107
108
|
"entries": {
|
|
108
109
|
"n8n": {
|
|
109
110
|
"enabled": true,
|
|
@@ -117,7 +118,7 @@ n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — which mea
|
|
|
117
118
|
}
|
|
118
119
|
```
|
|
119
120
|
|
|
120
|
-
Put the API key in your OpenClaw workspace env
|
|
121
|
+
Put the API key in your OpenClaw workspace env:
|
|
121
122
|
|
|
122
123
|
```bash
|
|
123
124
|
# ~/.openclaw/workspace/.env
|
|
@@ -130,21 +131,32 @@ Restart the gateway:
|
|
|
130
131
|
systemctl --user restart openclaw-gateway
|
|
131
132
|
```
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
Config keys: `baseUrl`, `apiKey`, `apiKeyEnv`, `enableEdit`, `maxExecutionLogBytes`, `requestTimeoutMs`, `backupDir`. See [`openclaw.plugin.json`](./openclaw.plugin.json) for the full schema.
|
|
134
135
|
|
|
135
|
-
|
|
136
|
+
<details>
|
|
137
|
+
<summary><b>Other clients</b> — Claude Desktop, Hermes Agent, Codex CLI, manual OpenClaw install</summary>
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
### Claude Desktop
|
|
138
140
|
|
|
139
|
-
|
|
140
|
-
openclaw plugins install clawhub:n8n-ops-mcp
|
|
141
|
-
```
|
|
141
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"mcpServers": {
|
|
146
|
+
"n8n": {
|
|
147
|
+
"command": "n8n-ops-mcp",
|
|
148
|
+
"env": {
|
|
149
|
+
"N8N_BASE_URL": "http://localhost:5678",
|
|
150
|
+
"N8N_API_KEY": "your-api-key-here"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
144
156
|
|
|
145
157
|
### Hermes Agent
|
|
146
158
|
|
|
147
|
-
[Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml
|
|
159
|
+
[Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml`:
|
|
148
160
|
|
|
149
161
|
```yaml
|
|
150
162
|
mcp_servers:
|
|
@@ -155,7 +167,7 @@ mcp_servers:
|
|
|
155
167
|
N8N_API_KEY: "your-api-key-here"
|
|
156
168
|
```
|
|
157
169
|
|
|
158
|
-
Then reload
|
|
170
|
+
Then reload from inside a session:
|
|
159
171
|
|
|
160
172
|
```
|
|
161
173
|
/reload-mcp
|
|
@@ -163,8 +175,6 @@ Then reload MCP from inside a Hermes session:
|
|
|
163
175
|
|
|
164
176
|
### Codex CLI
|
|
165
177
|
|
|
166
|
-
[Codex CLI](https://github.com/openai/codex) registers MCP servers via `codex mcp add`:
|
|
167
|
-
|
|
168
178
|
```bash
|
|
169
179
|
codex mcp add n8n \
|
|
170
180
|
--env N8N_BASE_URL=http://localhost:5678 \
|
|
@@ -172,53 +182,79 @@ codex mcp add n8n \
|
|
|
172
182
|
-- n8n-ops-mcp
|
|
173
183
|
```
|
|
174
184
|
|
|
175
|
-
|
|
185
|
+
Writes the entry to `~/.codex/config.toml` under `[mcp_servers.n8n]`. Verify with `codex mcp list`.
|
|
176
186
|
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
### OpenClaw — manual (non-ClawHub) install
|
|
188
|
+
|
|
189
|
+
If you want to point OpenClaw at a local clone instead of the registry:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"plugins": {
|
|
194
|
+
"allow": ["n8n"],
|
|
195
|
+
"load": {
|
|
196
|
+
"paths": ["/absolute/path/to/n8n-ops-mcp"]
|
|
197
|
+
},
|
|
198
|
+
"entries": {
|
|
199
|
+
"n8n": {
|
|
200
|
+
"enabled": true,
|
|
201
|
+
"config": {
|
|
202
|
+
"baseUrl": "http://your-n8n-host:5678",
|
|
203
|
+
"enableEdit": false
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
179
209
|
```
|
|
180
210
|
|
|
211
|
+
</details>
|
|
212
|
+
|
|
181
213
|
## Example prompts
|
|
182
214
|
|
|
183
215
|
> What n8n workflows broke today?
|
|
184
216
|
|
|
185
|
-
Calls `n8n_list_executions` with `status=error`, then
|
|
217
|
+
Calls `n8n_list_executions` with `status=error`, then `n8n_get_execution` for the failing run.
|
|
218
|
+
|
|
219
|
+
> Which workflow errored with "ECONNREFUSED"?
|
|
220
|
+
|
|
221
|
+
Calls `n8n_search_executions` with `query: "ECONNREFUSED"`.
|
|
186
222
|
|
|
187
223
|
> Trigger the "nightly intel" workflow
|
|
188
224
|
|
|
189
|
-
Calls `n8n_list_webhooks` to find the
|
|
225
|
+
Calls `n8n_list_webhooks` to find the path, then `n8n_trigger` with `mode=webhook`.
|
|
190
226
|
|
|
191
227
|
> Audit my workflows for deprecated Code-node API usage
|
|
192
228
|
|
|
193
229
|
Calls `n8n_list_workflows` then `n8n_validate_workflow` per id, filters for `code-node-old-node-ref` and `code-node-items-global` warnings.
|
|
194
230
|
|
|
195
|
-
> Deactivate the "experimental-bot" workflow (requires `N8N_ENABLE_EDIT=true`)
|
|
231
|
+
> Deactivate the "experimental-bot" workflow *(requires `N8N_ENABLE_EDIT=true`)*
|
|
196
232
|
|
|
197
233
|
Calls `n8n_list_workflows` with a name filter, then `n8n_deactivate` on the matching id.
|
|
198
234
|
|
|
235
|
+
> Kill the execution stuck on ECONNREFUSED *(requires `N8N_ENABLE_EDIT=true`)*
|
|
236
|
+
|
|
237
|
+
Calls `n8n_search_executions` with `query: "ECONNREFUSED"`, then `n8n_cancel_execution` on the match.
|
|
238
|
+
|
|
199
239
|
## Development
|
|
200
240
|
|
|
201
241
|
```bash
|
|
202
242
|
npm install
|
|
203
243
|
npm run dev # tsx on mcp-server.ts (MCP stdio)
|
|
204
|
-
npm run typecheck
|
|
244
|
+
npm run typecheck
|
|
245
|
+
npm test # vitest run
|
|
205
246
|
npm run build # tsup bundle to dist/mcp-server.js
|
|
206
247
|
npm start # node dist/mcp-server.js (post-build)
|
|
207
248
|
```
|
|
208
249
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
- [x] `n8n_validate_workflow` (Code node + deprecated node checks)
|
|
218
|
-
- [x] `n8n_activate` / `n8n_deactivate` (behind `enableEdit`)
|
|
219
|
-
- [x] `n8n_save_workflow` with auto-backup + validation gate (behind `enableEdit`)
|
|
220
|
-
- [x] MCP wrapper (stdio)
|
|
221
|
-
- [ ] `n8n_search_executions` (text search across run logs)
|
|
250
|
+
Or install from source:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
git clone https://github.com/solomonneas/n8n-ops-mcp.git
|
|
254
|
+
cd n8n-ops-mcp
|
|
255
|
+
npm install
|
|
256
|
+
npm run build
|
|
257
|
+
```
|
|
222
258
|
|
|
223
259
|
## License
|
|
224
260
|
|
package/dist/mcp-server.js
CHANGED
|
@@ -25,6 +25,9 @@ var N8nClient = class {
|
|
|
25
25
|
this.apiKey = opts.apiKey;
|
|
26
26
|
this.timeoutMs = opts.timeoutMs ?? 15e3;
|
|
27
27
|
}
|
|
28
|
+
redact(text) {
|
|
29
|
+
return redactKey(text, this.apiKey);
|
|
30
|
+
}
|
|
28
31
|
async listWorkflows(params = {}) {
|
|
29
32
|
const qs = new URLSearchParams();
|
|
30
33
|
if (params.active !== void 0) qs.set("active", String(params.active));
|
|
@@ -122,6 +125,14 @@ var N8nClient = class {
|
|
|
122
125
|
`/api/v1/executions/${id}${qs.toString() ? `?${qs}` : ""}`
|
|
123
126
|
);
|
|
124
127
|
}
|
|
128
|
+
async stopExecution(id) {
|
|
129
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id)) {
|
|
130
|
+
throw new Error(`Invalid execution id: ${id}`);
|
|
131
|
+
}
|
|
132
|
+
return this.request(`/api/v1/executions/${id}/stop`, {
|
|
133
|
+
method: "POST"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
125
136
|
async listExecutions(params = {}) {
|
|
126
137
|
const qs = new URLSearchParams();
|
|
127
138
|
if (params.workflowId) qs.set("workflowId", params.workflowId);
|
|
@@ -468,35 +479,234 @@ function truncateRunData(runData, maxBytes) {
|
|
|
468
479
|
};
|
|
469
480
|
}
|
|
470
481
|
|
|
471
|
-
// src/tools/
|
|
482
|
+
// src/tools/search-executions.ts
|
|
472
483
|
import { Type as Type5 } from "@sinclair/typebox";
|
|
473
484
|
var Schema5 = Type5.Object(
|
|
474
485
|
{
|
|
475
|
-
|
|
476
|
-
|
|
486
|
+
query: Type5.String({
|
|
487
|
+
minLength: 1,
|
|
488
|
+
description: "Case-insensitive text to search for. Typical: an error fragment like 'ECONNREFUSED' or a node name."
|
|
477
489
|
}),
|
|
478
490
|
workflowId: Type5.Optional(
|
|
479
491
|
Type5.String({
|
|
492
|
+
description: "Filter to a single workflow id. Omit to scan across all workflows."
|
|
493
|
+
})
|
|
494
|
+
),
|
|
495
|
+
status: Type5.Optional(
|
|
496
|
+
Type5.Union(
|
|
497
|
+
[
|
|
498
|
+
Type5.Literal("success"),
|
|
499
|
+
Type5.Literal("error"),
|
|
500
|
+
Type5.Literal("running"),
|
|
501
|
+
Type5.Literal("waiting"),
|
|
502
|
+
Type5.Literal("canceled")
|
|
503
|
+
],
|
|
504
|
+
{
|
|
505
|
+
description: "Filter executions by status before searching. Default 'error' \u2014 matches the main use case ('which workflow errored with X?')."
|
|
506
|
+
}
|
|
507
|
+
)
|
|
508
|
+
),
|
|
509
|
+
scope: Type5.Optional(
|
|
510
|
+
Type5.Union(
|
|
511
|
+
[Type5.Literal("error"), Type5.Literal("all")],
|
|
512
|
+
{
|
|
513
|
+
description: "'error' (default) searches only the execution error payload. 'all' additionally greps the full per-node run log \u2014 slower and returns more raw data."
|
|
514
|
+
}
|
|
515
|
+
)
|
|
516
|
+
),
|
|
517
|
+
limit: Type5.Optional(
|
|
518
|
+
Type5.Integer({
|
|
519
|
+
minimum: 1,
|
|
520
|
+
maximum: 250,
|
|
521
|
+
description: "Max executions to scan (default 50)."
|
|
522
|
+
})
|
|
523
|
+
),
|
|
524
|
+
maxMatches: Type5.Optional(
|
|
525
|
+
Type5.Integer({
|
|
526
|
+
minimum: 1,
|
|
527
|
+
maximum: 100,
|
|
528
|
+
description: "Stop after this many matches (default 20)."
|
|
529
|
+
})
|
|
530
|
+
),
|
|
531
|
+
snippetChars: Type5.Optional(
|
|
532
|
+
Type5.Integer({
|
|
533
|
+
minimum: 40,
|
|
534
|
+
maximum: 600,
|
|
535
|
+
description: "Context window around each match (default 160)."
|
|
536
|
+
})
|
|
537
|
+
)
|
|
538
|
+
},
|
|
539
|
+
{ additionalProperties: false }
|
|
540
|
+
);
|
|
541
|
+
var DEFAULT_LIMIT = 50;
|
|
542
|
+
var DEFAULT_MAX_MATCHES = 20;
|
|
543
|
+
var DEFAULT_SNIPPET_CHARS = 160;
|
|
544
|
+
function createSearchExecutionsTool(getClient) {
|
|
545
|
+
return {
|
|
546
|
+
name: "n8n_search_executions",
|
|
547
|
+
label: "n8n: search executions",
|
|
548
|
+
description: "Text-search recent n8n executions without paging through them one by one. Fetches each candidate with includeData=true, then greps the error payload (scope='error', default) or the full per-node run log (scope='all'). Returns matched executions with workflow context and a snippet around each hit. Snippets are raw run data with the API key redacted \u2014 with scope='all' they may still contain credentials or payload data from node outputs, so treat as sensitive.",
|
|
549
|
+
parameters: Schema5,
|
|
550
|
+
execute: async (_toolCallId, rawParams) => {
|
|
551
|
+
const params = rawParams;
|
|
552
|
+
const client = getClient();
|
|
553
|
+
const query = params.query;
|
|
554
|
+
const needle = query.toLowerCase();
|
|
555
|
+
const scope = params.scope ?? "error";
|
|
556
|
+
const limit = params.limit ?? DEFAULT_LIMIT;
|
|
557
|
+
const maxMatches = params.maxMatches ?? DEFAULT_MAX_MATCHES;
|
|
558
|
+
const snippetChars = params.snippetChars ?? DEFAULT_SNIPPET_CHARS;
|
|
559
|
+
const status = params.status ?? "error";
|
|
560
|
+
const [executions, workflowIndex] = await Promise.all([
|
|
561
|
+
client.listExecutions({
|
|
562
|
+
workflowId: params.workflowId,
|
|
563
|
+
status,
|
|
564
|
+
limit
|
|
565
|
+
}),
|
|
566
|
+
loadWorkflowNames2(client)
|
|
567
|
+
]);
|
|
568
|
+
const matches = [];
|
|
569
|
+
const skipped = [];
|
|
570
|
+
let scannedCount = 0;
|
|
571
|
+
let truncated = false;
|
|
572
|
+
for (const summary of executions.data) {
|
|
573
|
+
scannedCount++;
|
|
574
|
+
let detail;
|
|
575
|
+
try {
|
|
576
|
+
detail = await client.getExecution(String(summary.id), {
|
|
577
|
+
includeData: true
|
|
578
|
+
});
|
|
579
|
+
} catch (err) {
|
|
580
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
581
|
+
skipped.push({
|
|
582
|
+
executionId: String(summary.id),
|
|
583
|
+
error: client.redact(msg)
|
|
584
|
+
});
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
const hits = findHits(detail, needle, scope, snippetChars);
|
|
588
|
+
if (hits.length === 0) continue;
|
|
589
|
+
const workflowId = String(detail.workflowId ?? summary.workflowId ?? "");
|
|
590
|
+
const errorMessage = extractErrorMessage(detail);
|
|
591
|
+
matches.push({
|
|
592
|
+
executionId: String(detail.id),
|
|
593
|
+
workflowId,
|
|
594
|
+
workflowName: detail.workflowData?.name ?? workflowIndex.get(workflowId) ?? null,
|
|
595
|
+
status: detail.status ?? (detail.finished ? "success" : "running"),
|
|
596
|
+
mode: detail.mode,
|
|
597
|
+
startedAt: detail.startedAt ?? null,
|
|
598
|
+
stoppedAt: detail.stoppedAt ?? null,
|
|
599
|
+
errorMessage: errorMessage ? client.redact(errorMessage) : null,
|
|
600
|
+
matchedIn: hits.map((h) => h.where),
|
|
601
|
+
snippets: hits.map((h) => ({
|
|
602
|
+
where: h.where,
|
|
603
|
+
text: client.redact(h.snippet)
|
|
604
|
+
}))
|
|
605
|
+
});
|
|
606
|
+
if (matches.length >= maxMatches) {
|
|
607
|
+
truncated = true;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return jsonToolResult({
|
|
612
|
+
query,
|
|
613
|
+
scope,
|
|
614
|
+
status,
|
|
615
|
+
scannedCount,
|
|
616
|
+
matchCount: matches.length,
|
|
617
|
+
skippedCount: skipped.length,
|
|
618
|
+
truncated,
|
|
619
|
+
matches,
|
|
620
|
+
skipped,
|
|
621
|
+
nextCursor: truncated ? null : executions.nextCursor ?? null
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function findHits(detail, needle, scope, snippetChars) {
|
|
627
|
+
const hits = [];
|
|
628
|
+
const error = detail.data?.resultData?.error;
|
|
629
|
+
if (error !== void 0) {
|
|
630
|
+
const errText = JSON.stringify(error);
|
|
631
|
+
const idx = errText.toLowerCase().indexOf(needle);
|
|
632
|
+
if (idx !== -1) {
|
|
633
|
+
hits.push({
|
|
634
|
+
where: "error",
|
|
635
|
+
snippet: snippet(errText, idx, needle.length, snippetChars)
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (scope === "all") {
|
|
640
|
+
const runData = detail.data?.resultData?.runData;
|
|
641
|
+
if (runData && typeof runData === "object") {
|
|
642
|
+
for (const [nodeName, nodeRuns] of Object.entries(runData)) {
|
|
643
|
+
const text = JSON.stringify(nodeRuns);
|
|
644
|
+
const idx = text.toLowerCase().indexOf(needle);
|
|
645
|
+
if (idx !== -1) {
|
|
646
|
+
hits.push({
|
|
647
|
+
where: `node:${nodeName}`,
|
|
648
|
+
snippet: snippet(text, idx, needle.length, snippetChars)
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return hits;
|
|
655
|
+
}
|
|
656
|
+
function snippet(text, matchStart, matchLen, window) {
|
|
657
|
+
const half = Math.floor(window / 2);
|
|
658
|
+
const start = Math.max(0, matchStart - half);
|
|
659
|
+
const end = Math.min(text.length, matchStart + matchLen + half);
|
|
660
|
+
const prefix = start > 0 ? "\u2026" : "";
|
|
661
|
+
const suffix = end < text.length ? "\u2026" : "";
|
|
662
|
+
return `${prefix}${text.slice(start, end)}${suffix}`;
|
|
663
|
+
}
|
|
664
|
+
function extractErrorMessage(ex) {
|
|
665
|
+
const err = ex.data?.resultData?.error;
|
|
666
|
+
if (err && typeof err.message === "string") return err.message;
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
async function loadWorkflowNames2(client) {
|
|
670
|
+
const index = /* @__PURE__ */ new Map();
|
|
671
|
+
try {
|
|
672
|
+
const res = await client.listWorkflows({ limit: 250 });
|
|
673
|
+
for (const w of res.data) {
|
|
674
|
+
index.set(String(w.id), w.name);
|
|
675
|
+
}
|
|
676
|
+
} catch {
|
|
677
|
+
}
|
|
678
|
+
return index;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/tools/trigger.ts
|
|
682
|
+
import { Type as Type6 } from "@sinclair/typebox";
|
|
683
|
+
var Schema6 = Type6.Object(
|
|
684
|
+
{
|
|
685
|
+
mode: Type6.Union([Type6.Literal("workflow"), Type6.Literal("webhook")], {
|
|
686
|
+
description: "'workflow' triggers by workflow id (manual-style). 'webhook' POSTs to a webhook path."
|
|
687
|
+
}),
|
|
688
|
+
workflowId: Type6.Optional(
|
|
689
|
+
Type6.String({
|
|
480
690
|
description: "Required when mode=workflow. Id from n8n_list_workflows."
|
|
481
691
|
})
|
|
482
692
|
),
|
|
483
|
-
webhookPath:
|
|
484
|
-
|
|
693
|
+
webhookPath: Type6.Optional(
|
|
694
|
+
Type6.String({
|
|
485
695
|
description: "Required when mode=webhook. Path portion after the base URL, e.g. /webhook/my-hook."
|
|
486
696
|
})
|
|
487
697
|
),
|
|
488
|
-
payload:
|
|
489
|
-
|
|
698
|
+
payload: Type6.Optional(
|
|
699
|
+
Type6.Record(Type6.String(), Type6.Unknown(), {
|
|
490
700
|
description: "Optional JSON body. Sent as request body for either mode."
|
|
491
701
|
})
|
|
492
702
|
),
|
|
493
|
-
method:
|
|
494
|
-
|
|
703
|
+
method: Type6.Optional(
|
|
704
|
+
Type6.Union(
|
|
495
705
|
[
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
706
|
+
Type6.Literal("POST"),
|
|
707
|
+
Type6.Literal("GET"),
|
|
708
|
+
Type6.Literal("PUT"),
|
|
709
|
+
Type6.Literal("DELETE")
|
|
500
710
|
],
|
|
501
711
|
{
|
|
502
712
|
description: "HTTP method for webhook mode. Default POST."
|
|
@@ -517,7 +727,7 @@ function createTriggerTool(getClient) {
|
|
|
517
727
|
name: "n8n_trigger",
|
|
518
728
|
label: "n8n: trigger workflow",
|
|
519
729
|
description: "Run an n8n workflow. mode='webhook' POSTs to a webhook path with an optional JSON payload \u2014 this is the supported path on n8n's Public API. mode='workflow' tries POST /api/v1/workflows/:id/execute with an active/manual/webhook/form pre-check; most n8n builds do NOT expose this endpoint and return 405 \u2014 prefer mode='webhook' for reliable triggers.",
|
|
520
|
-
parameters:
|
|
730
|
+
parameters: Schema6,
|
|
521
731
|
execute: async (_toolCallId, rawParams) => {
|
|
522
732
|
const params = rawParams;
|
|
523
733
|
const client = getClient();
|
|
@@ -627,21 +837,21 @@ function findTriggerNode(wf) {
|
|
|
627
837
|
}
|
|
628
838
|
|
|
629
839
|
// src/tools/list-webhooks.ts
|
|
630
|
-
import { Type as
|
|
631
|
-
var
|
|
840
|
+
import { Type as Type7 } from "@sinclair/typebox";
|
|
841
|
+
var Schema7 = Type7.Object(
|
|
632
842
|
{
|
|
633
|
-
workflowId:
|
|
634
|
-
|
|
843
|
+
workflowId: Type7.Optional(
|
|
844
|
+
Type7.String({
|
|
635
845
|
description: "Restrict to a single workflow. Omit to scan recent workflows."
|
|
636
846
|
})
|
|
637
847
|
),
|
|
638
|
-
activeOnly:
|
|
639
|
-
|
|
848
|
+
activeOnly: Type7.Optional(
|
|
849
|
+
Type7.Boolean({
|
|
640
850
|
description: "Only include active workflows. Default true."
|
|
641
851
|
})
|
|
642
852
|
),
|
|
643
|
-
limit:
|
|
644
|
-
|
|
853
|
+
limit: Type7.Optional(
|
|
854
|
+
Type7.Number({
|
|
645
855
|
minimum: 1,
|
|
646
856
|
maximum: 100,
|
|
647
857
|
description: "When workflowId is omitted, max workflows to fetch and scan (default 50)."
|
|
@@ -655,7 +865,7 @@ function createListWebhooksTool(deps) {
|
|
|
655
865
|
name: "n8n_list_webhooks",
|
|
656
866
|
label: "n8n: list webhooks",
|
|
657
867
|
description: "Surface webhook and form-trigger paths from n8n workflows so agents can call n8n_trigger with mode='webhook' without opening the n8n UI. Returns workflowId, workflowName, nodeName, method, path, and a fully-formed triggerUrl.",
|
|
658
|
-
parameters:
|
|
868
|
+
parameters: Schema7,
|
|
659
869
|
execute: async (_toolCallId, rawParams) => {
|
|
660
870
|
const params = rawParams;
|
|
661
871
|
const activeOnly = params.activeOnly !== false;
|
|
@@ -734,10 +944,10 @@ function extractWebhook(rawNode, wf, baseUrl) {
|
|
|
734
944
|
}
|
|
735
945
|
|
|
736
946
|
// src/tools/validate-workflow.ts
|
|
737
|
-
import { Type as
|
|
738
|
-
var
|
|
947
|
+
import { Type as Type8 } from "@sinclair/typebox";
|
|
948
|
+
var Schema8 = Type8.Object(
|
|
739
949
|
{
|
|
740
|
-
id:
|
|
950
|
+
id: Type8.String({
|
|
741
951
|
description: "Workflow id (from n8n_list_workflows)."
|
|
742
952
|
})
|
|
743
953
|
},
|
|
@@ -757,7 +967,7 @@ function createValidateWorkflowTool(getClient) {
|
|
|
757
967
|
name: "n8n_validate_workflow",
|
|
758
968
|
label: "n8n: validate workflow",
|
|
759
969
|
description: "Static checks on a workflow: deprecated node types (function \u2192 code), old Code-node API usage ($node[], items global, require()), orphan nodes, disabled nodes, and missing trigger. Returns a list of issues with severity.",
|
|
760
|
-
parameters:
|
|
970
|
+
parameters: Schema8,
|
|
761
971
|
execute: async (_toolCallId, rawParams) => {
|
|
762
972
|
const { id } = rawParams;
|
|
763
973
|
const wf = await getClient().getWorkflow(id);
|
|
@@ -909,10 +1119,10 @@ function summarize(issues) {
|
|
|
909
1119
|
}
|
|
910
1120
|
|
|
911
1121
|
// src/tools/activate.ts
|
|
912
|
-
import { Type as
|
|
913
|
-
var
|
|
1122
|
+
import { Type as Type9 } from "@sinclair/typebox";
|
|
1123
|
+
var Schema9 = Type9.Object(
|
|
914
1124
|
{
|
|
915
|
-
id:
|
|
1125
|
+
id: Type9.String({ description: "Workflow id to activate." })
|
|
916
1126
|
},
|
|
917
1127
|
{ additionalProperties: false }
|
|
918
1128
|
);
|
|
@@ -921,7 +1131,7 @@ function createActivateTool(getClient) {
|
|
|
921
1131
|
name: "n8n_activate",
|
|
922
1132
|
label: "n8n: activate workflow",
|
|
923
1133
|
description: "Activate an n8n workflow so its triggers (webhooks, schedules, polling) start running. Idempotent - activating an already-active workflow returns the current state. Requires enableEdit.",
|
|
924
|
-
parameters:
|
|
1134
|
+
parameters: Schema9,
|
|
925
1135
|
execute: async (_toolCallId, rawParams) => {
|
|
926
1136
|
const { id } = rawParams;
|
|
927
1137
|
const wf = await getClient().activateWorkflow(id);
|
|
@@ -938,10 +1148,10 @@ function createActivateTool(getClient) {
|
|
|
938
1148
|
}
|
|
939
1149
|
|
|
940
1150
|
// src/tools/deactivate.ts
|
|
941
|
-
import { Type as
|
|
942
|
-
var
|
|
1151
|
+
import { Type as Type10 } from "@sinclair/typebox";
|
|
1152
|
+
var Schema10 = Type10.Object(
|
|
943
1153
|
{
|
|
944
|
-
id:
|
|
1154
|
+
id: Type10.String({ description: "Workflow id to deactivate." })
|
|
945
1155
|
},
|
|
946
1156
|
{ additionalProperties: false }
|
|
947
1157
|
);
|
|
@@ -950,7 +1160,7 @@ function createDeactivateTool(getClient) {
|
|
|
950
1160
|
name: "n8n_deactivate",
|
|
951
1161
|
label: "n8n: deactivate workflow",
|
|
952
1162
|
description: "Deactivate an n8n workflow so its triggers stop firing. Running executions are not cancelled. Idempotent. Requires enableEdit.",
|
|
953
|
-
parameters:
|
|
1163
|
+
parameters: Schema10,
|
|
954
1164
|
execute: async (_toolCallId, rawParams) => {
|
|
955
1165
|
const { id } = rawParams;
|
|
956
1166
|
const wf = await getClient().deactivateWorkflow(id);
|
|
@@ -967,32 +1177,32 @@ function createDeactivateTool(getClient) {
|
|
|
967
1177
|
}
|
|
968
1178
|
|
|
969
1179
|
// src/tools/save-workflow.ts
|
|
970
|
-
import { Type as
|
|
1180
|
+
import { Type as Type11 } from "@sinclair/typebox";
|
|
971
1181
|
import { promises as fs } from "fs";
|
|
972
1182
|
import { homedir } from "os";
|
|
973
1183
|
import path from "path";
|
|
974
|
-
var
|
|
1184
|
+
var Schema11 = Type11.Object(
|
|
975
1185
|
{
|
|
976
|
-
id:
|
|
977
|
-
definition:
|
|
1186
|
+
id: Type11.String({ description: "Workflow id to overwrite." }),
|
|
1187
|
+
definition: Type11.Object(
|
|
978
1188
|
{
|
|
979
|
-
name:
|
|
980
|
-
nodes:
|
|
981
|
-
connections:
|
|
982
|
-
settings:
|
|
983
|
-
staticData:
|
|
1189
|
+
name: Type11.Optional(Type11.String()),
|
|
1190
|
+
nodes: Type11.Array(Type11.Record(Type11.String(), Type11.Unknown())),
|
|
1191
|
+
connections: Type11.Record(Type11.String(), Type11.Unknown()),
|
|
1192
|
+
settings: Type11.Optional(Type11.Record(Type11.String(), Type11.Unknown())),
|
|
1193
|
+
staticData: Type11.Optional(Type11.Unknown())
|
|
984
1194
|
},
|
|
985
1195
|
{
|
|
986
1196
|
additionalProperties: true,
|
|
987
1197
|
description: "Full new workflow body. Copy from n8n_get_workflow with includeDefinition=true, modify, then pass the nodes + connections (+ optional settings/staticData/name) here."
|
|
988
1198
|
}
|
|
989
1199
|
),
|
|
990
|
-
skipValidation:
|
|
991
|
-
|
|
1200
|
+
skipValidation: Type11.Optional(
|
|
1201
|
+
Type11.Boolean({
|
|
992
1202
|
description: "Skip the n8n_validate_workflow pre-check. Default false. Validation errors (not warnings) block the save by default."
|
|
993
1203
|
})
|
|
994
1204
|
),
|
|
995
|
-
confirm:
|
|
1205
|
+
confirm: Type11.Boolean({
|
|
996
1206
|
description: "Must be true to actually write. A snapshot of the current workflow is saved to backupDir regardless."
|
|
997
1207
|
})
|
|
998
1208
|
},
|
|
@@ -1003,7 +1213,7 @@ function createSaveWorkflowTool(deps) {
|
|
|
1003
1213
|
name: "n8n_save_workflow",
|
|
1004
1214
|
label: "n8n: save workflow",
|
|
1005
1215
|
description: "Overwrite an n8n workflow. Snapshots the current version to backupDir first, runs n8n_validate_workflow on the proposed new state (errors block, warnings pass through), then PUTs the new body. Requires enableEdit and explicit confirm=true.",
|
|
1006
|
-
parameters:
|
|
1216
|
+
parameters: Schema11,
|
|
1007
1217
|
execute: async (_toolCallId, rawParams) => {
|
|
1008
1218
|
const params = rawParams;
|
|
1009
1219
|
if (!params.confirm) {
|
|
@@ -1088,8 +1298,57 @@ async function writeBackup(dir, wf) {
|
|
|
1088
1298
|
return file;
|
|
1089
1299
|
}
|
|
1090
1300
|
|
|
1301
|
+
// src/tools/cancel-execution.ts
|
|
1302
|
+
import { Type as Type12 } from "@sinclair/typebox";
|
|
1303
|
+
var Schema12 = Type12.Object(
|
|
1304
|
+
{
|
|
1305
|
+
id: Type12.String({
|
|
1306
|
+
description: "Execution id to stop (from n8n_list_executions or n8n_search_executions)."
|
|
1307
|
+
})
|
|
1308
|
+
},
|
|
1309
|
+
{ additionalProperties: false }
|
|
1310
|
+
);
|
|
1311
|
+
function createCancelExecutionTool(getClient) {
|
|
1312
|
+
return {
|
|
1313
|
+
name: "n8n_cancel_execution",
|
|
1314
|
+
label: "n8n: cancel execution",
|
|
1315
|
+
description: "Stop a running or waiting n8n execution by id. Closes the triage loop after n8n_search_executions locates a stuck run. If the execution is already finished, deleted, or never existed, returns ok:false with reason 'not_found_or_finished' rather than throwing. Requires enableEdit.",
|
|
1316
|
+
parameters: Schema12,
|
|
1317
|
+
execute: async (_toolCallId, rawParams) => {
|
|
1318
|
+
const { id } = rawParams;
|
|
1319
|
+
const client = getClient();
|
|
1320
|
+
try {
|
|
1321
|
+
const ex = await client.stopExecution(id);
|
|
1322
|
+
const status = ex.status ?? (ex.finished ? "success" : "running");
|
|
1323
|
+
return jsonToolResult({
|
|
1324
|
+
ok: true,
|
|
1325
|
+
action: "cancel",
|
|
1326
|
+
executionId: String(ex.id),
|
|
1327
|
+
workflowId: String(ex.workflowId ?? ""),
|
|
1328
|
+
workflowName: ex.workflowData?.name ?? null,
|
|
1329
|
+
status,
|
|
1330
|
+
finished: ex.finished,
|
|
1331
|
+
startedAt: ex.startedAt ?? null,
|
|
1332
|
+
stoppedAt: ex.stoppedAt ?? null
|
|
1333
|
+
});
|
|
1334
|
+
} catch (err) {
|
|
1335
|
+
if (err instanceof N8nApiError && err.status === 404) {
|
|
1336
|
+
return jsonToolResult({
|
|
1337
|
+
ok: false,
|
|
1338
|
+
action: "cancel",
|
|
1339
|
+
executionId: id,
|
|
1340
|
+
reason: "not_found_or_finished",
|
|
1341
|
+
message: "Execution not found. It may have already finished, been deleted, or never existed."
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
throw err;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1091
1350
|
// mcp-server.ts
|
|
1092
|
-
var VERSION = "0.
|
|
1351
|
+
var VERSION = "0.3.0";
|
|
1093
1352
|
function readConfigFromEnv() {
|
|
1094
1353
|
const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
|
|
1095
1354
|
if (!baseUrl) {
|
|
@@ -1184,6 +1443,21 @@ async function main() {
|
|
|
1184
1443
|
)
|
|
1185
1444
|
}
|
|
1186
1445
|
);
|
|
1446
|
+
bind(server, createSearchExecutionsTool(getClient), {
|
|
1447
|
+
query: z.string().min(1).describe(
|
|
1448
|
+
"Case-insensitive text to search for (e.g. 'ECONNREFUSED')."
|
|
1449
|
+
),
|
|
1450
|
+
workflowId: z.string().optional().describe("Filter to a single workflow id. Omit to scan across all workflows."),
|
|
1451
|
+
status: z.enum(["success", "error", "running", "waiting", "canceled"]).optional().describe(
|
|
1452
|
+
"Filter executions by status before searching. Default 'error'."
|
|
1453
|
+
),
|
|
1454
|
+
scope: z.enum(["error", "all"]).optional().describe(
|
|
1455
|
+
"'error' (default) searches only the execution error payload. 'all' also greps the full per-node run log \u2014 slower and may return raw node output in snippets."
|
|
1456
|
+
),
|
|
1457
|
+
limit: z.number().int().min(1).max(250).optional().describe("Max executions to scan (default 50)."),
|
|
1458
|
+
maxMatches: z.number().int().min(1).max(100).optional().describe("Stop after this many matches (default 20)."),
|
|
1459
|
+
snippetChars: z.number().int().min(40).max(600).optional().describe("Context window around each match (default 160).")
|
|
1460
|
+
});
|
|
1187
1461
|
bind(server, createTriggerTool(getClient), {
|
|
1188
1462
|
mode: z.enum(["workflow", "webhook"]).describe(
|
|
1189
1463
|
"'workflow' triggers by workflow id (manual-style; most builds 405). 'webhook' POSTs to a webhook path."
|
|
@@ -1230,6 +1504,11 @@ async function main() {
|
|
|
1230
1504
|
confirm: z.boolean().describe("Must be true to actually write. Snapshot to backupDir happens regardless.")
|
|
1231
1505
|
}
|
|
1232
1506
|
);
|
|
1507
|
+
bind(server, createCancelExecutionTool(getClient), {
|
|
1508
|
+
id: z.string().describe(
|
|
1509
|
+
"Execution id to stop (from n8n_list_executions or n8n_search_executions)."
|
|
1510
|
+
)
|
|
1511
|
+
});
|
|
1233
1512
|
}
|
|
1234
1513
|
const transport = new StdioServerTransport();
|
|
1235
1514
|
await server.connect(transport);
|
package/index.ts
CHANGED
|
@@ -5,12 +5,14 @@ import { createListWorkflowsTool } from "./src/tools/list-workflows.ts";
|
|
|
5
5
|
import { createGetWorkflowTool } from "./src/tools/get-workflow.ts";
|
|
6
6
|
import { createListExecutionsTool } from "./src/tools/list-executions.ts";
|
|
7
7
|
import { createGetExecutionTool } from "./src/tools/get-execution.ts";
|
|
8
|
+
import { createSearchExecutionsTool } from "./src/tools/search-executions.ts";
|
|
8
9
|
import { createTriggerTool } from "./src/tools/trigger.ts";
|
|
9
10
|
import { createListWebhooksTool } from "./src/tools/list-webhooks.ts";
|
|
10
11
|
import { createValidateWorkflowTool } from "./src/tools/validate-workflow.ts";
|
|
11
12
|
import { createActivateTool } from "./src/tools/activate.ts";
|
|
12
13
|
import { createDeactivateTool } from "./src/tools/deactivate.ts";
|
|
13
14
|
import { createSaveWorkflowTool } from "./src/tools/save-workflow.ts";
|
|
15
|
+
import { createCancelExecutionTool } from "./src/tools/cancel-execution.ts";
|
|
14
16
|
|
|
15
17
|
export default definePluginEntry({
|
|
16
18
|
id: "n8n",
|
|
@@ -32,6 +34,7 @@ export default definePluginEntry({
|
|
|
32
34
|
maxLogBytes: config.maxExecutionLogBytes,
|
|
33
35
|
}) as AnyAgentTool,
|
|
34
36
|
);
|
|
37
|
+
api.registerTool(createSearchExecutionsTool(getClient) as AnyAgentTool);
|
|
35
38
|
api.registerTool(createTriggerTool(getClient) as AnyAgentTool);
|
|
36
39
|
api.registerTool(
|
|
37
40
|
createListWebhooksTool({ getClient, baseUrl: config.baseUrl }) as AnyAgentTool,
|
|
@@ -47,6 +50,7 @@ export default definePluginEntry({
|
|
|
47
50
|
backupDir: config.backupDir,
|
|
48
51
|
}) as AnyAgentTool,
|
|
49
52
|
);
|
|
53
|
+
api.registerTool(createCancelExecutionTool(getClient) as AnyAgentTool);
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
56
|
});
|
package/openclaw.plugin.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"enableEdit": {
|
|
25
25
|
"type": "boolean",
|
|
26
26
|
"default": false,
|
|
27
|
-
"description": "Enable write tools (save/activate/deactivate). Off by default."
|
|
27
|
+
"description": "Enable write tools (save/activate/deactivate/cancel-execution). Off by default."
|
|
28
28
|
},
|
|
29
29
|
"maxExecutionLogBytes": {
|
|
30
30
|
"type": "number",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"enableEdit": {
|
|
57
57
|
"label": "Enable Edit Tools",
|
|
58
|
-
"help": "Exposes save/activate/deactivate
|
|
58
|
+
"help": "Exposes save/activate/deactivate/cancel-execution. save has a confirm-gate and auto-backup; cancel stops running executions on the server."
|
|
59
59
|
},
|
|
60
60
|
"maxExecutionLogBytes": {
|
|
61
61
|
"label": "Max Log Bytes",
|
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-ops-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Ops-focused n8n tools (list, inspect, trigger, validate, save) for Claude-compatible clients. MCP server + first-class OpenClaw plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Solomon Neas <srneas@gmail.com>",
|
|
8
|
-
"keywords": [
|
|
8
|
+
"keywords": [
|
|
9
|
+
"n8n",
|
|
10
|
+
"mcp",
|
|
11
|
+
"model-context-protocol",
|
|
12
|
+
"openclaw",
|
|
13
|
+
"workflow",
|
|
14
|
+
"ops",
|
|
15
|
+
"automation"
|
|
16
|
+
],
|
|
9
17
|
"repository": {
|
|
10
18
|
"type": "git",
|
|
11
19
|
"url": "https://github.com/solomonneas/n8n-ops-mcp.git"
|
|
@@ -30,7 +38,9 @@
|
|
|
30
38
|
"LICENSE"
|
|
31
39
|
],
|
|
32
40
|
"openclaw": {
|
|
33
|
-
"extensions": [
|
|
41
|
+
"extensions": [
|
|
42
|
+
"./index.ts"
|
|
43
|
+
],
|
|
34
44
|
"compat": {
|
|
35
45
|
"pluginApi": ">=2026.3.24-beta.2",
|
|
36
46
|
"minGatewayVersion": "2026.3.24-beta.2"
|
|
@@ -55,15 +65,19 @@
|
|
|
55
65
|
},
|
|
56
66
|
"devDependencies": {
|
|
57
67
|
"@types/node": "^22.0.0",
|
|
68
|
+
"openclaw": "^2026.4.22",
|
|
58
69
|
"tsup": "^8.4.0",
|
|
59
70
|
"tsx": "^4.19.0",
|
|
60
|
-
"typescript": "^5.5.0"
|
|
71
|
+
"typescript": "^5.5.0",
|
|
72
|
+
"vitest": "^4.1.5"
|
|
61
73
|
},
|
|
62
74
|
"scripts": {
|
|
63
75
|
"typecheck": "tsc --noEmit",
|
|
64
76
|
"build": "tsup",
|
|
65
77
|
"start": "node dist/mcp-server.js",
|
|
66
78
|
"dev": "tsx mcp-server.ts",
|
|
67
|
-
"
|
|
79
|
+
"test": "vitest run",
|
|
80
|
+
"test:watch": "vitest",
|
|
81
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
68
82
|
}
|
|
69
83
|
}
|
package/src/client.ts
CHANGED
|
@@ -90,6 +90,10 @@ export class N8nClient {
|
|
|
90
90
|
this.timeoutMs = opts.timeoutMs ?? 15_000;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
redact(text: string): string {
|
|
94
|
+
return redactKey(text, this.apiKey);
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
async listWorkflows(params: {
|
|
94
98
|
active?: boolean;
|
|
95
99
|
tags?: string;
|
|
@@ -214,6 +218,15 @@ export class N8nClient {
|
|
|
214
218
|
);
|
|
215
219
|
}
|
|
216
220
|
|
|
221
|
+
async stopExecution(id: string): Promise<N8nExecution> {
|
|
222
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id)) {
|
|
223
|
+
throw new Error(`Invalid execution id: ${id}`);
|
|
224
|
+
}
|
|
225
|
+
return this.request<N8nExecution>(`/api/v1/executions/${id}/stop`, {
|
|
226
|
+
method: "POST",
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
217
230
|
async listExecutions(params: {
|
|
218
231
|
workflowId?: string;
|
|
219
232
|
status?: string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { N8nApiError, type N8nClient } from "../client.ts";
|
|
3
|
+
import { jsonToolResult } from "./result.ts";
|
|
4
|
+
|
|
5
|
+
const Schema = Type.Object(
|
|
6
|
+
{
|
|
7
|
+
id: Type.String({
|
|
8
|
+
description:
|
|
9
|
+
"Execution id to stop (from n8n_list_executions or n8n_search_executions).",
|
|
10
|
+
}),
|
|
11
|
+
},
|
|
12
|
+
{ additionalProperties: false },
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export function createCancelExecutionTool(getClient: () => N8nClient) {
|
|
16
|
+
return {
|
|
17
|
+
name: "n8n_cancel_execution",
|
|
18
|
+
label: "n8n: cancel execution",
|
|
19
|
+
description:
|
|
20
|
+
"Stop a running or waiting n8n execution by id. Closes the triage loop after n8n_search_executions locates a stuck run. If the execution is already finished, deleted, or never existed, returns ok:false with reason 'not_found_or_finished' rather than throwing. Requires enableEdit.",
|
|
21
|
+
parameters: Schema,
|
|
22
|
+
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
|
|
23
|
+
const { id } = rawParams as { id: string };
|
|
24
|
+
const client = getClient();
|
|
25
|
+
try {
|
|
26
|
+
const ex = await client.stopExecution(id);
|
|
27
|
+
const status = ex.status ?? (ex.finished ? "success" : "running");
|
|
28
|
+
return jsonToolResult({
|
|
29
|
+
ok: true,
|
|
30
|
+
action: "cancel",
|
|
31
|
+
executionId: String(ex.id),
|
|
32
|
+
workflowId: String(ex.workflowId ?? ""),
|
|
33
|
+
workflowName: ex.workflowData?.name ?? null,
|
|
34
|
+
status,
|
|
35
|
+
finished: ex.finished,
|
|
36
|
+
startedAt: ex.startedAt ?? null,
|
|
37
|
+
stoppedAt: ex.stoppedAt ?? null,
|
|
38
|
+
});
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err instanceof N8nApiError && err.status === 404) {
|
|
41
|
+
return jsonToolResult({
|
|
42
|
+
ok: false,
|
|
43
|
+
action: "cancel",
|
|
44
|
+
executionId: id,
|
|
45
|
+
reason: "not_found_or_finished",
|
|
46
|
+
message:
|
|
47
|
+
"Execution not found. It may have already finished, been deleted, or never existed.",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { N8nClient, N8nExecution } from "../client.ts";
|
|
3
|
+
import { jsonToolResult } from "./result.ts";
|
|
4
|
+
|
|
5
|
+
const Schema = Type.Object(
|
|
6
|
+
{
|
|
7
|
+
query: Type.String({
|
|
8
|
+
minLength: 1,
|
|
9
|
+
description:
|
|
10
|
+
"Case-insensitive text to search for. Typical: an error fragment like 'ECONNREFUSED' or a node name.",
|
|
11
|
+
}),
|
|
12
|
+
workflowId: Type.Optional(
|
|
13
|
+
Type.String({
|
|
14
|
+
description: "Filter to a single workflow id. Omit to scan across all workflows.",
|
|
15
|
+
}),
|
|
16
|
+
),
|
|
17
|
+
status: Type.Optional(
|
|
18
|
+
Type.Union(
|
|
19
|
+
[
|
|
20
|
+
Type.Literal("success"),
|
|
21
|
+
Type.Literal("error"),
|
|
22
|
+
Type.Literal("running"),
|
|
23
|
+
Type.Literal("waiting"),
|
|
24
|
+
Type.Literal("canceled"),
|
|
25
|
+
],
|
|
26
|
+
{
|
|
27
|
+
description:
|
|
28
|
+
"Filter executions by status before searching. Default 'error' — matches the main use case ('which workflow errored with X?').",
|
|
29
|
+
},
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
scope: Type.Optional(
|
|
33
|
+
Type.Union(
|
|
34
|
+
[Type.Literal("error"), Type.Literal("all")],
|
|
35
|
+
{
|
|
36
|
+
description:
|
|
37
|
+
"'error' (default) searches only the execution error payload. 'all' additionally greps the full per-node run log — slower and returns more raw data.",
|
|
38
|
+
},
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
limit: Type.Optional(
|
|
42
|
+
Type.Integer({
|
|
43
|
+
minimum: 1,
|
|
44
|
+
maximum: 250,
|
|
45
|
+
description: "Max executions to scan (default 50).",
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
maxMatches: Type.Optional(
|
|
49
|
+
Type.Integer({
|
|
50
|
+
minimum: 1,
|
|
51
|
+
maximum: 100,
|
|
52
|
+
description: "Stop after this many matches (default 20).",
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
snippetChars: Type.Optional(
|
|
56
|
+
Type.Integer({
|
|
57
|
+
minimum: 40,
|
|
58
|
+
maximum: 600,
|
|
59
|
+
description: "Context window around each match (default 160).",
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
{ additionalProperties: false },
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const DEFAULT_LIMIT = 50;
|
|
67
|
+
const DEFAULT_MAX_MATCHES = 20;
|
|
68
|
+
const DEFAULT_SNIPPET_CHARS = 160;
|
|
69
|
+
|
|
70
|
+
export function createSearchExecutionsTool(getClient: () => N8nClient) {
|
|
71
|
+
return {
|
|
72
|
+
name: "n8n_search_executions",
|
|
73
|
+
label: "n8n: search executions",
|
|
74
|
+
description:
|
|
75
|
+
"Text-search recent n8n executions without paging through them one by one. Fetches each candidate with includeData=true, then greps the error payload (scope='error', default) or the full per-node run log (scope='all'). Returns matched executions with workflow context and a snippet around each hit. Snippets are raw run data with the API key redacted — with scope='all' they may still contain credentials or payload data from node outputs, so treat as sensitive.",
|
|
76
|
+
parameters: Schema,
|
|
77
|
+
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
|
|
78
|
+
const params = rawParams as {
|
|
79
|
+
query: string;
|
|
80
|
+
workflowId?: string;
|
|
81
|
+
status?: string;
|
|
82
|
+
scope?: "error" | "all";
|
|
83
|
+
limit?: number;
|
|
84
|
+
maxMatches?: number;
|
|
85
|
+
snippetChars?: number;
|
|
86
|
+
};
|
|
87
|
+
const client = getClient();
|
|
88
|
+
const query = params.query;
|
|
89
|
+
const needle = query.toLowerCase();
|
|
90
|
+
const scope = params.scope ?? "error";
|
|
91
|
+
const limit = params.limit ?? DEFAULT_LIMIT;
|
|
92
|
+
const maxMatches = params.maxMatches ?? DEFAULT_MAX_MATCHES;
|
|
93
|
+
const snippetChars = params.snippetChars ?? DEFAULT_SNIPPET_CHARS;
|
|
94
|
+
const status = params.status ?? "error";
|
|
95
|
+
|
|
96
|
+
const [executions, workflowIndex] = await Promise.all([
|
|
97
|
+
client.listExecutions({
|
|
98
|
+
workflowId: params.workflowId,
|
|
99
|
+
status,
|
|
100
|
+
limit,
|
|
101
|
+
}),
|
|
102
|
+
loadWorkflowNames(client),
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const matches: Array<Record<string, unknown>> = [];
|
|
106
|
+
const skipped: Array<{ executionId: string; error: string }> = [];
|
|
107
|
+
let scannedCount = 0;
|
|
108
|
+
let truncated = false;
|
|
109
|
+
|
|
110
|
+
for (const summary of executions.data) {
|
|
111
|
+
scannedCount++;
|
|
112
|
+
let detail: N8nExecution;
|
|
113
|
+
try {
|
|
114
|
+
detail = await client.getExecution(String(summary.id), {
|
|
115
|
+
includeData: true,
|
|
116
|
+
});
|
|
117
|
+
} catch (err) {
|
|
118
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
119
|
+
skipped.push({
|
|
120
|
+
executionId: String(summary.id),
|
|
121
|
+
error: client.redact(msg),
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const hits = findHits(detail, needle, scope, snippetChars);
|
|
127
|
+
if (hits.length === 0) continue;
|
|
128
|
+
|
|
129
|
+
const workflowId = String(detail.workflowId ?? summary.workflowId ?? "");
|
|
130
|
+
const errorMessage = extractErrorMessage(detail);
|
|
131
|
+
matches.push({
|
|
132
|
+
executionId: String(detail.id),
|
|
133
|
+
workflowId,
|
|
134
|
+
workflowName:
|
|
135
|
+
detail.workflowData?.name ?? workflowIndex.get(workflowId) ?? null,
|
|
136
|
+
status: detail.status ?? (detail.finished ? "success" : "running"),
|
|
137
|
+
mode: detail.mode,
|
|
138
|
+
startedAt: detail.startedAt ?? null,
|
|
139
|
+
stoppedAt: detail.stoppedAt ?? null,
|
|
140
|
+
errorMessage: errorMessage ? client.redact(errorMessage) : null,
|
|
141
|
+
matchedIn: hits.map((h) => h.where),
|
|
142
|
+
snippets: hits.map((h) => ({
|
|
143
|
+
where: h.where,
|
|
144
|
+
text: client.redact(h.snippet),
|
|
145
|
+
})),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (matches.length >= maxMatches) {
|
|
149
|
+
truncated = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return jsonToolResult({
|
|
155
|
+
query,
|
|
156
|
+
scope,
|
|
157
|
+
status,
|
|
158
|
+
scannedCount,
|
|
159
|
+
matchCount: matches.length,
|
|
160
|
+
skippedCount: skipped.length,
|
|
161
|
+
truncated,
|
|
162
|
+
matches,
|
|
163
|
+
skipped,
|
|
164
|
+
nextCursor: truncated ? null : executions.nextCursor ?? null,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface Hit {
|
|
171
|
+
where: string;
|
|
172
|
+
snippet: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function findHits(
|
|
176
|
+
detail: N8nExecution,
|
|
177
|
+
needle: string,
|
|
178
|
+
scope: "error" | "all",
|
|
179
|
+
snippetChars: number,
|
|
180
|
+
): Hit[] {
|
|
181
|
+
const hits: Hit[] = [];
|
|
182
|
+
|
|
183
|
+
const error = detail.data?.resultData?.error;
|
|
184
|
+
if (error !== undefined) {
|
|
185
|
+
const errText = JSON.stringify(error);
|
|
186
|
+
const idx = errText.toLowerCase().indexOf(needle);
|
|
187
|
+
if (idx !== -1) {
|
|
188
|
+
hits.push({
|
|
189
|
+
where: "error",
|
|
190
|
+
snippet: snippet(errText, idx, needle.length, snippetChars),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (scope === "all") {
|
|
196
|
+
const runData = detail.data?.resultData?.runData;
|
|
197
|
+
if (runData && typeof runData === "object") {
|
|
198
|
+
for (const [nodeName, nodeRuns] of Object.entries(runData)) {
|
|
199
|
+
const text = JSON.stringify(nodeRuns);
|
|
200
|
+
const idx = text.toLowerCase().indexOf(needle);
|
|
201
|
+
if (idx !== -1) {
|
|
202
|
+
hits.push({
|
|
203
|
+
where: `node:${nodeName}`,
|
|
204
|
+
snippet: snippet(text, idx, needle.length, snippetChars),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return hits;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function snippet(
|
|
215
|
+
text: string,
|
|
216
|
+
matchStart: number,
|
|
217
|
+
matchLen: number,
|
|
218
|
+
window: number,
|
|
219
|
+
): string {
|
|
220
|
+
const half = Math.floor(window / 2);
|
|
221
|
+
const start = Math.max(0, matchStart - half);
|
|
222
|
+
const end = Math.min(text.length, matchStart + matchLen + half);
|
|
223
|
+
const prefix = start > 0 ? "…" : "";
|
|
224
|
+
const suffix = end < text.length ? "…" : "";
|
|
225
|
+
return `${prefix}${text.slice(start, end)}${suffix}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function extractErrorMessage(ex: N8nExecution): string | null {
|
|
229
|
+
const err = ex.data?.resultData?.error as
|
|
230
|
+
| { message?: unknown }
|
|
231
|
+
| undefined;
|
|
232
|
+
if (err && typeof err.message === "string") return err.message;
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function loadWorkflowNames(
|
|
237
|
+
client: N8nClient,
|
|
238
|
+
): Promise<Map<string, string>> {
|
|
239
|
+
const index = new Map<string, string>();
|
|
240
|
+
try {
|
|
241
|
+
const res = await client.listWorkflows({ limit: 250 });
|
|
242
|
+
for (const w of res.data) {
|
|
243
|
+
index.set(String(w.id), w.name);
|
|
244
|
+
}
|
|
245
|
+
} catch {
|
|
246
|
+
// best-effort
|
|
247
|
+
}
|
|
248
|
+
return index;
|
|
249
|
+
}
|