n8n-ops-mcp 0.2.0 → 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 CHANGED
@@ -1,89 +1,86 @@
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 | ✓ |
16
33
 
17
- **`n8n_get_workflow`** - fetch one workflow by id. Returns metadata by default. Pass `includeDefinition: true` to get the full node graph + connections.
34
+ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
18
35
 
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.
36
+ <details>
37
+ <summary><b>Detailed tool reference</b></summary>
20
38
 
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.
39
+ **`n8n_list_workflows`** — filter by `active`, `tags`, `name` (substring), `limit`. Returns id, name, active state, tags, updatedAt.
22
40
 
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.
41
+ **`n8n_get_workflow`** — fetch one by id. Returns metadata by default. Pass `includeDefinition: true` for the full node graph + connections.
24
42
 
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).
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
- **`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.
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
- ### Write tools (behind `enableEdit`)
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
- **`n8n_activate`** - activate a workflow so its triggers start firing. Idempotent.
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
- **`n8n_deactivate`** - deactivate a workflow so triggers stop firing. Running executions are not cancelled. Idempotent.
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_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.
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.
36
56
 
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.
57
+ **`n8n_activate`** / **`n8n_deactivate`** — idempotent. Deactivating does not cancel running executions.
40
58
 
41
- ## Install
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`.
42
60
 
43
- ```bash
44
- npm install -g n8n-ops-mcp
45
- ```
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).
62
+
63
+ </details>
46
64
 
47
- Or from source:
65
+ ## Install
48
66
 
49
67
  ```bash
50
- git clone https://github.com/solomonneas/n8n-ops-mcp.git
51
- cd n8n-ops-mcp
52
- npm install
53
- npm run build
68
+ npm install -g n8n-ops-mcp
54
69
  ```
55
70
 
56
71
  ## Configuration
57
72
 
58
- Generate an API key in n8n under Settings -> API, then set these env vars in your MCP client config:
73
+ Generate an API key in n8n under **Settings → API**, then set these env vars in your MCP client config:
59
74
 
60
75
  | Variable | Required | Default | Description |
61
76
  |---|---|---|---|
62
77
  | `N8N_BASE_URL` | yes | — | n8n base URL, e.g. `http://localhost:5678` |
63
78
  | `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` |
79
+ | `N8N_ENABLE_EDIT` | no | `false` | Expose write tools |
65
80
  | `N8N_BACKUP_DIR` | no | `~/.n8n-backups` | Where `n8n_save_workflow` writes pre-save snapshots |
66
81
  | `N8N_MAX_EXECUTION_LOG_BYTES` | no | `65536` | Cap on inline execution log bytes |
67
82
  | `N8N_REQUEST_TIMEOUT_MS` | no | `15000` | HTTP timeout for n8n API calls |
68
83
 
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
84
  ### Claude Code
88
85
 
89
86
  ```bash
@@ -95,17 +92,19 @@ claude mcp add n8n \
95
92
 
96
93
  Add `--scope user` to make it available from any directory instead of only the current project.
97
94
 
98
- ### OpenClaw (as a native plugin)
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.
98
+
99
+ ```bash
100
+ openclaw plugins install clawhub:n8n-ops-mcp
101
+ ```
99
102
 
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`:
103
+ Add the config block to `~/.openclaw/openclaw.json`:
101
104
 
102
105
  ```json
103
106
  {
104
107
  "plugins": {
105
- "allow": ["n8n"],
106
- "load": {
107
- "paths": ["/absolute/path/to/n8n-ops-mcp"]
108
- },
109
108
  "entries": {
110
109
  "n8n": {
111
110
  "enabled": true,
@@ -119,7 +118,7 @@ n8n-ops-mcp is a first-class OpenClaw plugin — not an MCP bridge — which mea
119
118
  }
120
119
  ```
121
120
 
122
- Put the API key in your OpenClaw workspace env so the plugin can read it without inlining:
121
+ Put the API key in your OpenClaw workspace env:
123
122
 
124
123
  ```bash
125
124
  # ~/.openclaw/workspace/.env
@@ -132,21 +131,32 @@ Restart the gateway:
132
131
  systemctl --user restart openclaw-gateway
133
132
  ```
134
133
 
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.
134
+ Config keys: `baseUrl`, `apiKey`, `apiKeyEnv`, `enableEdit`, `maxExecutionLogBytes`, `requestTimeoutMs`, `backupDir`. See [`openclaw.plugin.json`](./openclaw.plugin.json) for the full schema.
136
135
 
137
- ### OpenClaw (via ClawHub)
136
+ <details>
137
+ <summary><b>Other clients</b> — Claude Desktop, Hermes Agent, Codex CLI, manual OpenClaw install</summary>
138
138
 
139
- If you prefer the registry path:
139
+ ### Claude Desktop
140
140
 
141
- ```bash
142
- openclaw plugins install clawhub:n8n-ops-mcp
143
- ```
141
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
144
142
 
