@muloka/figma-console-mcp 0.5.4 → 0.5.5

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 (93) hide show
  1. package/dist/apps/design-system-dashboard/mcp-app.html +26 -26
  2. package/dist/apps/token-browser/mcp-app.html +34 -34
  3. package/dist/core/http-request-guard.js +1 -1
  4. package/dist/core/http-request-guard.js.map +1 -1
  5. package/dist/core/write-tools.js +1 -1
  6. package/package.json +1 -1
  7. package/dist/cloudflare/apps/design-system-dashboard/scoring/accessibility.js +0 -277
  8. package/dist/cloudflare/apps/design-system-dashboard/scoring/component-metadata.js +0 -357
  9. package/dist/cloudflare/apps/design-system-dashboard/scoring/consistency.js +0 -341
  10. package/dist/cloudflare/apps/design-system-dashboard/scoring/coverage.js +0 -230
  11. package/dist/cloudflare/apps/design-system-dashboard/scoring/engine.js +0 -92
  12. package/dist/cloudflare/apps/design-system-dashboard/scoring/naming-semantics.js +0 -308
  13. package/dist/cloudflare/apps/design-system-dashboard/scoring/token-architecture.js +0 -349
  14. package/dist/cloudflare/apps/design-system-dashboard/scoring/types.js +0 -40
  15. package/dist/cloudflare/apps/design-system-dashboard/server.js +0 -159
  16. package/dist/cloudflare/apps/token-browser/server.js +0 -136
  17. package/dist/cloudflare/browser-manager.js +0 -157
  18. package/dist/cloudflare/core/accessibility-tools.js +0 -361
  19. package/dist/cloudflare/core/annotation-tools.js +0 -230
  20. package/dist/cloudflare/core/cloud-websocket-connector.js +0 -419
  21. package/dist/cloudflare/core/cloud-websocket-relay.js +0 -198
  22. package/dist/cloudflare/core/comment-tools.js +0 -292
  23. package/dist/cloudflare/core/config.js +0 -153
  24. package/dist/cloudflare/core/console-monitor.js +0 -427
  25. package/dist/cloudflare/core/deep-component-tools.js +0 -128
  26. package/dist/cloudflare/core/design-code-tools.js +0 -2793
  27. package/dist/cloudflare/core/design-system-manifest.js +0 -265
  28. package/dist/cloudflare/core/design-system-tools.js +0 -882
  29. package/dist/cloudflare/core/diagnose-tool.js +0 -100
  30. package/dist/cloudflare/core/diff/changelog-formatter.js +0 -275
  31. package/dist/cloudflare/core/diff/diff-engine.js +0 -334
  32. package/dist/cloudflare/core/diff/property-compare.js +0 -36
  33. package/dist/cloudflare/core/diff/version-cache.js +0 -74
  34. package/dist/cloudflare/core/enrichment/enrichment-service.js +0 -374
  35. package/dist/cloudflare/core/enrichment/index.js +0 -7
  36. package/dist/cloudflare/core/enrichment/relationship-mapper.js +0 -351
  37. package/dist/cloudflare/core/enrichment/style-resolver.js +0 -346
  38. package/dist/cloudflare/core/figjam-tools.js +0 -547
  39. package/dist/cloudflare/core/figma-api.js +0 -509
  40. package/dist/cloudflare/core/figma-connector.js +0 -7
  41. package/dist/cloudflare/core/figma-reconstruction-spec.js +0 -402
  42. package/dist/cloudflare/core/figma-style-extractor.js +0 -311
  43. package/dist/cloudflare/core/figma-tools.js +0 -3353
  44. package/dist/cloudflare/core/identity.js +0 -96
  45. package/dist/cloudflare/core/library-tools.js +0 -580
  46. package/dist/cloudflare/core/logger.js +0 -53
  47. package/dist/cloudflare/core/port-discovery.js +0 -935
  48. package/dist/cloudflare/core/resolve-package-root.js +0 -11
  49. package/dist/cloudflare/core/slides-tools.js +0 -714
  50. package/dist/cloudflare/core/slot-tools.js +0 -334
  51. package/dist/cloudflare/core/snippet-injector.js +0 -96
  52. package/dist/cloudflare/core/tokens/alias-resolver.js +0 -205
  53. package/dist/cloudflare/core/tokens/config.js +0 -294
  54. package/dist/cloudflare/core/tokens/dialect.js +0 -232
  55. package/dist/cloudflare/core/tokens/figma-converter.js +0 -323
  56. package/dist/cloudflare/core/tokens/formatters/css-vars.js +0 -338
  57. package/dist/cloudflare/core/tokens/formatters/dtcg.js +0 -376
  58. package/dist/cloudflare/core/tokens/formatters/index.js +0 -45
  59. package/dist/cloudflare/core/tokens/formatters/json.js +0 -205
  60. package/dist/cloudflare/core/tokens/formatters/less.js +0 -4
  61. package/dist/cloudflare/core/tokens/formatters/scss.js +0 -258
  62. package/dist/cloudflare/core/tokens/formatters/stubs.js +0 -13
  63. package/dist/cloudflare/core/tokens/formatters/style-dictionary-v3.js +0 -213
  64. package/dist/cloudflare/core/tokens/formatters/tailwind-v3.js +0 -237
  65. package/dist/cloudflare/core/tokens/formatters/tailwind-v4.js +0 -335
  66. package/dist/cloudflare/core/tokens/formatters/tokens-studio.js +0 -256
  67. package/dist/cloudflare/core/tokens/formatters/ts-module.js +0 -198
  68. package/dist/cloudflare/core/tokens/index.js +0 -16
  69. package/dist/cloudflare/core/tokens/parsers/css-vars.js +0 -4
  70. package/dist/cloudflare/core/tokens/parsers/dtcg.js +0 -280
  71. package/dist/cloudflare/core/tokens/parsers/index.js +0 -138
  72. package/dist/cloudflare/core/tokens/parsers/json.js +0 -7
  73. package/dist/cloudflare/core/tokens/parsers/scss.js +0 -4
  74. package/dist/cloudflare/core/tokens/parsers/stubs.js +0 -20
  75. package/dist/cloudflare/core/tokens/parsers/style-dictionary-v3.js +0 -4
  76. package/dist/cloudflare/core/tokens/parsers/tailwind-v3.js +0 -4
  77. package/dist/cloudflare/core/tokens/parsers/tailwind-v4.js +0 -4
  78. package/dist/cloudflare/core/tokens/parsers/tokens-studio.js +0 -4
  79. package/dist/cloudflare/core/tokens/schemas.js +0 -152
  80. package/dist/cloudflare/core/tokens/transforms/color.js +0 -12
  81. package/dist/cloudflare/core/tokens/transforms/index.js +0 -29
  82. package/dist/cloudflare/core/tokens/transforms/size.js +0 -7
  83. package/dist/cloudflare/core/tokens/types.js +0 -18
  84. package/dist/cloudflare/core/tokens-tools.js +0 -1788
  85. package/dist/cloudflare/core/types/design-code.js +0 -4
  86. package/dist/cloudflare/core/types/enriched.js +0 -5
  87. package/dist/cloudflare/core/types/index.js +0 -4
  88. package/dist/cloudflare/core/variable-resolver.js +0 -85
  89. package/dist/cloudflare/core/version-tools.js +0 -1199
  90. package/dist/cloudflare/core/websocket-connector.js +0 -436
  91. package/dist/cloudflare/core/websocket-server.js +0 -1009
  92. package/dist/cloudflare/core/write-tools.js +0 -2506
  93. package/dist/cloudflare/index.js +0 -3010
