figma-console-mcp 1.17.0 → 1.17.2
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/dist/cloudflare/core/cloud-websocket-connector.js +75 -0
- package/dist/cloudflare/core/figjam-tools.js +485 -0
- package/dist/cloudflare/core/figma-desktop-connector.js +25 -0
- package/dist/cloudflare/core/figma-tools.js +4 -1
- package/dist/cloudflare/core/slides-tools.js +607 -0
- package/dist/cloudflare/core/websocket-connector.js +75 -0
- package/dist/cloudflare/core/websocket-server.js +11 -0
- package/dist/cloudflare/index.js +29 -7
- package/dist/core/figma-tools.d.ts.map +1 -1
- package/dist/core/figma-tools.js +90 -29
- package/dist/core/figma-tools.js.map +1 -1
- package/figma-desktop-bridge/code.js +3 -1
- package/package.json +1 -1
|
@@ -244,6 +244,81 @@ export class CloudWebSocketConnector {
|
|
|
244
244
|
return this.sendCommand('LINT_DESIGN', params, 120000);
|
|
245
245
|
}
|
|
246
246
|
// ============================================================================
|
|
247
|
+
// FigJam operations
|
|
248
|
+
// ============================================================================
|
|
249
|
+
async createSticky(params) {
|
|
250
|
+
return this.sendCommand('CREATE_STICKY', params);
|
|
251
|
+
}
|
|
252
|
+
async createStickies(params) {
|
|
253
|
+
return this.sendCommand('CREATE_STICKIES', params, 30000);
|
|
254
|
+
}
|
|
255
|
+
async createConnector(params) {
|
|
256
|
+
return this.sendCommand('CREATE_CONNECTOR', params);
|
|
257
|
+
}
|
|
258
|
+
async createShapeWithText(params) {
|
|
259
|
+
return this.sendCommand('CREATE_SHAPE_WITH_TEXT', params);
|
|
260
|
+
}
|
|
261
|
+
async createTable(params) {
|
|
262
|
+
return this.sendCommand('CREATE_TABLE', params, 30000);
|
|
263
|
+
}
|
|
264
|
+
async createCodeBlock(params) {
|
|
265
|
+
return this.sendCommand('CREATE_CODE_BLOCK', params);
|
|
266
|
+
}
|
|
267
|
+
async getBoardContents(params) {
|
|
268
|
+
return this.sendCommand('GET_BOARD_CONTENTS', params, 30000);
|
|
269
|
+
}
|
|
270
|
+
async getConnections() {
|
|
271
|
+
return this.sendCommand('GET_CONNECTIONS', {}, 15000);
|
|
272
|
+
}
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Slides operations
|
|
275
|
+
// ============================================================================
|
|
276
|
+
async listSlides() {
|
|
277
|
+
return this.sendCommand('LIST_SLIDES', {}, 10000);
|
|
278
|
+
}
|
|
279
|
+
async getSlideContent(params) {
|
|
280
|
+
return this.sendCommand('GET_SLIDE_CONTENT', params, 10000);
|
|
281
|
+
}
|
|
282
|
+
async createSlide(params) {
|
|
283
|
+
return this.sendCommand('CREATE_SLIDE', params, 10000);
|
|
284
|
+
}
|
|
285
|
+
async deleteSlide(params) {
|
|
286
|
+
return this.sendCommand('DELETE_SLIDE', params, 5000);
|
|
287
|
+
}
|
|
288
|
+
async duplicateSlide(params) {
|
|
289
|
+
return this.sendCommand('DUPLICATE_SLIDE', params, 5000);
|
|
290
|
+
}
|
|
291
|
+
async getSlideGrid() {
|
|
292
|
+
return this.sendCommand('GET_SLIDE_GRID', {}, 10000);
|
|
293
|
+
}
|
|
294
|
+
async reorderSlides(params) {
|
|
295
|
+
return this.sendCommand('REORDER_SLIDES', params, 15000);
|
|
296
|
+
}
|
|
297
|
+
async setSlideTransition(params) {
|
|
298
|
+
return this.sendCommand('SET_SLIDE_TRANSITION', params, 5000);
|
|
299
|
+
}
|
|
300
|
+
async getSlideTransition(params) {
|
|
301
|
+
return this.sendCommand('GET_SLIDE_TRANSITION', params, 5000);
|
|
302
|
+
}
|
|
303
|
+
async setSlidesViewMode(params) {
|
|
304
|
+
return this.sendCommand('SET_SLIDES_VIEW_MODE', params, 5000);
|
|
305
|
+
}
|
|
306
|
+
async getFocusedSlide() {
|
|
307
|
+
return this.sendCommand('GET_FOCUSED_SLIDE', {}, 5000);
|
|
308
|
+
}
|
|
309
|
+
async focusSlide(params) {
|
|
310
|
+
return this.sendCommand('FOCUS_SLIDE', params, 5000);
|
|
311
|
+
}
|
|
312
|
+
async skipSlide(params) {
|
|
313
|
+
return this.sendCommand('SKIP_SLIDE', params, 5000);
|
|
314
|
+
}
|
|
315
|
+
async addTextToSlide(params) {
|
|
316
|
+
return this.sendCommand('ADD_TEXT_TO_SLIDE', params, 10000);
|
|
317
|
+
}
|
|
318
|
+
async addShapeToSlide(params) {
|
|
319
|
+
return this.sendCommand('ADD_SHAPE_TO_SLIDE', params, 5000);
|
|
320
|
+
}
|
|
321
|
+
// ============================================================================
|
|
247
322
|
// Cache management (no-op for cloud relay)
|
|
248
323
|
// ============================================================================
|
|
249
324
|
clearFrameCache() {
|
|
@@ -0,0 +1,485 @@
|
|
|
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
|
+
startNodeId: z.string().describe("Node ID of the start element"),
|
|
143
|
+
endNodeId: z.string().describe("Node ID of the end element"),
|
|
144
|
+
label: z
|
|
145
|
+
.string()
|
|
146
|
+
.max(MAX_TEXT_LENGTH)
|
|
147
|
+
.optional()
|
|
148
|
+
.describe("Optional text label on the connector"),
|
|
149
|
+
}, async ({ startNodeId, endNodeId, label }) => {
|
|
150
|
+
try {
|
|
151
|
+
const connector = await getDesktopConnector();
|
|
152
|
+
const result = await connector.createConnector({
|
|
153
|
+
startNodeId,
|
|
154
|
+
endNodeId,
|
|
155
|
+
label,
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
logger.error({ error }, "figjam_create_connector failed");
|
|
163
|
+
return {
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
type: "text",
|
|
167
|
+
text: JSON.stringify({
|
|
168
|
+
error: error instanceof Error ? error.message : String(error),
|
|
169
|
+
hint: "This tool only works in FigJam files. Both start and end nodes must exist.",
|
|
170
|
+
}),
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
isError: true,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// SHAPE WITH TEXT TOOL
|
|
179
|
+
// ============================================================================
|
|
180
|
+
server.tool("figjam_create_shape_with_text", `Create a labeled shape on a FigJam board. Use for flowchart nodes, process diagrams, and visual organization.
|
|
181
|
+
|
|
182
|
+
**Shape types:** ROUNDED_RECTANGLE (default), DIAMOND, ELLIPSE, TRIANGLE_UP, TRIANGLE_DOWN, PARALLELOGRAM_RIGHT, PARALLELOGRAM_LEFT, ENG_DATABASE, ENG_QUEUE, ENG_FILE, ENG_FOLDER`, {
|
|
183
|
+
text: z
|
|
184
|
+
.string()
|
|
185
|
+
.max(MAX_TEXT_LENGTH)
|
|
186
|
+
.optional()
|
|
187
|
+
.describe("Text label for the shape"),
|
|
188
|
+
shapeType: z
|
|
189
|
+
.enum(SHAPE_TYPES)
|
|
190
|
+
.optional()
|
|
191
|
+
.describe("Shape type"),
|
|
192
|
+
x: z.number().optional().describe("X position on canvas"),
|
|
193
|
+
y: z.number().optional().describe("Y position on canvas"),
|
|
194
|
+
}, async ({ text, shapeType, x, y }) => {
|
|
195
|
+
try {
|
|
196
|
+
const connector = await getDesktopConnector();
|
|
197
|
+
const result = await connector.createShapeWithText({
|
|
198
|
+
text,
|
|
199
|
+
shapeType,
|
|
200
|
+
x,
|
|
201
|
+
y,
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
logger.error({ error }, "figjam_create_shape_with_text failed");
|
|
209
|
+
return {
|
|
210
|
+
content: [
|
|
211
|
+
{
|
|
212
|
+
type: "text",
|
|
213
|
+
text: JSON.stringify({
|
|
214
|
+
error: error instanceof Error ? error.message : String(error),
|
|
215
|
+
hint: "This tool only works in FigJam files.",
|
|
216
|
+
}),
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
isError: true,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
// ============================================================================
|
|
224
|
+
// TABLE TOOL
|
|
225
|
+
// ============================================================================
|
|
226
|
+
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.
|
|
227
|
+
|
|
228
|
+
**Data format:** 2D array of strings, e.g. [["Header1", "Header2"], ["Row1Col1", "Row1Col2"]]`, {
|
|
229
|
+
rows: z
|
|
230
|
+
.number()
|
|
231
|
+
.min(1)
|
|
232
|
+
.max(MAX_TABLE_ROWS)
|
|
233
|
+
.describe(`Number of rows (1-${MAX_TABLE_ROWS})`),
|
|
234
|
+
columns: z
|
|
235
|
+
.number()
|
|
236
|
+
.min(1)
|
|
237
|
+
.max(MAX_TABLE_COLUMNS)
|
|
238
|
+
.describe(`Number of columns (1-${MAX_TABLE_COLUMNS})`),
|
|
239
|
+
data: z
|
|
240
|
+
.array(z.array(z.string().max(MAX_TEXT_LENGTH)))
|
|
241
|
+
.optional()
|
|
242
|
+
.describe("2D array of cell text content (row-major order)"),
|
|
243
|
+
x: z.number().optional().describe("X position on canvas"),
|
|
244
|
+
y: z.number().optional().describe("Y position on canvas"),
|
|
245
|
+
}, async ({ rows, columns, data, x, y }) => {
|
|
246
|
+
try {
|
|
247
|
+
const connector = await getDesktopConnector();
|
|
248
|
+
const result = await connector.createTable({
|
|
249
|
+
rows,
|
|
250
|
+
columns,
|
|
251
|
+
data,
|
|
252
|
+
x,
|
|
253
|
+
y,
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
logger.error({ error }, "figjam_create_table failed");
|
|
261
|
+
return {
|
|
262
|
+
content: [
|
|
263
|
+
{
|
|
264
|
+
type: "text",
|
|
265
|
+
text: JSON.stringify({
|
|
266
|
+
error: error instanceof Error ? error.message : String(error),
|
|
267
|
+
hint: "This tool only works in FigJam files.",
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
isError: true,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// CODE BLOCK TOOL
|
|
277
|
+
// ============================================================================
|
|
278
|
+
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.`, {
|
|
279
|
+
code: z.string().max(MAX_CODE_LENGTH).describe("The code content"),
|
|
280
|
+
language: z
|
|
281
|
+
.string()
|
|
282
|
+
.optional()
|
|
283
|
+
.describe("Programming language (e.g., 'JAVASCRIPT', 'PYTHON', 'TYPESCRIPT', 'JSON', 'HTML', 'CSS')"),
|
|
284
|
+
x: z.number().optional().describe("X position on canvas"),
|
|
285
|
+
y: z.number().optional().describe("Y position on canvas"),
|
|
286
|
+
}, async ({ code, language, x, y }) => {
|
|
287
|
+
try {
|
|
288
|
+
const connector = await getDesktopConnector();
|
|
289
|
+
const result = await connector.createCodeBlock({
|
|
290
|
+
code,
|
|
291
|
+
language,
|
|
292
|
+
x,
|
|
293
|
+
y,
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
logger.error({ error }, "figjam_create_code_block failed");
|
|
301
|
+
return {
|
|
302
|
+
content: [
|
|
303
|
+
{
|
|
304
|
+
type: "text",
|
|
305
|
+
text: JSON.stringify({
|
|
306
|
+
error: error instanceof Error ? error.message : String(error),
|
|
307
|
+
hint: "This tool only works in FigJam files.",
|
|
308
|
+
}),
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
isError: true,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
// ============================================================================
|
|
316
|
+
// LAYOUT HELPER TOOL
|
|
317
|
+
// ============================================================================
|
|
318
|
+
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.`, {
|
|
319
|
+
nodeIds: z
|
|
320
|
+
.array(z.string())
|
|
321
|
+
.max(MAX_ARRANGE_NODES)
|
|
322
|
+
.describe(`Array of node IDs to arrange (max ${MAX_ARRANGE_NODES})`),
|
|
323
|
+
layout: z
|
|
324
|
+
.enum(["grid", "horizontal", "vertical"])
|
|
325
|
+
.optional()
|
|
326
|
+
.default("grid")
|
|
327
|
+
.describe("Layout type: grid, horizontal, or vertical"),
|
|
328
|
+
spacing: z
|
|
329
|
+
.number()
|
|
330
|
+
.optional()
|
|
331
|
+
.default(40)
|
|
332
|
+
.describe("Spacing between nodes in pixels"),
|
|
333
|
+
columns: z
|
|
334
|
+
.number()
|
|
335
|
+
.optional()
|
|
336
|
+
.describe("Number of columns for grid layout (defaults to sqrt of node count)"),
|
|
337
|
+
}, async ({ nodeIds, layout, spacing, columns }) => {
|
|
338
|
+
try {
|
|
339
|
+
const connector = await getDesktopConnector();
|
|
340
|
+
// Compute grid columns safely on the server side — no string interpolation
|
|
341
|
+
const gridCols = columns || Math.ceil(Math.sqrt(nodeIds.length));
|
|
342
|
+
// Pass all parameters as a JSON object to avoid code injection.
|
|
343
|
+
// The plugin code reads from the params object, not interpolated strings.
|
|
344
|
+
const paramsJson = JSON.stringify({
|
|
345
|
+
nodeIds,
|
|
346
|
+
layout,
|
|
347
|
+
spacing,
|
|
348
|
+
gridCols,
|
|
349
|
+
});
|
|
350
|
+
// Use JSON.stringify to produce a properly-escaped double-quoted JS string literal.
|
|
351
|
+
// This handles all control characters including \u2028/\u2029 that manual
|
|
352
|
+
// single-quote escaping would miss.
|
|
353
|
+
const code = `
|
|
354
|
+
const params = JSON.parse(${JSON.stringify(paramsJson)});
|
|
355
|
+
const nodes = [];
|
|
356
|
+
for (const id of params.nodeIds) {
|
|
357
|
+
const node = await figma.getNodeByIdAsync(id);
|
|
358
|
+
if (node) nodes.push(node);
|
|
359
|
+
}
|
|
360
|
+
if (nodes.length === 0) throw new Error('No valid nodes found');
|
|
361
|
+
|
|
362
|
+
let x = nodes[0].x;
|
|
363
|
+
let y = nodes[0].y;
|
|
364
|
+
const startX = x;
|
|
365
|
+
let maxRowHeight = 0;
|
|
366
|
+
|
|
367
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
368
|
+
const node = nodes[i];
|
|
369
|
+
if (params.layout === 'horizontal') {
|
|
370
|
+
node.x = x;
|
|
371
|
+
node.y = y;
|
|
372
|
+
x += node.width + params.spacing;
|
|
373
|
+
} else if (params.layout === 'vertical') {
|
|
374
|
+
node.x = x;
|
|
375
|
+
node.y = y;
|
|
376
|
+
y += node.height + params.spacing;
|
|
377
|
+
} else {
|
|
378
|
+
const col = i % params.gridCols;
|
|
379
|
+
if (col === 0 && i > 0) {
|
|
380
|
+
y += maxRowHeight + params.spacing;
|
|
381
|
+
maxRowHeight = 0;
|
|
382
|
+
x = startX;
|
|
383
|
+
}
|
|
384
|
+
node.x = x;
|
|
385
|
+
node.y = y;
|
|
386
|
+
maxRowHeight = Math.max(maxRowHeight, node.height);
|
|
387
|
+
x += node.width + params.spacing;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return { arranged: nodes.length, layout: params.layout };
|
|
391
|
+
`;
|
|
392
|
+
const result = await connector.executeCodeViaUI(code, 10000);
|
|
393
|
+
return {
|
|
394
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
logger.error({ error }, "figjam_auto_arrange failed");
|
|
399
|
+
return {
|
|
400
|
+
content: [
|
|
401
|
+
{
|
|
402
|
+
type: "text",
|
|
403
|
+
text: JSON.stringify({
|
|
404
|
+
error: error instanceof Error ? error.message : String(error),
|
|
405
|
+
hint: "Make sure all node IDs are valid and the Desktop Bridge plugin is running.",
|
|
406
|
+
}),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
isError: true,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
// ============================================================================
|
|
414
|
+
// READ TOOLS — Query existing FigJam board content
|
|
415
|
+
// ============================================================================
|
|
416
|
+
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.
|
|
417
|
+
|
|
418
|
+
Use this to understand what's on a board before modifying it, or to extract structured data from collaborative sessions.
|
|
419
|
+
|
|
420
|
+
**Filters:** Pass nodeTypes to limit results (e.g., ["STICKY"] for only stickies). Omit for everything.`, {
|
|
421
|
+
nodeTypes: z
|
|
422
|
+
.array(z.enum(FIGJAM_NODE_TYPES))
|
|
423
|
+
.optional()
|
|
424
|
+
.describe("Filter by node types. Omit for all."),
|
|
425
|
+
maxNodes: z
|
|
426
|
+
.number()
|
|
427
|
+
.min(1)
|
|
428
|
+
.max(MAX_READ_NODES)
|
|
429
|
+
.optional()
|
|
430
|
+
.default(500)
|
|
431
|
+
.describe(`Maximum nodes to return (1-${MAX_READ_NODES}, default: 500)`),
|
|
432
|
+
}, async ({ nodeTypes, maxNodes }) => {
|
|
433
|
+
try {
|
|
434
|
+
const connector = await getDesktopConnector();
|
|
435
|
+
const result = await connector.getBoardContents({
|
|
436
|
+
nodeTypes,
|
|
437
|
+
maxNodes,
|
|
438
|
+
});
|
|
439
|
+
return {
|
|
440
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
logger.error({ error }, "figjam_get_board_contents failed");
|
|
445
|
+
return {
|
|
446
|
+
content: [
|
|
447
|
+
{
|
|
448
|
+
type: "text",
|
|
449
|
+
text: JSON.stringify({
|
|
450
|
+
error: error instanceof Error ? error.message : String(error),
|
|
451
|
+
hint: "This tool only works in FigJam files. Make sure the Desktop Bridge plugin is running in a FigJam board.",
|
|
452
|
+
}),
|
|
453
|
+
},
|
|
454
|
+
],
|
|
455
|
+
isError: true,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
server.tool("figjam_get_connections", `Read the connection graph from a FigJam board. Returns all connectors with their start/end node references and labels.
|
|
460
|
+
|
|
461
|
+
Use this to understand relationships, flowcharts, and diagrams. Returns edges as {startNodeId, endNodeId, label} plus a summary of connected nodes.`, {}, async () => {
|
|
462
|
+
try {
|
|
463
|
+
const connector = await getDesktopConnector();
|
|
464
|
+
const result = await connector.getConnections();
|
|
465
|
+
return {
|
|
466
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
logger.error({ error }, "figjam_get_connections failed");
|
|
471
|
+
return {
|
|
472
|
+
content: [
|
|
473
|
+
{
|
|
474
|
+
type: "text",
|
|
475
|
+
text: JSON.stringify({
|
|
476
|
+
error: error instanceof Error ? error.message : String(error),
|
|
477
|
+
hint: "This tool only works in FigJam files. Make sure the Desktop Bridge plugin is running in a FigJam board.",
|
|
478
|
+
}),
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
isError: true,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
@@ -1180,5 +1180,30 @@ export class FigmaDesktopConnector {
|
|
|
1180
1180
|
throw error;
|
|
1181
1181
|
}
|
|
1182
1182
|
}
|
|
1183
|
+
// FigJam operations — not supported via legacy CDP transport
|
|
1184
|
+
async createSticky() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1185
|
+
async createStickies() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1186
|
+
async createConnector() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1187
|
+
async createShapeWithText() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1188
|
+
async createTable() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1189
|
+
async createCodeBlock() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1190
|
+
async getBoardContents() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1191
|
+
async getConnections() { throw new Error('FigJam operations require WebSocket transport'); }
|
|
1192
|
+
// Slides operations — not supported via legacy CDP transport
|
|
1193
|
+
async listSlides() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1194
|
+
async getSlideContent() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1195
|
+
async createSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1196
|
+
async deleteSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1197
|
+
async duplicateSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1198
|
+
async getSlideGrid() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1199
|
+
async reorderSlides() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1200
|
+
async setSlideTransition() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1201
|
+
async getSlideTransition() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1202
|
+
async setSlidesViewMode() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1203
|
+
async getFocusedSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1204
|
+
async focusSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1205
|
+
async skipSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1206
|
+
async addTextToSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1207
|
+
async addShapeToSlide() { throw new Error('Slides operations require WebSocket transport'); }
|
|
1183
1208
|
}
|
|
1184
1209
|
FigmaDesktopConnector.DEBUG = process.env.DEBUG === '1' || process.env.DEBUG === 'true';
|
|
@@ -551,11 +551,14 @@ function resolveVariableAliases(variables, allVariablesMap, collectionsMap) {
|
|
|
551
551
|
const collection = collectionsMap.get(variable.variableCollectionId);
|
|
552
552
|
const modes = collection?.modes || [];
|
|
553
553
|
const resolvedValuesByMode = {};
|
|
554
|
+
// Use the full cached variable's valuesByMode if the response variable was stripped by verbosity filtering
|
|
555
|
+
const fullVariable = allVariablesMap.get(variable.id);
|
|
556
|
+
const valuesByMode = variable.valuesByMode || fullVariable?.valuesByMode;
|
|
554
557
|
for (const mode of modes) {
|
|
555
558
|
const modeId = getModeId(mode);
|
|
556
559
|
if (!modeId)
|
|
557
560
|
continue;
|
|
558
|
-
const rawValue =
|
|
561
|
+
const rawValue = valuesByMode?.[modeId];
|
|
559
562
|
if (rawValue === undefined)
|
|
560
563
|
continue;
|
|
561
564
|
const { resolved, aliasChain } = resolveValue(rawValue, variable.resolvedType, new Set());
|