nodered-mcp-full 0.3.0 → 0.4.1
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/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/index.js +167 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 (2026-11-17)
|
|
4
|
+
- get_errors: include_last_status:true adds nodes_in_error_now (nodes whose latest status is red) and last_status_seen (latest status per node seen by the monitor). Verified against real Node-RED: the comms channel has NO status replay on subscribe, so silent nodes appear only after they emit again.
|
|
5
|
+
|
|
6
|
+
## 0.4.0 (2026-11-17)
|
|
7
|
+
- get_errors: live runtime error monitor via the editor /comms websocket (auth-packet login, status + notification subscriptions, auto-reconnect, heartbeat echo). Rolling 500-event buffer of red/yellow node statuses and error notifications with node name/type/tab resolved; filters: limit, tab_id, include_warnings, clear. No more SSH/docker to read why a node is in error.
|
|
8
|
+
|
|
3
9
|
## 0.3.0 (2026-11-17)
|
|
4
10
|
- AI-first comprehension layer: get_flow_map (outline / mermaid / json, wiring resolved to node names), list_flows detail:true (type histogram, entry points, config refs, subflow instances), search_nodes (fields + function code), list_config_nodes (usage counts)
|
|
5
11
|
- Surgical writes: patch_batch (one deploy for many patches), upsert_node (auto id/position, optional wire_from), delete_node (+splice bypass) - the model sends only diffs, the server merges and deploys the full array
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ Built for real-world setups:
|
|
|
32
32
|
| `validate_flows` | Validate a candidate flow array without deploying (dup ids, dangling wires, legacy HA v3 fields, `flow.get(...,'file')` traps) |
|
|
33
33
|
| `deploy_flows` | Deploy a complete flow array — `dry_run` validation, auto backup, needs `confirm:true` |
|
|
34
34
|
| `call_endpoint` | GET any HTTP endpoint served by your flows (custom diagnostics, APIs) |
|
|
35
|
+
| `get_errors` | **Live runtime errors/warnings**: red/yellow node statuses + error notifications from the editor comms channel, node and tab resolved - no SSH needed |
|
|
35
36
|
| `list_backups` | List automatic pre-deploy backups |
|
|
36
37
|
| `restore_backup` | Restore a backup in one command — needs `confirm:true` |
|
|
37
38
|
| `list_node_types` | Installed palette modules and node types |
|
package/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* nodered-mcp-full - MCP server for the Node-RED Admin API
|
|
4
4
|
*
|
|
5
|
+
* v0.4.0 - get_errors: live runtime error monitor via the editor /comms websocket
|
|
6
|
+
* (red/yellow node statuses + error notifications, node/tab resolved)
|
|
5
7
|
* v0.3.0 - AI-first flow comprehension layer:
|
|
6
8
|
* - get_flow_map: tab/subflow rendered as outline or Mermaid, wiring resolved to names
|
|
7
9
|
* - list_flows detail, search_nodes, list_config_nodes
|
|
@@ -26,6 +28,7 @@ import fs from "node:fs";
|
|
|
26
28
|
import path from "node:path";
|
|
27
29
|
import os from "node:os";
|
|
28
30
|
import crypto from "node:crypto";
|
|
31
|
+
import WebSocket from "ws";
|
|
29
32
|
|
|
30
33
|
// ---------------- environment ----------------
|
|
31
34
|
const URL_BASE = (process.env.NODE_RED_URL || "http://localhost:1880").replace(/\/+$/, "");
|
|
@@ -74,6 +77,114 @@ async function getToken(force) {
|
|
|
74
77
|
});
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
// ---------------- runtime error monitor (editor comms websocket) ----------------
|
|
81
|
+
// Connects to the same /comms websocket the Node-RED editor uses, authenticates
|
|
82
|
+
// with the admin token (auth packet), subscribes to status + notification and
|
|
83
|
+
// keeps a rolling buffer of red/yellow node statuses and error notifications.
|
|
84
|
+
const MONITOR_MAX = 500;
|
|
85
|
+
const monitor = { ws: null, state: "idle", since: null, buffer: [], lastFill: new Map(), lastStatus: new Map(), reconnectMs: 4000, reconnectTimer: null, closedByUs: false };
|
|
86
|
+
let nodeNames = null; let nodeNamesAt = 0;
|
|
87
|
+
|
|
88
|
+
function monitorRecord(kind, entry) {
|
|
89
|
+
monitor.buffer.push(Object.assign({ ts: Date.now(), kind }, entry));
|
|
90
|
+
if (monitor.buffer.length > MONITOR_MAX) monitor.buffer.splice(0, monitor.buffer.length - MONITOR_MAX);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function nodeNameMap() {
|
|
94
|
+
if (nodeNames && Date.now() - nodeNamesAt < 60000) return nodeNames;
|
|
95
|
+
try {
|
|
96
|
+
const flows = await apiGetJson("/flows");
|
|
97
|
+
const tabs = new Map();
|
|
98
|
+
flows.forEach(function (f) { if (f.type === "tab") tabs.set(f.id, f.label || f.id); });
|
|
99
|
+
const map = new Map();
|
|
100
|
+
flows.forEach(function (f) {
|
|
101
|
+
if (f.type === "tab" || f.type === "subflow") return;
|
|
102
|
+
map.set(f.id, { name: f.name || f.type || f.id, type: f.type, tab_id: f.z || null, tab_label: f.z ? (tabs.get(f.z) || f.z) : "(config)" });
|
|
103
|
+
});
|
|
104
|
+
nodeNames = { map: map }; nodeNamesAt = Date.now();
|
|
105
|
+
return nodeNames;
|
|
106
|
+
} catch (e) { return nodeNames || { map: new Map() }; }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function monitorConnect() {
|
|
110
|
+
if (monitor.ws && (monitor.ws.readyState === 0 || monitor.ws.readyState === 1)) return;
|
|
111
|
+
monitor.closedByUs = false;
|
|
112
|
+
monitor.state = "connecting";
|
|
113
|
+
const wsUrl = URL_BASE.replace(/^http/, "ws") + "/comms";
|
|
114
|
+
let ws;
|
|
115
|
+
try { ws = new WebSocket(wsUrl, { headers: Object.assign({}, EXTRA_HEADERS), ca: ca || undefined, rejectUnauthorized: !INSECURE_TLS }); }
|
|
116
|
+
catch (e) { monitor.state = "error: " + e.message; scheduleReconnect(); return; }
|
|
117
|
+
ws.on("open", async function () {
|
|
118
|
+
monitor.ws = ws;
|
|
119
|
+
monitor.state = "authorizing";
|
|
120
|
+
try {
|
|
121
|
+
const t = AUTH_USER ? await getToken() : (TOKEN || "");
|
|
122
|
+
ws.send(JSON.stringify({ auth: t || "" }));
|
|
123
|
+
} catch (e) { monitor.state = "auth-error"; monitor.closedByUs = true; try { ws.close(); } catch (e2) {} }
|
|
124
|
+
});
|
|
125
|
+
ws.on("message", function (raw) {
|
|
126
|
+
let m; try { m = JSON.parse(raw.toString()); } catch (e) { return; }
|
|
127
|
+
if (m && m.auth) {
|
|
128
|
+
if (m.auth === "ok") {
|
|
129
|
+
monitor.state = "open"; monitor.since = Date.now();
|
|
130
|
+
try { ws.send(JSON.stringify({ subscribe: "status" })); ws.send(JSON.stringify({ subscribe: "notification" })); } catch (e) {}
|
|
131
|
+
} else { monitor.state = "auth-fail"; monitor.closedByUs = true; try { ws.close(); } catch (e) {} }
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const arr = Array.isArray(m) ? m : [m];
|
|
135
|
+
for (const one of arr) {
|
|
136
|
+
if (!one || typeof one !== "object") continue;
|
|
137
|
+
const topic = String(one.topic || "");
|
|
138
|
+
if (topic === "hb") { try { ws.send(JSON.stringify({ topic: "hb" })); } catch (e) {} continue; }
|
|
139
|
+
if (topic.indexOf("status/") === 0) {
|
|
140
|
+
const id = topic.slice(7);
|
|
141
|
+
const d = one.data || {};
|
|
142
|
+
if (d.fill) {
|
|
143
|
+
monitor.lastFill.set(id, d.fill);
|
|
144
|
+
monitor.lastStatus.set(id, { ts: Date.now(), fill: d.fill, shape: d.shape || null, text: String(d.text || "").slice(0, 200) });
|
|
145
|
+
if (monitor.lastStatus.size > 1000) {
|
|
146
|
+
const sorted = Array.from(monitor.lastStatus.entries()).sort(function (a, b) { return a[1].ts - b[1].ts; });
|
|
147
|
+
for (let i = 0; i < 200; i++) monitor.lastStatus.delete(sorted[i][0]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (d.fill === "red" || d.fill === "yellow") monitorRecord("status", { node_id: id, fill: d.fill, shape: d.shape || null, text: String(d.text || "") });
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (topic.indexOf("notification/") === 0) {
|
|
154
|
+
const d = one.data || {};
|
|
155
|
+
if (d && (d.type === "error" || d.type === "warning")) monitorRecord("notification", { level: d.type, text: String(d.text || "") });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
ws.on("close", function () {
|
|
161
|
+
if (monitor.ws === ws) {
|
|
162
|
+
monitor.ws = null;
|
|
163
|
+
if (!monitor.closedByUs) { monitor.state = "reconnect-wait"; scheduleReconnect(); }
|
|
164
|
+
else monitor.state = "closed";
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
ws.on("error", function () { /* close handler reschedules */ });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function scheduleReconnect() {
|
|
171
|
+
if (monitor.reconnectTimer) return;
|
|
172
|
+
monitor.reconnectTimer = setTimeout(function () { monitor.reconnectTimer = null; monitorConnect(); }, monitor.reconnectMs);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function ensureMonitor() {
|
|
176
|
+
if (monitor.ws && monitor.ws.readyState === 1) return;
|
|
177
|
+
if (monitor.ws && monitor.ws.readyState === 0) {
|
|
178
|
+
const t0 = Date.now();
|
|
179
|
+
while (Date.now() - t0 < 3000 && monitor.state !== "open") await new Promise(function (r) { setTimeout(r, 100); });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (AUTH_USER) { try { await getToken(true); } catch (e) { /* proceed, auth packet will fail visibly */ } }
|
|
183
|
+
monitorConnect();
|
|
184
|
+
const t0 = Date.now();
|
|
185
|
+
while (Date.now() - t0 < 4000 && monitor.state !== "open") await new Promise(function (r) { setTimeout(r, 100); });
|
|
186
|
+
}
|
|
187
|
+
|
|
77
188
|
// ---------------- http client ----------------
|
|
78
189
|
async function request(method, urlPath, body, extraHeaders) {
|
|
79
190
|
const tk = await getToken(false);
|
|
@@ -401,7 +512,7 @@ function removeNode(flows, nodeId) {
|
|
|
401
512
|
}
|
|
402
513
|
|
|
403
514
|
// ---------------- server ----------------
|
|
404
|
-
const server = new McpServer({ name: "nodered-mcp", version: "0.
|
|
515
|
+
const server = new McpServer({ name: "nodered-mcp", version: "0.4.1" });
|
|
405
516
|
const log = (msg) => console.error("[nodered-mcp] " + msg);
|
|
406
517
|
log("target " + URL_BASE + (TOKEN ? " (token)" : "") + (READ_ONLY ? " READ-ONLY" : ""));
|
|
407
518
|
|
|
@@ -650,5 +761,59 @@ server.tool("list_node_types", "List installed palette modules and node types",
|
|
|
650
761
|
return { content: [{ type: "text", text: txt(nodes.map(m => ({ module: m.module, version: m.version, types: m.types, local: m.local, disabled: m.disabled }))) }] };
|
|
651
762
|
});
|
|
652
763
|
|
|
764
|
+
server.tool("get_errors", "Live runtime errors and warnings from the Node-RED editor comms channel: node statuses with red/yellow fill (e.g. 'Call-service error...', rejected commands) and runtime error notifications, with node name/type/tab resolved. The monitor connects on first call and keeps a rolling in-memory buffer (reconnects automatically); events are captured from the moment it first connects - there is no history before that. include_warnings:false hides yellow; tab_id filters one tab; clear:true empties the buffer after reading. include_last_status:true adds nodes_in_error_now (nodes whose latest status is red) and last_status_seen (latest status per node seen by the monitor - Node-RED has no status replay: silent nodes show nothing until they emit again).", {
|
|
765
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
766
|
+
tab_id: z.string().optional(),
|
|
767
|
+
include_warnings: z.boolean().optional(),
|
|
768
|
+
clear: z.boolean().optional(),
|
|
769
|
+
include_last_status: z.boolean().optional()
|
|
770
|
+
}, async ({ limit, tab_id, include_warnings, clear, include_last_status }) => {
|
|
771
|
+
await ensureMonitor();
|
|
772
|
+
const names = await nodeNameMap();
|
|
773
|
+
const wanted = limit || 30;
|
|
774
|
+
let seen = 0;
|
|
775
|
+
const entries = [];
|
|
776
|
+
const reversed = monitor.buffer.slice().reverse();
|
|
777
|
+
for (const e of reversed) {
|
|
778
|
+
if (entries.length >= wanted) break;
|
|
779
|
+
const isWarn = (e.kind === "status" && e.fill === "yellow") || (e.kind === "notification" && e.level === "warning");
|
|
780
|
+
if (include_warnings === false && isWarn) continue;
|
|
781
|
+
const info = e.node_id ? names.map.get(e.node_id) : null;
|
|
782
|
+
if (tab_id && (!info || (info.tab_id !== tab_id && info.tab_label !== tab_id))) continue;
|
|
783
|
+
entries.push({
|
|
784
|
+
time: new Date(e.ts).toISOString(),
|
|
785
|
+
kind: e.kind,
|
|
786
|
+
node_id: e.node_id || undefined,
|
|
787
|
+
node: info ? info.name : undefined,
|
|
788
|
+
node_type: info ? info.type : undefined,
|
|
789
|
+
tab: info ? info.tab_label : undefined,
|
|
790
|
+
fill: e.fill || undefined,
|
|
791
|
+
level: e.level || undefined,
|
|
792
|
+
still_current: e.kind === "status" ? ((monitor.lastStatus.get(e.node_id) || {}).fill) === e.fill : undefined,
|
|
793
|
+
text: e.text
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
if (clear) monitor.buffer.length = 0;
|
|
797
|
+
const out = {
|
|
798
|
+
monitor: { state: monitor.state, connected_since: monitor.since ? new Date(monitor.since).toISOString() : null, captured_events: monitor.buffer.length },
|
|
799
|
+
errors: entries
|
|
800
|
+
};
|
|
801
|
+
if (include_last_status) {
|
|
802
|
+
const seen = [];
|
|
803
|
+
const nowRed = [];
|
|
804
|
+
for (const [id, st] of monitor.lastStatus.entries()) {
|
|
805
|
+
const info = names.map.get(id);
|
|
806
|
+
if (tab_id && (!info || (info.tab_id !== tab_id && info.tab_label !== tab_id))) continue;
|
|
807
|
+
const row = { node_id: id, node: info ? info.name : undefined, node_type: info ? info.type : undefined, tab: info ? info.tab_label : undefined, fill: st.fill, shape: st.shape || undefined, text: st.text, seen_at: new Date(st.ts).toISOString() };
|
|
808
|
+
seen.push(row);
|
|
809
|
+
if (st.fill === "red") nowRed.push(row);
|
|
810
|
+
}
|
|
811
|
+
seen.sort(function (a, b) { return a.seen_at < b.seen_at ? 1 : -1; });
|
|
812
|
+
out.nodes_in_error_now = nowRed;
|
|
813
|
+
out.last_status_seen = seen.slice(0, 50);
|
|
814
|
+
}
|
|
815
|
+
return { content: [{ type: "text", text: txt(out) }] };
|
|
816
|
+
});
|
|
817
|
+
|
|
653
818
|
await server.connect(new StdioServerTransport());
|
|
654
|
-
log("ready:
|
|
819
|
+
log("ready: 18 tools (v0.4.1)");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodered-mcp-full",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Full-featured MCP server for Node-RED: complete admin-API access for AI agents — read AND safe write (confirm + automatic backups + restore), env-driven for any setup: direct, reverse proxy with custom CA, adminAuth token, read-only mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
26
|
+
"ws": "^8.23.0",
|
|
26
27
|
"zod": "^3.23.0"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
@@ -43,4 +44,4 @@
|
|
|
43
44
|
"LICENSE",
|
|
44
45
|
"CHANGELOG.md"
|
|
45
46
|
]
|
|
46
|
-
}
|
|
47
|
+
}
|