@@ -1,547 +0,0 @@
1
- import { z } from "zod";
2
- import { createChildLogger } from "./logger.js";
3
- const logger = createChildLogger({ component: "figjam-tools" });
4
- /** Valid sticky note colors */
5
- const STICKY_COLORS = [
6
- "YELLOW",
7
- "BLUE",
8
- "GREEN",
9
- "PINK",
10
- "ORANGE",
11
- "PURPLE",
12
- "RED",
13
- "LIGHT_GRAY",
14
- "GRAY",
15
- ];
16
- /** Valid FigJam shape types */
17
- const SHAPE_TYPES = [
18
- "ROUNDED_RECTANGLE",
19
- "DIAMOND",
20
- "ELLIPSE",
21
- "TRIANGLE_UP",
22
- "TRIANGLE_DOWN",
23
- "PARALLELOGRAM_RIGHT",
24
- "PARALLELOGRAM_LEFT",
25
- "ENG_DATABASE",
26
- "ENG_QUEUE",
27
- "ENG_FILE",
28
- "ENG_FOLDER",
29
- ];
30
- /** Valid FigJam node types for board content filtering */
31
- const FIGJAM_NODE_TYPES = [
32
- "STICKY",
33
- "SHAPE_WITH_TEXT",
34
- "CONNECTOR",
35
- "TABLE",
36
- "CODE_BLOCK",
37
- "SECTION",
38
- "FRAME",
39
- "TEXT",
40
- ];
41
- /** Maximum items for batch operations to prevent DoS / plugin timeouts */
42
- const MAX_BATCH_SIZE = 200;
43
- /** Maximum table dimensions */
44
- const MAX_TABLE_ROWS = 100;
45
- const MAX_TABLE_COLUMNS = 50;
46
- /** Maximum text length per field */
47
- const MAX_TEXT_LENGTH = 5000;
48
- /** Maximum code block length */
49
- const MAX_CODE_LENGTH = 50000;
50
- /** Maximum node IDs for arrangement */
51
- const MAX_ARRANGE_NODES = 500;
52
- /** Maximum nodes to return from board content reads */
53
- const MAX_READ_NODES = 1000;
54
- /**
55
- * Register FigJam-specific tools.
56
- * These tools only work when the connected file is a FigJam board (editorType === 'figjam').
57
- * Used by both local mode (src/local.ts) and cloud mode (src/index.ts).
58
- */
59
- export function registerFigJamTools(server, getDesktopConnector) {
60
- // ============================================================================
61
- // STICKY NOTE TOOLS
62
- // ============================================================================
63
- server.tool("figjam_create_sticky", `Create a sticky note on a FigJam board. Only works in FigJam files.
64
-
65
- **Colors:** YELLOW, BLUE, GREEN, PINK, ORANGE, PURPLE, RED, LIGHT_GRAY, GRAY (default: YELLOW)`, {
66
- text: z
67
- .string()
68
- .max(MAX_TEXT_LENGTH)
69
- .describe("Text content for the sticky note"),
70
- color: z
71
- .enum(STICKY_COLORS)
72
- .optional()
73
- .describe("Sticky color"),
74
- x: z.number().optional().describe("X position on canvas"),
75
- y: z.number().optional().describe("Y position on canvas"),
76
- }, async ({ text, color, x, y }) => {
77
- try {
78
- const connector = await getDesktopConnector();
79
- const result = await connector.createSticky({ text, color, x, y });
80
- return {
81
- content: [{ type: "text", text: JSON.stringify(result) }],
82
- };
83
- }
84
- catch (error) {
85
- logger.error({ error }, "figjam_create_sticky failed");
86
- return {
87
- content: [
88
- {
89
- type: "text",
90
- text: JSON.stringify({
91
- error: error instanceof Error ? error.message : String(error),
92
- hint: "This tool only works in FigJam files. Make sure the Desktop Bridge plugin is running in a FigJam board.",
93
- }),
94
- },
95
- ],
96
- isError: true,
97
- };
98
- }
99
- });
100
- server.tool("figjam_create_stickies", `Batch create multiple sticky notes on a FigJam board (max ${MAX_BATCH_SIZE}). Use this to populate boards from structured data (meeting notes, brainstorm ideas, etc.).
101
-
102
- **Colors:** YELLOW, BLUE, GREEN, PINK, ORANGE, PURPLE, RED, LIGHT_GRAY, GRAY`, {
103
- stickies: z
104
- .array(z.object({
105
- text: z.string().max(MAX_TEXT_LENGTH).describe("Text content"),
106
- color: z.enum(STICKY_COLORS).optional().describe("Sticky color"),
107
- x: z.number().optional().describe("X position"),
108
- y: z.number().optional().describe("Y position"),
109
- }))
110
- .max(MAX_BATCH_SIZE)
111
- .describe(`Array of sticky note specifications (max ${MAX_BATCH_SIZE})`),
112
- }, async ({ stickies }) => {
113
- try {
114
- const connector = await getDesktopConnector();
115
- const result = await connector.createStickies({ stickies });
116
- return {
117
- content: [{ type: "text", text: JSON.stringify(result) }],
118
- };
119
- }
120
- catch (error) {
121
- logger.error({ error }, "figjam_create_stickies failed");
122
- return {
123
- content: [
124
- {
125
- type: "text",
126
- text: JSON.stringify({
127
- error: error instanceof Error ? error.message : String(error),
128
- hint: "This tool only works in FigJam files.",
129
- }),
130
- },
131
- ],
132
- isError: true,
133
- };
134
- }
135
- });
136
- // ============================================================================
137
- // CONNECTOR TOOL
138
- // ============================================================================
139
- server.tool("figjam_create_connector", `Connect two nodes with a connector line in FigJam. Use to create flowcharts, diagrams, and relationship maps.
140
-
141
- Nodes must exist on the board (stickies, shapes, etc.). Use their node IDs from creation results.
142
-
143
- **Magnet positions:** AUTO (default), TOP, BOTTOM, LEFT, RIGHT — controls where the connector attaches to each node.`, {
144
- startNodeId: z.string().describe("Node ID of the start element"),
145
- endNodeId: z.string().describe("Node ID of the end element"),
146
- label: z
147
- .string()
148
- .max(MAX_TEXT_LENGTH)
149
- .optional()
150
- .describe("Optional text label on the connector"),
151
- startMagnet: z
152
- .enum(["AUTO", "TOP", "BOTTOM", "LEFT", "RIGHT"])
153
- .optional()
154
- .default("AUTO")
155
- .describe("Magnet position on the start node"),
156
- endMagnet: z
157
- .enum(["AUTO", "TOP", "BOTTOM", "LEFT", "RIGHT"])
158
- .optional()
159
- .default("AUTO")
160
- .describe("Magnet position on the end node"),
161
- }, async ({ startNodeId, endNodeId, label, startMagnet, endMagnet }) => {
162
- try {
163
- const connector = await getDesktopConnector();
164
- const result = await connector.createConnector({
165
- startNodeId,
166
- endNodeId,
167
- label,
168
- startMagnet,
169
- endMagnet,
170
- });
171
- return {
172
- content: [{ type: "text", text: JSON.stringify(result) }],
173
- };
174
- }
175
- catch (error) {
176
- logger.error({ error }, "figjam_create_connector failed");
177
- return {
178
- content: [
179
- {
180
- type: "text",
181
- text: JSON.stringify({
182
- error: error instanceof Error ? error.message : String(error),
183
- hint: "This tool only works in FigJam files. Both start and end nodes must exist.",
184
- }),
185
- },
186
- ],
187
- isError: true,
188
- };
189
- }
190
- });
191
- // ============================================================================
192
- // SHAPE WITH TEXT TOOL
193
- // ============================================================================
194
- server.tool("figjam_create_shape_with_text", `Create a labeled shape on a FigJam board with optional size, colors, and font control. Use for flowchart nodes, process diagrams, and visual organization.
195
-
196
- **Shape types:** ROUNDED_RECTANGLE (default), DIAMOND, ELLIPSE, TRIANGLE_UP, TRIANGLE_DOWN, PARALLELOGRAM_RIGHT, PARALLELOGRAM_LEFT, ENG_DATABASE, ENG_QUEUE, ENG_FILE, ENG_FOLDER`, {
197
- text: z
198
- .string()
199
- .max(MAX_TEXT_LENGTH)
200
- .optional()
201
- .describe("Text label for the shape"),
202
- shapeType: z
203
- .enum(SHAPE_TYPES)
204
- .optional()
205
- .describe("Shape type"),
206
- x: z.number().optional().describe("X position on canvas"),
207
- y: z.number().optional().describe("Y position on canvas"),
208
- width: z.number().min(1).max(10000).optional().describe("Width in pixels"),
209
- height: z.number().min(1).max(10000).optional().describe("Height in pixels"),
210
- fillColor: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional().describe("Fill color as hex (e.g., '#E1F5EE')"),
211
- strokeColor: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional().describe("Stroke/border color as hex"),
212
- fontSize: z.number().min(1).max(200).optional().describe("Text font size in pixels"),
213
- strokeDashPattern: z.string().optional().describe("Dash pattern as comma-separated numbers (e.g., '10,5' for dashed)"),
214
- }, async ({ text, shapeType, x, y, width, height, fillColor, strokeColor, fontSize, strokeDashPattern }) => {
215
- try {
216
- const connector = await getDesktopConnector();
217
- const result = await connector.createShapeWithText({
218
- text,
219
- shapeType,
220
- x,
221
- y,
222
- width,
223
- height,
224
- fillColor,
225
- strokeColor,
226
- fontSize,
227
- strokeDashPattern,
228
- });
229
- return {
230
- content: [{ type: "text", text: JSON.stringify(result) }],
231
- };
232
- }
233
- catch (error) {
234
- logger.error({ error }, "figjam_create_shape_with_text failed");
235
- return {
236
- content: [
237
- {
238
- type: "text",
239
- text: JSON.stringify({
240
- error: error instanceof Error ? error.message : String(error),
241
- hint: "This tool only works in FigJam files.",
242
- }),
243
- },
244
- ],
245
- isError: true,
246
- };
247
- }
248
- });
249
- // ============================================================================
250
- // SECTION TOOL
251
- // ============================================================================
252
- server.tool("figjam_create_section", `Create a section on a FigJam board. Sections are containers that can hold other elements. Use for grouping related content.\n\n**Note:** After creating a section, place elements inside it by setting their x/y coordinates within the section's bounds, then use figma_execute to call section.appendChild(node) to parent them.`, {
253
- name: z.string().max(500).optional().describe("Section name/title"),
254
- x: z.number().optional().describe("X position on canvas"),
255
- y: z.number().optional().describe("Y position on canvas"),
256
- width: z.number().min(1).max(20000).optional().default(1000).describe("Section width in pixels"),
257
- height: z.number().min(1).max(20000).optional().default(800).describe("Section height in pixels"),
258
- fillColor: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional().describe("Fill color as hex"),
259
- }, async ({ name, x, y, width, height, fillColor }) => {
260
- try {
261
- const connector = await getDesktopConnector();
262
- const result = await connector.createSection({
263
- name, x, y, width, height, fillColor,
264
- });
265
- return {
266
- content: [{ type: "text", text: JSON.stringify(result) }],
267
- };
268
- }
269
- catch (error) {
270
- logger.error({ error }, "figjam_create_section failed");
271
- return {
272
- content: [
273
- {
274
- type: "text",
275
- text: JSON.stringify({
276
- error: error instanceof Error ? error.message : String(error),
277
- hint: "This tool only works in FigJam files.",
278
- }),
279
- },
280
- ],
281
- isError: true,
282
- };
283
- }
284
- });
285
- // ============================================================================
286
- // TABLE TOOL
287
- // ============================================================================
288
- server.tool("figjam_create_table", `Create a table on a FigJam board with optional cell data. Use for structured data display, comparison matrices, and organized information.
289
-
290
- **Data format:** 2D array of strings, e.g. [["Header1", "Header2"], ["Row1Col1", "Row1Col2"]]`, {
291
- rows: z
292
- .number()
293
- .min(1)
294
- .max(MAX_TABLE_ROWS)
295
- .describe(`Number of rows (1-${MAX_TABLE_ROWS})`),
296
- columns: z
297
- .number()
298
- .min(1)
299
- .max(MAX_TABLE_COLUMNS)
300
- .describe(`Number of columns (1-${MAX_TABLE_COLUMNS})`),
301
- data: z
302
- .array(z.array(z.string().max(MAX_TEXT_LENGTH)))
303
- .optional()
304
- .describe("2D array of cell text content (row-major order)"),
305
- x: z.number().optional().describe("X position on canvas"),
306
- y: z.number().optional().describe("Y position on canvas"),
307
- }, async ({ rows, columns, data, x, y }) => {
308
- try {
309
- const connector = await getDesktopConnector();
310
- const result = await connector.createTable({
311
- rows,
312
- columns,
313
- data,
314
- x,
315
- y,
316
- });
317
- return {
318
- content: [{ type: "text", text: JSON.stringify(result) }],
319
- };
320
- }
321
- catch (error) {
322
- logger.error({ error }, "figjam_create_table failed");
323
- return {
324
- content: [
325
- {
326
- type: "text",
327
- text: JSON.stringify({
328
- error: error instanceof Error ? error.message : String(error),
329
- hint: "This tool only works in FigJam files.",
330
- }),
331
- },
332
- ],
333
- isError: true,
334
- };
335
- }
336
- });
337
- // ============================================================================
338
- // CODE BLOCK TOOL
339
- // ============================================================================
340
- server.tool("figjam_create_code_block", `Create a code block on a FigJam board. Use for sharing code snippets, config examples, or technical documentation in collaborative boards.`, {
341
- code: z.string().max(MAX_CODE_LENGTH).describe("The code content"),
342
- language: z
343
- .string()
344
- .optional()
345
- .describe("Programming language (e.g., 'JAVASCRIPT', 'PYTHON', 'TYPESCRIPT', 'JSON', 'HTML', 'CSS')"),
346
- x: z.number().optional().describe("X position on canvas"),
347
- y: z.number().optional().describe("Y position on canvas"),
348
- }, async ({ code, language, x, y }) => {
349
- try {
350
- const connector = await getDesktopConnector();
351
- const result = await connector.createCodeBlock({
352
- code,
353
- language,
354
- x,
355
- y,
356
- });
357
- return {
358
- content: [{ type: "text", text: JSON.stringify(result) }],
359
- };
360
- }
361
- catch (error) {
362
- logger.error({ error }, "figjam_create_code_block failed");
363
- return {
364
- content: [
365
- {
366
- type: "text",
367
- text: JSON.stringify({
368
- error: error instanceof Error ? error.message : String(error),
369
- hint: "This tool only works in FigJam files.",
370
- }),
371
- },
372
- ],
373
- isError: true,
374
- };
375
- }
376
- });
377
- // ============================================================================
378
- // LAYOUT HELPER TOOL
379
- // ============================================================================
380
- server.tool("figjam_auto_arrange", `Arrange nodes on a FigJam board in a grid, horizontal row, or vertical column layout. Use after batch-creating elements to organize them neatly.`, {
381
- nodeIds: z
382
- .array(z.string())
383
- .max(MAX_ARRANGE_NODES)
384
- .describe(`Array of node IDs to arrange (max ${MAX_ARRANGE_NODES})`),
385
- layout: z
386
- .enum(["grid", "horizontal", "vertical"])
387
- .optional()
388
- .default("grid")
389
- .describe("Layout type: grid, horizontal, or vertical"),
390
- spacing: z
391
- .number()
392
- .optional()
393
- .default(40)
394
- .describe("Spacing between nodes in pixels"),
395
- columns: z
396
- .number()
397
- .optional()
398
- .describe("Number of columns for grid layout (defaults to sqrt of node count)"),
399
- }, async ({ nodeIds, layout, spacing, columns }) => {
400
- try {
401
- const connector = await getDesktopConnector();
402
- // Compute grid columns safely on the server side — no string interpolation
403
- const gridCols = columns || Math.ceil(Math.sqrt(nodeIds.length));
404
- // Pass all parameters as a JSON object to avoid code injection.
405
- // The plugin code reads from the params object, not interpolated strings.
406
- const paramsJson = JSON.stringify({
407
- nodeIds,
408
- layout,
409
- spacing,
410
- gridCols,
411
- });
412
- // Use JSON.stringify to produce a properly-escaped double-quoted JS string literal.
413
- // This handles all control characters including \u2028/\u2029 that manual
414
- // single-quote escaping would miss.
415
- const code = `
416
- const params = JSON.parse(${JSON.stringify(paramsJson)});
417
- const nodes = [];
418
- for (const id of params.nodeIds) {
419
- const node = await figma.getNodeByIdAsync(id);
420
- if (node) nodes.push(node);
421
- }
422
- if (nodes.length === 0) throw new Error('No valid nodes found');
423
-
424
- let x = nodes[0].x;
425
- let y = nodes[0].y;
426
- const startX = x;
427
- let maxRowHeight = 0;
428
-
429
- for (let i = 0; i < nodes.length; i++) {
430
- const node = nodes[i];
431
- if (params.layout === 'horizontal') {
432
- node.x = x;
433
- node.y = y;
434
- x += node.width + params.spacing;
435
- } else if (params.layout === 'vertical') {
436
- node.x = x;
437
- node.y = y;
438
- y += node.height + params.spacing;
439
- } else {
440
- const col = i % params.gridCols;
441
- if (col === 0 && i > 0) {
442
- y += maxRowHeight + params.spacing;
443
- maxRowHeight = 0;
444
- x = startX;
445
- }
446
- node.x = x;
447
- node.y = y;
448
- maxRowHeight = Math.max(maxRowHeight, node.height);
449
- x += node.width + params.spacing;
450
- }
451
- }
452
- return { arranged: nodes.length, layout: params.layout };
453
- `;
454
- const result = await connector.executeCodeViaUI(code, 10000);
455
- return {
456
- content: [{ type: "text", text: JSON.stringify(result) }],
457
- };
458
- }
459
- catch (error) {
460
- logger.error({ error }, "figjam_auto_arrange failed");
461
- return {
462
- content: [
463
- {
464
- type: "text",
465
- text: JSON.stringify({
466
- error: error instanceof Error ? error.message : String(error),
467
- hint: "Make sure all node IDs are valid and the Desktop Bridge plugin is running.",
468
- }),
469
- },
470
- ],
471
- isError: true,
472
- };
473
- }
474
- });
475
- // ============================================================================
476
- // READ TOOLS — Query existing FigJam board content
477
- // ============================================================================
478
- server.tool("figjam_get_board_contents", `Read all content from a FigJam board. Returns stickies, shapes, connectors, tables, code blocks, and sections with their text content and positions.
479
-
480
- Use this to understand what's on a board before modifying it, or to extract structured data from collaborative sessions.
481
-
482
- **Filters:** Pass nodeTypes to limit results (e.g., ["STICKY"] for only stickies). Omit for everything.`, {
483
- nodeTypes: z
484
- .array(z.enum(FIGJAM_NODE_TYPES))
485
- .optional()
486
- .describe("Filter by node types. Omit for all."),
487
- maxNodes: z
488
- .number()
489
- .min(1)
490
- .max(MAX_READ_NODES)
491
- .optional()
492
- .default(500)
493
- .describe(`Maximum nodes to return (1-${MAX_READ_NODES}, default: 500)`),
494
- }, async ({ nodeTypes, maxNodes }) => {
495
- try {
496
- const connector = await getDesktopConnector();
497
- const result = await connector.getBoardContents({
498
- nodeTypes,
499
- maxNodes,
500
- });
501
- return {
502
- content: [{ type: "text", text: JSON.stringify(result) }],
503
- };
504
- }
505
- catch (error) {
506
- logger.error({ error }, "figjam_get_board_contents failed");
507
- return {
508
- content: [
509
- {
510
- type: "text",
511
- text: JSON.stringify({
512
- error: error instanceof Error ? error.message : String(error),
513
- hint: "This tool only works in FigJam files. Make sure the Desktop Bridge plugin is running in a FigJam board.",
514
- }),
515
- },
516
- ],
517
- isError: true,
518
- };
519
- }
520
- });
521
- server.tool("figjam_get_connections", `Read the connection graph from a FigJam board. Returns all connectors with their start/end node references and labels.
522
-
523
- Use this to understand relationships, flowcharts, and diagrams. Returns edges as {startNodeId, endNodeId, label} plus a summary of connected nodes.`, {}, async () => {
524
- try {
525
- const connector = await getDesktopConnector();
526
- const result = await connector.getConnections();
527
- return {
528
- content: [{ type: "text", text: JSON.stringify(result) }],
529
- };
530
- }
531
- catch (error) {
532
- logger.error({ error }, "figjam_get_connections failed");
533
- return {
534
- content: [
535
- {
536
- type: "text",
537
- text: JSON.stringify({
538
- error: error instanceof Error ? error.message : String(error),
539
- hint: "This tool only works in FigJam files. Make sure the Desktop Bridge plugin is running in a FigJam board.",
540
- }),
541
- },
542
- ],
543
- isError: true,
544
- };
545
- }
546
- });
547
- }