145
- Then add a `plugins.entries.n8n` config block as above, restart the gateway, and you're done. ClawHub handles install + updates.
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
+ ```
146
156
 
147
157
  ### Hermes Agent
148
158
 
149
- [Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml` under the `mcp_servers` key:
159
+ [Hermes Agent](https://github.com/NousResearch/hermes-agent) reads MCP config from `~/.hermes/config.yaml`:
150
160
 
151
161
  ```yaml
152
162
  mcp_servers:
@@ -157,7 +167,7 @@ mcp_servers:
157
167
  N8N_API_KEY: "your-api-key-here"
158
168
  ```
159
169
 
160
- Then reload MCP from inside a Hermes session:
170
+ Then reload from inside a session:
161
171
 
162
172
  ```
163
173
  /reload-mcp
@@ -165,8 +175,6 @@ Then reload MCP from inside a Hermes session:
165
175
 
166
176
  ### Codex CLI
167
177
 
168
- [Codex CLI](https://github.com/openai/codex) registers MCP servers via `codex mcp add`:
169
-
170
178
  ```bash
171
179
  codex mcp add n8n \
172
180
  --env N8N_BASE_URL=http://localhost:5678 \
@@ -174,53 +182,79 @@ codex mcp add n8n \
174
182
  -- n8n-ops-mcp
175
183
  ```
176
184
 
177
- Codex writes the entry to `~/.codex/config.toml` under `[mcp_servers.n8n]`. Verify with:
185
+ Writes the entry to `~/.codex/config.toml` under `[mcp_servers.n8n]`. Verify with `codex mcp list`.
178
186
 
179
- ```bash
180
- codex mcp list
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
+ }
181
209
  ```
182
210
 
211
+ </details>
212
+
183
213
  ## Example prompts
184
214
 
185
215
  > What n8n workflows broke today?
186
216
 
187
- Calls `n8n_list_executions` with `status=error`, then optionally `n8n_get_execution` for the failing run log.
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"`.
188
222
 
189
223
  > Trigger the "nightly intel" workflow
190
224
 
191
- Calls `n8n_list_webhooks` to find the webhook path, then `n8n_trigger` with `mode=webhook`.
225
+ Calls `n8n_list_webhooks` to find the path, then `n8n_trigger` with `mode=webhook`.
192
226
 
193
227
  > Audit my workflows for deprecated Code-node API usage
194
228
 
195
229
  Calls `n8n_list_workflows` then `n8n_validate_workflow` per id, filters for `code-node-old-node-ref` and `code-node-items-global` warnings.
196
230
 
197
- > Deactivate the "experimental-bot" workflow (requires `N8N_ENABLE_EDIT=true`)
231
+ > Deactivate the "experimental-bot" workflow *(requires `N8N_ENABLE_EDIT=true`)*
198
232
 
199
233
  Calls `n8n_list_workflows` with a name filter, then `n8n_deactivate` on the matching id.
200
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
+
201
239
  ## Development
202
240
 
203
241
  ```bash
204
242
  npm install
205
243
  npm run dev # tsx on mcp-server.ts (MCP stdio)
206
- npm run typecheck # tsc --noEmit
244
+ npm run typecheck
245
+ npm test # vitest run
207
246
  npm run build # tsup bundle to dist/mcp-server.js
208
247
  npm start # node dist/mcp-server.js (post-build)
209
248
  ```
210
249
 
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)
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
+ ```
224
258
 
225
259
  ## License
226
260
 
@@ -125,6 +125,14 @@ 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
+ }
128
136
  async listExecutions(params = {}) {
129
137
  const qs = new URLSearchParams();
130
138
  if (params.workflowId) qs.set("workflowId", params.workflowId);
@@ -1290,8 +1298,57 @@ async function writeBackup(dir, wf) {
1290
1298
  return file;
1291
1299
  }
1292
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
+
1293
1350
  // mcp-server.ts
1294
- var VERSION = "0.2.0";
1351
+ var VERSION = "0.3.0";
1295
1352
  function readConfigFromEnv() {
1296
1353
  const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
1297
1354
  if (!baseUrl) {
@@ -1447,6 +1504,11 @@ async function main() {
1447
1504
  confirm: z.boolean().describe("Must be true to actually write. Snapshot to backupDir happens regardless.")
1448
1505
  }
1449
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
+ });
1450
1512
  }
1451
1513
  const transport = new StdioServerTransport();
1452
1514
  await server.connect(transport);
package/index.ts CHANGED
@@ -12,6 +12,7 @@ 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";
15
16
 
16
17
  export default definePluginEntry({
17
18
  id: "n8n",
@@ -49,6 +50,7 @@ export default definePluginEntry({
49
50
  backupDir: config.backupDir,
50
51
  }) as AnyAgentTool,
51
52
  );
53
+ api.registerTool(createCancelExecutionTool(getClient) as AnyAgentTool);
52
54
  }
53
55
  },
54
56
  });
@@ -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 with confirm-gates and auto-rollback."
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.2.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": ["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,15 @@ 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
+
221
230
  async listExecutions(params: {
222
231
  workflowId?: string;
223
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
+ }