@omnidim-ai/mcp-server 0.14.0 → 0.15.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.
@@ -0,0 +1,320 @@
1
+ // MCP Apps view (ui:// resource) that draws a workflow draft inside the chat.
2
+ // The page holds no API key: every read and edit goes back through this
3
+ // server's own tools via the host, so it runs on the user's existing login.
4
+
5
+ export const WORKFLOW_CANVAS_URI = "ui://omnidim/workflow-canvas";
6
+
7
+ const CANVAS_TOOLS = new Set(["getWorkflow", "createWorkflow", "editWorkflow"]);
8
+
9
+ export function toolMeta(name: string): { ui: { resourceUri: string } } | undefined {
10
+ return CANVAS_TOOLS.has(name) ? { ui: { resourceUri: WORKFLOW_CANVAS_URI } } : undefined;
11
+ }
12
+
13
+ interface ToolResult { isError?: boolean; content?: Array<{ type: string; text?: string }>; }
14
+
15
+ // Embedded into the page with toString(), so it must not reference anything outside itself.
16
+ export function readWorkflow(result: ToolResult): { workflow: any; workflowId: number | null; error: string | null } {
17
+ const text = (result.content || []).filter((c) => c.type === "text").map((c) => c.text || "").join("\n");
18
+ if (result.isError) return { workflow: null, workflowId: null, error: text };
19
+ const body = text.startsWith("API Response") ? text.slice(text.indexOf("\n") + 1) : text;
20
+ let data: any;
21
+ try { data = JSON.parse(body); } catch { return { workflow: null, workflowId: null, error: text }; }
22
+ const wf = data && (data.workflow || data);
23
+ const id = wf && (wf.id ?? wf.workflow_id);
24
+ const workflowId = typeof id === "number" ? id : null;
25
+ return { workflow: wf && wf.draft ? wf : null, workflowId, error: null };
26
+ }
27
+
28
+ export const WORKFLOW_CANVAS_HTML = `<!doctype html>
29
+ <html lang="en">
30
+ <head>
31
+ <meta charset="utf-8">
32
+ <meta name="viewport" content="width=device-width, initial-scale=1">
33
+ <title>Workflow canvas</title>
34
+ <style>
35
+ :root {
36
+ --bg: #f7f6f2; --panel: #ffffff; --ink: #1d1c19; --muted: #6b675e; --line: #d9d5ca;
37
+ --edge: #9a9486; --grid: #e8e4da; --sel: #2f5bd3; --err: #b3261e;
38
+ --trigger: #2e7d4f; --logic: #b26a00; --voice: #6a3fb5; --msg: #0f7b74; --mail: #2f5bd3; --other: #5f5b52;
39
+ color-scheme: light;
40
+ }
41
+ :root[data-theme="dark"] {
42
+ --bg: #17161a; --panel: #211f25; --ink: #ecebe6; --muted: #a29e94; --line: #3a3741;
43
+ --edge: #7d7888; --grid: #24222a; --sel: #8aa8ff; --err: #ff8a80;
44
+ --trigger: #6fcf97; --logic: #f2b84b; --voice: #b49cf0; --msg: #5fd3c7; --mail: #8aa8ff; --other: #b0aba1;
45
+ color-scheme: dark;
46
+ }
47
+ * { box-sizing: border-box; }
48
+ body { margin: 0; font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
49
+ header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
50
+ header h1 { font-size: 14px; margin: 0; font-weight: 600; flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
51
+ .pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
52
+ button { font: inherit; font-size: 12px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
53
+ button:hover { border-color: var(--edge); }
54
+ button:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
55
+ #stage { overflow: auto; background-color: var(--bg); background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 16px 16px; }
56
+ :root[data-mode="fullscreen"] #stage { max-height: none; height: calc(100vh - 160px); }
57
+ svg { display: block; touch-action: none; }
58
+ .node rect.card { fill: var(--panel); stroke: var(--line); stroke-width: 1; }
59
+ .node.selected rect.card { stroke: var(--sel); stroke-width: 2; }
60
+ .node { cursor: grab; }
61
+ .node.dragging { cursor: grabbing; opacity: .85; }
62
+ .node .label { font-size: 13px; font-weight: 600; fill: var(--ink); }
63
+ .node .type { font-size: 11px; fill: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
64
+ .edge { fill: none; stroke: var(--edge); stroke-width: 1.5; }
65
+ .handle-label { font-size: 11px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
66
+ #detail { padding: 10px 12px; border-top: 1px solid var(--line); min-height: 44px; }
67
+ #detail .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
68
+ #detail pre { margin: 8px 0 0; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; max-height: 180px; overflow: auto; font-size: 11px; }
69
+ .muted { color: var(--muted); }
70
+ #status { font-size: 12px; color: var(--muted); }
71
+ #status.error { color: var(--err); }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <header>
76
+ <h1 id="title">Loading workflow</h1>
77
+ <span class="pill" id="state" hidden></span>
78
+ <button id="refresh" type="button">Refresh</button>
79
+ <button id="full" type="button">Full screen</button>
80
+ <button id="open" type="button">Open in dashboard</button>
81
+ </header>
82
+ <div id="stage"><svg id="canvas" role="img" aria-label="Workflow graph"></svg></div>
83
+ <div id="detail">
84
+ <div id="status">Waiting for the workflow.</div>
85
+ <div id="node" hidden>
86
+ <div class="row"><strong id="n-label"></strong><span class="pill" id="n-type"></span><span class="muted" id="n-id"></span>
87
+ <button id="ask" type="button">Ask Claude about this node</button></div>
88
+ <pre id="n-config"></pre>
89
+ </div>
90
+ </div>
91
+ <script>
92
+ const readWorkflow = ${readWorkflow.toString()};
93
+ const NODE_W = 210, NODE_H = 58, PAD = 40, MIN_SCALE = 0.45;
94
+ const SVG_NS = "http://www.w3.org/2000/svg";
95
+ const $ = (id) => document.getElementById(id);
96
+ const state = { wf: null, id: null, selected: null, busy: false };
97
+
98
+ // JSON-RPC over postMessage to the host (MCP Apps protocol 2026-01-26).
99
+ let nextId = 1;
100
+ const pending = new Map();
101
+ function send(msg) { window.parent.postMessage(Object.assign({ jsonrpc: "2.0" }, msg), "*"); }
102
+ function request(method, params) {
103
+ const id = nextId++;
104
+ send({ id, method, params });
105
+ return new Promise((resolve, reject) => pending.set(id, { resolve, reject }));
106
+ }
107
+ function notify(method, params) { send({ method, params }); }
108
+
109
+ window.addEventListener("message", (event) => {
110
+ if (event.source !== window.parent) return;
111
+ const msg = event.data;
112
+ if (!msg || msg.jsonrpc !== "2.0") return;
113
+ if (msg.id !== undefined && pending.has(msg.id) && !msg.method) {
114
+ const p = pending.get(msg.id); pending.delete(msg.id);
115
+ msg.error ? p.reject(new Error(msg.error.message || "Request failed")) : p.resolve(msg.result);
116
+ return;
117
+ }
118
+ if (msg.method === "ui/notifications/tool-input") {
119
+ const id = msg.params && msg.params.arguments && msg.params.arguments.workflow_id;
120
+ if (typeof id === "number") state.id = id;
121
+ } else if (msg.method === "ui/notifications/tool-result") {
122
+ applyResult(msg.params);
123
+ } else if (msg.method === "ui/notifications/host-context-changed") {
124
+ applyContext(msg.params);
125
+ } else if (msg.method === "ui/resource-teardown" && msg.id !== undefined) {
126
+ send({ id: msg.id, result: {} });
127
+ } else if (msg.id !== undefined && msg.method) {
128
+ send({ id: msg.id, error: { code: -32601, message: "Method not found" } });
129
+ }
130
+ });
131
+
132
+ function applyContext(ctx) {
133
+ if (!ctx) return;
134
+ if (ctx.theme) document.documentElement.dataset.theme = ctx.theme;
135
+ if (ctx.displayMode) document.documentElement.dataset.mode = ctx.displayMode;
136
+ }
137
+
138
+ function setStatus(text, isError) {
139
+ $("status").textContent = text;
140
+ $("status").className = isError ? "error" : "";
141
+ }
142
+
143
+ async function callTool(name, args) {
144
+ return request("tools/call", { name, arguments: args });
145
+ }
146
+
147
+ async function refresh() {
148
+ if (state.id == null || state.busy) return;
149
+ state.busy = true; setStatus("Loading the latest draft.");
150
+ try { applyResult(await callTool("getWorkflow", { workflow_id: state.id })); }
151
+ catch (e) { setStatus("Could not load the workflow: " + e.message, true); }
152
+ finally { state.busy = false; }
153
+ }
154
+
155
+ function applyResult(result) {
156
+ const r = readWorkflow(result || {});
157
+ if (r.error) { setStatus(r.error, true); return; }
158
+ if (r.workflowId != null) state.id = r.workflowId;
159
+ if (!r.workflow) { refresh(); return; }
160
+ state.wf = r.workflow;
161
+ render();
162
+ setStatus("Drag a node to move it. Select a node to see its settings.");
163
+ }
164
+
165
+ function accent(type) {
166
+ if (type === "trigger" || type.endsWith("_trigger")) return "var(--trigger)";
167
+ if (type.endsWith("_condition") || type === "switch" || type === "delay" || type === "code") return "var(--logic)";
168
+ if (type.startsWith("voice")) return "var(--voice)";
169
+ if (type.includes("whatsapp") || type.includes("sms")) return "var(--msg)";
170
+ if (type.includes("email")) return "var(--mail)";
171
+ return "var(--other)";
172
+ }
173
+
174
+ function el(tag, attrs, text) {
175
+ const e = document.createElementNS(SVG_NS, tag);
176
+ for (const k in attrs) e.setAttribute(k, attrs[k]);
177
+ if (text != null) e.textContent = text;
178
+ return e;
179
+ }
180
+
181
+ function clip(s, n) { return s.length > n ? s.slice(0, n - 1) + "\\u2026" : s; }
182
+
183
+ function render() {
184
+ const wf = state.wf, draft = wf.draft, svg = $("canvas");
185
+ $("title").textContent = wf.name || "Workflow " + wf.id;
186
+ $("state").hidden = false;
187
+ $("state").textContent = (wf.status || "draft") + " \\u00b7 " + draft.nodes.length + " nodes";
188
+ const pos = {};
189
+ draft.nodes.forEach((n, i) => { pos[n.id] = n.position || { x: i * 260, y: 0 }; });
190
+ const xs = Object.values(pos).map((p) => p.x), ys = Object.values(pos).map((p) => p.y);
191
+ const minX = Math.min(...xs, 0) - PAD, minY = Math.min(...ys, 0) - PAD;
192
+ const w = Math.max(...xs, 0) + NODE_W + PAD - minX, h = Math.max(...ys, 0) + NODE_H + PAD - minY;
193
+ const avail = $("stage").clientWidth || 600;
194
+ const scale = Math.max(MIN_SCALE, Math.min(1, avail / w));
195
+ svg.setAttribute("viewBox", minX + " " + minY + " " + w + " " + h);
196
+ svg.setAttribute("width", Math.round(w * scale));
197
+ svg.setAttribute("height", Math.round(h * scale));
198
+ svg.replaceChildren();
199
+
200
+ const edges = el("g", {});
201
+ for (const e of draft.edges) {
202
+ const a = pos[e.from], b = pos[e.to];
203
+ if (!a || !b) continue;
204
+ const x1 = a.x + NODE_W, y1 = a.y + NODE_H / 2, x2 = b.x, y2 = b.y + NODE_H / 2, dx = Math.max(40, (x2 - x1) / 2);
205
+ edges.append(el("path", { class: "edge", d: "M" + x1 + "," + y1 + " C" + (x1 + dx) + "," + y1 + " " + (x2 - dx) + "," + y2 + " " + x2 + "," + y2, "marker-end": "url(#arrow)" }));
206
+ if (e.handle && e.handle !== "default") {
207
+ edges.append(el("text", { class: "handle-label", x: x2 - 8, y: y2 - 8, "text-anchor": "end" }, e.handle));
208
+ }
209
+ }
210
+ const defs = el("defs", {});
211
+ const marker = el("marker", { id: "arrow", viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse" });
212
+ marker.append(el("path", { d: "M0,0 L10,5 L0,10 z", fill: "var(--edge)" }));
213
+ defs.append(marker);
214
+ svg.append(defs, edges);
215
+
216
+ for (const n of draft.nodes) {
217
+ const p = pos[n.id];
218
+ const g = el("g", { class: "node" + (state.selected === n.id ? " selected" : ""), transform: "translate(" + p.x + "," + p.y + ")", tabindex: "0", role: "button", "aria-label": (n.label || n.id) + ", " + n.type });
219
+ g.append(el("rect", { class: "card", width: NODE_W, height: NODE_H, rx: 8 }));
220
+ g.append(el("rect", { width: 4, height: NODE_H - 16, x: 0, y: 8, rx: 2, fill: accent(n.type) }));
221
+ g.append(el("text", { class: "label", x: 14, y: 24 }, clip(n.label || n.id, 26)));
222
+ g.append(el("text", { class: "type", x: 14, y: 43 }, clip(n.type, 30)));
223
+ g.addEventListener("pointerdown", (ev) => startDrag(ev, n, g, p));
224
+ g.addEventListener("keydown", (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); select(n.id); } });
225
+ svg.append(g);
226
+ }
227
+ if (state.selected) showNode(draft.nodes.find((n) => n.id === state.selected));
228
+ }
229
+
230
+ function toSvg(ev) {
231
+ const svg = $("canvas"), pt = svg.createSVGPoint();
232
+ pt.x = ev.clientX; pt.y = ev.clientY;
233
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
234
+ }
235
+
236
+ function startDrag(ev, node, g, p) {
237
+ if (state.busy) return;
238
+ const start = toSvg(ev), origin = { x: p.x, y: p.y };
239
+ let moved = false;
240
+ g.setPointerCapture(ev.pointerId);
241
+ const move = (e) => {
242
+ const cur = toSvg(e), dx = cur.x - start.x, dy = cur.y - start.y;
243
+ if (!moved && Math.hypot(dx, dy) < 4) return;
244
+ moved = true; g.classList.add("dragging");
245
+ p.x = Math.round(origin.x + dx); p.y = Math.round(origin.y + dy);
246
+ g.setAttribute("transform", "translate(" + p.x + "," + p.y + ")");
247
+ };
248
+ const up = () => {
249
+ g.removeEventListener("pointermove", move);
250
+ g.removeEventListener("pointerup", up);
251
+ g.classList.remove("dragging");
252
+ if (!moved) { select(node.id); return; }
253
+ saveMove(node, { x: p.x, y: p.y }, origin);
254
+ };
255
+ g.addEventListener("pointermove", move);
256
+ g.addEventListener("pointerup", up);
257
+ }
258
+
259
+ async function saveMove(node, position, origin) {
260
+ state.busy = true; setStatus("Saving the new position.");
261
+ try {
262
+ const res = await callTool("editWorkflow", { workflow_id: state.id, requestBody: { revision: state.wf.draft.revision, ops: [{ op: "move_node", id: node.id, position }] } });
263
+ const r = readWorkflow(res || {});
264
+ if (r.error) throw new Error(r.error);
265
+ node.position = position;
266
+ notify("ui/update-model-context", { content: [{ type: "text", text: "The user moved node \\"" + node.id + "\\" on workflow " + state.id + " in the canvas. Call getWorkflow for the new revision before your next edit." }] });
267
+ } catch (e) {
268
+ node.position = origin;
269
+ setStatus("Not saved: " + e.message, true);
270
+ state.busy = false; render(); return;
271
+ }
272
+ state.busy = false;
273
+ await refresh();
274
+ }
275
+
276
+ function select(id) {
277
+ state.selected = id;
278
+ render();
279
+ const n = state.wf.draft.nodes.find((x) => x.id === id);
280
+ notify("ui/update-model-context", { content: [{ type: "text", text: "In the workflow canvas the user selected node \\"" + id + "\\" (" + n.type + ") on workflow " + state.id + "." }] });
281
+ }
282
+
283
+ function showNode(n) {
284
+ if (!n) { $("node").hidden = true; return; }
285
+ $("node").hidden = false;
286
+ $("n-label").textContent = n.label || n.id;
287
+ $("n-type").textContent = n.type;
288
+ $("n-id").textContent = "id " + n.id;
289
+ $("n-config").textContent = n.config ? JSON.stringify(n.config, null, 2) : "Settings are not loaded in this view.";
290
+ }
291
+
292
+ $("refresh").addEventListener("click", refresh);
293
+ $("full").addEventListener("click", async () => {
294
+ const mode = document.documentElement.dataset.mode === "fullscreen" ? "inline" : "fullscreen";
295
+ try { const r = await request("ui/request-display-mode", { mode }); applyContext({ displayMode: r && r.mode }); render(); }
296
+ catch (e) { setStatus("This app cannot change size: " + e.message, true); }
297
+ });
298
+ $("open").addEventListener("click", () => {
299
+ if (state.id != null) request("ui/open-link", { url: "https://omnidim.io/workflow/" + state.id }).catch(() => {});
300
+ });
301
+ $("ask").addEventListener("click", () => {
302
+ const n = state.wf && state.wf.draft.nodes.find((x) => x.id === state.selected);
303
+ if (!n) return;
304
+ request("ui/message", { role: "user", content: [{ type: "text", text: "In workflow " + state.id + ", explain the \\"" + (n.label || n.id) + "\\" node (id " + n.id + ", " + n.type + ") and check its settings for problems." }] }).catch((e) => setStatus(e.message, true));
305
+ });
306
+
307
+ new ResizeObserver(() => notify("ui/notifications/size-changed", { width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight })).observe(document.body);
308
+
309
+ request("ui/initialize", {
310
+ protocolVersion: "2026-01-26",
311
+ appInfo: { name: "omnidim-workflow-canvas", version: "0.1.0" },
312
+ appCapabilities: { availableDisplayModes: ["inline", "fullscreen"] },
313
+ }).then((r) => {
314
+ applyContext(r && r.hostContext);
315
+ notify("ui/notifications/initialized", {});
316
+ }).catch((e) => setStatus("The host did not accept the view: " + e.message, true));
317
+ </script>
318
+ </body>
319
+ </html>
320
+ `;