n8n-ops-mcp 0.3.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 +7 -0
- package/dist/mcp-server.js +85 -1
- package/index.ts +2 -0
- package/openclaw.plugin.json +2 -2
- package/package.json +1 -1
- package/src/client.ts +14 -0
- package/src/tools/retry-execution.ts +77 -0
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ For a catalog/docs tool that indexes n8n's node library, see [n8n-mcp](https://w
|
|
|
30
30
|
| `n8n_deactivate` | Disable a workflow's triggers | ✓ |
|
|
31
31
|
| `n8n_save_workflow` | Overwrite a workflow with auto-backup + validation + confirm gate | ✓ |
|
|
32
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) | ✓ |
|
|
33
34
|
|
|
34
35
|
Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
35
36
|
|
|
@@ -60,6 +61,8 @@ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
|
60
61
|
|
|
61
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).
|
|
62
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.
|
|
65
|
+
|
|
63
66
|
</details>
|
|
64
67
|
|
|
65
68
|
## Install
|
|
@@ -236,6 +239,10 @@ Calls `n8n_list_workflows` with a name filter, then `n8n_deactivate` on the matc
|
|
|
236
239
|
|
|
237
240
|
Calls `n8n_search_executions` with `query: "ECONNREFUSED"`, then `n8n_cancel_execution` on the match.
|
|
238
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
|
+
|
|
239
246
|
## Development
|
|
240
247
|
|
|
241
248
|
```bash
|
package/dist/mcp-server.js
CHANGED
|
@@ -133,6 +133,16 @@ var N8nClient = class {
|
|
|
133
133
|
method: "POST"
|
|
134
134
|
});
|
|
135
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
|
+
}
|
|
136
146
|
async listExecutions(params = {}) {
|
|
137
147
|
const qs = new URLSearchParams();
|
|
138
148
|
if (params.workflowId) qs.set("workflowId", params.workflowId);
|
|
@@ -1347,8 +1357,74 @@ function createCancelExecutionTool(getClient) {
|
|
|
1347
1357
|
};
|
|
1348
1358
|
}
|
|
1349
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
|
+
|
|
1350
1426
|
// mcp-server.ts
|
|
1351
|
-
var VERSION = "0.
|
|
1427
|
+
var VERSION = "0.4.0";
|
|
1352
1428
|
function readConfigFromEnv() {
|
|
1353
1429
|
const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
|
|
1354
1430
|
if (!baseUrl) {
|
|
@@ -1509,6 +1585,14 @@ async function main() {
|
|
|
1509
1585
|
"Execution id to stop (from n8n_list_executions or n8n_search_executions)."
|
|
1510
1586
|
)
|
|
1511
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
|
+
});
|
|
1512
1596
|
}
|
|
1513
1597
|
const transport = new StdioServerTransport();
|
|
1514
1598
|
await server.connect(transport);
|
package/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ 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
15
|
import { createCancelExecutionTool } from "./src/tools/cancel-execution.ts";
|
|
16
|
+
import { createRetryExecutionTool } from "./src/tools/retry-execution.ts";
|
|
16
17
|
|
|
17
18
|
export default definePluginEntry({
|
|
18
19
|
id: "n8n",
|
|
@@ -51,6 +52,7 @@ export default definePluginEntry({
|
|
|
51
52
|
}) as AnyAgentTool,
|
|
52
53
|
);
|
|
53
54
|
api.registerTool(createCancelExecutionTool(getClient) as AnyAgentTool);
|
|
55
|
+
api.registerTool(createRetryExecutionTool(getClient) as AnyAgentTool);
|
|
54
56
|
}
|
|
55
57
|
},
|
|
56
58
|
});
|
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/cancel-execution). 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/cancel-execution. save has a confirm-gate and auto-backup; cancel stops running executions
|
|
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
package/src/client.ts
CHANGED
|
@@ -227,6 +227,20 @@ export class N8nClient {
|
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
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
|
+
|
|
230
244
|
async listExecutions(params: {
|
|
231
245
|
workflowId?: string;
|
|
232
246
|
status?: string;
|
|
@@ -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
|
+
}
|