n8n-ops-mcp 0.10.0 → 0.12.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 +17 -0
- package/dist/mcp-server.js +577 -1
- package/index.ts +6 -0
- package/package.json +1 -1
- package/src/tools/list-schedules.ts +363 -0
- package/src/tools/pin-node-data.ts +176 -0
- package/src/tools/unpin-node-data.ts +129 -0
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ For a catalog/docs tool that indexes n8n's node library, see [n8n-mcp](https://w
|
|
|
26
26
|
| `n8n_list_webhooks` | Enumerate webhook + form-trigger URLs | |
|
|
27
27
|
| `n8n_validate_workflow` | Static checks: deprecated nodes, legacy Code-node API, orphans | |
|
|
28
28
|
| `n8n_diff_workflow` | Compare a workflow against a snapshot file or inline object - semantic diff (added/removed/modified nodes with field paths) | |
|
|
29
|
+
| `n8n_list_schedules` | List every schedule trigger across workflows with human-readable descriptions ("daily at 03:00", "cron: 0 */6 * * *") | |
|
|
29
30
|
| `n8n_trigger` | Run a workflow via webhook (reliable) or workflow-id | |
|
|
30
31
|
| `n8n_audit_browser_bridge_usage` | Find every workflow that calls the [`browser-bridge`](https://github.com/solomonneas/browser-bridge) CLI (Execute Command, Code, SSH nodes) | |
|
|
31
32
|
| `n8n_scaffold_browser_bridge_node` | Generate a ready-to-paste n8n node that calls a `browser-bridge <platform> <action>` (no API call) | |
|
|
@@ -40,6 +41,8 @@ For a catalog/docs tool that indexes n8n's node library, see [n8n-mcp](https://w
|
|
|
40
41
|
| `n8n_retry_execution` | Retry a failed execution by id (returns a new execution) | ✓ |
|
|
41
42
|
| `n8n_delete_execution` | Permanently delete an execution record (confirm-gated, irreversible) | ✓ |
|
|
42
43
|
| `n8n_delete_executions` | Batch form of delete (client-side fan-out, confirm-gated, irreversible, max 50 ids) | ✓ |
|
|
44
|
+
| `n8n_pin_node_data` | Pin sample data to a node so downstream nodes use it during testing (confirm-gated, replace-or-merge) | ✓ |
|
|
45
|
+
| `n8n_unpin_node_data` | Clear pinned data on one node or the whole workflow (confirm-gated, idempotent) | ✓ |
|
|
43
46
|
|
|
44
47
|
Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
45
48
|
|
|
@@ -60,6 +63,8 @@ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
|
60
63
|
|
|
61
64
|
**`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.
|
|
62
65
|
|
|
66
|
+
**`n8n_list_schedules`** - scans `n8n-nodes-base.scheduleTrigger` and the legacy `n8n-nodes-base.cron` nodes across workflows and decodes each interval rule into a human-readable string. Answers "what's running at 3am?" without clicking through the n8n UI. Supported rule fields: `seconds` / `minutes` / `hours` / `days` / `weeks` / `months` (with `triggerAtHour`, `triggerAtMinute`, `triggerAtDay`, `triggerAtDayOfMonth`) and raw `cronExpression`. One entry per interval — multi-interval rules emit multiple rows. Each row includes `workflowId`, `workflowName`, `active`, `nodeName`, `nodeType`, `schedule`, `field`, optional `cronExpression`, and the original `raw` rule for further inspection. Optional `workflowId` (single-workflow scan), `activeOnly` (default true — inactive schedules don't fire), `limit` (default 100, max 250).
|
|
67
|
+
|
|
63
68
|
**`n8n_diff_workflow`** - compare a workflow's current state against a snapshot. Pass `id` plus exactly one of `snapshotPath` (absolute path; `~` resolved) or `snapshot` (inline object). Snapshot accepts both shapes: the flat backup written by `n8n_save_workflow` / `n8n_delete_workflow`, and the nested `n8n_get_workflow(includeDefinition=true)` shape (graph data under `definition`). Returns `summary` (counts: added/removed/modified/nameChanged/connectionsChanged/settingsChanged) plus `diff` with per-node `fieldsChanged` paths (e.g. `parameters.command`, `parameters.url`, `disabled`). Node matching is two-pass: id first, then name fallback for any unmatched nodes — handles legacy/hand-edited snapshots. Cosmetic changes (`position`, `webhookId`) are suppressed by default; pass `ignoreCosmetic: false` to surface them. Per-node detail is capped at `maxModifiedDetails` (default 50, max 500); `summary.nodesModified` counter is uncapped and `diff.nodesModifiedTruncated: true` flags when detail was clipped. Read-only.
|
|
64
69
|
|
|
65
70
|
**`n8n_audit_browser_bridge_usage`** - scans every workflow for nodes that invoke the `browser-bridge` CLI. Inspects `command` (Execute Command + SSH nodes) and `jsCode` / `pythonCode` / `functionCode` (Code + legacy Function nodes). Heuristic: `\bbrowser-bridge\.[cm]?js` followed by two kebab-slug args; the bare bin form is intentionally not detected to avoid false positives from path mentions like `cd /opt/browser-bridge`. Returns one finding per `(workflowId, nodeName, platform, action)` plus a `summary` of platform×action counts. Optional `platform`, `action`, `activeOnly` (default false), `includeArchived` (default false), `maxWorkflows` (default 250, max 1000), `concurrency` (default 3, max 8). Read-only. Pairs with `n8n_scaffold_browser_bridge_node` when you need to add another call. Companion repo: [browser-bridge](https://github.com/solomonneas/browser-bridge).
|
|
@@ -88,6 +93,10 @@ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
|
88
93
|
|
|
89
94
|
**`n8n_delete_execution`** - `DELETE /executions/{id}`. Permanently removes an execution record: logs, per-node run data, and error payloads are erased from n8n. Requires `confirm: true` to actually delete; calling with `confirm: false` returns `ok: false` and never touches the API (omitting `confirm` is rejected at the MCP schema layer). Returns `ok: false` with `reason: "not_found"` on 404; all other API errors rethrow. Not idempotent from an agent's perspective: the record is gone after the first successful call, so fetch `n8n_get_execution` first if you may need it later.
|
|
90
95
|
|
|
96
|
+
**`n8n_pin_node_data`** - pin sample data to a node so downstream nodes use it during testing/development without re-running the upstream node. Pairs naturally with `n8n_scaffold_browser_bridge_node`: scaffold a browser-bridge call, run it once, capture the output, pin it, then iterate on downstream nodes without re-spawning the browser. Inputs: `id`, `nodeName` (case-sensitive, must match an existing node), `data` (1-50 items; raw objects are auto-wrapped into `{json: <object>}`, items already shaped as `{json: ..., binary?: ...}` pass through unchanged), optional `merge: true` to append to existing pinned data instead of replacing (combined still capped at 50), `confirm: true`. Issues PUT `/workflows/{id}` with merged `pinData` plus the existing nodes/connections/settings/staticData (so the PUT does not blank them). Pinned data persists across executions until cleared — easy to forget; the response includes an `unpinHint`.
|
|
97
|
+
|
|
98
|
+
**`n8n_unpin_node_data`** - clear pinned data on one node (when `nodeName` is supplied) or the whole workflow (when omitted). Idempotent: clearing a node that wasn't pinned returns `ok: true` with `noop: true` and never touches the API. When clearing actually happens, the PUT includes the rest of the workflow body so other fields are not blanked. Requires `confirm: true`.
|
|
99
|
+
|
|
91
100
|
**`n8n_delete_executions`** - batch form. Client-side fan-out over `DELETE /executions/{id}` with bounded concurrency (default 3, max 10). Takes an `ids` array (deduped before fan-out, capped at 50), requires `confirm: true`. Response surfaces `requested`/`attempted`/`deleted`/`alreadyDeleted`/`failed`/`skipped`/`aborted` counters plus a `results: Array<{id, ok, reason?, message?}>` - order is completion order, not input order, so look up by id. 404 per id is treated as `already_deleted` (idempotent). A 5xx on any id aborts the batch via an `AbortController`: no new ids are claimed and any already-in-flight `fetch`es are cancelled client-side. Under concurrency N, up to N-1 deletes may have already reached the server before the 5xx is observed, so the batch is best-effort, not transactional - clear signal the server is sick; don't retry blindly. Per-id error messages are passed through the API-key redactor. Compose with `n8n_search_executions` to purge a known set of noisy runs in one call.
|
|
92
101
|
|
|
93
102
|
</details>
|
|
@@ -259,6 +268,10 @@ Calls `n8n_search_executions` with `query: "ECONNREFUSED"`.
|
|
|
259
268
|
|
|
260
269
|
Calls `n8n_list_webhooks` to find the path, then `n8n_trigger` with `mode=webhook`.
|
|
261
270
|
|
|
271
|
+
> What's running at 3am?
|
|
272
|
+
|
|
273
|
+
Calls `n8n_list_schedules`, then filters the result for any schedule whose description contains "03:00" (or whose `cronExpression` matches an early-morning hour).
|
|
274
|
+
|
|
262
275
|
> What changed in my "intel pipeline" workflow since yesterday's backup?
|
|
263
276
|
|
|
264
277
|
Calls `n8n_diff_workflow` with `id` and `snapshotPath` pointing to the backup file. Returns added/removed/modified nodes with parameter-level field paths.
|
|
@@ -271,6 +284,10 @@ Calls `n8n_audit_browser_bridge_usage` with `platform: "linktree"` to list every
|
|
|
271
284
|
|
|
272
285
|
Calls `n8n_scaffold_browser_bridge_node` with `platform: "coderlegion"`, `action: "scan-comments"`, `input: {limit: 5}` to get a Code node JSON, then pastes it into n8n.
|
|
273
286
|
|
|
287
|
+
> Pin a sample browser-bridge response on the "BB call" node so I can iterate on downstream parsing without re-spawning the browser *(requires `N8N_ENABLE_EDIT=true`)*
|
|
288
|
+
|
|
289
|
+
Calls `n8n_get_execution` to grab the most recent successful output of the node, then `n8n_pin_node_data` with `nodeName: "BB call"`, `data: <captured items>`, `confirm: true`. Clear later via `n8n_unpin_node_data`.
|
|
290
|
+
|
|
274
291
|
> Audit my workflows for deprecated Code-node API usage
|
|
275
292
|
|
|
276
293
|
Calls `n8n_list_workflows` then `n8n_validate_workflow` per id, filters for `code-node-old-node-ref` and `code-node-items-global` warnings.
|
package/dist/mcp-server.js
CHANGED
|
@@ -2670,8 +2670,551 @@ function deepEqual(a, b) {
|
|
|
2670
2670
|
return true;
|
|
2671
2671
|
}
|
|
2672
2672
|
|
|
2673
|
+
// src/tools/pin-node-data.ts
|
|
2674
|
+
import { Type as Type22 } from "@sinclair/typebox";
|
|
2675
|
+
var Schema22 = Type22.Object(
|
|
2676
|
+
{
|
|
2677
|
+
id: Type22.String({ description: "Workflow id (from n8n_list_workflows)." }),
|
|
2678
|
+
nodeName: Type22.String({
|
|
2679
|
+
minLength: 1,
|
|
2680
|
+
description: "Name of the node to pin data on (case-sensitive). Must be the n8n node 'name' field, not the type. Use n8n_get_workflow(includeDefinition=true) to look up exact names."
|
|
2681
|
+
}),
|
|
2682
|
+
data: Type22.Array(
|
|
2683
|
+
Type22.Record(Type22.String(), Type22.Unknown()),
|
|
2684
|
+
{
|
|
2685
|
+
minItems: 1,
|
|
2686
|
+
maxItems: 50,
|
|
2687
|
+
description: "Items to pin (max 50). Each item may be a fully-shaped n8n run item (`{json: {...}, binary?: {...}}`) or a raw object \u2014 raw objects are auto-wrapped into `{json: <object>}`."
|
|
2688
|
+
}
|
|
2689
|
+
),
|
|
2690
|
+
merge: Type22.Optional(
|
|
2691
|
+
Type22.Boolean({
|
|
2692
|
+
description: "If true, append to existing pinned data on the node instead of replacing it (combined total still capped at 50). Default false (replace)."
|
|
2693
|
+
})
|
|
2694
|
+
),
|
|
2695
|
+
confirm: Type22.Boolean({
|
|
2696
|
+
description: "Must be true to actually write. Pinned data persists across executions and overrides node output until cleared via n8n_unpin_node_data \u2014 easy to forget about."
|
|
2697
|
+
})
|
|
2698
|
+
},
|
|
2699
|
+
{ additionalProperties: false }
|
|
2700
|
+
);
|
|
2701
|
+
var MAX_TOTAL_ITEMS = 50;
|
|
2702
|
+
function createPinNodeDataTool(getClient) {
|
|
2703
|
+
return {
|
|
2704
|
+
name: "n8n_pin_node_data",
|
|
2705
|
+
label: "n8n: pin node data",
|
|
2706
|
+
description: "Pin sample data to a node so downstream nodes use it during testing/development without re-running the upstream node. Useful after scaffolding a browser-bridge call: run it once, capture the output, pin it, then iterate on downstream nodes without re-spawning the browser. Issues PUT /workflows/{id} with merged pinData. Pinned data overrides actual node output on subsequent executions until cleared with n8n_unpin_node_data \u2014 easy to forget. Requires enableEdit and explicit confirm=true.",
|
|
2707
|
+
parameters: Schema22,
|
|
2708
|
+
execute: async (_toolCallId, rawParams) => {
|
|
2709
|
+
const params = rawParams;
|
|
2710
|
+
if (!params.confirm) {
|
|
2711
|
+
return jsonToolResult({
|
|
2712
|
+
ok: false,
|
|
2713
|
+
error: "confirm must be true to pin data"
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
const client = getClient();
|
|
2717
|
+
let current;
|
|
2718
|
+
try {
|
|
2719
|
+
current = await client.getWorkflow(params.id);
|
|
2720
|
+
} catch (err) {
|
|
2721
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2722
|
+
return jsonToolResult({
|
|
2723
|
+
ok: false,
|
|
2724
|
+
error: `failed to fetch workflow: ${client.redact(msg)}`
|
|
2725
|
+
});
|
|
2726
|
+
}
|
|
2727
|
+
const nodeExists = nodeNameExists(current.nodes, params.nodeName);
|
|
2728
|
+
if (!nodeExists) {
|
|
2729
|
+
return jsonToolResult({
|
|
2730
|
+
ok: false,
|
|
2731
|
+
error: `node "${params.nodeName}" not found in workflow ${params.id}. Use n8n_get_workflow(includeDefinition=true) to look up exact names.`
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
const incoming = params.data.map(normalizeItem);
|
|
2735
|
+
const existingForNode = readNodePinData(current.pinData, params.nodeName);
|
|
2736
|
+
const merged = params.merge ? [...existingForNode, ...incoming] : incoming;
|
|
2737
|
+
if (merged.length > MAX_TOTAL_ITEMS) {
|
|
2738
|
+
return jsonToolResult({
|
|
2739
|
+
ok: false,
|
|
2740
|
+
error: `combined pinned items (${merged.length}) exceeds cap of ${MAX_TOTAL_ITEMS}. Reduce the input or unpin existing data first.`
|
|
2741
|
+
});
|
|
2742
|
+
}
|
|
2743
|
+
const newPinData = {
|
|
2744
|
+
...current.pinData ?? {},
|
|
2745
|
+
[params.nodeName]: merged
|
|
2746
|
+
};
|
|
2747
|
+
const body = buildBody(current, { pinData: newPinData });
|
|
2748
|
+
try {
|
|
2749
|
+
const saved = await client.saveWorkflow(params.id, body);
|
|
2750
|
+
return jsonToolResult({
|
|
2751
|
+
ok: true,
|
|
2752
|
+
action: "pin",
|
|
2753
|
+
workflowId: saved.id,
|
|
2754
|
+
nodeName: params.nodeName,
|
|
2755
|
+
pinnedItemCount: merged.length,
|
|
2756
|
+
replaced: !params.merge && existingForNode.length > 0,
|
|
2757
|
+
appended: params.merge ? incoming.length : 0,
|
|
2758
|
+
versionId: saved.versionId ?? null,
|
|
2759
|
+
updatedAt: saved.updatedAt,
|
|
2760
|
+
unpinHint: `To clear: n8n_unpin_node_data(id=${saved.id}, nodeName=${JSON.stringify(params.nodeName)}, confirm=true).`
|
|
2761
|
+
});
|
|
2762
|
+
} catch (err) {
|
|
2763
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2764
|
+
return jsonToolResult({
|
|
2765
|
+
ok: false,
|
|
2766
|
+
error: `pin failed: ${client.redact(msg)}`
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
function nodeNameExists(nodes, nodeName) {
|
|
2773
|
+
if (!Array.isArray(nodes)) return false;
|
|
2774
|
+
return nodes.some(
|
|
2775
|
+
(n) => n && typeof n === "object" && typeof n.name === "string" && n.name === nodeName
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
function readNodePinData(pinData, nodeName) {
|
|
2779
|
+
if (!pinData) return [];
|
|
2780
|
+
const existing = pinData[nodeName];
|
|
2781
|
+
return Array.isArray(existing) ? existing : [];
|
|
2782
|
+
}
|
|
2783
|
+
function normalizeItem(item) {
|
|
2784
|
+
if ("json" in item) return item;
|
|
2785
|
+
return { json: item };
|
|
2786
|
+
}
|
|
2787
|
+
function buildBody(current, patch) {
|
|
2788
|
+
const body = {
|
|
2789
|
+
name: current.name,
|
|
2790
|
+
nodes: current.nodes,
|
|
2791
|
+
connections: current.connections,
|
|
2792
|
+
settings: current.settings ?? {}
|
|
2793
|
+
};
|
|
2794
|
+
if (patch.staticData !== void 0) {
|
|
2795
|
+
body.staticData = patch.staticData;
|
|
2796
|
+
} else if (current.staticData !== void 0) {
|
|
2797
|
+
body.staticData = current.staticData;
|
|
2798
|
+
}
|
|
2799
|
+
if (patch.pinData !== void 0) {
|
|
2800
|
+
body.pinData = patch.pinData;
|
|
2801
|
+
} else if (current.pinData !== void 0) {
|
|
2802
|
+
body.pinData = current.pinData;
|
|
2803
|
+
}
|
|
2804
|
+
return body;
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
// src/tools/unpin-node-data.ts
|
|
2808
|
+
import { Type as Type23 } from "@sinclair/typebox";
|
|
2809
|
+
var Schema23 = Type23.Object(
|
|
2810
|
+
{
|
|
2811
|
+
id: Type23.String({ description: "Workflow id (from n8n_list_workflows)." }),
|
|
2812
|
+
nodeName: Type23.Optional(
|
|
2813
|
+
Type23.String({
|
|
2814
|
+
minLength: 1,
|
|
2815
|
+
description: "Name of the node to unpin (case-sensitive). Omit to clear ALL pinned data on the workflow."
|
|
2816
|
+
})
|
|
2817
|
+
),
|
|
2818
|
+
confirm: Type23.Boolean({
|
|
2819
|
+
description: "Must be true to actually clear the pinned data. Idempotent: nodes with no pinned data are a no-op (returns ok=true with noop=true)."
|
|
2820
|
+
})
|
|
2821
|
+
},
|
|
2822
|
+
{ additionalProperties: false }
|
|
2823
|
+
);
|
|
2824
|
+
function createUnpinNodeDataTool(getClient) {
|
|
2825
|
+
return {
|
|
2826
|
+
name: "n8n_unpin_node_data",
|
|
2827
|
+
label: "n8n: unpin node data",
|
|
2828
|
+
description: "Clear pinned data on one node (or the whole workflow when nodeName is omitted) so executions return to using live node output. Idempotent \u2014 clearing a node that wasn't pinned returns ok=true with noop=true. Issues PUT /workflows/{id} with the modified pinData. Requires enableEdit and explicit confirm=true.",
|
|
2829
|
+
parameters: Schema23,
|
|
2830
|
+
execute: async (_toolCallId, rawParams) => {
|
|
2831
|
+
const params = rawParams;
|
|
2832
|
+
if (!params.confirm) {
|
|
2833
|
+
return jsonToolResult({
|
|
2834
|
+
ok: false,
|
|
2835
|
+
error: "confirm must be true to unpin data"
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
const client = getClient();
|
|
2839
|
+
let current;
|
|
2840
|
+
try {
|
|
2841
|
+
current = await client.getWorkflow(params.id);
|
|
2842
|
+
} catch (err) {
|
|
2843
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2844
|
+
return jsonToolResult({
|
|
2845
|
+
ok: false,
|
|
2846
|
+
error: `failed to fetch workflow: ${client.redact(msg)}`
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
const existing = current.pinData ?? {};
|
|
2850
|
+
const existingKeys = Object.keys(existing);
|
|
2851
|
+
if (!params.nodeName) {
|
|
2852
|
+
if (existingKeys.length === 0) {
|
|
2853
|
+
return jsonToolResult({
|
|
2854
|
+
ok: true,
|
|
2855
|
+
action: "unpin",
|
|
2856
|
+
workflowId: current.id,
|
|
2857
|
+
scope: "workflow",
|
|
2858
|
+
noop: true,
|
|
2859
|
+
clearedNodes: []
|
|
2860
|
+
});
|
|
2861
|
+
}
|
|
2862
|
+
const body2 = buildBody(current, { pinData: {} });
|
|
2863
|
+
try {
|
|
2864
|
+
const saved = await client.saveWorkflow(params.id, body2);
|
|
2865
|
+
return jsonToolResult({
|
|
2866
|
+
ok: true,
|
|
2867
|
+
action: "unpin",
|
|
2868
|
+
workflowId: saved.id,
|
|
2869
|
+
scope: "workflow",
|
|
2870
|
+
noop: false,
|
|
2871
|
+
clearedNodes: existingKeys,
|
|
2872
|
+
versionId: saved.versionId ?? null,
|
|
2873
|
+
updatedAt: saved.updatedAt
|
|
2874
|
+
});
|
|
2875
|
+
} catch (err) {
|
|
2876
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2877
|
+
return jsonToolResult({
|
|
2878
|
+
ok: false,
|
|
2879
|
+
error: `unpin failed: ${client.redact(msg)}`
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
const nodeName = params.nodeName;
|
|
2884
|
+
if (!(nodeName in existing)) {
|
|
2885
|
+
return jsonToolResult({
|
|
2886
|
+
ok: true,
|
|
2887
|
+
action: "unpin",
|
|
2888
|
+
workflowId: current.id,
|
|
2889
|
+
scope: "node",
|
|
2890
|
+
nodeName,
|
|
2891
|
+
noop: true
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
const newPinData = { ...existing };
|
|
2895
|
+
delete newPinData[nodeName];
|
|
2896
|
+
const body = buildBody(current, { pinData: newPinData });
|
|
2897
|
+
try {
|
|
2898
|
+
const saved = await client.saveWorkflow(params.id, body);
|
|
2899
|
+
return jsonToolResult({
|
|
2900
|
+
ok: true,
|
|
2901
|
+
action: "unpin",
|
|
2902
|
+
workflowId: saved.id,
|
|
2903
|
+
scope: "node",
|
|
2904
|
+
nodeName,
|
|
2905
|
+
noop: false,
|
|
2906
|
+
versionId: saved.versionId ?? null,
|
|
2907
|
+
updatedAt: saved.updatedAt
|
|
2908
|
+
});
|
|
2909
|
+
} catch (err) {
|
|
2910
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2911
|
+
return jsonToolResult({
|
|
2912
|
+
ok: false,
|
|
2913
|
+
error: `unpin failed: ${client.redact(msg)}`
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
// src/tools/list-schedules.ts
|
|
2921
|
+
import { Type as Type24 } from "@sinclair/typebox";
|
|
2922
|
+
var Schema24 = Type24.Object(
|
|
2923
|
+
{
|
|
2924
|
+
workflowId: Type24.Optional(
|
|
2925
|
+
Type24.String({
|
|
2926
|
+
description: "Restrict the scan to a single workflow. Omit to scan recent workflows."
|
|
2927
|
+
})
|
|
2928
|
+
),
|
|
2929
|
+
activeOnly: Type24.Optional(
|
|
2930
|
+
Type24.Boolean({
|
|
2931
|
+
description: "Only include schedules from active workflows. Default true \u2014 inactive schedules don't fire."
|
|
2932
|
+
})
|
|
2933
|
+
),
|
|
2934
|
+
limit: Type24.Optional(
|
|
2935
|
+
Type24.Number({
|
|
2936
|
+
minimum: 1,
|
|
2937
|
+
maximum: 250,
|
|
2938
|
+
description: "When workflowId is omitted, max workflows to fetch and scan (default 100)."
|
|
2939
|
+
})
|
|
2940
|
+
)
|
|
2941
|
+
},
|
|
2942
|
+
{ additionalProperties: false }
|
|
2943
|
+
);
|
|
2944
|
+
var SCHEDULE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
2945
|
+
"n8n-nodes-base.scheduleTrigger",
|
|
2946
|
+
"n8n-nodes-base.cron"
|
|
2947
|
+
]);
|
|
2948
|
+
var DAY_NAMES = [
|
|
2949
|
+
"Sunday",
|
|
2950
|
+
"Monday",
|
|
2951
|
+
"Tuesday",
|
|
2952
|
+
"Wednesday",
|
|
2953
|
+
"Thursday",
|
|
2954
|
+
"Friday",
|
|
2955
|
+
"Saturday"
|
|
2956
|
+
];
|
|
2957
|
+
function createListSchedulesTool(getClient) {
|
|
2958
|
+
return {
|
|
2959
|
+
name: "n8n_list_schedules",
|
|
2960
|
+
label: "n8n: list schedules",
|
|
2961
|
+
description: "Surface every schedule trigger across workflows so you can answer 'what's running at 3am?' without clicking through the n8n UI. Walks scheduleTrigger and legacy cron nodes, decodes their interval rules into human-readable strings (e.g. 'every 2 hours', 'daily at 03:00', 'cron: 0 */6 * * *'), and returns workflow context + the raw rule for further inspection. Read-only.",
|
|
2962
|
+
parameters: Schema24,
|
|
2963
|
+
execute: async (_toolCallId, rawParams) => {
|
|
2964
|
+
const params = rawParams;
|
|
2965
|
+
const activeOnly = params.activeOnly !== false;
|
|
2966
|
+
const client = getClient();
|
|
2967
|
+
const workflows = [];
|
|
2968
|
+
if (params.workflowId) {
|
|
2969
|
+
workflows.push(await client.getWorkflow(params.workflowId));
|
|
2970
|
+
} else {
|
|
2971
|
+
const list = await client.listWorkflows({
|
|
2972
|
+
active: activeOnly ? true : void 0,
|
|
2973
|
+
limit: params.limit ?? 100
|
|
2974
|
+
});
|
|
2975
|
+
const defs = await Promise.all(
|
|
2976
|
+
list.data.map((w) => client.getWorkflow(w.id))
|
|
2977
|
+
);
|
|
2978
|
+
workflows.push(...defs);
|
|
2979
|
+
}
|
|
2980
|
+
const schedules = [];
|
|
2981
|
+
for (const wf of workflows) {
|
|
2982
|
+
if (activeOnly && !wf.active) continue;
|
|
2983
|
+
if (!Array.isArray(wf.nodes)) continue;
|
|
2984
|
+
for (const node of wf.nodes) {
|
|
2985
|
+
for (const entry of extractSchedules(node, wf)) {
|
|
2986
|
+
schedules.push(entry);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
return jsonToolResult({
|
|
2991
|
+
scannedWorkflows: workflows.length,
|
|
2992
|
+
activeOnly,
|
|
2993
|
+
count: schedules.length,
|
|
2994
|
+
schedules
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
function extractSchedules(rawNode, wf) {
|
|
3000
|
+
if (!rawNode || typeof rawNode !== "object") return [];
|
|
3001
|
+
const n = rawNode;
|
|
3002
|
+
const type = String(n.type ?? "");
|
|
3003
|
+
if (!SCHEDULE_NODE_TYPES.has(type)) return [];
|
|
3004
|
+
const name = typeof n.name === "string" ? n.name : "";
|
|
3005
|
+
const params = n.parameters ?? {};
|
|
3006
|
+
if (type === "n8n-nodes-base.scheduleTrigger") {
|
|
3007
|
+
return decodeScheduleTrigger(params).map((entry) => ({
|
|
3008
|
+
workflowId: String(wf.id),
|
|
3009
|
+
workflowName: wf.name,
|
|
3010
|
+
active: wf.active,
|
|
3011
|
+
nodeName: name,
|
|
3012
|
+
nodeType: type,
|
|
3013
|
+
...entry
|
|
3014
|
+
}));
|
|
3015
|
+
}
|
|
3016
|
+
return decodeLegacyCron(params).map((entry) => ({
|
|
3017
|
+
workflowId: String(wf.id),
|
|
3018
|
+
workflowName: wf.name,
|
|
3019
|
+
active: wf.active,
|
|
3020
|
+
nodeName: name,
|
|
3021
|
+
nodeType: type,
|
|
3022
|
+
...entry
|
|
3023
|
+
}));
|
|
3024
|
+
}
|
|
3025
|
+
function decodeScheduleTrigger(params) {
|
|
3026
|
+
const rule = params.rule;
|
|
3027
|
+
if (!rule) {
|
|
3028
|
+
return [
|
|
3029
|
+
{
|
|
3030
|
+
schedule: "(no rule configured \u2014 uses node default)",
|
|
3031
|
+
raw: null
|
|
3032
|
+
}
|
|
3033
|
+
];
|
|
3034
|
+
}
|
|
3035
|
+
const intervals = rule.interval;
|
|
3036
|
+
if (!Array.isArray(intervals) || intervals.length === 0) {
|
|
3037
|
+
return [{ schedule: "(rule has no intervals)", raw: rule }];
|
|
3038
|
+
}
|
|
3039
|
+
return intervals.map((iv) => describeInterval(iv));
|
|
3040
|
+
}
|
|
3041
|
+
function describeInterval(iv) {
|
|
3042
|
+
if (!iv || typeof iv !== "object") {
|
|
3043
|
+
return { schedule: "(unparseable interval)", raw: iv };
|
|
3044
|
+
}
|
|
3045
|
+
const i = iv;
|
|
3046
|
+
const field = typeof i.field === "string" ? i.field : "(unknown field)";
|
|
3047
|
+
switch (field) {
|
|
3048
|
+
case "cronExpression": {
|
|
3049
|
+
const expression = typeof i.expression === "string" ? i.expression : "(empty)";
|
|
3050
|
+
return {
|
|
3051
|
+
field,
|
|
3052
|
+
cronExpression: expression,
|
|
3053
|
+
schedule: `cron: ${expression}`,
|
|
3054
|
+
raw: i
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
case "seconds": {
|
|
3058
|
+
const n = numberField(i, "secondsInterval", 1);
|
|
3059
|
+
return {
|
|
3060
|
+
field,
|
|
3061
|
+
schedule: `every ${pluralize(n, "second")}`,
|
|
3062
|
+
raw: i
|
|
3063
|
+
};
|
|
3064
|
+
}
|
|
3065
|
+
case "minutes": {
|
|
3066
|
+
const n = numberField(i, "minutesInterval", 1);
|
|
3067
|
+
return {
|
|
3068
|
+
field,
|
|
3069
|
+
schedule: `every ${pluralize(n, "minute")}`,
|
|
3070
|
+
raw: i
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
case "hours": {
|
|
3074
|
+
const n = numberField(i, "hoursInterval", 1);
|
|
3075
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
3076
|
+
return {
|
|
3077
|
+
field,
|
|
3078
|
+
schedule: `every ${pluralize(n, "hour")} at :${pad(minute)}`,
|
|
3079
|
+
raw: i
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
case "days": {
|
|
3083
|
+
const n = numberField(i, "daysInterval", 1);
|
|
3084
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
3085
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
3086
|
+
const cadence = n === 1 ? "daily" : `every ${pluralize(n, "day")}`;
|
|
3087
|
+
return {
|
|
3088
|
+
field,
|
|
3089
|
+
schedule: `${cadence} at ${pad(hour)}:${pad(minute)}`,
|
|
3090
|
+
raw: i
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
case "weeks": {
|
|
3094
|
+
const n = numberField(i, "weeksInterval", 1);
|
|
3095
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
3096
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
3097
|
+
const days = arrayField(i, "triggerAtDay").map((d) => DAY_NAMES[Number(d)] ?? `day-${d}`).filter(Boolean);
|
|
3098
|
+
const dayPart = days.length > 0 ? ` on ${days.join(", ")}` : "";
|
|
3099
|
+
const cadence = n === 1 ? "weekly" : `every ${pluralize(n, "week")}`;
|
|
3100
|
+
return {
|
|
3101
|
+
field,
|
|
3102
|
+
schedule: `${cadence}${dayPart} at ${pad(hour)}:${pad(minute)}`,
|
|
3103
|
+
raw: i
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
case "months": {
|
|
3107
|
+
const n = numberField(i, "monthsInterval", 1);
|
|
3108
|
+
const dayOfMonth = numberField(i, "triggerAtDayOfMonth", 1);
|
|
3109
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
3110
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
3111
|
+
const cadence = n === 1 ? "monthly" : `every ${pluralize(n, "month")}`;
|
|
3112
|
+
return {
|
|
3113
|
+
field,
|
|
3114
|
+
schedule: `${cadence} on day ${dayOfMonth} at ${pad(hour)}:${pad(minute)}`,
|
|
3115
|
+
raw: i
|
|
3116
|
+
};
|
|
3117
|
+
}
|
|
3118
|
+
default:
|
|
3119
|
+
return {
|
|
3120
|
+
field,
|
|
3121
|
+
schedule: `(unsupported field: ${field})`,
|
|
3122
|
+
raw: i
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
function decodeLegacyCron(params) {
|
|
3127
|
+
const cronTimes = params.triggerTimes;
|
|
3128
|
+
const items = cronTimes?.item ?? [];
|
|
3129
|
+
if (items.length === 0) {
|
|
3130
|
+
const expr = params.cronExpression;
|
|
3131
|
+
if (typeof expr === "string" && expr.trim()) {
|
|
3132
|
+
return [
|
|
3133
|
+
{
|
|
3134
|
+
field: "cronExpression",
|
|
3135
|
+
cronExpression: expr,
|
|
3136
|
+
schedule: `cron: ${expr}`,
|
|
3137
|
+
raw: params
|
|
3138
|
+
}
|
|
3139
|
+
];
|
|
3140
|
+
}
|
|
3141
|
+
return [{ schedule: "(legacy cron node with no triggerTimes configured)", raw: params }];
|
|
3142
|
+
}
|
|
3143
|
+
return items.map((item) => describeLegacyCronItem(item));
|
|
3144
|
+
}
|
|
3145
|
+
function describeLegacyCronItem(item) {
|
|
3146
|
+
if (!item || typeof item !== "object") {
|
|
3147
|
+
return { schedule: "(unparseable cron item)", raw: item };
|
|
3148
|
+
}
|
|
3149
|
+
const i = item;
|
|
3150
|
+
const mode = typeof i.mode === "string" ? i.mode : "everyMinute";
|
|
3151
|
+
const hour = numberField(i, "hour", 0);
|
|
3152
|
+
const minute = numberField(i, "minute", 0);
|
|
3153
|
+
switch (mode) {
|
|
3154
|
+
case "everyMinute":
|
|
3155
|
+
return { field: "minutes", schedule: "every minute", raw: i };
|
|
3156
|
+
case "everyHour":
|
|
3157
|
+
return {
|
|
3158
|
+
field: "hours",
|
|
3159
|
+
schedule: `every hour at :${pad(minute)}`,
|
|
3160
|
+
raw: i
|
|
3161
|
+
};
|
|
3162
|
+
case "everyDay":
|
|
3163
|
+
return {
|
|
3164
|
+
field: "days",
|
|
3165
|
+
schedule: `daily at ${pad(hour)}:${pad(minute)}`,
|
|
3166
|
+
raw: i
|
|
3167
|
+
};
|
|
3168
|
+
case "everyWeek": {
|
|
3169
|
+
const dow = numberField(i, "weekday", 0);
|
|
3170
|
+
return {
|
|
3171
|
+
field: "weeks",
|
|
3172
|
+
schedule: `weekly on ${DAY_NAMES[dow] ?? `day-${dow}`} at ${pad(hour)}:${pad(minute)}`,
|
|
3173
|
+
raw: i
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
3176
|
+
case "everyMonth": {
|
|
3177
|
+
const dom = numberField(i, "dayOfMonth", 1);
|
|
3178
|
+
return {
|
|
3179
|
+
field: "months",
|
|
3180
|
+
schedule: `monthly on day ${dom} at ${pad(hour)}:${pad(minute)}`,
|
|
3181
|
+
raw: i
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
case "custom": {
|
|
3185
|
+
const expr = typeof i.cronExpression === "string" ? i.cronExpression : "(empty)";
|
|
3186
|
+
return {
|
|
3187
|
+
field: "cronExpression",
|
|
3188
|
+
cronExpression: expr,
|
|
3189
|
+
schedule: `cron: ${expr}`,
|
|
3190
|
+
raw: i
|
|
3191
|
+
};
|
|
3192
|
+
}
|
|
3193
|
+
default:
|
|
3194
|
+
return {
|
|
3195
|
+
field: mode,
|
|
3196
|
+
schedule: `(unsupported legacy mode: ${mode})`,
|
|
3197
|
+
raw: i
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
function numberField(obj, key, fallback) {
|
|
3202
|
+
const v = obj[key];
|
|
3203
|
+
return typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
3204
|
+
}
|
|
3205
|
+
function arrayField(obj, key) {
|
|
3206
|
+
const v = obj[key];
|
|
3207
|
+
return Array.isArray(v) ? v : [];
|
|
3208
|
+
}
|
|
3209
|
+
function pad(n) {
|
|
3210
|
+
return n.toString().padStart(2, "0");
|
|
3211
|
+
}
|
|
3212
|
+
function pluralize(n, unit) {
|
|
3213
|
+
return n === 1 ? `1 ${unit}` : `${n} ${unit}s`;
|
|
3214
|
+
}
|
|
3215
|
+
|
|
2673
3216
|
// mcp-server.ts
|
|
2674
|
-
var VERSION = "0.
|
|
3217
|
+
var VERSION = "0.12.0";
|
|
2675
3218
|
function readConfigFromEnv() {
|
|
2676
3219
|
const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
|
|
2677
3220
|
if (!baseUrl) {
|
|
@@ -2831,6 +3374,15 @@ async function main() {
|
|
|
2831
3374
|
),
|
|
2832
3375
|
position: z.tuple([z.number(), z.number()]).optional().describe("n8n canvas position [x, y]. Default [0, 0].")
|
|
2833
3376
|
});
|
|
3377
|
+
bind(server, createListSchedulesTool(getClient), {
|
|
3378
|
+
workflowId: z.string().optional().describe("Restrict the scan to a single workflow. Omit to scan recent workflows."),
|
|
3379
|
+
activeOnly: z.boolean().optional().describe(
|
|
3380
|
+
"Only include schedules from active workflows. Default true \u2014 inactive schedules don't fire."
|
|
3381
|
+
),
|
|
3382
|
+
limit: z.number().int().min(1).max(250).optional().describe(
|
|
3383
|
+
"When workflowId is omitted, max workflows to fetch and scan (default 100)."
|
|
3384
|
+
)
|
|
3385
|
+
});
|
|
2834
3386
|
bind(server, createDiffWorkflowTool(getClient), {
|
|
2835
3387
|
id: z.string().describe("Workflow id to fetch as the 'after' side of the diff."),
|
|
2836
3388
|
snapshotPath: z.string().optional().describe(
|
|
@@ -2929,6 +3481,30 @@ async function main() {
|
|
|
2929
3481
|
),
|
|
2930
3482
|
skipValidation: z.boolean().optional().describe("Skip the validate-workflow pre-check. Default false.")
|
|
2931
3483
|
});
|
|
3484
|
+
bind(server, createPinNodeDataTool(getClient), {
|
|
3485
|
+
id: z.string().describe("Workflow id (from n8n_list_workflows)."),
|
|
3486
|
+
nodeName: z.string().min(1).describe(
|
|
3487
|
+
"Name of the node to pin data on (case-sensitive). Must be the n8n node 'name' field, not the type."
|
|
3488
|
+
),
|
|
3489
|
+
data: z.array(z.record(z.string(), z.unknown())).min(1).max(50).describe(
|
|
3490
|
+
"Items to pin (max 50). Each item may be a fully-shaped n8n run item (`{json: {...}}`) or a raw object \u2014 raw objects are auto-wrapped into `{json: <object>}`."
|
|
3491
|
+
),
|
|
3492
|
+
merge: z.boolean().optional().describe(
|
|
3493
|
+
"If true, append to existing pinned data on the node instead of replacing (combined total still capped at 50). Default false."
|
|
3494
|
+
),
|
|
3495
|
+
confirm: z.boolean().describe(
|
|
3496
|
+
"Must be true to actually write. Pinned data persists across executions and overrides node output until cleared."
|
|
3497
|
+
)
|
|
3498
|
+
});
|
|
3499
|
+
bind(server, createUnpinNodeDataTool(getClient), {
|
|
3500
|
+
id: z.string().describe("Workflow id (from n8n_list_workflows)."),
|
|
3501
|
+
nodeName: z.string().min(1).optional().describe(
|
|
3502
|
+
"Name of the node to unpin (case-sensitive). Omit to clear ALL pinned data on the workflow."
|
|
3503
|
+
),
|
|
3504
|
+
confirm: z.boolean().describe(
|
|
3505
|
+
"Must be true to actually clear pinned data. Idempotent: clearing a node that wasn't pinned returns ok=true with noop=true."
|
|
3506
|
+
)
|
|
3507
|
+
});
|
|
2932
3508
|
}
|
|
2933
3509
|
const transport = new StdioServerTransport();
|
|
2934
3510
|
await server.connect(transport);
|
package/index.ts
CHANGED
|
@@ -25,6 +25,9 @@ import { createCreateWorkflowTool } from "./src/tools/create-workflow.ts";
|
|
|
25
25
|
import { createAuditBrowserBridgeUsageTool } from "./src/tools/audit-browser-bridge-usage.ts";
|
|
26
26
|
import { createScaffoldBrowserBridgeNodeTool } from "./src/tools/scaffold-browser-bridge-node.ts";
|
|
27
27
|
import { createDiffWorkflowTool } from "./src/tools/diff-workflow.ts";
|
|
28
|
+
import { createPinNodeDataTool } from "./src/tools/pin-node-data.ts";
|
|
29
|
+
import { createUnpinNodeDataTool } from "./src/tools/unpin-node-data.ts";
|
|
30
|
+
import { createListSchedulesTool } from "./src/tools/list-schedules.ts";
|
|
28
31
|
|
|
29
32
|
export default definePluginEntry({
|
|
30
33
|
id: "n8n",
|
|
@@ -59,6 +62,7 @@ export default definePluginEntry({
|
|
|
59
62
|
createScaffoldBrowserBridgeNodeTool() as AnyAgentTool,
|
|
60
63
|
);
|
|
61
64
|
api.registerTool(createDiffWorkflowTool(getClient) as AnyAgentTool);
|
|
65
|
+
api.registerTool(createListSchedulesTool(getClient) as AnyAgentTool);
|
|
62
66
|
|
|
63
67
|
if (config.enableEdit) {
|
|
64
68
|
api.registerTool(createActivateTool(getClient) as AnyAgentTool);
|
|
@@ -82,6 +86,8 @@ export default definePluginEntry({
|
|
|
82
86
|
}) as AnyAgentTool,
|
|
83
87
|
);
|
|
84
88
|
api.registerTool(createCreateWorkflowTool({ getClient }) as AnyAgentTool);
|
|
89
|
+
api.registerTool(createPinNodeDataTool(getClient) as AnyAgentTool);
|
|
90
|
+
api.registerTool(createUnpinNodeDataTool(getClient) as AnyAgentTool);
|
|
85
91
|
}
|
|
86
92
|
},
|
|
87
93
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-ops-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Ops-focused n8n tools for any MCP-compatible client: list, inspect, trigger, validate, plus full workflow + execution lifecycle (create, save, archive, delete, cancel, retry). MCP server + first-class OpenClaw plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { N8nClient, N8nWorkflow } from "../client.ts";
|
|
3
|
+
import { jsonToolResult } from "./result.ts";
|
|
4
|
+
|
|
5
|
+
const Schema = Type.Object(
|
|
6
|
+
{
|
|
7
|
+
workflowId: Type.Optional(
|
|
8
|
+
Type.String({
|
|
9
|
+
description:
|
|
10
|
+
"Restrict the scan to a single workflow. Omit to scan recent workflows.",
|
|
11
|
+
}),
|
|
12
|
+
),
|
|
13
|
+
activeOnly: Type.Optional(
|
|
14
|
+
Type.Boolean({
|
|
15
|
+
description:
|
|
16
|
+
"Only include schedules from active workflows. Default true — inactive schedules don't fire.",
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
limit: Type.Optional(
|
|
20
|
+
Type.Number({
|
|
21
|
+
minimum: 1,
|
|
22
|
+
maximum: 250,
|
|
23
|
+
description:
|
|
24
|
+
"When workflowId is omitted, max workflows to fetch and scan (default 100).",
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
},
|
|
28
|
+
{ additionalProperties: false },
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const SCHEDULE_NODE_TYPES = new Set<string>([
|
|
32
|
+
"n8n-nodes-base.scheduleTrigger",
|
|
33
|
+
"n8n-nodes-base.cron",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const DAY_NAMES = [
|
|
37
|
+
"Sunday",
|
|
38
|
+
"Monday",
|
|
39
|
+
"Tuesday",
|
|
40
|
+
"Wednesday",
|
|
41
|
+
"Thursday",
|
|
42
|
+
"Friday",
|
|
43
|
+
"Saturday",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
export interface ScheduleEntry {
|
|
47
|
+
workflowId: string;
|
|
48
|
+
workflowName: string;
|
|
49
|
+
active: boolean;
|
|
50
|
+
nodeName: string;
|
|
51
|
+
nodeType: string;
|
|
52
|
+
schedule: string;
|
|
53
|
+
field?: string;
|
|
54
|
+
cronExpression?: string;
|
|
55
|
+
raw: unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createListSchedulesTool(getClient: () => N8nClient) {
|
|
59
|
+
return {
|
|
60
|
+
name: "n8n_list_schedules",
|
|
61
|
+
label: "n8n: list schedules",
|
|
62
|
+
description:
|
|
63
|
+
"Surface every schedule trigger across workflows so you can answer 'what's running at 3am?' without clicking through the n8n UI. Walks scheduleTrigger and legacy cron nodes, decodes their interval rules into human-readable strings (e.g. 'every 2 hours', 'daily at 03:00', 'cron: 0 */6 * * *'), and returns workflow context + the raw rule for further inspection. Read-only.",
|
|
64
|
+
parameters: Schema,
|
|
65
|
+
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
|
|
66
|
+
const params = rawParams as {
|
|
67
|
+
workflowId?: string;
|
|
68
|
+
activeOnly?: boolean;
|
|
69
|
+
limit?: number;
|
|
70
|
+
};
|
|
71
|
+
const activeOnly = params.activeOnly !== false;
|
|
72
|
+
const client = getClient();
|
|
73
|
+
|
|
74
|
+
const workflows: N8nWorkflow[] = [];
|
|
75
|
+
if (params.workflowId) {
|
|
76
|
+
workflows.push(await client.getWorkflow(params.workflowId));
|
|
77
|
+
} else {
|
|
78
|
+
const list = await client.listWorkflows({
|
|
79
|
+
active: activeOnly ? true : undefined,
|
|
80
|
+
limit: params.limit ?? 100,
|
|
81
|
+
});
|
|
82
|
+
const defs = await Promise.all(
|
|
83
|
+
list.data.map((w) => client.getWorkflow(w.id)),
|
|
84
|
+
);
|
|
85
|
+
workflows.push(...defs);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const schedules: ScheduleEntry[] = [];
|
|
89
|
+
for (const wf of workflows) {
|
|
90
|
+
if (activeOnly && !wf.active) continue;
|
|
91
|
+
if (!Array.isArray(wf.nodes)) continue;
|
|
92
|
+
for (const node of wf.nodes) {
|
|
93
|
+
for (const entry of extractSchedules(node, wf)) {
|
|
94
|
+
schedules.push(entry);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return jsonToolResult({
|
|
100
|
+
scannedWorkflows: workflows.length,
|
|
101
|
+
activeOnly,
|
|
102
|
+
count: schedules.length,
|
|
103
|
+
schedules,
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function extractSchedules(
|
|
110
|
+
rawNode: unknown,
|
|
111
|
+
wf: N8nWorkflow,
|
|
112
|
+
): ScheduleEntry[] {
|
|
113
|
+
if (!rawNode || typeof rawNode !== "object") return [];
|
|
114
|
+
const n = rawNode as Record<string, unknown>;
|
|
115
|
+
const type = String(n.type ?? "");
|
|
116
|
+
if (!SCHEDULE_NODE_TYPES.has(type)) return [];
|
|
117
|
+
const name = typeof n.name === "string" ? n.name : "";
|
|
118
|
+
const params = (n.parameters as Record<string, unknown>) ?? {};
|
|
119
|
+
|
|
120
|
+
if (type === "n8n-nodes-base.scheduleTrigger") {
|
|
121
|
+
return decodeScheduleTrigger(params).map((entry) => ({
|
|
122
|
+
workflowId: String(wf.id),
|
|
123
|
+
workflowName: wf.name,
|
|
124
|
+
active: wf.active,
|
|
125
|
+
nodeName: name,
|
|
126
|
+
nodeType: type,
|
|
127
|
+
...entry,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Legacy `cron` node — single rule per node, simpler shape.
|
|
132
|
+
return decodeLegacyCron(params).map((entry) => ({
|
|
133
|
+
workflowId: String(wf.id),
|
|
134
|
+
workflowName: wf.name,
|
|
135
|
+
active: wf.active,
|
|
136
|
+
nodeName: name,
|
|
137
|
+
nodeType: type,
|
|
138
|
+
...entry,
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface DecodedSchedule {
|
|
143
|
+
schedule: string;
|
|
144
|
+
field?: string;
|
|
145
|
+
cronExpression?: string;
|
|
146
|
+
raw: unknown;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function decodeScheduleTrigger(
|
|
150
|
+
params: Record<string, unknown>,
|
|
151
|
+
): DecodedSchedule[] {
|
|
152
|
+
const rule = params.rule as Record<string, unknown> | undefined;
|
|
153
|
+
if (!rule) {
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
schedule: "(no rule configured — uses node default)",
|
|
157
|
+
raw: null,
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
const intervals = rule.interval;
|
|
162
|
+
if (!Array.isArray(intervals) || intervals.length === 0) {
|
|
163
|
+
return [{ schedule: "(rule has no intervals)", raw: rule }];
|
|
164
|
+
}
|
|
165
|
+
return intervals.map((iv: unknown) => describeInterval(iv));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function describeInterval(iv: unknown): DecodedSchedule {
|
|
169
|
+
if (!iv || typeof iv !== "object") {
|
|
170
|
+
return { schedule: "(unparseable interval)", raw: iv };
|
|
171
|
+
}
|
|
172
|
+
const i = iv as Record<string, unknown>;
|
|
173
|
+
const field = typeof i.field === "string" ? i.field : "(unknown field)";
|
|
174
|
+
|
|
175
|
+
switch (field) {
|
|
176
|
+
case "cronExpression": {
|
|
177
|
+
const expression =
|
|
178
|
+
typeof i.expression === "string" ? i.expression : "(empty)";
|
|
179
|
+
return {
|
|
180
|
+
field,
|
|
181
|
+
cronExpression: expression,
|
|
182
|
+
schedule: `cron: ${expression}`,
|
|
183
|
+
raw: i,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
case "seconds": {
|
|
187
|
+
const n = numberField(i, "secondsInterval", 1);
|
|
188
|
+
return {
|
|
189
|
+
field,
|
|
190
|
+
schedule: `every ${pluralize(n, "second")}`,
|
|
191
|
+
raw: i,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
case "minutes": {
|
|
195
|
+
const n = numberField(i, "minutesInterval", 1);
|
|
196
|
+
return {
|
|
197
|
+
field,
|
|
198
|
+
schedule: `every ${pluralize(n, "minute")}`,
|
|
199
|
+
raw: i,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
case "hours": {
|
|
203
|
+
const n = numberField(i, "hoursInterval", 1);
|
|
204
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
205
|
+
return {
|
|
206
|
+
field,
|
|
207
|
+
schedule: `every ${pluralize(n, "hour")} at :${pad(minute)}`,
|
|
208
|
+
raw: i,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
case "days": {
|
|
212
|
+
const n = numberField(i, "daysInterval", 1);
|
|
213
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
214
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
215
|
+
const cadence =
|
|
216
|
+
n === 1 ? "daily" : `every ${pluralize(n, "day")}`;
|
|
217
|
+
return {
|
|
218
|
+
field,
|
|
219
|
+
schedule: `${cadence} at ${pad(hour)}:${pad(minute)}`,
|
|
220
|
+
raw: i,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
case "weeks": {
|
|
224
|
+
const n = numberField(i, "weeksInterval", 1);
|
|
225
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
226
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
227
|
+
const days = arrayField(i, "triggerAtDay")
|
|
228
|
+
.map((d) => DAY_NAMES[Number(d)] ?? `day-${d}`)
|
|
229
|
+
.filter(Boolean);
|
|
230
|
+
const dayPart = days.length > 0 ? ` on ${days.join(", ")}` : "";
|
|
231
|
+
const cadence =
|
|
232
|
+
n === 1 ? "weekly" : `every ${pluralize(n, "week")}`;
|
|
233
|
+
return {
|
|
234
|
+
field,
|
|
235
|
+
schedule: `${cadence}${dayPart} at ${pad(hour)}:${pad(minute)}`,
|
|
236
|
+
raw: i,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
case "months": {
|
|
240
|
+
const n = numberField(i, "monthsInterval", 1);
|
|
241
|
+
const dayOfMonth = numberField(i, "triggerAtDayOfMonth", 1);
|
|
242
|
+
const hour = numberField(i, "triggerAtHour", 0);
|
|
243
|
+
const minute = numberField(i, "triggerAtMinute", 0);
|
|
244
|
+
const cadence =
|
|
245
|
+
n === 1 ? "monthly" : `every ${pluralize(n, "month")}`;
|
|
246
|
+
return {
|
|
247
|
+
field,
|
|
248
|
+
schedule: `${cadence} on day ${dayOfMonth} at ${pad(hour)}:${pad(minute)}`,
|
|
249
|
+
raw: i,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
default:
|
|
253
|
+
return {
|
|
254
|
+
field,
|
|
255
|
+
schedule: `(unsupported field: ${field})`,
|
|
256
|
+
raw: i,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function decodeLegacyCron(params: Record<string, unknown>): DecodedSchedule[] {
|
|
262
|
+
const cronTimes = params.triggerTimes as Record<string, unknown> | undefined;
|
|
263
|
+
const items = (cronTimes?.item as unknown[] | undefined) ?? [];
|
|
264
|
+
if (items.length === 0) {
|
|
265
|
+
// Some legacy installs use `cronExpression` directly on params.
|
|
266
|
+
const expr = params.cronExpression;
|
|
267
|
+
if (typeof expr === "string" && expr.trim()) {
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
field: "cronExpression",
|
|
271
|
+
cronExpression: expr,
|
|
272
|
+
schedule: `cron: ${expr}`,
|
|
273
|
+
raw: params,
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
return [{ schedule: "(legacy cron node with no triggerTimes configured)", raw: params }];
|
|
278
|
+
}
|
|
279
|
+
return items.map((item) => describeLegacyCronItem(item));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function describeLegacyCronItem(item: unknown): DecodedSchedule {
|
|
283
|
+
if (!item || typeof item !== "object") {
|
|
284
|
+
return { schedule: "(unparseable cron item)", raw: item };
|
|
285
|
+
}
|
|
286
|
+
const i = item as Record<string, unknown>;
|
|
287
|
+
const mode = typeof i.mode === "string" ? i.mode : "everyMinute";
|
|
288
|
+
const hour = numberField(i, "hour", 0);
|
|
289
|
+
const minute = numberField(i, "minute", 0);
|
|
290
|
+
switch (mode) {
|
|
291
|
+
case "everyMinute":
|
|
292
|
+
return { field: "minutes", schedule: "every minute", raw: i };
|
|
293
|
+
case "everyHour":
|
|
294
|
+
return {
|
|
295
|
+
field: "hours",
|
|
296
|
+
schedule: `every hour at :${pad(minute)}`,
|
|
297
|
+
raw: i,
|
|
298
|
+
};
|
|
299
|
+
case "everyDay":
|
|
300
|
+
return {
|
|
301
|
+
field: "days",
|
|
302
|
+
schedule: `daily at ${pad(hour)}:${pad(minute)}`,
|
|
303
|
+
raw: i,
|
|
304
|
+
};
|
|
305
|
+
case "everyWeek": {
|
|
306
|
+
const dow = numberField(i, "weekday", 0);
|
|
307
|
+
return {
|
|
308
|
+
field: "weeks",
|
|
309
|
+
schedule: `weekly on ${DAY_NAMES[dow] ?? `day-${dow}`} at ${pad(hour)}:${pad(minute)}`,
|
|
310
|
+
raw: i,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
case "everyMonth": {
|
|
314
|
+
const dom = numberField(i, "dayOfMonth", 1);
|
|
315
|
+
return {
|
|
316
|
+
field: "months",
|
|
317
|
+
schedule: `monthly on day ${dom} at ${pad(hour)}:${pad(minute)}`,
|
|
318
|
+
raw: i,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
case "custom": {
|
|
322
|
+
const expr =
|
|
323
|
+
typeof i.cronExpression === "string" ? i.cronExpression : "(empty)";
|
|
324
|
+
return {
|
|
325
|
+
field: "cronExpression",
|
|
326
|
+
cronExpression: expr,
|
|
327
|
+
schedule: `cron: ${expr}`,
|
|
328
|
+
raw: i,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
default:
|
|
332
|
+
return {
|
|
333
|
+
field: mode,
|
|
334
|
+
schedule: `(unsupported legacy mode: ${mode})`,
|
|
335
|
+
raw: i,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function numberField(
|
|
341
|
+
obj: Record<string, unknown>,
|
|
342
|
+
key: string,
|
|
343
|
+
fallback: number,
|
|
344
|
+
): number {
|
|
345
|
+
const v = obj[key];
|
|
346
|
+
return typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function arrayField(
|
|
350
|
+
obj: Record<string, unknown>,
|
|
351
|
+
key: string,
|
|
352
|
+
): unknown[] {
|
|
353
|
+
const v = obj[key];
|
|
354
|
+
return Array.isArray(v) ? v : [];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function pad(n: number): string {
|
|
358
|
+
return n.toString().padStart(2, "0");
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function pluralize(n: number, unit: string): string {
|
|
362
|
+
return n === 1 ? `1 ${unit}` : `${n} ${unit}s`;
|
|
363
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { N8nClient, N8nWorkflow } from "../client.ts";
|
|
3
|
+
import { jsonToolResult } from "./result.ts";
|
|
4
|
+
|
|
5
|
+
const Schema = Type.Object(
|
|
6
|
+
{
|
|
7
|
+
id: Type.String({ description: "Workflow id (from n8n_list_workflows)." }),
|
|
8
|
+
nodeName: Type.String({
|
|
9
|
+
minLength: 1,
|
|
10
|
+
description:
|
|
11
|
+
"Name of the node to pin data on (case-sensitive). Must be the n8n node 'name' field, not the type. Use n8n_get_workflow(includeDefinition=true) to look up exact names.",
|
|
12
|
+
}),
|
|
13
|
+
data: Type.Array(
|
|
14
|
+
Type.Record(Type.String(), Type.Unknown()),
|
|
15
|
+
{
|
|
16
|
+
minItems: 1,
|
|
17
|
+
maxItems: 50,
|
|
18
|
+
description:
|
|
19
|
+
"Items to pin (max 50). Each item may be a fully-shaped n8n run item (`{json: {...}, binary?: {...}}`) or a raw object — raw objects are auto-wrapped into `{json: <object>}`.",
|
|
20
|
+
},
|
|
21
|
+
),
|
|
22
|
+
merge: Type.Optional(
|
|
23
|
+
Type.Boolean({
|
|
24
|
+
description:
|
|
25
|
+
"If true, append to existing pinned data on the node instead of replacing it (combined total still capped at 50). Default false (replace).",
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
confirm: Type.Boolean({
|
|
29
|
+
description:
|
|
30
|
+
"Must be true to actually write. Pinned data persists across executions and overrides node output until cleared via n8n_unpin_node_data — easy to forget about.",
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
{ additionalProperties: false },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const MAX_TOTAL_ITEMS = 50;
|
|
37
|
+
|
|
38
|
+
export function createPinNodeDataTool(getClient: () => N8nClient) {
|
|
39
|
+
return {
|
|
40
|
+
name: "n8n_pin_node_data",
|
|
41
|
+
label: "n8n: pin node data",
|
|
42
|
+
description:
|
|
43
|
+
"Pin sample data to a node so downstream nodes use it during testing/development without re-running the upstream node. Useful after scaffolding a browser-bridge call: run it once, capture the output, pin it, then iterate on downstream nodes without re-spawning the browser. Issues PUT /workflows/{id} with merged pinData. Pinned data overrides actual node output on subsequent executions until cleared with n8n_unpin_node_data — easy to forget. Requires enableEdit and explicit confirm=true.",
|
|
44
|
+
parameters: Schema,
|
|
45
|
+
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
|
|
46
|
+
const params = rawParams as {
|
|
47
|
+
id: string;
|
|
48
|
+
nodeName: string;
|
|
49
|
+
data: Array<Record<string, unknown>>;
|
|
50
|
+
merge?: boolean;
|
|
51
|
+
confirm: boolean;
|
|
52
|
+
};
|
|
53
|
+
if (!params.confirm) {
|
|
54
|
+
return jsonToolResult({
|
|
55
|
+
ok: false,
|
|
56
|
+
error: "confirm must be true to pin data",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const client = getClient();
|
|
61
|
+
|
|
62
|
+
let current: N8nWorkflow;
|
|
63
|
+
try {
|
|
64
|
+
current = await client.getWorkflow(params.id);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
67
|
+
return jsonToolResult({
|
|
68
|
+
ok: false,
|
|
69
|
+
error: `failed to fetch workflow: ${client.redact(msg)}`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const nodeExists = nodeNameExists(current.nodes, params.nodeName);
|
|
74
|
+
if (!nodeExists) {
|
|
75
|
+
return jsonToolResult({
|
|
76
|
+
ok: false,
|
|
77
|
+
error: `node "${params.nodeName}" not found in workflow ${params.id}. Use n8n_get_workflow(includeDefinition=true) to look up exact names.`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const incoming = params.data.map(normalizeItem);
|
|
82
|
+
const existingForNode = readNodePinData(current.pinData, params.nodeName);
|
|
83
|
+
const merged = params.merge
|
|
84
|
+
? [...existingForNode, ...incoming]
|
|
85
|
+
: incoming;
|
|
86
|
+
|
|
87
|
+
if (merged.length > MAX_TOTAL_ITEMS) {
|
|
88
|
+
return jsonToolResult({
|
|
89
|
+
ok: false,
|
|
90
|
+
error: `combined pinned items (${merged.length}) exceeds cap of ${MAX_TOTAL_ITEMS}. Reduce the input or unpin existing data first.`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const newPinData: Record<string, unknown> = {
|
|
95
|
+
...(current.pinData ?? {}),
|
|
96
|
+
[params.nodeName]: merged,
|
|
97
|
+
};
|
|
98
|
+
const body = buildBody(current, { pinData: newPinData });
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const saved = await client.saveWorkflow(params.id, body);
|
|
102
|
+
return jsonToolResult({
|
|
103
|
+
ok: true,
|
|
104
|
+
action: "pin",
|
|
105
|
+
workflowId: saved.id,
|
|
106
|
+
nodeName: params.nodeName,
|
|
107
|
+
pinnedItemCount: merged.length,
|
|
108
|
+
replaced: !params.merge && existingForNode.length > 0,
|
|
109
|
+
appended: params.merge ? incoming.length : 0,
|
|
110
|
+
versionId: saved.versionId ?? null,
|
|
111
|
+
updatedAt: saved.updatedAt,
|
|
112
|
+
unpinHint: `To clear: n8n_unpin_node_data(id=${saved.id}, nodeName=${JSON.stringify(params.nodeName)}, confirm=true).`,
|
|
113
|
+
});
|
|
114
|
+
} catch (err) {
|
|
115
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
116
|
+
return jsonToolResult({
|
|
117
|
+
ok: false,
|
|
118
|
+
error: `pin failed: ${client.redact(msg)}`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function nodeNameExists(nodes: unknown, nodeName: string): boolean {
|
|
126
|
+
if (!Array.isArray(nodes)) return false;
|
|
127
|
+
return nodes.some(
|
|
128
|
+
(n) =>
|
|
129
|
+
n &&
|
|
130
|
+
typeof n === "object" &&
|
|
131
|
+
typeof (n as Record<string, unknown>).name === "string" &&
|
|
132
|
+
(n as Record<string, unknown>).name === nodeName,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function readNodePinData(
|
|
137
|
+
pinData: Record<string, unknown> | undefined,
|
|
138
|
+
nodeName: string,
|
|
139
|
+
): Array<Record<string, unknown>> {
|
|
140
|
+
if (!pinData) return [];
|
|
141
|
+
const existing = pinData[nodeName];
|
|
142
|
+
return Array.isArray(existing)
|
|
143
|
+
? (existing as Array<Record<string, unknown>>)
|
|
144
|
+
: [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function normalizeItem(item: Record<string, unknown>): Record<string, unknown> {
|
|
148
|
+
// Accept both shapes: full run-item (`{json: ..., binary?: ...}`) or raw
|
|
149
|
+
// payload — raw wraps into `{json: item}` so callers don't have to remember
|
|
150
|
+
// n8n's internal item shape.
|
|
151
|
+
if ("json" in item) return item;
|
|
152
|
+
return { json: item };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function buildBody(
|
|
156
|
+
current: N8nWorkflow,
|
|
157
|
+
patch: { pinData?: Record<string, unknown>; staticData?: unknown },
|
|
158
|
+
): Record<string, unknown> {
|
|
159
|
+
const body: Record<string, unknown> = {
|
|
160
|
+
name: current.name,
|
|
161
|
+
nodes: current.nodes,
|
|
162
|
+
connections: current.connections,
|
|
163
|
+
settings: current.settings ?? {},
|
|
164
|
+
};
|
|
165
|
+
if (patch.staticData !== undefined) {
|
|
166
|
+
body.staticData = patch.staticData;
|
|
167
|
+
} else if (current.staticData !== undefined) {
|
|
168
|
+
body.staticData = current.staticData;
|
|
169
|
+
}
|
|
170
|
+
if (patch.pinData !== undefined) {
|
|
171
|
+
body.pinData = patch.pinData;
|
|
172
|
+
} else if (current.pinData !== undefined) {
|
|
173
|
+
body.pinData = current.pinData;
|
|
174
|
+
}
|
|
175
|
+
return body;
|
|
176
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { N8nClient, N8nWorkflow } from "../client.ts";
|
|
3
|
+
import { jsonToolResult } from "./result.ts";
|
|
4
|
+
import { buildBody } from "./pin-node-data.ts";
|
|
5
|
+
|
|
6
|
+
const Schema = Type.Object(
|
|
7
|
+
{
|
|
8
|
+
id: Type.String({ description: "Workflow id (from n8n_list_workflows)." }),
|
|
9
|
+
nodeName: Type.Optional(
|
|
10
|
+
Type.String({
|
|
11
|
+
minLength: 1,
|
|
12
|
+
description:
|
|
13
|
+
"Name of the node to unpin (case-sensitive). Omit to clear ALL pinned data on the workflow.",
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
confirm: Type.Boolean({
|
|
17
|
+
description:
|
|
18
|
+
"Must be true to actually clear the pinned data. Idempotent: nodes with no pinned data are a no-op (returns ok=true with noop=true).",
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
{ additionalProperties: false },
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export function createUnpinNodeDataTool(getClient: () => N8nClient) {
|
|
25
|
+
return {
|
|
26
|
+
name: "n8n_unpin_node_data",
|
|
27
|
+
label: "n8n: unpin node data",
|
|
28
|
+
description:
|
|
29
|
+
"Clear pinned data on one node (or the whole workflow when nodeName is omitted) so executions return to using live node output. Idempotent — clearing a node that wasn't pinned returns ok=true with noop=true. Issues PUT /workflows/{id} with the modified pinData. Requires enableEdit and explicit confirm=true.",
|
|
30
|
+
parameters: Schema,
|
|
31
|
+
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
|
|
32
|
+
const params = rawParams as {
|
|
33
|
+
id: string;
|
|
34
|
+
nodeName?: string;
|
|
35
|
+
confirm: boolean;
|
|
36
|
+
};
|
|
37
|
+
if (!params.confirm) {
|
|
38
|
+
return jsonToolResult({
|
|
39
|
+
ok: false,
|
|
40
|
+
error: "confirm must be true to unpin data",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const client = getClient();
|
|
44
|
+
|
|
45
|
+
let current: N8nWorkflow;
|
|
46
|
+
try {
|
|
47
|
+
current = await client.getWorkflow(params.id);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
50
|
+
return jsonToolResult({
|
|
51
|
+
ok: false,
|
|
52
|
+
error: `failed to fetch workflow: ${client.redact(msg)}`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const existing = current.pinData ?? {};
|
|
57
|
+
const existingKeys = Object.keys(existing);
|
|
58
|
+
|
|
59
|
+
// Whole-workflow unpin path.
|
|
60
|
+
if (!params.nodeName) {
|
|
61
|
+
if (existingKeys.length === 0) {
|
|
62
|
+
return jsonToolResult({
|
|
63
|
+
ok: true,
|
|
64
|
+
action: "unpin",
|
|
65
|
+
workflowId: current.id,
|
|
66
|
+
scope: "workflow",
|
|
67
|
+
noop: true,
|
|
68
|
+
clearedNodes: [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const body = buildBody(current, { pinData: {} });
|
|
72
|
+
try {
|
|
73
|
+
const saved = await client.saveWorkflow(params.id, body);
|
|
74
|
+
return jsonToolResult({
|
|
75
|
+
ok: true,
|
|
76
|
+
action: "unpin",
|
|
77
|
+
workflowId: saved.id,
|
|
78
|
+
scope: "workflow",
|
|
79
|
+
noop: false,
|
|
80
|
+
clearedNodes: existingKeys,
|
|
81
|
+
versionId: saved.versionId ?? null,
|
|
82
|
+
updatedAt: saved.updatedAt,
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
86
|
+
return jsonToolResult({
|
|
87
|
+
ok: false,
|
|
88
|
+
error: `unpin failed: ${client.redact(msg)}`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Single-node unpin path.
|
|
94
|
+
const nodeName = params.nodeName;
|
|
95
|
+
if (!(nodeName in existing)) {
|
|
96
|
+
return jsonToolResult({
|
|
97
|
+
ok: true,
|
|
98
|
+
action: "unpin",
|
|
99
|
+
workflowId: current.id,
|
|
100
|
+
scope: "node",
|
|
101
|
+
nodeName,
|
|
102
|
+
noop: true,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const newPinData: Record<string, unknown> = { ...existing };
|
|
106
|
+
delete newPinData[nodeName];
|
|
107
|
+
const body = buildBody(current, { pinData: newPinData });
|
|
108
|
+
try {
|
|
109
|
+
const saved = await client.saveWorkflow(params.id, body);
|
|
110
|
+
return jsonToolResult({
|
|
111
|
+
ok: true,
|
|
112
|
+
action: "unpin",
|
|
113
|
+
workflowId: saved.id,
|
|
114
|
+
scope: "node",
|
|
115
|
+
nodeName,
|
|
116
|
+
noop: false,
|
|
117
|
+
versionId: saved.versionId ?? null,
|
|
118
|
+
updatedAt: saved.updatedAt,
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
122
|
+
return jsonToolResult({
|
|
123
|
+
ok: false,
|
|
124
|
+
error: `unpin failed: ${client.redact(msg)}`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|