infiniteboard-mcp 0.0.0-stage → 0.2.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.
Files changed (5) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +15 -2
  3. package/package.json +42 -4
  4. package/server.mjs +113 -0
  5. package/tools.mjs +138 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # infiniteboard-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lets AI assistants (Claude Code, Claude Desktop, Cursor, VS Code, or any MCP client) read and draw on your open Infiniteboard whiteboard.
4
+
5
+ 1. Open the board and click **AI** in the top bar. The board starts waiting for your assistant.
6
+ 2. Add this MCP server to your assistant. The dialog shows the exact steps for each app. The command is:
7
+
8
+ ```bash
9
+ npx -y infiniteboard-mcp
10
+ ```
11
+
12
+ 3. Ask away: *"Sketch a user-signup flowchart on my board"*.
13
+
14
+ The server runs on your machine. The board tab connects to it over `ws://127.0.0.1:3917` only while its AI switch is on.
15
+
16
+ Options: `--port <n>` (open the board with `?mcp=<n>` to match) and `--allow-origin <url>` for a hosted board other than localhost. Requires Node.js 18+.
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "infiniteboard-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Let AI assistants (Claude, Cursor, VS Code, any MCP client) draw on your open Infiniteboard whiteboard",
5
+ "type": "module",
6
+ "bin": {
7
+ "infiniteboard-mcp": "server.mjs"
8
+ },
9
+ "scripts": {
10
+ "start": "node server.mjs"
11
+ },
12
+ "dependencies": {
13
+ "@modelcontextprotocol/sdk": "1.32.1",
14
+ "ws": "8.22.0",
15
+ "zod": "4.6.7"
16
+ },
17
+ "files": [
18
+ "server.mjs",
19
+ "tools.mjs",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "keywords": [
27
+ "mcp",
28
+ "model-context-protocol",
29
+ "whiteboard",
30
+ "claude",
31
+ "ai"
32
+ ],
33
+ "license": "Apache-2.0",
34
+ "author": "Isaiah Isayev",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/isaiahoo/infiniteboard.git",
38
+ "directory": "mcp"
39
+ },
40
+ "homepage": "https://github.com/isaiahoo/infiniteboard/tree/main/mcp",
41
+ "bugs": {
42
+ "url": "https://github.com/isaiahoo/infiniteboard/issues"
43
+ }
44
+ }
package/server.mjs ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ // MCP server for the whiteboard. AI assistants talk to it over stdio; it relays each tool call
3
+ // to the open whiteboard tab, which connects to a loopback WebSocket once the user enables
4
+ // "Let a local AI assistant edit this board" in the menu.
5
+ //
6
+ // Options (flags or env):
7
+ // --port <n> | WHITEBOARD_BRIDGE_PORT WebSocket port (default 3917; the page uses ?mcp=<port> to match)
8
+ // --allow-origin <url> | WHITEBOARD_ALLOWED_ORIGINS extra page origins allowed to connect (repeatable / comma-separated);
9
+ // localhost and 127.0.0.1 are always allowed
10
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import { WebSocketServer } from "ws";
13
+ import { INSTRUCTIONS, registerBoardTools } from "./tools.mjs";
14
+
15
+ const argv = process.argv.slice(2);
16
+ const flag = (name) => argv.flatMap((a, i) => (a === name && argv[i + 1] ? [argv[i + 1]] : a.startsWith(`${name}=`) ? [a.slice(name.length + 1)] : []));
17
+ const PORT = Number(flag("--port")[0] ?? process.env.WHITEBOARD_BRIDGE_PORT) || 3917;
18
+ const EXTRA_ORIGINS = [...flag("--allow-origin"), ...(process.env.WHITEBOARD_ALLOWED_ORIGINS ?? "").split(",")]
19
+ .map((s) => s.trim().replace(/\/$/, ""))
20
+ .filter(Boolean);
21
+ const log = (...args) => console.error("[whiteboard-mcp]", ...args); // stdout is reserved for MCP
22
+
23
+ function originAllowed(origin) {
24
+ if (!origin) return false;
25
+ try {
26
+ const u = new URL(origin);
27
+ if (["localhost", "127.0.0.1", "[::1]"].includes(u.hostname)) return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ return EXTRA_ORIGINS.includes(origin);
32
+ }
33
+
34
+ // ---------- bridge to the board tab ----------
35
+
36
+ let board = null;
37
+ let bridgeError = null;
38
+ let seq = 0;
39
+ const pending = new Map();
40
+
41
+ const wss = new WebSocketServer({
42
+ host: "127.0.0.1",
43
+ port: PORT,
44
+ maxPayload: 32 * 1024 * 1024,
45
+ verifyClient: ({ origin }) => {
46
+ const ok = originAllowed(origin);
47
+ if (!ok) log(`rejected connection from origin ${origin ?? "(none)"}; start the server with --allow-origin ${origin} to allow it`);
48
+ return ok;
49
+ },
50
+ });
51
+ wss.on("listening", () => log(`waiting for the whiteboard on ws://127.0.0.1:${PORT}`));
52
+ wss.on("error", (e) => {
53
+ bridgeError = e.code === "EADDRINUSE" ? `Port ${PORT} is already in use (is another whiteboard MCP server running?)` : String(e.message ?? e);
54
+ log(bridgeError);
55
+ });
56
+ wss.on("connection", (ws) => {
57
+ // Newest tab wins; code 4000 tells the old tab to stop reconnecting instead of fighting for the slot.
58
+ if (board && board !== ws) board.close(4000, "Another board tab connected");
59
+ board = ws;
60
+ log("board connected");
61
+ ws.on("message", (data) => {
62
+ let msg;
63
+ try {
64
+ msg = JSON.parse(String(data));
65
+ } catch {
66
+ return;
67
+ }
68
+ if (msg.type === "hello") return log(`board: "${msg.title}"`);
69
+ const p = pending.get(msg.id);
70
+ if (!p) return;
71
+ pending.delete(msg.id);
72
+ clearTimeout(p.timer);
73
+ if (msg.error) p.reject(new Error(msg.error));
74
+ else p.resolve(msg.result);
75
+ });
76
+ ws.on("close", () => {
77
+ if (board === ws) board = null;
78
+ log("board disconnected");
79
+ });
80
+ });
81
+
82
+ function call(method, params = {}) {
83
+ if (bridgeError) return Promise.reject(new Error(bridgeError));
84
+ if (!board || board.readyState !== board.OPEN) {
85
+ return Promise.reject(new Error(
86
+ "No whiteboard is connected. Ask the user to open the whiteboard and click the AI button in its top bar.",
87
+ ));
88
+ }
89
+ const id = ++seq;
90
+ return new Promise((resolve, reject) => {
91
+ const timer = setTimeout(() => {
92
+ pending.delete(id);
93
+ reject(new Error(`The board did not answer "${method}" within 20s`));
94
+ }, 20000);
95
+ pending.set(id, { resolve, reject, timer });
96
+ board.send(JSON.stringify({ id, method, params }));
97
+ });
98
+ }
99
+
100
+ // ---------- MCP server ----------
101
+
102
+ const server = new McpServer({ name: "infiniteboard", version: "0.2.0" }, { instructions: INSTRUCTIONS });
103
+ registerBoardTools(server, call);
104
+ await server.connect(new StdioServerTransport());
105
+ log("MCP server ready on stdio");
106
+
107
+ const shutdown = () => {
108
+ wss.close();
109
+ process.exit(0);
110
+ };
111
+ process.stdin.on("close", shutdown);
112
+ process.on("SIGINT", shutdown);
113
+ process.on("SIGTERM", shutdown);
package/tools.mjs ADDED
@@ -0,0 +1,138 @@
1
+ // Board tools shared by the local stdio server (server.mjs) and the hosted endpoint (api/mcp.js).
2
+ // `call(method, params)` delivers one command to the open board tab and resolves with its result.
3
+ import { z } from "zod";
4
+
5
+ export const INSTRUCTIONS = [
6
+ "Tools for reading and editing the user's open whiteboard (an infinite canvas).",
7
+ "Coordinates are world units: 1 unit = 1 px at 100% zoom, x grows right, y grows down. Elements have x/y (top-left) and w/h.",
8
+ "Typical sizes: sticky 180×180, shape 160×110, frame 800×500, text 20px font. Leave ~40–80 units between items.",
9
+ "Start with get_board to see what exists; omit x/y when creating to place items in free space to the right of existing content.",
10
+ "Connectors attach to elements via from/to (ids, or refs defined earlier in the same create_elements call) and follow them when they move.",
11
+ "Each create/update/delete call is one undo step for the user. Use get_screenshot to check the visual result.",
12
+ ].join(" ");
13
+
14
+ const asText = (value) => ({ content: [{ type: "text", text: JSON.stringify(value, null, 1) }] });
15
+ const asError = (e) => ({ isError: true, content: [{ type: "text", text: e instanceof Error ? e.message : String(e) }] });
16
+ const relayVia = (call) => (method) => async (params) => {
17
+ try {
18
+ return asText(await call(method, params));
19
+ } catch (e) {
20
+ return asError(e);
21
+ }
22
+ };
23
+
24
+ /**
25
+ * @param {import("@modelcontextprotocol/sdk/server/mcp.js").McpServer} server
26
+ * @param {(method: string, params?: object) => Promise<any>} call
27
+ */
28
+ export function registerBoardTools(server, call) {
29
+ const relay = relayVia(call);
30
+ const color = z.string().describe("Hex colour (#rrggbb) or a name: yellow, orange, pink, purple, blue, green, lime, gray, white, black, red, darkblue, darkgreen");
31
+ const point = z.tuple([z.number(), z.number()]);
32
+ const common = {
33
+ x: z.number().optional().describe("Left edge (world units). Omit x and y to auto-place in free space"),
34
+ y: z.number().optional().describe("Top edge (world units)"),
35
+ w: z.number().positive().optional(),
36
+ h: z.number().positive().optional(),
37
+ text: z.string().optional().describe("Text for sticky, shape and text elements (plain text, \\n for new lines)"),
38
+ title: z.string().optional().describe("Frame title"),
39
+ color: color.optional().describe("Sticky/frame: background. Text/shape: text colour. Connector/stroke: line colour"),
40
+ fill: z.string().optional().describe('Shape fill colour, or "none"'),
41
+ stroke: color.optional().describe("Shape border colour"),
42
+ kind: z.enum(["rect", "roundrect", "ellipse", "diamond", "triangle"]).optional().describe("Shape kind (default rect)"),
43
+ fontSize: z.number().positive().optional(),
44
+ align: z.enum(["left", "center", "right"]).optional(),
45
+ bold: z.boolean().optional(),
46
+ angle: z.number().optional().describe("Rotation in degrees, clockwise"),
47
+ from: z.string().optional().describe("Connector start: element id or ref"),
48
+ to: z.string().optional().describe("Connector end: element id or ref"),
49
+ fromPoint: point.optional().describe("Connector start as [x, y] when not attached"),
50
+ toPoint: point.optional().describe("Connector end as [x, y] when not attached"),
51
+ route: z.enum(["straight", "elbow", "curved"]).optional(),
52
+ label: z.string().optional().describe("Connector label"),
53
+ endHead: z.enum(["none", "open", "filled"]).optional(),
54
+ startHead: z.enum(["none", "open", "filled"]).optional(),
55
+ dash: z.enum(["solid", "dashed", "dotted"]).optional(),
56
+ };
57
+
58
+ server.registerTool("get_board", {
59
+ title: "Read the board",
60
+ description: "Lists the board's elements (id, type, position, size, text, colours, frame membership, connector endpoints), the visible viewport, content bounds and current selection.",
61
+ inputSchema: {
62
+ type: z.enum(["sticky", "shape", "text", "frame", "connector", "stroke", "image"]).optional().describe("Only list this element type"),
63
+ limit: z.number().int().positive().max(5000).optional().describe("Maximum elements to return (default 500)"),
64
+ },
65
+ annotations: { readOnlyHint: true },
66
+ }, relay("get_board"));
67
+
68
+ server.registerTool("create_elements", {
69
+ title: "Create elements",
70
+ description:
71
+ "Creates sticky notes, shapes, text, frames, connectors and pen strokes in one undoable step. " +
72
+ "Give elements a `ref` to connect them in the same call, e.g. [{type:'sticky',ref:'a',text:'Idea'},{type:'sticky',ref:'b',text:'Plan'},{type:'connector',from:'a',to:'b'}]. " +
73
+ "Elements placed at least half inside a frame automatically belong to it. Returns the new ids.",
74
+ inputSchema: {
75
+ elements: z.array(z.object({
76
+ type: z.enum(["sticky", "shape", "text", "frame", "connector", "stroke"]),
77
+ ref: z.string().optional().describe("Your own key for referring to this element later in the same call"),
78
+ ...common,
79
+ points: z.array(point).optional().describe("Stroke points [[x, y], …] in world units"),
80
+ width: z.number().positive().optional().describe("Stroke width"),
81
+ })).min(1).max(500),
82
+ },
83
+ }, relay("create_elements"));
84
+
85
+ server.registerTool("update_elements", {
86
+ title: "Update elements",
87
+ description: "Moves, resizes, recolours, retexts or rewires existing elements (one undoable step). Only the fields you pass change. Set locked to stop the user moving an element.",
88
+ inputSchema: {
89
+ updates: z.array(z.object({ id: z.string(), ...common, locked: z.boolean().optional() })).min(1).max(1000),
90
+ },
91
+ }, relay("update_elements"));
92
+
93
+ server.registerTool("delete_elements", {
94
+ title: "Delete elements",
95
+ description: "Deletes elements by id (deleting a frame deletes its contents). Pass all: true to clear the board. One undoable step.",
96
+ inputSchema: {
97
+ ids: z.array(z.string()).optional(),
98
+ all: z.boolean().optional().describe("Delete everything on the board"),
99
+ },
100
+ annotations: { destructiveHint: true },
101
+ }, relay("delete_elements"));
102
+
103
+ server.registerTool("focus_view", {
104
+ title: "Move the view",
105
+ description: "Pans/zooms the user's view: fit the given element ids, centre on x/y (optionally at a zoom), set a zoom level, or with no arguments fit the whole board.",
106
+ inputSchema: {
107
+ ids: z.array(z.string()).optional(),
108
+ x: z.number().optional(),
109
+ y: z.number().optional(),
110
+ zoom: z.number().positive().max(8).optional().describe("1 = 100%"),
111
+ },
112
+ }, relay("focus_view"));
113
+
114
+ server.registerTool("select_elements", {
115
+ title: "Select elements",
116
+ description: "Highlights elements for the user by selecting them (empty list clears the selection).",
117
+ inputSchema: { ids: z.array(z.string()) },
118
+ }, relay("select"));
119
+
120
+ server.registerTool("undo", { title: "Undo", description: "Undoes the last change on the board (the user's or the assistant's).", inputSchema: {} }, relay("undo"));
121
+ server.registerTool("redo", { title: "Redo", description: "Redoes the last undone change.", inputSchema: {} }, relay("redo"));
122
+
123
+ server.registerTool("get_screenshot", {
124
+ title: "Screenshot the board",
125
+ description: "Returns a PNG of what the user currently sees. Use focus_view first to frame the area you want to check.",
126
+ inputSchema: { maxWidth: z.number().int().min(200).max(2400).optional().describe("Maximum image width in pixels (default 1280)") },
127
+ annotations: { readOnlyHint: true },
128
+ }, async (params) => {
129
+ try {
130
+ const { image } = await call("screenshot", params);
131
+ const m = /^data:(image\/\w+);base64,(.*)$/s.exec(image ?? "");
132
+ if (!m) throw new Error("The board returned no image");
133
+ return { content: [{ type: "image", mimeType: m[1], data: m[2] }] };
134
+ } catch (e) {
135
+ return asError(e);
136
+ }
137
+ });
138
+ }