n8n-ops-mcp 0.11.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 +7 -0
- package/dist/mcp-server.js +306 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/tools/list-schedules.ts +363 -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) | |
|
|
@@ -62,6 +63,8 @@ Write tools are hidden unless `N8N_ENABLE_EDIT=true`.
|
|
|
62
63
|
|
|
63
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.
|
|
64
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
|
+
|
|
65
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.
|
|
66
69
|
|
|
67
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).
|
|
@@ -265,6 +268,10 @@ Calls `n8n_search_executions` with `query: "ECONNREFUSED"`.
|
|
|
265
268
|
|
|
266
269
|
Calls `n8n_list_webhooks` to find the path, then `n8n_trigger` with `mode=webhook`.
|
|
267
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
|
+
|
|
268
275
|
> What changed in my "intel pipeline" workflow since yesterday's backup?
|
|
269
276
|
|
|
270
277
|
Calls `n8n_diff_workflow` with `id` and `snapshotPath` pointing to the backup file. Returns added/removed/modified nodes with parameter-level field paths.
|
package/dist/mcp-server.js
CHANGED
|
@@ -2917,8 +2917,304 @@ function createUnpinNodeDataTool(getClient) {
|
|
|
2917
2917
|
};
|
|
2918
2918
|
}
|
|
2919
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
|
+
|
|
2920
3216
|
// mcp-server.ts
|
|
2921
|
-
var VERSION = "0.
|
|
3217
|
+
var VERSION = "0.12.0";
|
|
2922
3218
|
function readConfigFromEnv() {
|
|
2923
3219
|
const baseUrl = (process.env.N8N_BASE_URL ?? "").trim();
|
|
2924
3220
|
if (!baseUrl) {
|
|
@@ -3078,6 +3374,15 @@ async function main() {
|
|
|
3078
3374
|
),
|
|
3079
3375
|
position: z.tuple([z.number(), z.number()]).optional().describe("n8n canvas position [x, y]. Default [0, 0].")
|
|
3080
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
|
+
});
|
|
3081
3386
|
bind(server, createDiffWorkflowTool(getClient), {
|
|
3082
3387
|
id: z.string().describe("Workflow id to fetch as the 'after' side of the diff."),
|
|
3083
3388
|
snapshotPath: z.string().optional().describe(
|
package/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { createScaffoldBrowserBridgeNodeTool } from "./src/tools/scaffold-browse
|
|
|
27
27
|
import { createDiffWorkflowTool } from "./src/tools/diff-workflow.ts";
|
|
28
28
|
import { createPinNodeDataTool } from "./src/tools/pin-node-data.ts";
|
|
29
29
|
import { createUnpinNodeDataTool } from "./src/tools/unpin-node-data.ts";
|
|
30
|
+
import { createListSchedulesTool } from "./src/tools/list-schedules.ts";
|
|
30
31
|
|
|
31
32
|
export default definePluginEntry({
|
|
32
33
|
id: "n8n",
|
|
@@ -61,6 +62,7 @@ export default definePluginEntry({
|
|
|
61
62
|
createScaffoldBrowserBridgeNodeTool() as AnyAgentTool,
|
|
62
63
|
);
|
|
63
64
|
api.registerTool(createDiffWorkflowTool(getClient) as AnyAgentTool);
|
|
65
|
+
api.registerTool(createListSchedulesTool(getClient) as AnyAgentTool);
|
|
64
66
|
|
|
65
67
|
if (config.enableEdit) {
|
|
66
68
|
api.registerTool(createActivateTool(getClient) as AnyAgentTool);
|
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
|
+
}
|