n8n-ops-mcp 0.2.0 → 0.4.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 CHANGED
@@ -1,89 +1,89 @@
1
1
  # n8n-ops-mcp
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/n8n-ops-mcp.svg)](https://www.npmjs.com/package/n8n-ops-mcp)
4
+ [![license](https://img.shields.io/npm/l/n8n-ops-mcp.svg)](./LICENSE)
5
+ [![MCP](https://img.shields.io/badge/MCP-compatible-blue)](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. If a pipeline breaks, you SSH to the host or open the n8n UI. With this package, your agent can answer "what's broken in my n8n?" from chat, and trigger manual workflows without you leaving your client.
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
- This is an **ops** tool — focused on listing, triggering, validating, and editing workflows. If you want a catalog/docs tool that indexes n8n's node library, see [n8n-mcp](https://www.npmjs.com/package/n8n-mcp).
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
- **`n8n_list_workflows`** - list workflows with optional `active`, `tags`, `name` (substring), `limit` filters. Returns id, name, active state, tags, updatedAt.
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 | ✓ |
33
+ | `n8n_retry_execution` | Retry a failed execution by id (returns a new execution) | ✓ |
16
34
 
17
- **`n8n_get_workflow`** - fetch one workflow by id. Returns metadata by default. Pass `includeDefinition: true` to get the full node graph + connections.
35
+ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
18
36
 
19
- **`n8n_list_executions`** - list recent executions with optional `workflowId`, `status` (success/error/running/waiting/canceled), `limit` filters. Returns id, workflowId, workflowName, status, mode, startedAt, stoppedAt.
37
+ <details>
38
+ <summary><b>Detailed tool reference</b></summary>
20
39
 
21
- **`n8n_get_execution`** - fetch one execution by id. Includes per-node run log (truncated to `maxExecutionLogBytes`, default 64 KB, with a tail hint when it exceeds) and the raw error object verbatim when status is `error`. Pass `includeRunData: false` to skip the run log and get just status + error.
40
+ **`n8n_list_workflows`** — filter by `active`, `tags`, `name` (substring), `limit`. Returns id, name, active state, tags, updatedAt.
22
41
 
23
- **`n8n_search_executions`** - text-search recent executions without paging through them. Defaults to scanning executions with `status=error` 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 the full per-node run log — slower and may return node output data, so treat snippets as sensitive. Optional `workflowId`, `status` (override default `error`), `limit` (default 50, max 250), `maxMatches` (default 20), `snippetChars` (default 160). Returns `matches`, plus `skipped` entries for any execution that failed to fetch.
42
+ **`n8n_get_workflow`** — fetch one by id. Returns metadata by default. Pass `includeDefinition: true` for the full node graph + connections.
24
43
 
25
- **`n8n_list_webhooks`** - scan workflows for webhook and form-trigger nodes and return their paths + fully-formed `triggerUrl`. Pairs with `n8n_trigger` mode='webhook' so agents can discover and call webhooks without opening n8n. Optional `workflowId` for a single workflow, `activeOnly` (default true), `limit` (default 50).
44
+ **`n8n_list_executions`** — filter by `workflowId`, `status` (success/error/running/waiting/canceled), `limit`. Returns id, workflowId, workflowName, status, mode, startedAt, stoppedAt.
26
45
 
27
- **`n8n_validate_workflow`** - static checks on a workflow: 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) and a summary count.
46
+ **`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
47
 
29
- ### Write tools (behind `enableEdit`)
48
+ **`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
49
 
31
- **`n8n_activate`** - activate a workflow so its triggers start firing. Idempotent.
50
+ **`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
51
 
33
- **`n8n_deactivate`** - deactivate a workflow so triggers stop firing. Running executions are not cancelled. Idempotent.
52
+ **`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
53
 
35
- **`n8n_save_workflow`** - overwrite a workflow. Before writing: fetches the current version, snapshots it to `backupDir` as `<id>-<timestamp>.json` (mode 0600), runs `validateWorkflow` on the proposed new 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` describing how to roll back.
54
+ **`n8n_trigger`** — two modes:
55
+ - `mode: "webhook"` + `webhookPath` — POST (or GET/PUT/DELETE) to the configured base URL + path, with an optional JSON `payload`. This is the reliable path.
56
+ - `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.
36
57
 
37
- **`n8n_trigger`** - run a workflow. Two modes:
38
- - `mode: "webhook"` + `webhookPath` - POST (or GET/PUT/DELETE) to the configured base URL + path, with an optional JSON `payload`. This is the reliable path.
39
- - `mode: "workflow"` + `workflowId` - attempts `POST /api/v1/workflows/:id/execute`. Pre-checks that the workflow is active and has a webhook/manual/form trigger node. Most n8n builds do not expose this endpoint on the Public API and will 405; the tool surfaces a hint to switch to webhook mode in that case.
58
+ **`n8n_activate`** / **`n8n_deactivate`** — idempotent. Deactivating does not cancel running executions.
40
59
 
41
- ## Install
60
+ **`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`.
42
61
 
43
- ```bash
44
- npm install -g n8n-ops-mcp
45
- ```
62
+ **`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).
63
+
64
+ **`n8n_retry_execution`** — `POST /executions/{id}/retry`. Creates a NEW execution — the response surfaces both `originalExecutionId` and `newExecutionId` so agents can follow up with `n8n_get_execution` on the retry. Optional `loadWorkflow: true` retries against the currently saved workflow instead of the version captured at original execution time. Returns `ok: false` with `reason: "not_found"` on 404 or `reason: "not_retryable"` on 409 (e.g. still running); all other API errors rethrow.
46
65
 
47
- Or from source:
66
+ </details>
67
+
68
+ ## Install
48
69
 
49
70
  ```bash
50
- git clone https://github.com/solomonneas/n8n-ops-mcp.git
51
- cd n8n-ops-mcp
52
- npm install
53
- npm run build
71
+ npm install -g n8n-ops-mcp
54
72
  ```
55
73
 
56
74
  ## Configuration
57
75
 
58
- Generate an API key in n8n under Settings -> API, then set these env vars in your MCP client config:
76
+ Generate an API key in n8n under **Settings → API**, then set these env vars in your MCP client config:
59
77
 
60
78
  | Variable | Required | Default | Description |
61
79
  |---|---|---|---|
62
80
  | `N8N_BASE_URL` | yes | — | n8n base URL, e.g. `http://localhost:5678` |
63
81
  | `N8N_API_KEY` | yes | — | n8n Public API key (`X-N8N-API-KEY`) |
64
- | `N8N_ENABLE_EDIT` | no | `false` | Set to `true` to expose `n8n_activate`, `n8n_deactivate`, `n8n_save_workflow` |
82
+ | `N8N_ENABLE_EDIT` | no | `false` | Expose write tools |
65
83
  | `N8N_BACKUP_DIR` | no | `~/.n8n-backups` | Where `n8n_save_workflow` writes pre-save snapshots |
66
84
  | `N8N_MAX_EXECUTION_LOG_BYTES` | no | `65536` | Cap on inline execution log bytes |
67
85
  | `N8N_REQUEST_TIMEOUT_MS` | no | `15000` | HTTP timeout for n8n API calls |
68
86
 
69
- ### Claude Desktop
70
-
71
- Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
72
-
73
- ```json
74
- {
75
- "mcpServers": {
76
- "n8n": {
77
- "command": "n8n-ops-mcp",
78
- "env": {
79
- "N8N_BASE_URL": "http://localhost:5678",
80
- "N8N_API_KEY": "your-api-key-here"
81
- }
82
- }
83
- }
84
- }
85
- ```
86
-
87
87
  ### Claude Code
88
88
 
89
89
  ```bash
@@ -95,17 +95,19 @@ claude mcp add n8n \
95
95
 
96
96
  Add `--scope user` to make it available from any directory instead of only the current project.
97
97
 
98
- ### OpenClaw (as a native plugin)
98
+ ### OpenClaw
99
+
100
+ n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — so it shares the gateway's process, auth profiles, and hooks.
101
+
102
+ ```bash
103
+ openclaw plugins install clawhub:n8n-ops-mcp
104
+ ```
99
105
 
100
- n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — which means it shares the gateway's process, auth profiles, and hooks. Register it in `~/.openclaw/openclaw.json`:
106
+ Add the config block to `~/.openclaw/openclaw.json`:
101
107
 
102
108
  ```json
103
109
  {
104
110
  "plugins": {
105
- "allow": ["n8n"],
106
- "load": {
107
- "paths": ["/absolute/path/to/n8n-ops-mcp"]
108
- },
109
111
  "entries": {
110
112
  "n8n": {
111
113
  "enabled": true,
@@ -119,7 +121,7 @@ n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — which mea
119
121
  }
120
122
  ```
121
123
 
122
- Put the API key in your OpenClaw workspace env so the plugin can read it without inlining:
124
+ Put the API key in your OpenClaw workspace env:
123
125
 
124
126
  ```bash
125
127
  # ~/.openclaw/workspace/.env
@@ -132,21 +134,32 @@ Restart the gateway:
132
134
  systemctl --user restart openclaw-gateway
133
135
  ```
134
136
 
135
- OpenClaw plugin config keys (passed via `plugins.entries.n8n.config`): `baseUrl`, `apiKey`, `apiKeyEnv`, `enableEdit`, `maxExecutionLogBytes`, `requestTimeoutMs`, `backupDir`. See [`openclaw.plugin.json`](./openclaw.plugin.json) for the full schema.
137
+ Config keys: `baseUrl`, `apiKey`, `apiKeyEnv`, `enableEdit`, `maxExecutionLogBytes`, `requestTimeoutMs`, `backupDir`. See [`openclaw.plugin.json`](./openclaw.plugin.json) for the full schema.
136
138
 
137
- ### OpenClaw (via ClawHub)
139
+ <details>
140
+ <summary><b>Other clients</b> — Claude Desktop, Hermes Agent, Codex CLI, manual OpenClaw install</summary>
138
141
 
139
- If you prefer the registry path:
142
+ ### Claude Desktop
140
143
 
141
- ```bash
142
- openclaw plugins install clawhub:n8n-ops-mcp
143
- ```
144
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
144
145
 
145
- Then add a `plugins.entries.n8n` config block as above, restart the gateway, and you're done. ClawHub handles install + updates.
146
+ ```json
147
+ {
148
+ "mcpServers": {
149
+ "n8n": {
150
+ "command": "n8n-ops-mcp",
151
+ "env": {
152
+ "N8N_BASE_URL": "http://localhost:5678",
153
+ "N8N_API_KEY": "your-api-key-here"
154
+ }
155
+ }
156
+ }
157
+ }
158
+ ```
146
159
 
147
160
  ### Hermes Agent
148
161
 
149
- [Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml` under the `mcp_servers` key:
162
+ [Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml`:
150
163
 
151
164
  ```yaml
152
165
  mcp_servers:
@@ -157,7 +170,7 @@ mcp_servers:
157
170
  N8N_API_KEY: "your-api-key-here"
158
171
  ```
159
172
 
160
- Then reload MCP from inside a Hermes session:
173
+ Then reload from inside a session:
161
174
 
162
175
  ```
163
176
  /reload-mcp
@@ -165,8 +178,6 @@ Then reload MCP from inside a Hermes session:
165
178
 
166
179
  ### Codex CLI
167
180
 
168
- [Codex CLI](https://github.com/openai/codex) registers MCP servers via `codex mcp add`:
169
-
170
181
  ```bash
171
182
  codex mcp add n8n \
172
183
  --env N8N_BASE_URL=http://localhost:5678 \
@@ -174,53 +185,83 @@ codex mcp add n8n \
174
185
  -- n8n-ops-mcp
175
186
  ```
176
187
 
177
- Codex writes the entry to `~/.codex/config.toml` under `[mcp_servers.n8n]`. Verify with:
188
+ Writes the entry to `~/.codex/config.toml` under `[mcp_servers.n8n]`. Verify with `codex mcp list`.
178
189
 
179
- ```bash
180
- codex mcp list
190
+ ### OpenClaw — manual (non-ClawHub) install
191
+
192
+ If you want to point OpenClaw at a local clone instead of the registry:
193
+
194
+ ```json
195
+ {
196
+ "plugins": {
197
+ "allow": ["n8n"],
198
+ "load": {
199
+ "paths": ["/absolute/path/to/n8n-ops-mcp"]
200
+ },
201
+ "entries": {
202
+ "n8n": {
203
+ "enabled": true,
204
+ "config": {
205
+ "baseUrl": "http://your-n8n-host:5678",
206
+ "enableEdit": false
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
181
212
  ```
182
213
 
214
+ </details>
215
+
183
216
  ## Example prompts
184
217
 
185
218
  > What n8n workflows broke today?
186
219
 
187
- Calls `n8n_list_executions` with `status=error`, then optionally `n8n_get_execution` for the failing run log.
220
+ Calls `n8n_list_executions` with `status=error`, then `n8n_get_execution` for the failing run.
221
+
222
+ > Which workflow errored with "ECONNREFUSED"?
223
+
224
+ Calls `n8n_search_executions` with `query: "ECONNREFUSED"`.
188
225
 
189
226
  > Trigger the "nightly intel" workflow
190
227
 
191
- Calls `n8n_list_webhooks` to find the webhook path, then `n8n_trigger` with `mode=webhook`.
228
+ Calls `n8n_list_webhooks` to find the path, then `n8n_trigger` with `mode=webhook`.
192
229
 
193
230
  > Audit my workflows for deprecated Code-node API usage
194
231
 
195
232
  Calls `n8n_list_workflows` then `n8n_validate_workflow` per id, filters for `code-node-old-node-ref` and `code-node-items-global` warnings.
196
233
 
197
- > Deactivate the "experimental-bot" workflow (requires `N8N_ENABLE_EDIT=true`)
234
+ > Deactivate the "experimental-bot" workflow *(requires `N8N_ENABLE_EDIT=true`)*
198
235
 
199
236
  Calls `n8n_list_workflows` with a name filter, then `n8n_deactivate` on the matching id.
200
237
 
238
+ > Kill the execution stuck on ECONNREFUSED *(requires `N8N_ENABLE_EDIT=true`)*
239
+
240
+ Calls `n8n_search_executions` with `query: "ECONNREFUSED"`, then `n8n_cancel_execution` on the match.
241
+
242
+ > Retry yesterday's failed "nightly intel" run against the current workflow *(requires `N8N_ENABLE_EDIT=true`)*
243
+
244
+ Calls `n8n_search_executions` to find the failed id, then `n8n_retry_execution` with `loadWorkflow: true`.
245
+
201
246
  ## Development
202
247
 
203
248
  ```bash
204
249
  npm install
205
250
  npm run dev # tsx on mcp-server.ts (MCP stdio)
206
- npm run typecheck # tsc --noEmit
251
+ npm run typecheck
252
+ npm test # vitest run
207
253
  npm run build # tsup bundle to dist/mcp-server.js
208
254
  npm start # node dist/mcp-server.js (post-build)
209
255
  ```
210
256
 
211
- ## Roadmap
212
-
213
- - [x] `n8n_list_workflows`
214
- - [x] `n8n_get_workflow`
215
- - [x] `n8n_list_executions`
216
- - [x] `n8n_get_execution`
217
- - [x] `n8n_trigger` (webhook + manual)
218
- - [x] `n8n_list_webhooks` (surface webhook paths for mode='webhook')
219
- - [x] `n8n_validate_workflow` (Code node + deprecated node checks)
220
- - [x] `n8n_activate` / `n8n_deactivate` (behind `enableEdit`)
221
- - [x] `n8n_save_workflow` with auto-backup + validation gate (behind `enableEdit`)
222
- - [x] MCP wrapper (stdio)
223
- - [x] `n8n_search_executions` (text search across run logs)
257
+ Or install from source:
258
+
259
+ ```bash
260
+ git clone https://github.com/solomonneas/n8n-ops-mcp.git
261
+ cd n8n-ops-mcp
262
+ npm install
263
+ npm run build
264
+ ```
224
265
 
225
266
  ## License
226
267
 
@@ -125,6 +125,24 @@ var N8nClient = class {
125
125
  `/api/v1/executions/${id}${qs.toString() ? `?${qs}` : ""}`
126
126
  );
127
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
+ }
136
+ async retryExecution(id, opts = {}) {
137
+ if (!/^[A-Za-z0-9_-]+$/.test(id)) {
138
+ throw new Error(`Invalid execution id: ${id}`);
139
+ }
140
+ const init = { method: "POST" };
141
+ if (opts.loadWorkflow !== void 0) {
142
+ init.body = JSON.stringify({ loadWorkflow: opts.loadWorkflow });
143
+ }
144
+ return this.request(`/api/v1/executions/${id}/retry`, init);
145
+ }
128
146
  async listExecutions(params = {}) {
129
147
  const qs = new URLSearchParams();
130
148
  if (params.workflowId) qs.set("workflowId", params.workflowId);
@@ -1290,8 +1308,123 @@ async function writeBackup(dir, wf) {
1290
1308
  return file;
1291
1309
  }
1292
1310
 
1311
+ // src/tools/cancel-execution.ts
1312
+ import { Type as Type12 } from "@sinclair/typebox";
1313
+ var Schema12 = Type12.Object(
1314
+ {
1315
+ id: Type12.String({
1316
+ description: "Execution id to stop (from n8n_list_executions or n8n_search_executions)."
1317
+ })
1318
+ },
1319
+ { additionalProperties: false }
1320
+ );
1321
+ function createCancelExecutionTool(getClient) {
1322
+ return {
1323
+ name: "n8n_cancel_execution",
1324
+ label: "n8n: cancel execution",
1325
+ 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.",
1326
+ parameters: Schema12,
1327
+ execute: async (_toolCallId, rawParams) => {
1328
+ const { id } = rawParams;
1329
+ const client = getClient();
1330
+ try {
1331
+ const ex = await client.stopExecution(id);
1332
+ const status = ex.status ?? (ex.finished ? "success" : "running");
1333
+ return jsonToolResult({
1334
+ ok: true,
1335
+ action: "cancel",
1336
+ executionId: String(ex.id),
1337
+ workflowId: String(ex.workflowId ?? ""),
1338
+ workflowName: ex.workflowData?.name ?? null,
1339
+ status,
1340
+ finished: ex.finished,
1341
+ startedAt: ex.startedAt ?? null,
1342
+ stoppedAt: ex.stoppedAt ?? null
1343
+ });
1344
+ } catch (err) {
1345
+ if (err instanceof N8nApiError && err.status === 404) {
1346
+ return jsonToolResult({
1347
+ ok: false,
1348
+ action: "cancel",
1349
+ executionId: id,
1350
+ reason: "not_found_or_finished",
1351
+ message: "Execution not found. It may have already finished, been deleted, or never existed."
1352
+ });
1353
+ }
1354
+ throw err;
1355
+ }
1356
+ }
1357
+ };
1358
+ }
1359
+
1360
+ // src/tools/retry-execution.ts
1361
+ import { Type as Type13 } from "@sinclair/typebox";
1362
+ var Schema13 = Type13.Object(
1363
+ {
1364
+ id: Type13.String({
1365
+ description: "Execution id to retry (from n8n_list_executions or n8n_search_executions)."
1366
+ }),
1367
+ loadWorkflow: Type13.Optional(
1368
+ Type13.Boolean({
1369
+ description: "If true, retry against the currently saved workflow instead of the version captured at the original execution time. Omit to accept n8n's default."
1370
+ })
1371
+ )
1372
+ },
1373
+ { additionalProperties: false }
1374
+ );
1375
+ function createRetryExecutionTool(getClient) {
1376
+ return {
1377
+ name: "n8n_retry_execution",
1378
+ label: "n8n: retry execution",
1379
+ description: "Retry a failed n8n execution by id via POST /executions/{id}/retry. Creates a NEW execution \u2014 the response surfaces both the original id and the newExecutionId so agents can follow up. If the id no longer matches an execution (404), returns ok:false with reason 'not_found'. If the execution is not retryable (409 \u2014 typically still running), returns ok:false with reason 'not_retryable'. All other API errors rethrow. Optional loadWorkflow:true retries against the current saved workflow rather than the version captured at the original execution time. Requires enableEdit.",
1380
+ parameters: Schema13,
1381
+ execute: async (_toolCallId, rawParams) => {
1382
+ const { id, loadWorkflow } = rawParams;
1383
+ const client = getClient();
1384
+ const opts = loadWorkflow === void 0 ? {} : { loadWorkflow };
1385
+ try {
1386
+ const ex = await client.retryExecution(id, opts);
1387
+ const status = ex.status ?? (ex.finished ? "success" : "running");
1388
+ return jsonToolResult({
1389
+ ok: true,
1390
+ action: "retry",
1391
+ originalExecutionId: id,
1392
+ newExecutionId: String(ex.id),
1393
+ workflowId: String(ex.workflowId ?? ""),
1394
+ workflowName: ex.workflowData?.name ?? null,
1395
+ status,
1396
+ finished: ex.finished,
1397
+ startedAt: ex.startedAt ?? null,
1398
+ stoppedAt: ex.stoppedAt ?? null,
1399
+ loadWorkflow: loadWorkflow ?? null
1400
+ });
1401
+ } catch (err) {
1402
+ if (err instanceof N8nApiError && err.status === 404) {
1403
+ return jsonToolResult({
1404
+ ok: false,
1405
+ action: "retry",
1406
+ originalExecutionId: id,
1407
+ reason: "not_found",
1408
+ message: "Execution not found. It may have been deleted or never existed."
1409
+ });
1410
+ }
1411
+ if (err instanceof N8nApiError && err.status === 409) {
1412
+ return jsonToolResult({
1413
+ ok: false,
1414
+ action: "retry",
1415
+ originalExecutionId: id,
1416
+ reason: "not_retryable",
1417
+ message: "Execution is not retryable. It may still be running, or n8n refused the retry for this execution's state."
1418
+ });
1419
+ }
1420
+ throw err;
1421
+ }
1422
+ }
1423
+ };
1424
+ }
1425
+
1293
1426
  // mcp-server.ts
1294
- var VERSION = "0.2.0";
1427
+ var VERSION = "0.4.0";
1295
1428
  function readConfigFromEnv() {
1296
1429
  const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
1297
1430
  if (!baseUrl) {
@@ -1447,6 +1580,19 @@ async function main() {
1447
1580
  confirm: z.boolean().describe("Must be true to actually write. Snapshot to backupDir happens regardless.")
1448
1581
  }
1449
1582
  );
1583
+ bind(server, createCancelExecutionTool(getClient), {
1584
+ id: z.string().describe(
1585
+ "Execution id to stop (from n8n_list_executions or n8n_search_executions)."
1586
+ )
1587
+ });
1588
+ bind(server, createRetryExecutionTool(getClient), {
1589
+ id: z.string().describe(
1590
+ "Execution id to retry (from n8n_list_executions or n8n_search_executions). The response contains a NEW execution id."
1591
+ ),
1592
+ loadWorkflow: z.boolean().optional().describe(
1593
+ "If true, retry against the currently saved workflow instead of the version captured at the original execution time. Omit to accept n8n's default."
1594
+ )
1595
+ });
1450
1596
  }
1451
1597
  const transport = new StdioServerTransport();
1452
1598
  await server.connect(transport);
package/index.ts CHANGED
@@ -12,6 +12,8 @@ import { createValidateWorkflowTool } from "./src/tools/validate-workflow.ts";
12
12
  import { createActivateTool } from "./src/tools/activate.ts";
13
13
  import { createDeactivateTool } from "./src/tools/deactivate.ts";
14
14
  import { createSaveWorkflowTool } from "./src/tools/save-workflow.ts";
15
+ import { createCancelExecutionTool } from "./src/tools/cancel-execution.ts";
16
+ import { createRetryExecutionTool } from "./src/tools/retry-execution.ts";
15
17
 
16
18
  export default definePluginEntry({
17
19
  id: "n8n",
@@ -49,6 +51,8 @@ export default definePluginEntry({
49
51
  backupDir: config.backupDir,
50
52
  }) as AnyAgentTool,
51
53
  );
54
+ api.registerTool(createCancelExecutionTool(getClient) as AnyAgentTool);
55
+ api.registerTool(createRetryExecutionTool(getClient) as AnyAgentTool);
52
56
  }
53
57
  },
54
58
  });
@@ -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/retry-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 with confirm-gates and auto-rollback."
58
+ "help": "Exposes save/activate/deactivate/cancel-execution/retry-execution. save has a confirm-gate and auto-backup; cancel stops running executions; retry re-runs a failed execution and returns a NEW execution id."
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.2.0",
3
+ "version": "0.4.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": ["n8n", "mcp", "model-context-protocol", "openclaw", "workflow", "ops", "automation"],
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": ["./index.ts"],
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
- "prepublishOnly": "npm run typecheck && npm run build"
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
@@ -218,6 +218,29 @@ export class N8nClient {
218
218
  );
219
219
  }
220
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
+
230
+ async retryExecution(
231
+ id: string,
232
+ opts: { loadWorkflow?: boolean } = {},
233
+ ): Promise<N8nExecution> {
234
+ if (!/^[A-Za-z0-9_-]+$/.test(id)) {
235
+ throw new Error(`Invalid execution id: ${id}`);
236
+ }
237
+ const init: RequestInit = { method: "POST" };
238
+ if (opts.loadWorkflow !== undefined) {
239
+ init.body = JSON.stringify({ loadWorkflow: opts.loadWorkflow });
240
+ }
241
+ return this.request<N8nExecution>(`/api/v1/executions/${id}/retry`, init);
242
+ }
243
+
221
244
  async listExecutions(params: {
222
245
  workflowId?: string;
223
246
  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,77 @@
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 retry (from n8n_list_executions or n8n_search_executions).",
10
+ }),
11
+ loadWorkflow: Type.Optional(
12
+ Type.Boolean({
13
+ description:
14
+ "If true, retry against the currently saved workflow instead of the version captured at the original execution time. Omit to accept n8n's default.",
15
+ }),
16
+ ),
17
+ },
18
+ { additionalProperties: false },
19
+ );
20
+
21
+ export function createRetryExecutionTool(getClient: () => N8nClient) {
22
+ return {
23
+ name: "n8n_retry_execution",
24
+ label: "n8n: retry execution",
25
+ description:
26
+ "Retry a failed n8n execution by id via POST /executions/{id}/retry. Creates a NEW execution — the response surfaces both the original id and the newExecutionId so agents can follow up. If the id no longer matches an execution (404), returns ok:false with reason 'not_found'. If the execution is not retryable (409 — typically still running), returns ok:false with reason 'not_retryable'. All other API errors rethrow. Optional loadWorkflow:true retries against the current saved workflow rather than the version captured at the original execution time. Requires enableEdit.",
27
+ parameters: Schema,
28
+ execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
29
+ const { id, loadWorkflow } = rawParams as {
30
+ id: string;
31
+ loadWorkflow?: boolean;
32
+ };
33
+ const client = getClient();
34
+ const opts: { loadWorkflow?: boolean } =
35
+ loadWorkflow === undefined ? {} : { loadWorkflow };
36
+ try {
37
+ const ex = await client.retryExecution(id, opts);
38
+ const status = ex.status ?? (ex.finished ? "success" : "running");
39
+ return jsonToolResult({
40
+ ok: true,
41
+ action: "retry",
42
+ originalExecutionId: id,
43
+ newExecutionId: String(ex.id),
44
+ workflowId: String(ex.workflowId ?? ""),
45
+ workflowName: ex.workflowData?.name ?? null,
46
+ status,
47
+ finished: ex.finished,
48
+ startedAt: ex.startedAt ?? null,
49
+ stoppedAt: ex.stoppedAt ?? null,
50
+ loadWorkflow: loadWorkflow ?? null,
51
+ });
52
+ } catch (err) {
53
+ if (err instanceof N8nApiError && err.status === 404) {
54
+ return jsonToolResult({
55
+ ok: false,
56
+ action: "retry",
57
+ originalExecutionId: id,
58
+ reason: "not_found",
59
+ message:
60
+ "Execution not found. It may have been deleted or never existed.",
61
+ });
62
+ }
63
+ if (err instanceof N8nApiError && err.status === 409) {
64
+ return jsonToolResult({
65
+ ok: false,
66
+ action: "retry",
67
+ originalExecutionId: id,
68
+ reason: "not_retryable",
69
+ message:
70
+ "Execution is not retryable. It may still be running, or n8n refused the retry for this execution's state.",
71
+ });
72
+ }
73
+ throw err;
74
+ }
75
+ },
76
+ };
77
+ }