@ufira/vibma 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +7 -7
  2. package/dist/mcp.cjs +807 -1429
  3. package/dist/mcp.cjs.map +1 -1
  4. package/dist/mcp.js +807 -1430
  5. package/dist/mcp.js.map +1 -1
  6. package/dist/tools/endpoint.cjs +119 -0
  7. package/dist/tools/endpoint.cjs.map +1 -0
  8. package/dist/tools/endpoint.d.cts +94 -0
  9. package/dist/tools/endpoint.d.ts +94 -0
  10. package/dist/tools/endpoint.js +92 -0
  11. package/dist/tools/endpoint.js.map +1 -0
  12. package/dist/tools/registry.cjs +73 -0
  13. package/dist/tools/registry.cjs.map +1 -0
  14. package/dist/tools/registry.d.cts +14 -0
  15. package/dist/tools/registry.d.ts +14 -0
  16. package/dist/tools/registry.js +47 -0
  17. package/dist/tools/registry.js.map +1 -0
  18. package/dist/tools/schemas.cjs +101 -0
  19. package/dist/tools/schemas.cjs.map +1 -0
  20. package/dist/tools/schemas.d.cts +52 -0
  21. package/dist/tools/schemas.d.ts +52 -0
  22. package/dist/tools/schemas.js +70 -0
  23. package/dist/tools/schemas.js.map +1 -0
  24. package/dist/tools/types.cjs +52 -0
  25. package/dist/tools/types.cjs.map +1 -0
  26. package/dist/tools/types.d.cts +53 -0
  27. package/dist/tools/types.d.ts +53 -0
  28. package/dist/tools/types.js +27 -0
  29. package/dist/tools/types.js.map +1 -0
  30. package/dist/utils/coercion.cjs +56 -0
  31. package/dist/utils/coercion.cjs.map +1 -0
  32. package/dist/utils/coercion.d.cts +10 -0
  33. package/dist/utils/coercion.d.ts +10 -0
  34. package/dist/utils/coercion.js +30 -0
  35. package/dist/utils/coercion.js.map +1 -0
  36. package/dist/utils/color.cjs +38 -0
  37. package/dist/utils/color.cjs.map +1 -0
  38. package/dist/utils/color.d.cts +4 -0
  39. package/dist/utils/color.d.ts +4 -0
  40. package/dist/utils/color.js +14 -0
  41. package/dist/utils/color.js.map +1 -0
  42. package/dist/utils/wcag.cjs +123 -0
  43. package/dist/utils/wcag.cjs.map +1 -0
  44. package/dist/utils/wcag.d.cts +80 -0
  45. package/dist/utils/wcag.d.ts +80 -0
  46. package/dist/utils/wcag.js +92 -0
  47. package/dist/utils/wcag.js.map +1 -0
  48. package/package.json +44 -15
  49. package/LICENSE +0 -22
package/dist/mcp.cjs CHANGED
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
8
  var __copyProps = (to, from, except, desc) => {
12
9
  if (from && typeof from === "object" || typeof from === "function") {
13
10
  for (let key of __getOwnPropNames(from))
@@ -25,32 +22,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
22
  mod
26
23
  ));
27
24
 
28
- // src/utils/color.ts
29
- var init_color = __esm({
30
- "src/utils/color.ts"() {
31
- }
32
- });
33
-
34
- // src/utils/serialize-node.ts
35
- var init_serialize_node = __esm({
36
- "src/utils/serialize-node.ts"() {
37
- init_color();
38
- }
39
- });
40
-
41
25
  // src/mcp.ts
42
26
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
43
27
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
44
- var import_zod19 = require("zod");
28
+ var import_zod18 = require("zod");
45
29
  var import_ws = __toESM(require("ws"), 1);
46
30
  var import_uuid = require("uuid");
47
31
  var import_fs = require("fs");
48
32
  var import_path = require("path");
49
33
  var import_url = require("url");
50
34
 
51
- // src/tools/document.ts
52
- var import_zod = require("zod");
53
-
54
35
  // src/tools/types.ts
55
36
  var MAX_RESPONSE_CHARS = 5e4;
56
37
  function mcpJson(data) {
@@ -74,89 +55,80 @@ function mcpError(prefix, error) {
74
55
  return { content: [{ type: "text", text: `${prefix}: ${msg}` }] };
75
56
  }
76
57
 
77
- // src/tools/document.ts
78
- function registerMcpTools(server2, sendCommand) {
79
- server2.tool(
80
- "get_document_info",
81
- "Get the document name, current page, and list of all pages.",
82
- {},
83
- async () => {
84
- try {
85
- return mcpJson(await sendCommand("get_document_info"));
86
- } catch (e) {
87
- return mcpError("Error getting document info", e);
88
- }
89
- }
90
- );
91
- server2.tool(
92
- "get_current_page",
93
- "Get the current page info and its top-level children. Always safe \u2014 never touches unloaded pages.",
94
- {},
95
- async () => {
58
+ // src/tools/registry.ts
59
+ function registerTools(server2, sendCommand, caps2, tools16) {
60
+ for (const tool of tools16) {
61
+ if (tool.tier === "create" && !caps2.create) continue;
62
+ if (tool.tier === "edit" && !caps2.edit) continue;
63
+ const schema = typeof tool.schema === "function" ? tool.schema(caps2) : tool.schema;
64
+ const command = tool.command ?? tool.name;
65
+ const timeout = tool.timeout;
66
+ const format = tool.formatResponse ?? mcpJson;
67
+ server2.registerTool(tool.name, { description: tool.description, inputSchema: schema }, async (params) => {
96
68
  try {
97
- return mcpJson(await sendCommand("get_current_page"));
69
+ if (tool.validate) tool.validate(params);
70
+ const result = await sendCommand(command, params, timeout);
71
+ return format(result);
98
72
  } catch (e) {
99
- return mcpError("Error getting current page", e);
73
+ return mcpError(`${tool.name} error`, e);
100
74
  }
101
- }
102
- );
103
- server2.tool(
104
- "get_pages",
105
- "Get all pages in the document with their IDs, names, and child counts.",
106
- {},
107
- async () => {
108
- try {
109
- return mcpJson(await sendCommand("get_pages"));
110
- } catch (e) {
111
- return mcpError("Error getting pages", e);
112
- }
113
- }
114
- );
115
- server2.tool(
116
- "set_current_page",
117
- "Switch to a different page. Provide either pageId or pageName.",
118
- {
75
+ });
76
+ }
77
+ }
78
+
79
+ // src/tools/defs/connection.ts
80
+ var tools = [
81
+ {
82
+ name: "ping",
83
+ description: "Verify end-to-end connection to Figma. Call this right after join_channel. Returns { status: 'pong', documentName, currentPage } if the full chain (MCP \u2192 relay \u2192 plugin \u2192 Figma) is working. If this times out, the Figma plugin is not connected \u2014 ask the user to check the plugin window for the correct port and channel name.",
84
+ schema: {},
85
+ tier: "read",
86
+ timeout: 5e3
87
+ }
88
+ ];
89
+
90
+ // src/tools/defs/document.ts
91
+ var import_zod = require("zod");
92
+ var tools2 = [
93
+ {
94
+ name: "get_document_info",
95
+ description: "Get the document name, current page, and list of all pages.",
96
+ schema: {},
97
+ tier: "read"
98
+ },
99
+ {
100
+ name: "get_current_page",
101
+ description: "Get the current page info and its top-level children.",
102
+ schema: {},
103
+ tier: "read"
104
+ },
105
+ {
106
+ name: "set_current_page",
107
+ description: "Switch to a different page. Provide either pageId or pageName.",
108
+ schema: {
119
109
  pageId: import_zod.z.string().optional().describe("The page ID to switch to"),
120
110
  pageName: import_zod.z.string().optional().describe("The page name (case-insensitive, partial match)")
121
111
  },
122
- async (params) => {
123
- try {
124
- return mcpJson(await sendCommand("set_current_page", params));
125
- } catch (e) {
126
- return mcpError("Error setting current page", e);
127
- }
128
- }
129
- );
130
- server2.tool(
131
- "create_page",
132
- "Create a new page in the document",
133
- { name: import_zod.z.string().optional().describe("Name for the new page (default: 'New Page')") },
134
- async ({ name }) => {
135
- try {
136
- return mcpJson(await sendCommand("create_page", { name }));
137
- } catch (e) {
138
- return mcpError("Error creating page", e);
139
- }
140
- }
141
- );
142
- server2.tool(
143
- "rename_page",
144
- "Rename a page. Defaults to current page if no pageId given.",
145
- {
112
+ tier: "read"
113
+ },
114
+ {
115
+ name: "create_page",
116
+ description: "Create a new page in the document",
117
+ schema: { name: import_zod.z.string().optional().describe("Name for the new page (default: 'New Page')") },
118
+ tier: "create"
119
+ },
120
+ {
121
+ name: "rename_page",
122
+ description: "Rename a page. Defaults to current page if no pageId given.",
123
+ schema: {
146
124
  newName: import_zod.z.string().describe("New name for the page"),
147
125
  pageId: import_zod.z.string().optional().describe("Page ID (default: current page)")
148
126
  },
149
- async (params) => {
150
- try {
151
- return mcpJson(await sendCommand("rename_page", params));
152
- } catch (e) {
153
- return mcpError("Error renaming page", e);
154
- }
155
- }
156
- );
157
- }
127
+ tier: "edit"
128
+ }
129
+ ];
158
130
 
159
- // src/tools/selection.ts
131
+ // src/tools/defs/selection.ts
160
132
  var import_zod3 = require("zod");
161
133
 
162
134
  // src/utils/coercion.ts
@@ -184,114 +156,41 @@ var flexNum = (inner) => import_zod2.z.preprocess((v) => {
184
156
  return v;
185
157
  }, inner);
186
158
 
187
- // src/tools/selection.ts
188
- function registerMcpTools2(server2, sendCommand) {
189
- server2.tool(
190
- "get_selection",
191
- "Get information about the current selection in Figma",
192
- {},
193
- async () => {
194
- try {
195
- return mcpJson(await sendCommand("get_selection"));
196
- } catch (e) {
197
- return mcpError("Error getting selection", e);
198
- }
199
- }
200
- );
201
- server2.tool(
202
- "read_my_design",
203
- "Read the nodes the user has selected in Figma (or set via set_selection). Returns nothing if no selection exists \u2014 ask the user to select something, or use get_node_info with specific node IDs. Use depth to control child traversal.",
204
- { depth: import_zod3.z.coerce.number().optional().describe("Levels of children to recurse. 0=selection only, -1 or omit for unlimited.") },
205
- async ({ depth: depth2 }) => {
206
- try {
207
- return mcpJson(await sendCommand("read_my_design", { depth: depth2 }));
208
- } catch (e) {
209
- return mcpError("Error reading design", e);
210
- }
211
- }
212
- );
213
- server2.tool(
214
- "set_selection",
215
- "Set selection to nodes and scroll viewport to show them. Also works as focus (single node).",
216
- {
159
+ // src/tools/defs/selection.ts
160
+ var tools3 = [
161
+ {
162
+ name: "get_selection",
163
+ description: "Get the current selection. Without depth, returns stubs (id/name/type). With depth, returns full serialized node trees.",
164
+ schema: { depth: import_zod3.z.coerce.number().optional().describe("Child recursion depth. Omit for stubs only, 0=selected nodes' properties, -1=unlimited.") },
165
+ tier: "read"
166
+ },
167
+ {
168
+ name: "set_selection",
169
+ description: "Set selection to nodes and scroll viewport to show them. Also works as focus (single node).",
170
+ schema: {
217
171
  nodeIds: flexJson(import_zod3.z.array(import_zod3.z.string())).describe('Array of node IDs to select. Example: ["1:2","1:3"]')
218
172
  },
219
- async ({ nodeIds: nodeIds2 }) => {
220
- try {
221
- return mcpJson(await sendCommand("set_selection", { nodeIds: nodeIds2 }));
222
- } catch (e) {
223
- return mcpError("Error setting selection", e);
224
- }
225
- }
226
- );
227
- server2.tool(
228
- "zoom_into_view",
229
- "Zoom the viewport to fit specific nodes (like pressing Shift+1)",
230
- {
231
- nodeIds: flexJson(import_zod3.z.array(import_zod3.z.string())).describe("Array of node IDs to zoom into")
232
- },
233
- async ({ nodeIds: nodeIds2 }) => {
234
- try {
235
- return mcpJson(await sendCommand("zoom_into_view", { nodeIds: nodeIds2 }));
236
- } catch (e) {
237
- return mcpError("Error zooming", e);
238
- }
239
- }
240
- );
241
- server2.tool(
242
- "set_viewport",
243
- "Set viewport center position and/or zoom level",
244
- {
245
- center: flexJson(import_zod3.z.object({ x: import_zod3.z.coerce.number(), y: import_zod3.z.coerce.number() })).optional().describe("Viewport center point. Omit to keep current center."),
246
- zoom: import_zod3.z.coerce.number().optional().describe("Zoom level (1 = 100%). Omit to keep current zoom.")
247
- },
248
- async (params) => {
249
- try {
250
- return mcpJson(await sendCommand("set_viewport", params));
251
- } catch (e) {
252
- return mcpError("Error setting viewport", e);
253
- }
254
- }
255
- );
256
- }
173
+ tier: "read"
174
+ }
175
+ ];
257
176
 
258
- // src/tools/node-info.ts
177
+ // src/tools/defs/node-info.ts
259
178
  var import_zod4 = require("zod");
260
- init_serialize_node();
261
- function registerMcpTools3(server2, sendCommand) {
262
- server2.tool(
263
- "get_node_info",
264
- "Get detailed information about one or more nodes. Always pass an array of IDs. Use `fields` to select only the properties you need (reduces context size).",
265
- {
179
+ var tools4 = [
180
+ {
181
+ name: "get_node_info",
182
+ description: "Get detailed information about one or more nodes. Always pass an array of IDs. Use `fields` to select only the properties you need (reduces context size).",
183
+ schema: {
266
184
  nodeIds: flexJson(import_zod4.z.array(import_zod4.z.string())).describe('Array of node IDs. Example: ["1:2","1:3"]'),
267
185
  depth: import_zod4.z.coerce.number().optional().describe("Child recursion depth (default: unlimited). 0=stubs only."),
268
- fields: flexJson(import_zod4.z.array(import_zod4.z.string())).optional().describe('Whitelist of property names to include. Always includes id, name, type. Example: ["absoluteBoundingBox","layoutMode","fills"]. Omit to return all properties.')
186
+ fields: flexJson(import_zod4.z.array(import_zod4.z.string())).optional().describe('Whitelist of property names to include. Example: ["absoluteBoundingBox","layoutMode","fills"]. Omit to return all properties.')
269
187
  },
270
- async (params) => {
271
- try {
272
- const result = await sendCommand("get_node_info", params);
273
- return mcpJson(result);
274
- } catch (e) {
275
- return mcpError("Error getting node info", e);
276
- }
277
- }
278
- );
279
- server2.tool(
280
- "get_node_css",
281
- "Get CSS properties for a node (useful for dev handoff)",
282
- { nodeId: import_zod4.z.string().describe("The node ID to get CSS for") },
283
- async ({ nodeId: nodeId2 }) => {
284
- try {
285
- return mcpJson(await sendCommand("get_node_css", { nodeId: nodeId2 }));
286
- } catch (e) {
287
- return mcpError("Error getting CSS", e);
288
- }
289
- }
290
- );
291
- server2.tool(
292
- "search_nodes",
293
- "Search for nodes by layer name and/or type. Searches current page only \u2014 use set_current_page to switch pages first. Matches layer names (text nodes are often auto-named from their content). Returns paginated results.",
294
- {
188
+ tier: "read"
189
+ },
190
+ {
191
+ name: "search_nodes",
192
+ description: "Search nodes on the current page by name and/or type. Use set_current_page first to search other pages. Paginated (default 50).",
193
+ schema: {
295
194
  query: import_zod4.z.string().optional().describe("Name search (case-insensitive substring). Omit to match all names."),
296
195
  types: flexJson(import_zod4.z.array(import_zod4.z.string())).optional().describe('Filter by types. Example: ["FRAME","TEXT"]. Omit to match all types.'),
297
196
  scopeNodeId: import_zod4.z.string().optional().describe("Node ID to search within (defaults to current page)"),
@@ -299,36 +198,27 @@ function registerMcpTools3(server2, sendCommand) {
299
198
  limit: import_zod4.z.coerce.number().optional().describe("Max results (default 50)"),
300
199
  offset: import_zod4.z.coerce.number().optional().describe("Skip N results for pagination (default 0)")
301
200
  },
302
- async (params) => {
303
- try {
304
- return mcpJson(await sendCommand("search_nodes", params));
305
- } catch (e) {
306
- return mcpError("Error searching nodes", e);
307
- }
308
- }
309
- );
310
- server2.tool(
311
- "export_node_as_image",
312
- "Export a node as an image from Figma",
313
- {
201
+ tier: "read"
202
+ },
203
+ {
204
+ name: "export_node_as_image",
205
+ description: "Export a node as an image from Figma",
206
+ schema: {
314
207
  nodeId: import_zod4.z.string().describe("The node ID to export"),
315
208
  format: import_zod4.z.enum(["PNG", "JPG", "SVG", "PDF"]).optional().describe("Export format (default: PNG)"),
316
209
  scale: import_zod4.z.coerce.number().positive().optional().describe("Export scale (default: 1)")
317
210
  },
318
- async ({ nodeId: nodeId2, format, scale }) => {
319
- try {
320
- const result = await sendCommand("export_node_as_image", { nodeId: nodeId2, format, scale });
321
- return {
322
- content: [{ type: "image", data: result.imageData, mimeType: result.mimeType || "image/png" }]
323
- };
324
- } catch (e) {
325
- return mcpError("Error exporting image", e);
326
- }
211
+ tier: "read",
212
+ formatResponse: (result) => {
213
+ const r = result;
214
+ return {
215
+ content: [{ type: "image", data: r.imageData, mimeType: r.mimeType || "image/png" }]
216
+ };
327
217
  }
328
- );
329
- }
218
+ }
219
+ ];
330
220
 
331
- // src/tools/create-shape.ts
221
+ // src/tools/defs/create-shape.ts
332
222
  var import_zod6 = require("zod");
333
223
 
334
224
  // src/tools/schemas.ts
@@ -360,7 +250,7 @@ var colorRgba = import_zod5.z.preprocess((v) => {
360
250
  g: import_zod5.z.coerce.number().min(0).max(1),
361
251
  b: import_zod5.z.coerce.number().min(0).max(1),
362
252
  a: import_zod5.z.coerce.number().min(0).max(1).optional()
363
- }));
253
+ })).describe('Hex "#FF0000" or {r,g,b,a?} with values 0-1.');
364
254
  var effectEntry = import_zod5.z.object({
365
255
  type: import_zod5.z.enum(["DROP_SHADOW", "INNER_SHADOW", "LAYER_BLUR", "BACKGROUND_BLUR"]),
366
256
  color: flexJson(colorRgba).optional(),
@@ -371,34 +261,7 @@ var effectEntry = import_zod5.z.object({
371
261
  blendMode: import_zod5.z.string().optional()
372
262
  });
373
263
 
374
- // src/tools/helpers.ts
375
- init_serialize_node();
376
-
377
- // src/tools/create-shape.ts
378
- var rectItem = import_zod6.z.object({
379
- name: import_zod6.z.string().optional().describe("Name (default: 'Rectangle')"),
380
- x: xPos,
381
- y: yPos,
382
- width: import_zod6.z.coerce.number().optional().describe("Width (default: 100)"),
383
- height: import_zod6.z.coerce.number().optional().describe("Height (default: 100)"),
384
- parentId
385
- });
386
- var ellipseItem = import_zod6.z.object({
387
- name: import_zod6.z.string().optional().describe("Layer name (default: 'Ellipse')"),
388
- x: xPos,
389
- y: yPos,
390
- width: import_zod6.z.coerce.number().optional().describe("Width (default: 100)"),
391
- height: import_zod6.z.coerce.number().optional().describe("Height (default: 100)"),
392
- parentId
393
- });
394
- var lineItem = import_zod6.z.object({
395
- name: import_zod6.z.string().optional().describe("Layer name (default: 'Line')"),
396
- x: xPos,
397
- y: yPos,
398
- length: import_zod6.z.coerce.number().optional().describe("Length (default: 100)"),
399
- rotation: import_zod6.z.coerce.number().optional().describe("Rotation in degrees (default: 0)"),
400
- parentId
401
- });
264
+ // src/tools/defs/create-shape.ts
402
265
  var sectionItem = import_zod6.z.object({
403
266
  name: import_zod6.z.string().optional().describe("Name (default: 'Section')"),
404
267
  x: xPos,
@@ -414,87 +277,22 @@ var svgItem = import_zod6.z.object({
414
277
  y: yPos,
415
278
  parentId
416
279
  });
417
- var boolOpItem = import_zod6.z.object({
418
- nodeIds: flexJson(import_zod6.z.array(import_zod6.z.string())).describe("Array of node IDs (min 2)"),
419
- operation: import_zod6.z.enum(["UNION", "INTERSECT", "SUBTRACT", "EXCLUDE"]).describe("Boolean operation type"),
420
- name: import_zod6.z.string().optional().describe("Name for the result. Omit to auto-generate.")
421
- });
422
- function registerMcpTools4(server2, sendCommand) {
423
- server2.tool(
424
- "create_rectangle",
425
- "Create rectangles (leaf nodes \u2014 cannot have children). For containers/cards/panels, use create_frame instead. Batch: pass multiple items.",
426
- { items: flexJson(import_zod6.z.array(rectItem)).describe("Array of rectangles to create"), depth },
427
- async (params) => {
428
- try {
429
- return mcpJson(await sendCommand("create_rectangle", params));
430
- } catch (e) {
431
- return mcpError("Error creating rectangles", e);
432
- }
433
- }
434
- );
435
- server2.tool(
436
- "create_ellipse",
437
- "Create ellipses (leaf nodes \u2014 cannot have children). For circular containers, use create_frame with cornerRadius instead. Batch: pass multiple items.",
438
- { items: flexJson(import_zod6.z.array(ellipseItem)).describe("Array of ellipses to create"), depth },
439
- async (params) => {
440
- try {
441
- return mcpJson(await sendCommand("create_ellipse", params));
442
- } catch (e) {
443
- return mcpError("Error creating ellipses", e);
444
- }
445
- }
446
- );
447
- server2.tool(
448
- "create_line",
449
- "Create lines (leaf nodes \u2014 cannot have children). For dividers inside layouts, use create_frame with a thin height and fill color instead. Batch: pass multiple items.",
450
- { items: flexJson(import_zod6.z.array(lineItem)).describe("Array of lines to create"), depth },
451
- async (params) => {
452
- try {
453
- return mcpJson(await sendCommand("create_line", params));
454
- } catch (e) {
455
- return mcpError("Error creating lines", e);
456
- }
457
- }
458
- );
459
- server2.tool(
460
- "create_section",
461
- "Create section nodes to organize content on the canvas.",
462
- { items: flexJson(import_zod6.z.array(sectionItem)).describe("Array of sections to create"), depth },
463
- async (params) => {
464
- try {
465
- return mcpJson(await sendCommand("create_section", params));
466
- } catch (e) {
467
- return mcpError("Error creating sections", e);
468
- }
469
- }
470
- );
471
- server2.tool(
472
- "create_node_from_svg",
473
- "Create nodes from SVG strings.",
474
- { items: flexJson(import_zod6.z.array(svgItem)).describe("Array of SVG items to create"), depth },
475
- async (params) => {
476
- try {
477
- return mcpJson(await sendCommand("create_node_from_svg", params));
478
- } catch (e) {
479
- return mcpError("Error creating SVG nodes", e);
480
- }
481
- }
482
- );
483
- server2.tool(
484
- "create_boolean_operation",
485
- "Create a boolean operation (union, intersect, subtract, exclude) from multiple nodes.",
486
- { items: flexJson(import_zod6.z.array(boolOpItem)).describe("Array of boolean operations to create"), depth },
487
- async (params) => {
488
- try {
489
- return mcpJson(await sendCommand("create_boolean_operation", params));
490
- } catch (e) {
491
- return mcpError("Error creating boolean operations", e);
492
- }
493
- }
494
- );
495
- }
280
+ var tools5 = [
281
+ {
282
+ name: "create_section",
283
+ description: "Create section nodes to organize content on the canvas.",
284
+ schema: { items: flexJson(import_zod6.z.array(sectionItem)).describe("Array of sections to create"), depth },
285
+ tier: "create"
286
+ },
287
+ {
288
+ name: "create_node_from_svg",
289
+ description: "Create nodes from SVG strings.",
290
+ schema: { items: flexJson(import_zod6.z.array(svgItem)).describe("Array of SVG items to create"), depth },
291
+ tier: "create"
292
+ }
293
+ ];
496
294
 
497
- // src/tools/create-frame.ts
295
+ // src/tools/defs/create-frame.ts
498
296
  var import_zod7 = require("zod");
499
297
  var frameItem = import_zod7.z.object({
500
298
  name: import_zod7.z.string().optional().describe("Frame name (default: 'Frame')"),
@@ -503,8 +301,8 @@ var frameItem = import_zod7.z.object({
503
301
  width: import_zod7.z.coerce.number().optional().describe("Width (default: 100)"),
504
302
  height: import_zod7.z.coerce.number().optional().describe("Height (default: 100)"),
505
303
  parentId,
506
- fillColor: flexJson(colorRgba).optional().describe('Fill color. Hex "#FF0000" or {r,g,b,a?} 0-1. Default: no fill (empty fills array).'),
507
- strokeColor: flexJson(colorRgba).optional().describe('Stroke color. Hex "#FF0000" or {r,g,b,a?} 0-1. Default: none.'),
304
+ fillColor: flexJson(colorRgba).optional().describe("Fill color. Default: no fill."),
305
+ strokeColor: flexJson(colorRgba).optional().describe("Stroke color. Default: none."),
508
306
  strokeWeight: import_zod7.z.coerce.number().positive().optional().describe("Stroke weight (default: 1)"),
509
307
  cornerRadius: import_zod7.z.coerce.number().min(0).optional().describe("Corner radius (default: 0)"),
510
308
  layoutMode: import_zod7.z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).optional().describe("Auto-layout direction (default: NONE)"),
@@ -518,7 +316,6 @@ var frameItem = import_zod7.z.object({
518
316
  layoutSizingHorizontal: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
519
317
  layoutSizingVertical: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
520
318
  itemSpacing: import_zod7.z.coerce.number().optional().describe("Spacing between children (default: 0)"),
521
- // Style/variable references
522
319
  fillStyleName: import_zod7.z.string().optional().describe("Apply a fill paint style by name (case-insensitive). Omit to skip."),
523
320
  strokeStyleName: import_zod7.z.string().optional().describe("Apply a stroke paint style by name. Omit to skip."),
524
321
  fillVariableId: import_zod7.z.string().optional().describe("Bind a color variable to the fill. Creates a solid fill and binds the variable to fills/0/color."),
@@ -530,1110 +327,681 @@ var autoLayoutItem = import_zod7.z.object({
530
327
  layoutMode: import_zod7.z.enum(["HORIZONTAL", "VERTICAL"]).optional().describe("Direction (default: VERTICAL)"),
531
328
  itemSpacing: import_zod7.z.coerce.number().optional().describe("Spacing between children (default: 0)"),
532
329
  paddingTop: import_zod7.z.coerce.number().optional().describe("Top padding (default: 0)"),
533
- paddingRight: import_zod7.z.coerce.number().optional().describe("Right padding (default: 0)"),
534
- paddingBottom: import_zod7.z.coerce.number().optional().describe("Bottom padding (default: 0)"),
535
- paddingLeft: import_zod7.z.coerce.number().optional().describe("Left padding (default: 0)"),
536
- primaryAxisAlignItems: import_zod7.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional(),
537
- counterAxisAlignItems: import_zod7.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional(),
538
- layoutSizingHorizontal: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
539
- layoutSizingVertical: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
540
- layoutWrap: import_zod7.z.enum(["NO_WRAP", "WRAP"]).optional()
541
- });
542
- function registerMcpTools5(server2, sendCommand) {
543
- server2.tool(
544
- "create_frame",
545
- "Create frames in Figma. Batch supported. Use fillStyleName/fillVariableId and strokeStyleName/strokeVariableId instead of hardcoded colors \u2014 hardcoded values skip design tokens and will trigger lint warnings.",
546
- { items: flexJson(import_zod7.z.array(frameItem)).describe("Array of frames to create"), depth },
547
- async (params) => {
548
- try {
549
- return mcpJson(await sendCommand("create_frame", params));
550
- } catch (e) {
551
- return mcpError("Error creating frames", e);
552
- }
553
- }
554
- );
555
- server2.tool(
556
- "create_auto_layout",
557
- "Wrap existing nodes in an auto-layout frame. One call replaces create_frame + update_frame + insert_child \xD7 N.",
558
- { items: flexJson(import_zod7.z.array(autoLayoutItem)).describe("Array of auto-layout wraps to perform"), depth },
559
- async (params) => {
560
- try {
561
- return mcpJson(await sendCommand("create_auto_layout", params));
562
- } catch (e) {
563
- return mcpError("Error creating auto layout", e);
564
- }
565
- }
566
- );
567
- }
568
-
569
- // src/tools/create-text.ts
570
- var import_zod8 = require("zod");
571
- var textItem = import_zod8.z.object({
572
- text: import_zod8.z.string().describe("Text content"),
573
- name: import_zod8.z.string().optional().describe("Layer name (default: text content)"),
574
- x: xPos,
575
- y: yPos,
576
- fontFamily: import_zod8.z.string().optional().describe("Font family (default: Inter). Use get_available_fonts to list installed fonts."),
577
- fontStyle: import_zod8.z.string().optional().describe("Font style, e.g. 'Regular', 'Bold', 'Italic' (default: derived from fontWeight). Overrides fontWeight when set."),
578
- fontSize: import_zod8.z.coerce.number().optional().describe("Font size (default: 14)"),
579
- fontWeight: import_zod8.z.coerce.number().optional().describe("Font weight: 100-900 (default: 400). Ignored when fontStyle is set."),
580
- fontColor: flexJson(colorRgba).optional().describe('Font color. Hex "#000000" or {r,g,b,a?} 0-1. Default: black.'),
581
- fontColorVariableId: import_zod8.z.string().optional().describe("Bind a color variable to the text fill instead of hardcoded fontColor."),
582
- fontColorStyleName: import_zod8.z.string().optional().describe("Apply a paint style to the text fill by name (case-insensitive). Overrides fontColor."),
583
- parentId,
584
- textStyleId: import_zod8.z.string().optional().describe("Text style ID to apply (overrides fontSize/fontWeight). Omit to skip."),
585
- textStyleName: import_zod8.z.string().optional().describe("Text style name (case-insensitive match). Omit to skip."),
586
- textAlignHorizontal: import_zod8.z.enum(["LEFT", "CENTER", "RIGHT", "JUSTIFIED"]).optional().describe("Horizontal text alignment (default: LEFT)"),
587
- textAlignVertical: import_zod8.z.enum(["TOP", "CENTER", "BOTTOM"]).optional().describe("Vertical text alignment (default: TOP)"),
588
- layoutSizingHorizontal: import_zod8.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Horizontal sizing. FILL auto-sets textAutoResize to HEIGHT."),
589
- layoutSizingVertical: import_zod8.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Vertical sizing (default: HUG)"),
590
- textAutoResize: import_zod8.z.enum(["NONE", "WIDTH_AND_HEIGHT", "HEIGHT", "TRUNCATE"]).optional().describe("Text auto-resize behavior (default: WIDTH_AND_HEIGHT when FILL)")
591
- });
592
- function registerMcpTools6(server2, sendCommand) {
593
- server2.tool(
594
- "create_text",
595
- "Create text nodes. Max 10 per batch. Prefer textStyleName for typography and fontColorStyleName or fontColorVariableId for color \u2014 hardcoded values skip design tokens. Supports custom fonts via fontFamily.",
596
- { items: flexJson(import_zod8.z.array(textItem).max(10)).describe("Array of text nodes to create (max 10)"), depth },
597
- async (params) => {
598
- try {
599
- return mcpJson(await sendCommand("create_text", params));
600
- } catch (e) {
601
- return mcpError("Error creating text", e);
602
- }
603
- }
604
- );
605
- }
606
-
607
- // src/tools/modify-node.ts
608
- var import_zod9 = require("zod");
609
- var moveItem = import_zod9.z.object({
610
- nodeId,
611
- x: import_zod9.z.coerce.number().describe("New X"),
612
- y: import_zod9.z.coerce.number().describe("New Y")
613
- });
614
- var resizeItem = import_zod9.z.object({
615
- nodeId,
616
- width: import_zod9.z.coerce.number().positive().describe("New width"),
617
- height: import_zod9.z.coerce.number().positive().describe("New height")
618
- });
619
- var deleteItem = import_zod9.z.object({
620
- nodeId: import_zod9.z.string().describe("Node ID to delete")
621
- });
622
- var cloneItem = import_zod9.z.object({
623
- nodeId: import_zod9.z.string().describe("Node ID to clone"),
624
- parentId: import_zod9.z.string().optional().describe("Parent for the clone (e.g. a page ID). Defaults to same parent as original."),
625
- x: import_zod9.z.coerce.number().optional().describe("New X for clone. Omit to keep original position."),
626
- y: import_zod9.z.coerce.number().optional().describe("New Y for clone. Omit to keep original position.")
627
- });
628
- var insertItem = import_zod9.z.object({
629
- parentId: import_zod9.z.string().describe("Parent node ID"),
630
- childId: import_zod9.z.string().describe("Child node ID to move"),
631
- index: import_zod9.z.coerce.number().optional().describe("Index to insert at (0=first). Omit to append.")
632
- });
633
- function registerMcpTools7(server2, sendCommand) {
634
- server2.tool(
635
- "move_node",
636
- "Move nodes to new positions. Batch: pass multiple items.",
637
- { items: flexJson(import_zod9.z.array(moveItem)).describe("Array of {nodeId, x, y}"), depth },
638
- async (params) => {
639
- try {
640
- return mcpJson(await sendCommand("move_node", params));
641
- } catch (e) {
642
- return mcpError("Error moving nodes", e);
643
- }
644
- }
645
- );
646
- server2.tool(
647
- "resize_node",
648
- "Resize nodes. Batch: pass multiple items.",
649
- { items: flexJson(import_zod9.z.array(resizeItem)).describe("Array of {nodeId, width, height}"), depth },
650
- async (params) => {
651
- try {
652
- return mcpJson(await sendCommand("resize_node", params));
653
- } catch (e) {
654
- return mcpError("Error resizing nodes", e);
655
- }
656
- }
657
- );
658
- server2.tool(
659
- "delete_node",
660
- "Delete nodes. Batch: pass multiple items.",
661
- { items: flexJson(import_zod9.z.array(deleteItem)).describe("Array of {nodeId}") },
662
- async (params) => {
663
- try {
664
- return mcpJson(await sendCommand("delete_node", params));
665
- } catch (e) {
666
- return mcpError("Error deleting nodes", e);
667
- }
668
- }
669
- );
670
- server2.tool(
671
- "clone_node",
672
- "Clone nodes. Batch: pass multiple items.",
673
- { items: flexJson(import_zod9.z.array(cloneItem)).describe("Array of {nodeId, x?, y?}"), depth },
674
- async (params) => {
675
- try {
676
- return mcpJson(await sendCommand("clone_node", params));
677
- } catch (e) {
678
- return mcpError("Error cloning nodes", e);
679
- }
680
- }
681
- );
682
- server2.tool(
683
- "insert_child",
684
- "Move nodes into a parent at a specific index (reorder/reparent). Batch: pass multiple items.",
685
- { items: flexJson(import_zod9.z.array(insertItem)).describe("Array of {parentId, childId, index?}"), depth },
686
- async (params) => {
687
- try {
688
- return mcpJson(await sendCommand("insert_child", params));
689
- } catch (e) {
690
- return mcpError("Error inserting children", e);
691
- }
692
- }
693
- );
694
- }
695
-
696
- // src/tools/fill-stroke.ts
697
- var import_zod10 = require("zod");
698
- var fillItem = import_zod10.z.object({
699
- nodeId,
700
- color: flexJson(colorRgba).optional().describe('Fill color. Hex "#FF0000" or {r,g,b,a?} 0-1. Ignored when styleName is set.'),
701
- styleName: import_zod10.z.string().optional().describe("Apply fill paint style by name instead of color. Omit to use color.")
702
- });
703
- var strokeItem = import_zod10.z.object({
704
- nodeId,
705
- color: flexJson(colorRgba).optional().describe('Stroke color. Hex "#FF0000" or {r,g,b,a?} 0-1. Ignored when styleName is set.'),
706
- strokeWeight: import_zod10.z.coerce.number().positive().optional().describe("Stroke weight (default: 1)"),
707
- styleName: import_zod10.z.string().optional().describe("Apply stroke paint style by name instead of color. Omit to use color.")
708
- });
709
- var cornerItem = import_zod10.z.object({
710
- nodeId,
711
- radius: import_zod10.z.coerce.number().min(0).describe("Corner radius"),
712
- corners: flexJson(import_zod10.z.array(flexBool(import_zod10.z.boolean())).length(4)).optional().describe("Which corners to round [topLeft, topRight, bottomRight, bottomLeft]. Default: all corners [true,true,true,true].")
713
- });
714
- var opacityItem = import_zod10.z.object({
715
- nodeId,
716
- opacity: import_zod10.z.coerce.number().min(0).max(1).describe("Opacity (0-1)")
717
- });
718
- function registerMcpTools8(server2, sendCommand) {
719
- server2.tool(
720
- "set_fill_color",
721
- "Set fill color on nodes. Prefer styleName (design token) over hardcoded color \u2014 hardcoded values trigger lint warnings. Batch: pass multiple items.",
722
- { items: flexJson(import_zod10.z.array(fillItem)).describe("Array of {nodeId, color?, styleName?}"), depth },
723
- async (params) => {
724
- try {
725
- return mcpJson(await sendCommand("set_fill_color", params));
726
- } catch (e) {
727
- return mcpError("Error setting fill", e);
728
- }
729
- }
730
- );
731
- server2.tool(
732
- "set_stroke_color",
733
- "Set stroke color on nodes. Prefer styleName (design token) over hardcoded color \u2014 hardcoded values trigger lint warnings. Batch: pass multiple items.",
734
- { items: flexJson(import_zod10.z.array(strokeItem)).describe("Array of {nodeId, color?, strokeWeight?, styleName?}"), depth },
735
- async (params) => {
736
- try {
737
- return mcpJson(await sendCommand("set_stroke_color", params));
738
- } catch (e) {
739
- return mcpError("Error setting stroke", e);
740
- }
741
- }
742
- );
743
- server2.tool(
744
- "set_corner_radius",
745
- "Set corner radius on nodes. Batch: pass multiple items.",
746
- { items: flexJson(import_zod10.z.array(cornerItem)).describe("Array of {nodeId, radius, corners?}"), depth },
747
- async (params) => {
748
- try {
749
- return mcpJson(await sendCommand("set_corner_radius", params));
750
- } catch (e) {
751
- return mcpError("Error setting corner radius", e);
752
- }
753
- }
754
- );
755
- server2.tool(
756
- "set_opacity",
757
- "Set opacity on nodes. Batch: pass multiple items.",
758
- { items: flexJson(import_zod10.z.array(opacityItem)).describe("Array of {nodeId, opacity}"), depth },
759
- async (params) => {
760
- try {
761
- return mcpJson(await sendCommand("set_opacity", params));
762
- } catch (e) {
763
- return mcpError("Error setting opacity", e);
764
- }
765
- }
766
- );
767
- }
768
-
769
- // src/tools/update-frame.ts
770
- var import_zod11 = require("zod");
771
- var updateFrameItem = import_zod11.z.object({
772
- nodeId,
773
- layoutMode: import_zod11.z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).optional().describe("Auto-layout direction"),
774
- layoutWrap: import_zod11.z.enum(["NO_WRAP", "WRAP"]).optional().describe("Wrap (default: NO_WRAP)"),
775
- paddingTop: import_zod11.z.coerce.number().optional().describe("Top padding"),
776
- paddingRight: import_zod11.z.coerce.number().optional().describe("Right padding"),
777
- paddingBottom: import_zod11.z.coerce.number().optional().describe("Bottom padding"),
778
- paddingLeft: import_zod11.z.coerce.number().optional().describe("Left padding"),
779
- primaryAxisAlignItems: import_zod11.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional().describe("Primary axis alignment"),
780
- counterAxisAlignItems: import_zod11.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional().describe("Counter axis alignment"),
781
- layoutSizingHorizontal: import_zod11.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Horizontal sizing (works on any node in auto-layout)"),
782
- layoutSizingVertical: import_zod11.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Vertical sizing (works on any node in auto-layout)"),
783
- itemSpacing: import_zod11.z.coerce.number().optional().describe("Spacing between children"),
784
- counterAxisSpacing: import_zod11.z.coerce.number().optional().describe("Spacing between wrapped rows/columns (WRAP only)")
785
- });
786
- function registerMcpTools9(server2, sendCommand) {
787
- server2.tool(
788
- "update_frame",
789
- "Update layout properties on frames. Combines layout mode, padding, alignment, sizing, and spacing in one call. Batch: pass multiple items.",
790
- { items: flexJson(import_zod11.z.array(updateFrameItem)).describe("Array of {nodeId, ...layout properties}"), depth },
791
- async (params) => {
792
- try {
793
- return mcpJson(await sendCommand("update_frame", params));
794
- } catch (e) {
795
- return mcpError("Error updating frame", e);
796
- }
797
- }
798
- );
799
- }
800
-
801
- // src/tools/effects.ts
802
- var import_zod12 = require("zod");
803
- var effectItem = import_zod12.z.object({
804
- nodeId,
805
- effects: flexJson(import_zod12.z.array(effectEntry)).optional().describe("Array of effect objects. Ignored when effectStyleName is set."),
806
- effectStyleName: import_zod12.z.string().optional().describe("Apply an effect style by name (case-insensitive). Omit to use raw effects.")
807
- });
808
- var constraintItem = import_zod12.z.object({
809
- nodeId,
810
- horizontal: import_zod12.z.enum(["MIN", "CENTER", "MAX", "STRETCH", "SCALE"]),
811
- vertical: import_zod12.z.enum(["MIN", "CENTER", "MAX", "STRETCH", "SCALE"])
812
- });
813
- var exportSettingEntry = import_zod12.z.object({
814
- format: import_zod12.z.enum(["PNG", "JPG", "SVG", "PDF"]),
815
- suffix: import_zod12.z.string().optional(),
816
- contentsOnly: flexBool(import_zod12.z.boolean()).optional(),
817
- constraint: flexJson(import_zod12.z.object({
818
- type: import_zod12.z.enum(["SCALE", "WIDTH", "HEIGHT"]),
819
- value: import_zod12.z.coerce.number()
820
- })).optional()
821
- });
822
- var exportSettingsItem = import_zod12.z.object({
823
- nodeId,
824
- settings: flexJson(import_zod12.z.array(exportSettingEntry)).describe("Export settings array")
825
- });
826
- var nodePropertiesItem = import_zod12.z.object({
827
- nodeId,
828
- properties: flexJson(import_zod12.z.record(import_zod12.z.string(), import_zod12.z.unknown())).describe("Key-value properties to set")
829
- });
830
- function registerMcpTools10(server2, sendCommand) {
831
- server2.tool(
832
- "set_effects",
833
- "Set effects (shadows, blurs) on nodes. Use effectStyleName to apply by name, or provide raw effects. Batch: pass multiple items.",
834
- { items: flexJson(import_zod12.z.array(effectItem)).describe("Array of {nodeId, effects}"), depth },
835
- async (params) => {
836
- try {
837
- return mcpJson(await sendCommand("set_effects", params));
838
- } catch (e) {
839
- return mcpError("Error setting effects", e);
840
- }
841
- }
842
- );
843
- server2.tool(
844
- "set_constraints",
845
- "Set constraints on nodes. Batch: pass multiple items.",
846
- { items: flexJson(import_zod12.z.array(constraintItem)).describe("Array of {nodeId, horizontal, vertical}"), depth },
847
- async (params) => {
848
- try {
849
- return mcpJson(await sendCommand("set_constraints", params));
850
- } catch (e) {
851
- return mcpError("Error setting constraints", e);
852
- }
853
- }
854
- );
855
- server2.tool(
856
- "set_export_settings",
857
- "Set export settings on nodes. Batch: pass multiple items.",
858
- { items: flexJson(import_zod12.z.array(exportSettingsItem)).describe("Array of {nodeId, settings}"), depth },
859
- async (params) => {
860
- try {
861
- return mcpJson(await sendCommand("set_export_settings", params));
862
- } catch (e) {
863
- return mcpError("Error setting export settings", e);
864
- }
865
- }
866
- );
867
- server2.tool(
868
- "set_node_properties",
869
- "Set arbitrary properties on nodes. Batch: pass multiple items.",
870
- { items: flexJson(import_zod12.z.array(nodePropertiesItem)).describe("Array of {nodeId, properties}"), depth },
871
- async (params) => {
872
- try {
873
- return mcpJson(await sendCommand("set_node_properties", params));
874
- } catch (e) {
875
- return mcpError("Error setting node properties", e);
876
- }
877
- }
878
- );
879
- }
880
-
881
- // src/tools/text.ts
882
- var import_zod13 = require("zod");
883
- var textContentItem = import_zod13.z.object({
884
- nodeId: import_zod13.z.string().describe("Text node ID"),
885
- text: import_zod13.z.string().describe("New text content")
886
- });
887
- var textPropsItem = import_zod13.z.object({
888
- nodeId: import_zod13.z.string().describe("Text node ID"),
889
- fontSize: import_zod13.z.coerce.number().optional().describe("Font size"),
890
- fontWeight: import_zod13.z.coerce.number().optional().describe("Font weight: 100-900"),
891
- fontColor: flexJson(colorRgba).optional().describe('Font color. Hex "#000" or {r,g,b,a?} 0-1.'),
892
- textStyleId: import_zod13.z.string().optional().describe("Text style ID to apply (overrides font props)"),
893
- textStyleName: import_zod13.z.string().optional().describe("Text style name (case-insensitive match)"),
894
- textAlignHorizontal: import_zod13.z.enum(["LEFT", "CENTER", "RIGHT", "JUSTIFIED"]).optional().describe("Horizontal text alignment"),
895
- textAlignVertical: import_zod13.z.enum(["TOP", "CENTER", "BOTTOM"]).optional().describe("Vertical text alignment"),
896
- textAutoResize: import_zod13.z.enum(["NONE", "WIDTH_AND_HEIGHT", "HEIGHT", "TRUNCATE"]).optional(),
897
- layoutSizingHorizontal: import_zod13.z.enum(["FIXED", "HUG", "FILL"]).optional(),
898
- layoutSizingVertical: import_zod13.z.enum(["FIXED", "HUG", "FILL"]).optional()
899
- });
900
- var scanTextItem = import_zod13.z.object({
901
- nodeId,
902
- limit: import_zod13.z.coerce.number().optional().describe("Max text nodes to return (default: 50)"),
903
- includePath: flexBool(import_zod13.z.boolean()).optional().describe("Include ancestor path strings (default: true). Set false to reduce payload."),
904
- includeGeometry: flexBool(import_zod13.z.boolean()).optional().describe("Include absoluteX/absoluteY/width/height (default: true). Set false to reduce payload.")
905
- });
906
- function registerMcpTools11(server2, sendCommand) {
907
- server2.tool(
908
- "set_text_content",
909
- "Set text content on text nodes. Batch: pass multiple items to replace text in multiple nodes at once.",
910
- { items: flexJson(import_zod13.z.array(textContentItem)).describe("Array of {nodeId, text}"), depth },
911
- async (params) => {
912
- try {
913
- return mcpJson(await sendCommand("set_text_content", params));
914
- } catch (e) {
915
- return mcpError("Error setting text content", e);
916
- }
917
- }
918
- );
919
- server2.tool(
920
- "set_text_properties",
921
- "Set font properties on existing text nodes (fontSize, fontWeight, fontColor, textStyle). Batch: pass multiple items.",
922
- { items: flexJson(import_zod13.z.array(textPropsItem)).describe("Array of {nodeId, fontSize?, fontWeight?, fontColor?, ...}"), depth },
923
- async (params) => {
924
- try {
925
- return mcpJson(await sendCommand("set_text_properties", params));
926
- } catch (e) {
927
- return mcpError("Error setting text properties", e);
928
- }
929
- }
930
- );
931
- server2.tool(
932
- "scan_text_nodes",
933
- "Scan all text nodes within a node tree. Batch: pass multiple items.",
934
- { items: flexJson(import_zod13.z.array(scanTextItem)).describe("Array of {nodeId}") },
935
- async (params) => {
936
- try {
937
- return mcpJson(await sendCommand("scan_text_nodes", params));
938
- } catch (e) {
939
- return mcpError("Error scanning text nodes", e);
940
- }
941
- }
942
- );
943
- }
944
-
945
- // src/tools/fonts.ts
946
- var import_zod14 = require("zod");
947
- function registerMcpTools12(server2, sendCommand) {
948
- server2.tool(
949
- "get_available_fonts",
950
- "Get available fonts in Figma. Optionally filter by query string.",
951
- { query: import_zod14.z.string().optional().describe("Filter fonts by name (case-insensitive). Omit to list all fonts.") },
952
- async ({ query }) => {
953
- try {
954
- return mcpJson(await sendCommand("get_available_fonts", { query }));
955
- } catch (e) {
956
- return mcpError("Error getting fonts", e);
957
- }
958
- }
959
- );
960
- }
961
-
962
- // src/tools/components.ts
963
- var import_zod15 = require("zod");
964
- var componentItem = import_zod15.z.object({
965
- name: import_zod15.z.string().describe("Component name"),
966
- x: xPos,
967
- y: yPos,
968
- width: import_zod15.z.coerce.number().optional().describe("Width (default: 100)"),
969
- height: import_zod15.z.coerce.number().optional().describe("Height (default: 100)"),
970
- parentId,
971
- fillColor: flexJson(colorRgba).optional().describe('Fill color. Hex "#FF0000" or {r,g,b,a?} 0-1. Omit for no fill.'),
972
- fillStyleName: import_zod15.z.string().optional().describe("Apply a fill paint style by name (case-insensitive)."),
973
- fillVariableId: import_zod15.z.string().optional().describe("Bind a color variable to the fill."),
974
- strokeColor: flexJson(colorRgba).optional().describe('Stroke color. Hex "#FF0000" or {r,g,b,a?} 0-1. Omit for no stroke.'),
975
- strokeStyleName: import_zod15.z.string().optional().describe("Apply a stroke paint style by name."),
976
- strokeVariableId: import_zod15.z.string().optional().describe("Bind a color variable to the stroke."),
977
- strokeWeight: import_zod15.z.coerce.number().positive().optional().describe("Stroke weight (default: 1)"),
978
- cornerRadius: import_zod15.z.coerce.number().optional().describe("Corner radius (default: 0)"),
979
- layoutMode: import_zod15.z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).optional().describe("Layout direction (default: NONE)"),
980
- layoutWrap: import_zod15.z.enum(["NO_WRAP", "WRAP"]).optional().describe("Wrap behavior (default: NO_WRAP)"),
981
- paddingTop: import_zod15.z.coerce.number().optional().describe("Top padding (default: 0)"),
982
- paddingRight: import_zod15.z.coerce.number().optional().describe("Right padding (default: 0)"),
983
- paddingBottom: import_zod15.z.coerce.number().optional().describe("Bottom padding (default: 0)"),
984
- paddingLeft: import_zod15.z.coerce.number().optional().describe("Left padding (default: 0)"),
985
- primaryAxisAlignItems: import_zod15.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional().describe("Primary axis alignment (default: MIN)"),
986
- counterAxisAlignItems: import_zod15.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional().describe("Counter axis alignment (default: MIN)"),
987
- layoutSizingHorizontal: import_zod15.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Horizontal sizing (default: FIXED)"),
988
- layoutSizingVertical: import_zod15.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Vertical sizing (default: FIXED)"),
989
- itemSpacing: import_zod15.z.coerce.number().optional().describe("Spacing between children (default: 0)")
990
- });
991
- var fromNodeItem = import_zod15.z.object({
992
- nodeId
993
- });
994
- var combineItem = import_zod15.z.object({
995
- componentIds: flexJson(import_zod15.z.array(import_zod15.z.string())).describe("Component IDs to combine (min 2)"),
996
- name: import_zod15.z.string().optional().describe("Name for the component set. Omit to auto-generate.")
997
- });
998
- var propItem = import_zod15.z.object({
999
- componentId: import_zod15.z.string().describe("Component node ID"),
1000
- propertyName: import_zod15.z.string().describe("Property name"),
1001
- type: import_zod15.z.enum(["BOOLEAN", "TEXT", "INSTANCE_SWAP", "VARIANT"]).describe("Property type"),
1002
- defaultValue: flexBool(import_zod15.z.union([import_zod15.z.string(), import_zod15.z.boolean()])).describe("Default value (string for TEXT/VARIANT, boolean for BOOLEAN)"),
1003
- preferredValues: flexJson(import_zod15.z.array(import_zod15.z.object({
1004
- type: import_zod15.z.enum(["COMPONENT", "COMPONENT_SET"]),
1005
- key: import_zod15.z.string()
1006
- })).optional()).describe("Preferred values for INSTANCE_SWAP type. Omit for none.")
1007
- });
1008
- var instanceItem = import_zod15.z.object({
1009
- componentId: import_zod15.z.string().describe("Component or component set ID"),
1010
- variantProperties: flexJson(import_zod15.z.record(import_zod15.z.string(), import_zod15.z.string())).optional().describe('Pick variant by properties, e.g. {"Style":"Secondary","Size":"Large"}. Ignored for plain COMPONENT IDs.'),
1011
- x: import_zod15.z.coerce.number().optional().describe("X position. Omit to keep default."),
1012
- y: import_zod15.z.coerce.number().optional().describe("Y position. Omit to keep default."),
1013
- parentId
1014
- });
1015
- function registerMcpTools13(server2, sendCommand) {
1016
- server2.tool(
1017
- "create_component",
1018
- "Create components in Figma. Same layout params as create_frame. Name with 'Property=Value' pattern (e.g. 'Size=Small') if you plan to combine_as_variants later. Use fillStyleName/fillVariableId over hardcoded colors. After adding text children, use add_component_property to expose text as editable properties. Batch: pass multiple items.",
1019
- { items: flexJson(import_zod15.z.array(componentItem)).describe("Array of components to create"), depth },
1020
- async (params) => {
1021
- try {
1022
- return mcpJson(await sendCommand("create_component", params));
1023
- } catch (e) {
1024
- return mcpError("Error creating component", e);
1025
- }
1026
- }
1027
- );
1028
- server2.tool(
1029
- "create_component_from_node",
1030
- "Convert existing nodes into components. Batch: pass multiple items.",
1031
- { items: flexJson(import_zod15.z.array(fromNodeItem)).describe("Array of {nodeId}"), depth },
1032
- async (params) => {
1033
- try {
1034
- return mcpJson(await sendCommand("create_component_from_node", params));
1035
- } catch (e) {
1036
- return mcpError("Error creating component from node", e);
1037
- }
1038
- }
1039
- );
1040
- server2.tool(
1041
- "combine_as_variants",
1042
- "Combine components into variant sets. Name components with 'Property=Value' pattern (e.g. 'Style=Primary', 'Size=Large') BEFORE combining \u2014 Figma derives variant properties from component names. Avoid slashes in names. The resulting set is placed in the components' shared parent (or page root if parents differ). Batch: pass multiple items.",
1043
- { items: flexJson(import_zod15.z.array(combineItem)).describe("Array of {componentIds, name?}"), depth },
1044
- async (params) => {
1045
- try {
1046
- return mcpJson(await sendCommand("combine_as_variants", params));
1047
- } catch (e) {
1048
- return mcpError("Error combining variants", e);
1049
- }
1050
- }
1051
- );
1052
- server2.tool(
1053
- "add_component_property",
1054
- "Add properties to components. Batch: pass multiple items.",
1055
- { items: flexJson(import_zod15.z.array(propItem)).describe("Array of {componentId, propertyName, type, defaultValue, preferredValues?}") },
1056
- async (params) => {
1057
- try {
1058
- return mcpJson(await sendCommand("add_component_property", params));
1059
- } catch (e) {
1060
- return mcpError("Error adding component property", e);
1061
- }
1062
- }
1063
- );
1064
- server2.tool(
1065
- "create_instance_from_local",
1066
- 'Create instances of local components. For COMPONENT_SET, use variantProperties to pick a specific variant (e.g. {"Style":"Secondary"}). Batch: pass multiple items.',
1067
- { items: flexJson(import_zod15.z.array(instanceItem)).describe("Array of {componentId, x?, y?, parentId?}") },
1068
- async (params) => {
1069
- try {
1070
- return mcpJson(await sendCommand("create_instance_from_local", params));
1071
- } catch (e) {
1072
- return mcpError("Error creating instance", e);
1073
- }
1074
- }
1075
- );
1076
- server2.tool(
1077
- "search_components",
1078
- "Search local components and component sets across all pages. Returns component id, name, and which page it lives on.",
1079
- {
1080
- query: import_zod15.z.string().optional().describe("Filter by name (case-insensitive substring). Omit to list all."),
1081
- setsOnly: flexBool(import_zod15.z.boolean()).optional().describe("If true, return only COMPONENT_SET nodes"),
1082
- limit: import_zod15.z.coerce.number().optional().describe("Max results (default 100)"),
1083
- offset: import_zod15.z.coerce.number().optional().describe("Skip N results (default 0)")
1084
- },
1085
- async (params) => {
1086
- try {
1087
- return mcpJson(await sendCommand("search_components", params));
1088
- } catch (e) {
1089
- return mcpError("Error searching components", e);
1090
- }
1091
- }
1092
- );
1093
- server2.tool(
1094
- "get_component_by_id",
1095
- "Get detailed component info including property definitions and variants.",
1096
- {
1097
- componentId: import_zod15.z.string().describe("Component node ID"),
1098
- includeChildren: flexBool(import_zod15.z.boolean()).optional().describe("For COMPONENT_SETs: include variant children (default false)")
1099
- },
1100
- async (params) => {
1101
- try {
1102
- return mcpJson(await sendCommand("get_component_by_id", params));
1103
- } catch (e) {
1104
- return mcpError("Error getting component", e);
1105
- }
1106
- }
1107
- );
1108
- server2.tool(
1109
- "get_instance_overrides",
1110
- "Get override properties from a component instance.",
1111
- { nodeId: import_zod15.z.string().optional().describe("Instance node ID (uses selection if omitted)") },
1112
- async ({ nodeId: nodeId2 }) => {
1113
- try {
1114
- return mcpJson(await sendCommand("get_instance_overrides", { instanceNodeId: nodeId2 || null }));
1115
- } catch (e) {
1116
- return mcpError("Error getting overrides", e);
1117
- }
1118
- }
1119
- );
1120
- server2.tool(
1121
- "set_instance_properties",
1122
- "Set component property values on instances (e.g. text, boolean, instance swap). Use get_component_by_id to discover property keys. Batch: pass multiple items.",
1123
- { items: flexJson(import_zod15.z.array(import_zod15.z.object({
1124
- nodeId,
1125
- properties: flexJson(import_zod15.z.record(import_zod15.z.string(), import_zod15.z.union([import_zod15.z.string(), import_zod15.z.boolean()]))).describe('Property key\u2192value map, e.g. {"Label#1:0":"Click Me"}')
1126
- }))).describe("Array of {nodeId, properties}"), depth },
1127
- async (params) => {
1128
- try {
1129
- return mcpJson(await sendCommand("set_instance_properties", params));
1130
- } catch (e) {
1131
- return mcpError("Error setting instance properties", e);
1132
- }
1133
- }
1134
- );
1135
- }
1136
-
1137
- // src/tools/styles.ts
1138
- var import_zod16 = require("zod");
1139
- var paintStyleItem = import_zod16.z.object({
1140
- name: import_zod16.z.string().describe("Style name"),
1141
- color: flexJson(colorRgba).describe('Color. Hex "#FF0000" or {r,g,b,a?} 0-1.')
1142
- });
1143
- var textStyleItem = import_zod16.z.object({
1144
- name: import_zod16.z.string().describe("Style name"),
1145
- fontFamily: import_zod16.z.string().describe("Font family"),
1146
- fontStyle: import_zod16.z.string().optional().describe("Font style (default: Regular)"),
1147
- fontSize: import_zod16.z.coerce.number().describe("Font size"),
1148
- lineHeight: flexNum(import_zod16.z.union([
1149
- import_zod16.z.number(),
1150
- import_zod16.z.object({ value: import_zod16.z.coerce.number(), unit: import_zod16.z.enum(["PIXELS", "PERCENT", "AUTO"]) })
1151
- ])).optional().describe("Line height \u2014 number (px) or {value, unit}. Default: auto."),
1152
- letterSpacing: flexNum(import_zod16.z.union([
1153
- import_zod16.z.number(),
1154
- import_zod16.z.object({ value: import_zod16.z.coerce.number(), unit: import_zod16.z.enum(["PIXELS", "PERCENT"]) })
1155
- ])).optional().describe("Letter spacing \u2014 number (px) or {value, unit}. Default: 0."),
1156
- textCase: import_zod16.z.enum(["ORIGINAL", "UPPER", "LOWER", "TITLE"]).optional(),
1157
- textDecoration: import_zod16.z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).optional()
1158
- });
1159
- var effectStyleItem = import_zod16.z.object({
1160
- name: import_zod16.z.string().describe("Style name"),
1161
- effects: flexJson(import_zod16.z.array(effectEntry)).describe("Array of effects")
1162
- });
1163
- var updatePaintStyleItem = import_zod16.z.object({
1164
- id: import_zod16.z.string().describe("Style ID or name (case-insensitive match)"),
1165
- name: import_zod16.z.string().optional().describe("New name"),
1166
- color: flexJson(colorRgba).optional().describe('New color. Hex "#FF0000" or {r,g,b,a?} 0-1.')
1167
- });
1168
- var updateTextStyleItem = import_zod16.z.object({
1169
- id: import_zod16.z.string().describe("Style ID or name (case-insensitive match)"),
1170
- name: import_zod16.z.string().optional().describe("New name"),
1171
- fontFamily: import_zod16.z.string().optional().describe("Font family"),
1172
- fontStyle: import_zod16.z.string().optional().describe("Font style (e.g. Regular, Bold)"),
1173
- fontSize: import_zod16.z.coerce.number().optional().describe("Font size"),
1174
- lineHeight: flexNum(import_zod16.z.union([
1175
- import_zod16.z.number(),
1176
- import_zod16.z.object({ value: import_zod16.z.coerce.number(), unit: import_zod16.z.enum(["PIXELS", "PERCENT", "AUTO"]) })
1177
- ])).optional().describe("Line height \u2014 number (px) or {value, unit}. Default: auto."),
1178
- letterSpacing: flexNum(import_zod16.z.union([
1179
- import_zod16.z.number(),
1180
- import_zod16.z.object({ value: import_zod16.z.coerce.number(), unit: import_zod16.z.enum(["PIXELS", "PERCENT"]) })
1181
- ])).optional().describe("Letter spacing \u2014 number (px) or {value, unit}. Default: 0."),
1182
- textCase: import_zod16.z.enum(["ORIGINAL", "UPPER", "LOWER", "TITLE"]).optional(),
1183
- textDecoration: import_zod16.z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).optional()
1184
- });
1185
- var applyStyleItem = import_zod16.z.object({
1186
- nodeId,
1187
- styleId: import_zod16.z.string().optional().describe("Style ID. Provide either styleId or styleName."),
1188
- styleName: import_zod16.z.string().optional().describe("Style name (case-insensitive substring match). Provide either styleId or styleName."),
1189
- styleType: import_zod16.z.preprocess((v) => typeof v === "string" ? v.toLowerCase() : v, import_zod16.z.enum(["fill", "stroke", "text", "effect"])).describe("Type of style: fill, stroke, text, or effect (case-insensitive)")
1190
- });
1191
- function registerMcpTools14(server2, sendCommand) {
1192
- server2.tool(
1193
- "get_styles",
1194
- "List local styles (paint, text, effect, grid). Returns IDs and names only.",
1195
- {},
1196
- async () => {
1197
- try {
1198
- return mcpJson(await sendCommand("get_styles"));
1199
- } catch (e) {
1200
- return mcpError("Error getting styles", e);
1201
- }
1202
- }
1203
- );
1204
- server2.tool(
1205
- "get_style_by_id",
1206
- "Get detailed style info by ID. Returns full paint/font/effect/grid details.",
1207
- { styleId: import_zod16.z.string().describe("Style ID") },
1208
- async ({ styleId }) => {
1209
- try {
1210
- return mcpJson(await sendCommand("get_style_by_id", { styleId }));
1211
- } catch (e) {
1212
- return mcpError("Error getting style", e);
1213
- }
1214
- }
1215
- );
1216
- server2.tool(
1217
- "remove_style",
1218
- "Delete a style by ID.",
1219
- { styleId: import_zod16.z.string().describe("Style ID to remove") },
1220
- async ({ styleId }) => {
1221
- try {
1222
- return mcpJson(await sendCommand("remove_style", { styleId }));
1223
- } catch (e) {
1224
- return mcpError("Error removing style", e);
1225
- }
1226
- }
1227
- );
1228
- server2.tool(
1229
- "create_paint_style",
1230
- "Create color/paint styles. Batch: pass multiple items.",
1231
- { items: flexJson(import_zod16.z.array(paintStyleItem)).describe("Array of {name, color}") },
1232
- async (params) => {
1233
- try {
1234
- return mcpJson(await sendCommand("create_paint_style", params));
1235
- } catch (e) {
1236
- return mcpError("Error creating paint style", e);
1237
- }
1238
- }
1239
- );
1240
- server2.tool(
1241
- "create_text_style",
1242
- "Create text styles. Batch: pass multiple items.",
1243
- { items: flexJson(import_zod16.z.array(textStyleItem)).describe("Array of text style definitions") },
1244
- async (params) => {
1245
- try {
1246
- return mcpJson(await sendCommand("create_text_style", params));
1247
- } catch (e) {
1248
- return mcpError("Error creating text style", e);
1249
- }
1250
- }
1251
- );
1252
- server2.tool(
1253
- "create_effect_style",
1254
- "Create effect styles (shadows, blurs). Batch: pass multiple items.",
1255
- { items: flexJson(import_zod16.z.array(effectStyleItem)).describe("Array of {name, effects}") },
1256
- async (params) => {
1257
- try {
1258
- return mcpJson(await sendCommand("create_effect_style", params));
1259
- } catch (e) {
1260
- return mcpError("Error creating effect style", e);
1261
- }
1262
- }
1263
- );
1264
- server2.tool(
1265
- "apply_style_to_node",
1266
- "Apply a style to nodes by ID or name. Use styleName for convenience (case-insensitive). Batch: pass multiple items.",
1267
- { items: flexJson(import_zod16.z.array(applyStyleItem)).describe("Array of {nodeId, styleId?, styleName?, styleType}"), depth },
1268
- async (params) => {
1269
- try {
1270
- return mcpJson(await sendCommand("apply_style_to_node", params));
1271
- } catch (e) {
1272
- return mcpError("Error applying style", e);
1273
- }
1274
- }
1275
- );
1276
- server2.tool(
1277
- "update_paint_style",
1278
- "Update paint style color/name by ID or name. Changes propagate to all nodes using the style. Batch: pass multiple items.",
1279
- { items: flexJson(import_zod16.z.array(updatePaintStyleItem)).describe("Array of {id, name?, color?}") },
1280
- async (params) => {
1281
- try {
1282
- return mcpJson(await sendCommand("update_paint_style", params));
1283
- } catch (e) {
1284
- return mcpError("Error updating paint style", e);
1285
- }
1286
- }
1287
- );
1288
- server2.tool(
1289
- "update_text_style",
1290
- "Update text style properties by ID or name. Changes propagate to all nodes using the style. Batch: pass multiple items.",
1291
- { items: flexJson(import_zod16.z.array(updateTextStyleItem)).describe("Array of {id, name?, fontSize?, fontFamily?, ...}") },
1292
- async (params) => {
1293
- try {
1294
- return mcpJson(await sendCommand("update_text_style", params));
1295
- } catch (e) {
1296
- return mcpError("Error updating text style", e);
1297
- }
1298
- }
1299
- );
1300
- }
330
+ paddingRight: import_zod7.z.coerce.number().optional().describe("Right padding (default: 0)"),
331
+ paddingBottom: import_zod7.z.coerce.number().optional().describe("Bottom padding (default: 0)"),
332
+ paddingLeft: import_zod7.z.coerce.number().optional().describe("Left padding (default: 0)"),
333
+ primaryAxisAlignItems: import_zod7.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional(),
334
+ counterAxisAlignItems: import_zod7.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional(),
335
+ layoutSizingHorizontal: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
336
+ layoutSizingVertical: import_zod7.z.enum(["FIXED", "HUG", "FILL"]).optional(),
337
+ layoutWrap: import_zod7.z.enum(["NO_WRAP", "WRAP"]).optional()
338
+ });
339
+ var tools6 = [
340
+ {
341
+ name: "create_frame",
342
+ description: "Create frames in Figma. Batch supported. Use fillStyleName/fillVariableId and strokeStyleName/strokeVariableId instead of hardcoded colors \u2014 hardcoded values skip design tokens and will trigger lint warnings.",
343
+ schema: { items: flexJson(import_zod7.z.array(frameItem)).describe("Array of frames to create"), depth },
344
+ tier: "create"
345
+ },
346
+ {
347
+ name: "create_auto_layout",
348
+ description: "Wrap existing nodes in an auto-layout frame. One call replaces create_frame + update_frame + insert_child \xD7 N.",
349
+ schema: { items: flexJson(import_zod7.z.array(autoLayoutItem)).describe("Array of auto-layout wraps to perform"), depth },
350
+ tier: "create"
351
+ }
352
+ ];
1301
353
 
1302
- // src/tools/variables.ts
1303
- var import_zod17 = require("zod");
1304
- var collectionItem = import_zod17.z.object({
1305
- name: import_zod17.z.string().describe("Collection name")
354
+ // src/tools/defs/create-text.ts
355
+ var import_zod8 = require("zod");
356
+ var textItem = import_zod8.z.object({
357
+ text: import_zod8.z.string().describe("Text content"),
358
+ name: import_zod8.z.string().optional().describe("Layer name (default: text content)"),
359
+ x: xPos,
360
+ y: yPos,
361
+ fontFamily: import_zod8.z.string().optional().describe("Font family (default: Inter). Use get_available_fonts to list installed fonts."),
362
+ fontStyle: import_zod8.z.string().optional().describe("Font style, e.g. 'Regular', 'Bold', 'Italic' (default: derived from fontWeight). Overrides fontWeight when set."),
363
+ fontSize: import_zod8.z.coerce.number().optional().describe("Font size (default: 14)"),
364
+ fontWeight: import_zod8.z.coerce.number().optional().describe("Font weight: 100-900 (default: 400). Ignored when fontStyle is set."),
365
+ fontColor: flexJson(colorRgba).optional().describe("Font color. Default: black."),
366
+ fontColorVariableId: import_zod8.z.string().optional().describe("Bind a color variable to the text fill instead of hardcoded fontColor."),
367
+ fontColorStyleName: import_zod8.z.string().optional().describe("Apply a paint style to the text fill by name (case-insensitive). Overrides fontColor."),
368
+ parentId,
369
+ textStyleId: import_zod8.z.string().optional().describe("Text style ID to apply (overrides fontSize/fontWeight). Omit to skip."),
370
+ textStyleName: import_zod8.z.string().optional().describe("Text style name (case-insensitive match). Omit to skip."),
371
+ textAlignHorizontal: import_zod8.z.enum(["LEFT", "CENTER", "RIGHT", "JUSTIFIED"]).optional().describe("Horizontal text alignment (default: LEFT)"),
372
+ textAlignVertical: import_zod8.z.enum(["TOP", "CENTER", "BOTTOM"]).optional().describe("Vertical text alignment (default: TOP)"),
373
+ layoutSizingHorizontal: import_zod8.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Horizontal sizing. FILL auto-sets textAutoResize to HEIGHT."),
374
+ layoutSizingVertical: import_zod8.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Vertical sizing (default: HUG)"),
375
+ textAutoResize: import_zod8.z.enum(["NONE", "WIDTH_AND_HEIGHT", "HEIGHT", "TRUNCATE"]).optional().describe("Text auto-resize behavior (default: WIDTH_AND_HEIGHT when FILL)")
1306
376
  });
1307
- var variableItem = import_zod17.z.object({
1308
- collectionId: import_zod17.z.string().describe("Variable collection ID"),
1309
- name: import_zod17.z.string().describe("Variable name"),
1310
- resolvedType: import_zod17.z.enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"]).describe("Variable type")
377
+ var tools7 = [
378
+ {
379
+ name: "create_text",
380
+ description: "Create text nodes. Max 10 per batch. Prefer textStyleName for typography and fontColorStyleName or fontColorVariableId for color \u2014 hardcoded values skip design tokens. Supports custom fonts via fontFamily.",
381
+ schema: { items: flexJson(import_zod8.z.array(textItem).max(10)).describe("Array of text nodes to create (max 10)"), depth },
382
+ tier: "create"
383
+ }
384
+ ];
385
+
386
+ // src/tools/defs/modify-node.ts
387
+ var import_zod9 = require("zod");
388
+ var deleteItem = import_zod9.z.object({
389
+ nodeId: import_zod9.z.string().describe("Node ID to delete")
1311
390
  });
1312
- var setValueItem = import_zod17.z.object({
1313
- variableId: import_zod17.z.string().describe("Variable ID (use full ID from create_variable response, e.g. VariableID:1:6)"),
1314
- modeId: import_zod17.z.string().describe("Mode ID"),
1315
- value: flexJson(import_zod17.z.union([
1316
- import_zod17.z.number(),
1317
- import_zod17.z.boolean(),
1318
- colorRgba
1319
- ])).describe('Value: number, boolean, or color (hex "#RRGGBB" or {r,g,b,a?} 0-1)')
391
+ var cloneItem = import_zod9.z.object({
392
+ nodeId: import_zod9.z.string().describe("Node ID to clone"),
393
+ parentId: import_zod9.z.string().optional().describe("Parent for the clone (e.g. a page ID). Defaults to same parent as original."),
394
+ x: import_zod9.z.coerce.number().optional().describe("New X for clone. Omit to keep original position."),
395
+ y: import_zod9.z.coerce.number().optional().describe("New Y for clone. Omit to keep original position.")
1320
396
  });
1321
- var bindingItem = import_zod17.z.object({
1322
- nodeId: import_zod17.z.string().describe("Node ID"),
1323
- field: import_zod17.z.string().describe("Property field (e.g., 'opacity', 'fills/0/color')"),
1324
- variableId: import_zod17.z.string().describe("Variable ID (use full ID from create_variable response, e.g. VariableID:1:6)")
397
+ var insertItem = import_zod9.z.object({
398
+ parentId: import_zod9.z.string().describe("Parent node ID"),
399
+ childId: import_zod9.z.string().describe("Child node ID to move"),
400
+ index: import_zod9.z.coerce.number().optional().describe("Index to insert at (0=first). Omit to append.")
1325
401
  });
1326
- var addModeItem = import_zod17.z.object({
1327
- collectionId: import_zod17.z.string().describe("Collection ID"),
1328
- name: import_zod17.z.string().describe("Mode name")
402
+ var tools8 = [
403
+ {
404
+ name: "delete_node",
405
+ description: "Delete nodes. Batch: pass multiple items.",
406
+ schema: { items: flexJson(import_zod9.z.array(deleteItem)).describe("Array of {nodeId}") },
407
+ tier: "edit"
408
+ },
409
+ {
410
+ name: "clone_node",
411
+ description: "Clone nodes. Batch: pass multiple items.",
412
+ schema: { items: flexJson(import_zod9.z.array(cloneItem)).describe("Array of {nodeId, x?, y?}"), depth },
413
+ tier: "create"
414
+ },
415
+ {
416
+ name: "insert_child",
417
+ description: "Move nodes into a parent at a specific index (reorder/reparent). Batch: pass multiple items.",
418
+ schema: { items: flexJson(import_zod9.z.array(insertItem)).describe("Array of {parentId, childId, index?}"), depth },
419
+ tier: "edit"
420
+ }
421
+ ];
422
+
423
+ // src/tools/defs/patch-nodes.ts
424
+ var import_zod10 = require("zod");
425
+ var exportSettingEntry = import_zod10.z.object({
426
+ format: import_zod10.z.enum(["PNG", "JPG", "SVG", "PDF"]),
427
+ suffix: import_zod10.z.string().optional(),
428
+ contentsOnly: flexBool(import_zod10.z.boolean()).optional(),
429
+ constraint: flexJson(import_zod10.z.object({
430
+ type: import_zod10.z.enum(["SCALE", "WIDTH", "HEIGHT"]),
431
+ value: import_zod10.z.coerce.number()
432
+ })).optional()
1329
433
  });
1330
- var renameModeItem = import_zod17.z.object({
1331
- collectionId: import_zod17.z.string().describe("Collection ID"),
1332
- modeId: import_zod17.z.string().describe("Mode ID"),
1333
- name: import_zod17.z.string().describe("New name")
434
+ var patchNodeItem = import_zod10.z.object({
435
+ nodeId,
436
+ // Geometry (flat)
437
+ x: import_zod10.z.coerce.number().optional().describe("X position"),
438
+ y: import_zod10.z.coerce.number().optional().describe("Y position"),
439
+ width: import_zod10.z.coerce.number().positive().optional().describe("Width (must provide height too)"),
440
+ height: import_zod10.z.coerce.number().positive().optional().describe("Height (must provide width too)"),
441
+ // Appearance (nested)
442
+ fill: flexJson(import_zod10.z.object({
443
+ color: flexJson(colorRgba).optional(),
444
+ styleName: import_zod10.z.string().optional().describe("Paint style name (preferred over color)")
445
+ })).optional().describe("Fill color or style"),
446
+ stroke: flexJson(import_zod10.z.object({
447
+ color: flexJson(colorRgba).optional(),
448
+ weight: import_zod10.z.coerce.number().positive().optional().describe("Stroke weight"),
449
+ styleName: import_zod10.z.string().optional().describe("Paint style name (preferred over color)")
450
+ })).optional().describe("Stroke color/weight or style"),
451
+ cornerRadius: flexJson(import_zod10.z.object({
452
+ radius: import_zod10.z.coerce.number().min(0).describe("Corner radius"),
453
+ corners: flexJson(import_zod10.z.array(flexBool(import_zod10.z.boolean())).length(4)).optional().describe("Which corners [topLeft, topRight, bottomRight, bottomLeft]. Default: all.")
454
+ })).optional().describe("Corner radius"),
455
+ opacity: import_zod10.z.coerce.number().min(0).max(1).optional().describe("Opacity (0-1)"),
456
+ effects: flexJson(import_zod10.z.object({
457
+ effects: flexJson(import_zod10.z.array(effectEntry)).optional().describe("Effect objects"),
458
+ styleName: import_zod10.z.string().optional().describe("Effect style name (preferred over raw effects)")
459
+ })).optional().describe("Effects or effect style"),
460
+ constraints: flexJson(import_zod10.z.object({
461
+ horizontal: import_zod10.z.enum(["MIN", "CENTER", "MAX", "STRETCH", "SCALE"]),
462
+ vertical: import_zod10.z.enum(["MIN", "CENTER", "MAX", "STRETCH", "SCALE"])
463
+ })).optional().describe("Layout constraints"),
464
+ exportSettings: flexJson(import_zod10.z.array(exportSettingEntry)).optional().describe("Export settings"),
465
+ // Layout (nested)
466
+ layout: flexJson(import_zod10.z.object({
467
+ layoutMode: import_zod10.z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).optional(),
468
+ layoutWrap: import_zod10.z.enum(["NO_WRAP", "WRAP"]).optional(),
469
+ paddingTop: import_zod10.z.coerce.number().optional(),
470
+ paddingRight: import_zod10.z.coerce.number().optional(),
471
+ paddingBottom: import_zod10.z.coerce.number().optional(),
472
+ paddingLeft: import_zod10.z.coerce.number().optional(),
473
+ primaryAxisAlignItems: import_zod10.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional(),
474
+ counterAxisAlignItems: import_zod10.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional(),
475
+ layoutSizingHorizontal: import_zod10.z.enum(["FIXED", "HUG", "FILL"]).optional(),
476
+ layoutSizingVertical: import_zod10.z.enum(["FIXED", "HUG", "FILL"]).optional(),
477
+ itemSpacing: import_zod10.z.coerce.number().optional(),
478
+ counterAxisSpacing: import_zod10.z.coerce.number().optional()
479
+ })).optional().describe("Auto-layout properties"),
480
+ // Text (nested)
481
+ text: flexJson(import_zod10.z.object({
482
+ fontSize: import_zod10.z.coerce.number().optional(),
483
+ fontWeight: import_zod10.z.coerce.number().optional(),
484
+ fontColor: flexJson(colorRgba).optional(),
485
+ textStyleId: import_zod10.z.string().optional(),
486
+ textStyleName: import_zod10.z.string().optional(),
487
+ textAlignHorizontal: import_zod10.z.enum(["LEFT", "CENTER", "RIGHT", "JUSTIFIED"]).optional(),
488
+ textAlignVertical: import_zod10.z.enum(["TOP", "CENTER", "BOTTOM"]).optional(),
489
+ textAutoResize: import_zod10.z.enum(["NONE", "WIDTH_AND_HEIGHT", "HEIGHT", "TRUNCATE"]).optional(),
490
+ layoutSizingHorizontal: import_zod10.z.enum(["FIXED", "HUG", "FILL"]).optional(),
491
+ layoutSizingVertical: import_zod10.z.enum(["FIXED", "HUG", "FILL"]).optional()
492
+ })).optional().describe("Text properties (font, alignment, sizing)"),
493
+ // Escape hatch
494
+ properties: flexJson(import_zod10.z.record(import_zod10.z.string(), import_zod10.z.unknown())).optional().describe("Arbitrary key-value properties to set directly on the node")
1334
495
  });
1335
- var removeModeItem = import_zod17.z.object({
1336
- collectionId: import_zod17.z.string().describe("Collection ID"),
1337
- modeId: import_zod17.z.string().describe("Mode ID")
496
+ var tools9 = [
497
+ {
498
+ name: "patch_nodes",
499
+ description: "Patch properties on nodes. Combines geometry (x/y/width/height), appearance (fill, stroke, cornerRadius, opacity, effects, constraints, exportSettings), layout (auto-layout), text (font props), and arbitrary properties in one call. Prefer styleName over hardcoded colors. Batch: pass multiple items.",
500
+ schema: { items: flexJson(import_zod10.z.array(patchNodeItem)).describe("Array of nodes to patch"), depth },
501
+ tier: "edit"
502
+ }
503
+ ];
504
+
505
+ // src/tools/defs/text.ts
506
+ var import_zod11 = require("zod");
507
+ var textContentItem = import_zod11.z.object({
508
+ nodeId: import_zod11.z.string().describe("Text node ID"),
509
+ text: import_zod11.z.string().describe("New text content")
1338
510
  });
1339
- var setExplicitModeItem = import_zod17.z.object({
511
+ var scanTextItem = import_zod11.z.object({
1340
512
  nodeId,
1341
- collectionId: import_zod17.z.string().describe("Variable collection ID"),
1342
- modeId: import_zod17.z.string().describe("Mode ID to pin (e.g. Dark mode)")
513
+ limit: import_zod11.z.coerce.number().optional().describe("Max text nodes to return (default: 50)"),
514
+ includePath: flexBool(import_zod11.z.boolean()).optional().describe("Include ancestor path strings (default: true). Set false to reduce payload."),
515
+ includeGeometry: flexBool(import_zod11.z.boolean()).optional().describe("Include absoluteX/absoluteY/width/height (default: true). Set false to reduce payload.")
1343
516
  });
1344
- function registerMcpTools15(server2, sendCommand) {
1345
- server2.tool(
1346
- "create_variable_collection",
1347
- "Create variable collections. Batch: pass multiple items.",
1348
- { items: flexJson(import_zod17.z.array(collectionItem)).describe("Array of {name}") },
1349
- async ({ items }) => {
1350
- try {
1351
- return mcpJson(await sendCommand("create_variable_collection", { items }));
1352
- } catch (e) {
1353
- return mcpError("Error creating variable collection", e);
1354
- }
1355
- }
1356
- );
1357
- server2.tool(
1358
- "create_variable",
1359
- "Create variables in a collection. Batch: pass multiple items.",
1360
- { items: flexJson(import_zod17.z.array(variableItem)).describe("Array of {collectionId, name, resolvedType}") },
1361
- async ({ items }) => {
1362
- try {
1363
- return mcpJson(await sendCommand("create_variable", { items }));
1364
- } catch (e) {
1365
- return mcpError("Error creating variable", e);
1366
- }
1367
- }
1368
- );
1369
- server2.tool(
1370
- "set_variable_value",
1371
- "Set variable values for modes. Batch: pass multiple items.",
1372
- { items: flexJson(import_zod17.z.array(setValueItem)).describe("Array of {variableId, modeId, value}") },
1373
- async ({ items }) => {
1374
- try {
1375
- return mcpJson(await sendCommand("set_variable_value", { items }));
1376
- } catch (e) {
1377
- return mcpError("Error setting variable value", e);
1378
- }
1379
- }
1380
- );
1381
- server2.tool(
1382
- "get_local_variables",
1383
- "List local variables. Pass includeValues:true to get all mode values in bulk (avoids N separate get_variable_by_id calls).",
1384
- {
1385
- type: import_zod17.z.enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"]).optional().describe("Filter by type"),
1386
- collectionId: import_zod17.z.string().optional().describe("Filter by collection. Omit for all collections."),
1387
- includeValues: flexBool(import_zod17.z.boolean()).optional().describe("Include valuesByMode for each variable (default: false)")
1388
- },
1389
- async (params) => {
1390
- try {
1391
- return mcpJson(await sendCommand("get_local_variables", params));
1392
- } catch (e) {
1393
- return mcpError("Error getting variables", e);
1394
- }
1395
- }
1396
- );
1397
- server2.tool(
1398
- "get_local_variable_collections",
1399
- "List all local variable collections.",
1400
- {},
1401
- async () => {
1402
- try {
1403
- return mcpJson(await sendCommand("get_local_variable_collections"));
1404
- } catch (e) {
1405
- return mcpError("Error getting variable collections", e);
1406
- }
1407
- }
1408
- );
1409
- server2.tool(
1410
- "get_variable_by_id",
1411
- "Get detailed variable info including all mode values.",
1412
- { variableId: import_zod17.z.string().describe("Variable ID") },
1413
- async ({ variableId }) => {
1414
- try {
1415
- return mcpJson(await sendCommand("get_variable_by_id", { variableId }));
1416
- } catch (e) {
1417
- return mcpError("Error getting variable", e);
1418
- }
1419
- }
1420
- );
1421
- server2.tool(
1422
- "get_variable_collection_by_id",
1423
- "Get detailed variable collection info including modes and variable IDs.",
1424
- { collectionId: import_zod17.z.string().describe("Collection ID") },
1425
- async ({ collectionId }) => {
1426
- try {
1427
- return mcpJson(await sendCommand("get_variable_collection_by_id", { collectionId }));
1428
- } catch (e) {
1429
- return mcpError("Error getting variable collection", e);
1430
- }
1431
- }
1432
- );
1433
- server2.tool(
1434
- "set_variable_binding",
1435
- "Bind variables to node properties. Common fields: 'fills/0/color', 'strokes/0/color', 'opacity', 'topLeftRadius', 'itemSpacing'. Batch: pass multiple items.",
1436
- { items: flexJson(import_zod17.z.array(bindingItem)).describe("Array of {nodeId, field, variableId}") },
1437
- async ({ items }) => {
1438
- try {
1439
- return mcpJson(await sendCommand("set_variable_binding", { items }));
1440
- } catch (e) {
1441
- return mcpError("Error binding variable", e);
1442
- }
1443
- }
1444
- );
1445
- server2.tool(
1446
- "add_mode",
1447
- "Add modes to variable collections. Batch: pass multiple items.",
1448
- { items: flexJson(import_zod17.z.array(addModeItem)).describe("Array of {collectionId, name}") },
1449
- async ({ items }) => {
1450
- try {
1451
- return mcpJson(await sendCommand("add_mode", { items }));
1452
- } catch (e) {
1453
- return mcpError("Error adding mode", e);
1454
- }
1455
- }
1456
- );
1457
- server2.tool(
1458
- "rename_mode",
1459
- "Rename modes in variable collections. Batch: pass multiple items.",
1460
- { items: flexJson(import_zod17.z.array(renameModeItem)).describe("Array of {collectionId, modeId, name}") },
1461
- async ({ items }) => {
1462
- try {
1463
- return mcpJson(await sendCommand("rename_mode", { items }));
1464
- } catch (e) {
1465
- return mcpError("Error renaming mode", e);
1466
- }
1467
- }
1468
- );
1469
- server2.tool(
1470
- "remove_mode",
1471
- "Remove modes from variable collections. Batch: pass multiple items.",
1472
- { items: flexJson(import_zod17.z.array(removeModeItem)).describe("Array of {collectionId, modeId}") },
1473
- async ({ items }) => {
1474
- try {
1475
- return mcpJson(await sendCommand("remove_mode", { items }));
1476
- } catch (e) {
1477
- return mcpError("Error removing mode", e);
1478
- }
1479
- }
1480
- );
1481
- server2.tool(
1482
- "set_explicit_variable_mode",
1483
- "Pin a variable collection mode on a frame (e.g. show Dark mode). Batch: pass multiple items.",
1484
- { items: flexJson(import_zod17.z.array(setExplicitModeItem)).describe("Array of {nodeId, collectionId, modeId}") },
1485
- async ({ items }) => {
1486
- try {
1487
- return mcpJson(await sendCommand("set_explicit_variable_mode", { items }));
1488
- } catch (e) {
1489
- return mcpError("Error setting variable mode", e);
1490
- }
1491
- }
1492
- );
1493
- server2.tool(
1494
- "get_node_variables",
1495
- "Get variable bindings on a node. Returns which variables are bound to fills, strokes, opacity, corner radius, etc.",
1496
- { nodeId },
1497
- async ({ nodeId: nodeId2 }) => {
1498
- try {
1499
- return mcpJson(await sendCommand("get_node_variables", { nodeId: nodeId2 }));
1500
- } catch (e) {
1501
- return mcpError("Error getting node variables", e);
1502
- }
1503
- }
1504
- );
1505
- server2.tool(
1506
- "delete_variable_collection",
1507
- "Delete a variable collection and all its variables. This is destructive and cannot be undone.",
1508
- { collectionId: import_zod17.z.string().describe("Collection ID to delete") },
1509
- async ({ collectionId }) => {
1510
- try {
1511
- return mcpJson(await sendCommand("delete_variable_collection", { collectionId }));
1512
- } catch (e) {
1513
- return mcpError("Error deleting variable collection", e);
1514
- }
1515
- }
1516
- );
1517
- }
517
+ var tools10 = [
518
+ {
519
+ name: "set_text_content",
520
+ description: "Set text content on text nodes. Batch: pass multiple items to replace text in multiple nodes at once.",
521
+ schema: { items: flexJson(import_zod11.z.array(textContentItem)).describe("Array of {nodeId, text}"), depth },
522
+ tier: "edit"
523
+ },
524
+ {
525
+ name: "scan_text_nodes",
526
+ description: "Scan all text nodes within a node tree. Batch: pass multiple items.",
527
+ schema: { items: flexJson(import_zod11.z.array(scanTextItem)).describe("Array of {nodeId}") },
528
+ tier: "read"
529
+ }
530
+ ];
1518
531
 
1519
- // src/tools/lint.ts
1520
- var import_zod18 = require("zod");
1521
- init_color();
1522
- var lintRules = import_zod18.z.enum([
532
+ // src/tools/defs/fonts.ts
533
+ var import_zod12 = require("zod");
534
+ var tools11 = [
535
+ {
536
+ name: "get_available_fonts",
537
+ description: "Get available fonts in Figma. Optionally filter by query string.",
538
+ schema: { query: import_zod12.z.string().optional().describe("Filter fonts by name (case-insensitive). Omit to list all fonts.") },
539
+ tier: "read"
540
+ }
541
+ ];
542
+
543
+ // src/tools/defs/lint.ts
544
+ var import_zod13 = require("zod");
545
+ var lintRules = import_zod13.z.enum([
1523
546
  "no-autolayout",
1524
- // Frames with >1 child and no auto-layout
1525
547
  "shape-instead-of-frame",
1526
- // Shapes used where FRAME should be
1527
548
  "hardcoded-color",
1528
- // Fills/strokes not using styles
1529
549
  "no-text-style",
1530
- // Text nodes without text style
1531
550
  "fixed-in-autolayout",
1532
- // Fixed-size children in auto-layout parents
1533
551
  "default-name",
1534
- // Nodes with default/unnamed names
1535
552
  "empty-container",
1536
- // Frames/components with layout but no children
1537
553
  "stale-text-name",
1538
- // Text nodes where layer name diverges from content
1539
554
  "no-text-property",
1540
- // Text in components not bound to a component property
1541
- // ── WCAG 2.2 rules ──
1542
555
  "wcag-contrast",
1543
- // 1.4.3 AA text contrast (4.5:1 / 3:1 large)
1544
556
  "wcag-contrast-enhanced",
1545
- // 1.4.6 AAA text contrast (7:1 / 4.5:1 large)
1546
557
  "wcag-non-text-contrast",
1547
- // 1.4.11 AA non-text contrast (3:1)
1548
558
  "wcag-target-size",
1549
- // 2.5.8 AA target size minimum (24x24px)
1550
559
  "wcag-text-size",
1551
- // Best practice: minimum readable text (12px)
1552
560
  "wcag-line-height",
1553
- // 1.4.12 AA text spacing (line height 1.5x)
1554
561
  "wcag",
1555
- // Meta: run all wcag-* rules
1556
562
  "all"
1557
- // Run all rules (including WCAG)
1558
563
  ]);
1559
- function registerMcpTools16(server2, sendCommand) {
1560
- server2.tool(
1561
- "lint_node",
1562
- "Run design linter on a node tree. Returns issues grouped by category with affected node IDs and fix instructions. Lint child nodes individually for large trees.",
1563
- {
1564
- nodeId: import_zod18.z.string().optional().describe("Node ID to lint. Omit to lint current selection."),
1565
- rules: flexJson(import_zod18.z.array(lintRules)).optional().describe('Rules to run. Default: ["all"]. Options: no-autolayout, shape-instead-of-frame, hardcoded-color, no-text-style, fixed-in-autolayout, default-name, empty-container, stale-text-name, no-text-property, all, wcag-contrast, wcag-contrast-enhanced, wcag-non-text-contrast, wcag-target-size, wcag-text-size, wcag-line-height, wcag'),
1566
- maxDepth: import_zod18.z.coerce.number().optional().describe("Max depth to recurse (default: 10)"),
1567
- maxFindings: import_zod18.z.coerce.number().optional().describe("Stop after N findings (default: 50)")
564
+ var tools12 = [
565
+ {
566
+ name: "lint_node",
567
+ description: "Run design linter on a node tree. Returns issues grouped by category with affected node IDs and fix instructions. Lint child nodes individually for large trees.",
568
+ schema: {
569
+ nodeId: import_zod13.z.string().optional().describe("Node ID to lint. Omit to lint current selection."),
570
+ rules: flexJson(import_zod13.z.array(lintRules)).optional().describe('Rules to run. Default: ["all"]. Options: no-autolayout, shape-instead-of-frame, hardcoded-color, no-text-style, fixed-in-autolayout, default-name, empty-container, stale-text-name, no-text-property, all, wcag-contrast, wcag-contrast-enhanced, wcag-non-text-contrast, wcag-target-size, wcag-text-size, wcag-line-height, wcag'),
571
+ maxDepth: import_zod13.z.coerce.number().optional().describe("Max depth to recurse (default: 10)"),
572
+ maxFindings: import_zod13.z.coerce.number().optional().describe("Stop after N findings (default: 50)")
1568
573
  },
1569
- async (params) => {
1570
- try {
1571
- return mcpJson(await sendCommand("lint_node", params));
1572
- } catch (e) {
1573
- return mcpError("Error running lint", e);
1574
- }
1575
- }
1576
- );
1577
- server2.tool(
1578
- "lint_fix_autolayout",
1579
- "Auto-fix: convert frames with multiple children to auto-layout. Takes node IDs from lint_node 'no-autolayout' results.",
1580
- {
1581
- items: flexJson(import_zod18.z.array(import_zod18.z.object({
574
+ tier: "read"
575
+ },
576
+ {
577
+ name: "lint_fix_autolayout",
578
+ description: "Auto-fix: convert frames with multiple children to auto-layout. Takes node IDs from lint_node 'no-autolayout' results.",
579
+ schema: {
580
+ items: flexJson(import_zod13.z.array(import_zod13.z.object({
1582
581
  nodeId,
1583
- layoutMode: import_zod18.z.enum(["HORIZONTAL", "VERTICAL"]).optional().describe("Layout direction (default: auto-detect based on child positions)"),
1584
- itemSpacing: import_zod18.z.coerce.number().optional().describe("Spacing between children (default: 0)")
582
+ layoutMode: import_zod13.z.enum(["HORIZONTAL", "VERTICAL"]).optional().describe("Layout direction (default: auto-detect based on child positions)"),
583
+ itemSpacing: import_zod13.z.coerce.number().optional().describe("Spacing between children (default: 0)")
1585
584
  }))).describe("Array of frames to convert to auto-layout"),
1586
585
  depth
1587
586
  },
1588
- async (params) => {
1589
- try {
1590
- return mcpJson(await sendCommand("lint_fix_autolayout", params));
1591
- } catch (e) {
1592
- return mcpError("Error fixing auto-layout", e);
587
+ tier: "edit"
588
+ }
589
+ ];
590
+
591
+ // src/tools/defs/styles.ts
592
+ var import_zod15 = require("zod");
593
+
594
+ // src/tools/endpoint.ts
595
+ var import_zod14 = require("zod");
596
+ var DEFAULT_TIERS = {
597
+ get: "read",
598
+ list: "read",
599
+ create: "create",
600
+ update: "edit",
601
+ delete: "edit"
602
+ };
603
+ function endpointSchema(methods, capsOrExtra, extraOrTiers, methodTiers) {
604
+ let caps2;
605
+ let extra;
606
+ if (capsOrExtra && "create" in capsOrExtra && "edit" in capsOrExtra && typeof capsOrExtra.create === "boolean") {
607
+ caps2 = capsOrExtra;
608
+ extra = extraOrTiers;
609
+ } else {
610
+ extra = capsOrExtra;
611
+ }
612
+ let filtered = methods;
613
+ if (caps2) {
614
+ const tiers = { ...DEFAULT_TIERS, ...methodTiers };
615
+ filtered = methods.filter((m) => {
616
+ const tier = tiers[m] ?? "edit";
617
+ if (tier === "read") return true;
618
+ if (tier === "create") return caps2.create;
619
+ if (tier === "edit") return caps2.edit;
620
+ return false;
621
+ });
622
+ }
623
+ const schema = {
624
+ method: import_zod14.z.enum(filtered)
625
+ };
626
+ if (filtered.includes("get") || filtered.includes("delete")) {
627
+ schema.id = import_zod14.z.string().optional().describe("Resource ID (get, delete)");
628
+ }
629
+ if (filtered.includes("get") || filtered.includes("list")) {
630
+ schema.fields = flexJson(import_zod14.z.array(import_zod14.z.string())).optional().describe('Property whitelist (get/list). Identity fields (id, name, type) always included. Omit for stubs on list, full detail on get. Pass ["*"] for all fields.');
631
+ }
632
+ if (filtered.includes("list")) {
633
+ schema.offset = import_zod14.z.coerce.number().optional().describe("Skip N items for pagination (default 0)");
634
+ schema.limit = import_zod14.z.coerce.number().optional().describe("Max items per page (default 100)");
635
+ }
636
+ return { ...schema, ...extra };
637
+ }
638
+
639
+ // src/tools/defs/styles.ts
640
+ var paintStyleItem = import_zod15.z.object({
641
+ name: import_zod15.z.string().describe("Style name"),
642
+ color: flexJson(colorRgba).describe("Color.")
643
+ });
644
+ var textStyleItem = import_zod15.z.object({
645
+ name: import_zod15.z.string().describe("Style name"),
646
+ fontFamily: import_zod15.z.string().describe("Font family"),
647
+ fontStyle: import_zod15.z.string().optional().describe("Font style (default: Regular)"),
648
+ fontSize: import_zod15.z.coerce.number().describe("Font size"),
649
+ lineHeight: flexNum(import_zod15.z.union([
650
+ import_zod15.z.number(),
651
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT", "AUTO"]) })
652
+ ])).optional().describe("Line height \u2014 number (px) or {value, unit}. Default: auto."),
653
+ letterSpacing: flexNum(import_zod15.z.union([
654
+ import_zod15.z.number(),
655
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT"]) })
656
+ ])).optional().describe("Letter spacing \u2014 number (px) or {value, unit}. Default: 0."),
657
+ textCase: import_zod15.z.enum(["ORIGINAL", "UPPER", "LOWER", "TITLE"]).optional(),
658
+ textDecoration: import_zod15.z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).optional()
659
+ });
660
+ var effectStyleItem = import_zod15.z.object({
661
+ name: import_zod15.z.string().describe("Style name"),
662
+ effects: flexJson(import_zod15.z.array(effectEntry)).describe("Array of effects")
663
+ });
664
+ var patchBase = {
665
+ id: import_zod15.z.string().describe("Style ID or name (case-insensitive match)"),
666
+ name: import_zod15.z.string().optional().describe("Rename the style")
667
+ };
668
+ var patchPaintItem = import_zod15.z.object({
669
+ ...patchBase,
670
+ color: flexJson(colorRgba).optional().describe("New color.")
671
+ });
672
+ var patchTextItem = import_zod15.z.object({
673
+ ...patchBase,
674
+ fontFamily: import_zod15.z.string().optional().describe("Font family"),
675
+ fontStyle: import_zod15.z.string().optional().describe("Font style, e.g. Regular, Bold"),
676
+ fontSize: import_zod15.z.coerce.number().optional().describe("Font size"),
677
+ lineHeight: flexNum(import_zod15.z.union([
678
+ import_zod15.z.number(),
679
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT", "AUTO"]) })
680
+ ])).optional().describe("Line height \u2014 number (px) or {value, unit}"),
681
+ letterSpacing: flexNum(import_zod15.z.union([
682
+ import_zod15.z.number(),
683
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT"]) })
684
+ ])).optional().describe("Letter spacing \u2014 number (px) or {value, unit}"),
685
+ textCase: import_zod15.z.enum(["ORIGINAL", "UPPER", "LOWER", "TITLE"]).optional(),
686
+ textDecoration: import_zod15.z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).optional()
687
+ });
688
+ var patchEffectItem = import_zod15.z.object({
689
+ ...patchBase,
690
+ effects: flexJson(import_zod15.z.array(effectEntry)).optional().describe("Array of effects")
691
+ });
692
+ var patchAnyItem = import_zod15.z.object({
693
+ ...patchBase,
694
+ color: flexJson(colorRgba).optional(),
695
+ fontFamily: import_zod15.z.string().optional(),
696
+ fontStyle: import_zod15.z.string().optional(),
697
+ fontSize: import_zod15.z.coerce.number().optional(),
698
+ lineHeight: flexNum(import_zod15.z.union([
699
+ import_zod15.z.number(),
700
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT", "AUTO"]) })
701
+ ])).optional(),
702
+ letterSpacing: flexNum(import_zod15.z.union([
703
+ import_zod15.z.number(),
704
+ import_zod15.z.object({ value: import_zod15.z.coerce.number(), unit: import_zod15.z.enum(["PIXELS", "PERCENT"]) })
705
+ ])).optional(),
706
+ textCase: import_zod15.z.enum(["ORIGINAL", "UPPER", "LOWER", "TITLE"]).optional(),
707
+ textDecoration: import_zod15.z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).optional(),
708
+ effects: flexJson(import_zod15.z.array(effectEntry)).optional()
709
+ });
710
+ var createSchemas = {
711
+ paint: paintStyleItem,
712
+ text: textStyleItem,
713
+ effect: effectStyleItem
714
+ };
715
+ var updateSchemas = {
716
+ paint: patchPaintItem,
717
+ text: patchTextItem,
718
+ effect: patchEffectItem
719
+ };
720
+ var tools13 = [
721
+ {
722
+ name: "styles",
723
+ description: "CRUD endpoint for local styles (paint, text, effect).\n list \u2192 {type?, fields?, offset?, limit?} \u2192 {totalCount, items: [{id, name, type, ...}]}\n get \u2192 {id, fields?} \u2192 style object (full detail; fields to filter)\n create \u2192 {type, items: [...]} \u2192 {results: [{id}, ...]}\n update \u2192 {type?, items: [{id, ...}]} \u2192 {results: ['ok'|{warning}, ...]}\n delete \u2192 {id} or {items: [{id}, ...]} \u2192 'ok' or {results: ['ok', ...]}",
724
+ schema: (caps2) => endpointSchema(
725
+ ["create", "get", "list", "update", "delete"],
726
+ caps2,
727
+ {
728
+ type: import_zod15.z.enum(["paint", "text", "effect"]).optional().describe("Style type. Required for create. Filters list by type. Optional for update (strict per-type validation; omit to auto-detect)."),
729
+ items: flexJson(import_zod15.z.array(import_zod15.z.any())).optional().describe("Create: [{name, color}] (paint), [{name, fontFamily, fontSize, ...}] (text), [{name, effects}] (effect). Update: [{id, ...fields}]. Delete (batch): [{id}, ...]."),
730
+ depth
731
+ }
732
+ ),
733
+ tier: "read",
734
+ validate: (params) => {
735
+ if (params.items) {
736
+ const map = params.method === "update" ? updateSchemas : createSchemas;
737
+ const itemSchema = params.type && map[params.type] || patchAnyItem;
738
+ params.items = import_zod15.z.array(itemSchema).parse(params.items);
1593
739
  }
1594
740
  }
1595
- );
1596
- server2.tool(
1597
- "lint_fix_replace_shape_with_frame",
1598
- "Auto-fix: replace shapes with frames preserving visual properties. Overlapping siblings are re-parented into the new frame. Use after lint_node 'shape-instead-of-frame' results.",
1599
- {
1600
- items: flexJson(import_zod18.z.array(import_zod18.z.object({
1601
- nodeId,
1602
- adoptChildren: flexBool(import_zod18.z.boolean()).optional().describe("Re-parent overlapping siblings into the new frame (default: true)")
1603
- }))).describe("Array of shapes to convert to frames"),
1604
- depth
1605
- },
1606
- async (params) => {
1607
- try {
1608
- return mcpJson(await sendCommand("lint_fix_replace_shape_with_frame", params));
1609
- } catch (e) {
1610
- return mcpError("Error converting shapes to frames", e);
741
+ }
742
+ ];
743
+
744
+ // src/tools/defs/variables.ts
745
+ var import_zod16 = require("zod");
746
+ var collectionCreateItem = import_zod16.z.object({
747
+ name: import_zod16.z.string().describe("Collection name")
748
+ });
749
+ var addModeItem = import_zod16.z.object({
750
+ collectionId: import_zod16.z.string().describe("Collection ID"),
751
+ name: import_zod16.z.string().describe("Mode name")
752
+ });
753
+ var renameModeItem = import_zod16.z.object({
754
+ collectionId: import_zod16.z.string().describe("Collection ID"),
755
+ modeId: import_zod16.z.string().describe("Mode ID"),
756
+ name: import_zod16.z.string().describe("New name")
757
+ });
758
+ var removeModeItem = import_zod16.z.object({
759
+ collectionId: import_zod16.z.string().describe("Collection ID"),
760
+ modeId: import_zod16.z.string().describe("Mode ID")
761
+ });
762
+ var deleteCollectionItem = import_zod16.z.object({
763
+ id: import_zod16.z.string().describe("Collection ID")
764
+ });
765
+ var collectionMethodSchemas = {
766
+ create: collectionCreateItem,
767
+ delete: deleteCollectionItem,
768
+ add_mode: addModeItem,
769
+ rename_mode: renameModeItem,
770
+ remove_mode: removeModeItem
771
+ };
772
+ var variableCreateItem = import_zod16.z.object({
773
+ collectionId: import_zod16.z.string().describe("Variable collection ID"),
774
+ name: import_zod16.z.string().describe("Variable name"),
775
+ resolvedType: import_zod16.z.enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"]).describe("Variable type")
776
+ });
777
+ var variableUpdateItem = import_zod16.z.object({
778
+ id: import_zod16.z.string().describe("Variable ID (full ID, e.g. VariableID:1:6)"),
779
+ modeId: import_zod16.z.string().describe("Mode ID"),
780
+ value: flexJson(import_zod16.z.union([
781
+ import_zod16.z.number(),
782
+ import_zod16.z.boolean(),
783
+ colorRgba
784
+ ])).describe('Value: number, boolean, or color (hex "#RRGGBB" or {r,g,b,a?} 0-1)')
785
+ });
786
+ var variableMethodSchemas = {
787
+ create: variableCreateItem,
788
+ update: variableUpdateItem
789
+ };
790
+ var bindingItem = import_zod16.z.object({
791
+ nodeId: import_zod16.z.string().describe("Node ID"),
792
+ field: import_zod16.z.string().describe("Property field (e.g., 'opacity', 'fills/0/color')"),
793
+ variableId: import_zod16.z.string().describe("Variable ID (use full ID from create_variable response, e.g. VariableID:1:6)")
794
+ });
795
+ var setExplicitModeItem = import_zod16.z.object({
796
+ nodeId,
797
+ collectionId: import_zod16.z.string().describe("Variable collection ID"),
798
+ modeId: import_zod16.z.string().describe("Mode ID to pin (e.g. Dark mode)")
799
+ });
800
+ var vcMethodTiers = {
801
+ add_mode: "create",
802
+ rename_mode: "edit",
803
+ remove_mode: "edit"
804
+ };
805
+ var tools14 = [
806
+ {
807
+ name: "variable_collections",
808
+ description: `CRUD endpoint for variable collections + mode management.
809
+ create \u2192 {items: [{name}]} \u2192 {results: [{id, modes, defaultModeId}]}
810
+ get \u2192 {id, fields?} \u2192 collection object
811
+ list \u2192 {fields?, offset?, limit?} \u2192 paginated stubs
812
+ delete \u2192 {id} or {items: [{id}]} \u2192 'ok' or {results: ['ok', ...]}
813
+ add_mode \u2192 {items: [{collectionId, name}]} \u2192 {results: [{modeId, modes}]}
814
+ rename_mode \u2192 {items: [{collectionId, modeId, name}]} \u2192 {results: [{modes}]}
815
+ remove_mode \u2192 {items: [{collectionId, modeId}]} \u2192 {results: [{modes}]}`,
816
+ schema: (caps2) => endpointSchema(
817
+ ["create", "get", "list", "delete", "add_mode", "rename_mode", "remove_mode"],
818
+ caps2,
819
+ {
820
+ items: flexJson(import_zod16.z.array(import_zod16.z.any())).optional().describe("create: [{name}]. delete (batch): [{id}]. add_mode: [{collectionId, name}]. rename_mode: [{collectionId, modeId, name}]. remove_mode: [{collectionId, modeId}].")
821
+ },
822
+ vcMethodTiers
823
+ ),
824
+ tier: "read",
825
+ validate: (params) => {
826
+ if (params.items) {
827
+ const schema = collectionMethodSchemas[params.method];
828
+ if (schema) params.items = import_zod16.z.array(schema).parse(params.items);
1611
829
  }
1612
830
  }
1613
- );
1614
- }
831
+ },
832
+ {
833
+ name: "variables",
834
+ description: `CRUD endpoint for design variables.
835
+ create \u2192 {items: [{collectionId, name, resolvedType}]} \u2192 {results: [{id}]}
836
+ get \u2192 {id, fields?} \u2192 variable object (full detail)
837
+ list \u2192 {type?, collectionId?, fields?, offset?, limit?} \u2192 paginated stubs (fields for detail)
838
+ update \u2192 {items: [{id, modeId, value}]} \u2192 {results: ['ok', ...]}`,
839
+ schema: (caps2) => endpointSchema(
840
+ ["create", "get", "list", "update"],
841
+ caps2,
842
+ {
843
+ items: flexJson(import_zod16.z.array(import_zod16.z.any())).optional().describe("create: [{collectionId, name, resolvedType}]. update: [{id, modeId, value}]."),
844
+ type: import_zod16.z.enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"]).optional().describe("Filter list by variable type."),
845
+ collectionId: import_zod16.z.string().optional().describe("Filter list by collection ID.")
846
+ }
847
+ ),
848
+ tier: "read",
849
+ validate: (params) => {
850
+ if (params.items) {
851
+ const schema = variableMethodSchemas[params.method];
852
+ if (schema) params.items = import_zod16.z.array(schema).parse(params.items);
853
+ }
854
+ }
855
+ },
856
+ {
857
+ name: "set_variable_binding",
858
+ description: "Bind variables to node properties. Common fields: 'fills/0/color', 'strokes/0/color', 'opacity', 'topLeftRadius', 'itemSpacing'. Batch: pass multiple items.",
859
+ schema: { items: flexJson(import_zod16.z.array(bindingItem)).describe("Array of {nodeId, field, variableId}") },
860
+ tier: "edit"
861
+ },
862
+ {
863
+ name: "set_explicit_variable_mode",
864
+ description: "Pin a variable collection mode on a frame (e.g. show Dark mode). Batch: pass multiple items.",
865
+ schema: { items: flexJson(import_zod16.z.array(setExplicitModeItem)).describe("Array of {nodeId, collectionId, modeId}") },
866
+ tier: "edit"
867
+ },
868
+ {
869
+ name: "get_node_variables",
870
+ description: "Get variable bindings on a node. Returns which variables are bound to fills, strokes, opacity, corner radius, etc.",
871
+ schema: { nodeId },
872
+ tier: "read"
873
+ }
874
+ ];
1615
875
 
1616
- // src/tools/connection.ts
1617
- function registerMcpTools17(server2, sendCommand) {
1618
- server2.tool(
1619
- "ping",
1620
- "Verify end-to-end connection to Figma. Call this right after join_channel. Returns { status: 'pong', documentName, currentPage } if the full chain (MCP \u2192 relay \u2192 plugin \u2192 Figma) is working. If this times out, the Figma plugin is not connected \u2014 ask the user to check the plugin window for the correct port and channel name.",
1621
- {},
1622
- async () => {
1623
- try {
1624
- return mcpJson(await sendCommand("ping", {}, 5e3));
1625
- } catch (e) {
1626
- return mcpError("Connection verification failed", e);
876
+ // src/tools/defs/components.ts
877
+ var import_zod17 = require("zod");
878
+ var componentItem = import_zod17.z.object({
879
+ name: import_zod17.z.string().describe("Component name"),
880
+ x: xPos,
881
+ y: yPos,
882
+ width: import_zod17.z.coerce.number().optional().describe("Width (default: 100)"),
883
+ height: import_zod17.z.coerce.number().optional().describe("Height (default: 100)"),
884
+ parentId,
885
+ fillColor: flexJson(colorRgba).optional().describe("Fill color. Omit for no fill."),
886
+ fillStyleName: import_zod17.z.string().optional().describe("Apply a fill paint style by name (case-insensitive)."),
887
+ fillVariableId: import_zod17.z.string().optional().describe("Bind a color variable to the fill."),
888
+ strokeColor: flexJson(colorRgba).optional().describe("Stroke color. Omit for no stroke."),
889
+ strokeStyleName: import_zod17.z.string().optional().describe("Apply a stroke paint style by name."),
890
+ strokeVariableId: import_zod17.z.string().optional().describe("Bind a color variable to the stroke."),
891
+ strokeWeight: import_zod17.z.coerce.number().positive().optional().describe("Stroke weight (default: 1)"),
892
+ cornerRadius: import_zod17.z.coerce.number().optional().describe("Corner radius (default: 0)"),
893
+ layoutMode: import_zod17.z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).optional().describe("Layout direction (default: NONE)"),
894
+ layoutWrap: import_zod17.z.enum(["NO_WRAP", "WRAP"]).optional().describe("Wrap behavior (default: NO_WRAP)"),
895
+ paddingTop: import_zod17.z.coerce.number().optional().describe("Top padding (default: 0)"),
896
+ paddingRight: import_zod17.z.coerce.number().optional().describe("Right padding (default: 0)"),
897
+ paddingBottom: import_zod17.z.coerce.number().optional().describe("Bottom padding (default: 0)"),
898
+ paddingLeft: import_zod17.z.coerce.number().optional().describe("Left padding (default: 0)"),
899
+ primaryAxisAlignItems: import_zod17.z.enum(["MIN", "MAX", "CENTER", "SPACE_BETWEEN"]).optional().describe("Primary axis alignment (default: MIN)"),
900
+ counterAxisAlignItems: import_zod17.z.enum(["MIN", "MAX", "CENTER", "BASELINE"]).optional().describe("Counter axis alignment (default: MIN)"),
901
+ layoutSizingHorizontal: import_zod17.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Horizontal sizing (default: FIXED)"),
902
+ layoutSizingVertical: import_zod17.z.enum(["FIXED", "HUG", "FILL"]).optional().describe("Vertical sizing (default: FIXED)"),
903
+ itemSpacing: import_zod17.z.coerce.number().optional().describe("Spacing between children (default: 0)")
904
+ });
905
+ var fromNodeItem = import_zod17.z.object({
906
+ nodeId
907
+ });
908
+ var combineItem = import_zod17.z.object({
909
+ componentIds: flexJson(import_zod17.z.array(import_zod17.z.string())).describe("Component IDs to combine (min 2)"),
910
+ name: import_zod17.z.string().optional().describe("Name for the component set. Omit to auto-generate.")
911
+ });
912
+ var updateComponentItem = import_zod17.z.object({
913
+ id: import_zod17.z.string().describe("Component node ID"),
914
+ propertyName: import_zod17.z.string().describe("Property name"),
915
+ type: import_zod17.z.enum(["BOOLEAN", "TEXT", "INSTANCE_SWAP", "VARIANT"]).describe("Property type"),
916
+ defaultValue: flexBool(import_zod17.z.union([import_zod17.z.string(), import_zod17.z.boolean()])).describe("Default value (string for TEXT/VARIANT, boolean for BOOLEAN)"),
917
+ preferredValues: flexJson(import_zod17.z.array(import_zod17.z.object({
918
+ type: import_zod17.z.enum(["COMPONENT", "COMPONENT_SET"]),
919
+ key: import_zod17.z.string()
920
+ })).optional()).describe("Preferred values for INSTANCE_SWAP type. Omit for none.")
921
+ });
922
+ var componentCreateSchemas = {
923
+ component: componentItem,
924
+ from_node: fromNodeItem,
925
+ variant_set: combineItem
926
+ };
927
+ var instanceCreateItem = import_zod17.z.object({
928
+ componentId: import_zod17.z.string().describe("Component or component set ID"),
929
+ variantProperties: flexJson(import_zod17.z.record(import_zod17.z.string(), import_zod17.z.string())).optional().describe('Pick variant by properties, e.g. {"Style":"Secondary","Size":"Large"}. Ignored for plain COMPONENT IDs.'),
930
+ x: import_zod17.z.coerce.number().optional().describe("X position. Omit to keep default."),
931
+ y: import_zod17.z.coerce.number().optional().describe("Y position. Omit to keep default."),
932
+ parentId
933
+ });
934
+ var instanceUpdateItem = import_zod17.z.object({
935
+ id: nodeId,
936
+ properties: flexJson(import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), import_zod17.z.boolean()]))).describe('Property key\u2192value map, e.g. {"Label#1:0":"Click Me"}')
937
+ });
938
+ var tools15 = [
939
+ {
940
+ name: "components",
941
+ description: `CRUD endpoint for components.
942
+ create \u2192 {type, items, depth?} \u2192 {results: [{id}, ...]}
943
+ type 'component': create from scratch with layout/style params
944
+ type 'from_node': convert existing nodes to components
945
+ type 'variant_set': combine components into variant sets
946
+ get \u2192 {id, fields?} \u2192 component object (full detail, field-filterable)
947
+ list \u2192 {name?, setsOnly?, fields?, offset?, limit?} \u2192 paginated stubs
948
+ update \u2192 {items: [{id, propertyName, type, defaultValue}]} \u2192 {results: ['ok', ...]}`,
949
+ schema: (caps2) => endpointSchema(
950
+ ["create", "get", "list", "update"],
951
+ caps2,
952
+ {
953
+ items: flexJson(import_zod17.z.array(import_zod17.z.any())).optional().describe("create (component): [{name, parentId?, ...layout}]. create (from_node): [{nodeId}]. create (variant_set): [{componentIds, name?}]. update: [{id, propertyName, type, defaultValue}]."),
954
+ type: import_zod17.z.enum(["component", "from_node", "variant_set"]).optional().describe("Create type. Required for create: 'component' (from scratch), 'from_node' (convert existing), 'variant_set' (combine as variants)."),
955
+ depth,
956
+ name: import_zod17.z.string().optional().describe("Filter list by name (case-insensitive substring)."),
957
+ setsOnly: flexBool(import_zod17.z.boolean()).optional().describe("If true, list returns only COMPONENT_SET nodes.")
958
+ }
959
+ ),
960
+ tier: "read",
961
+ validate: (params) => {
962
+ if (params.items) {
963
+ if (params.method === "create") {
964
+ const schema = params.type && componentCreateSchemas[params.type];
965
+ if (!schema) throw new Error(`create requires type: component, from_node, or variant_set`);
966
+ params.items = import_zod17.z.array(schema).parse(params.items);
967
+ } else if (params.method === "update") {
968
+ params.items = import_zod17.z.array(updateComponentItem).parse(params.items);
969
+ }
1627
970
  }
1628
971
  }
1629
- );
1630
- }
972
+ },
973
+ {
974
+ name: "instances",
975
+ description: `CRUD endpoint for component instances.
976
+ create \u2192 {items: [{componentId, variantProperties?, x?, y?, parentId?}], depth?} \u2192 {results: [{id}]}
977
+ get \u2192 {id} \u2192 {mainComponentId, overrides: [{id, fields}]}
978
+ update \u2192 {items: [{id, properties}]} \u2192 {results: ['ok', ...]}`,
979
+ schema: (caps2) => endpointSchema(
980
+ ["create", "get", "update"],
981
+ caps2,
982
+ {
983
+ items: flexJson(import_zod17.z.array(import_zod17.z.any())).optional().describe("create: [{componentId, variantProperties?, x?, y?, parentId?}]. update: [{id, properties}]."),
984
+ depth
985
+ }
986
+ ),
987
+ tier: "read",
988
+ validate: (params) => {
989
+ if (params.items) {
990
+ if (params.method === "create") {
991
+ params.items = import_zod17.z.array(instanceCreateItem).parse(params.items);
992
+ } else if (params.method === "update") {
993
+ params.items = import_zod17.z.array(instanceUpdateItem).parse(params.items);
994
+ }
995
+ }
996
+ }
997
+ }
998
+ ];
1631
999
 
1632
1000
  // src/tools/prompts.ts
1633
1001
  function registerPrompts(server2) {
1634
- server2.prompt(
1002
+ server2.registerPrompt(
1635
1003
  "design_strategy",
1636
- "Best practices for working with Figma designs",
1004
+ { description: "Best practices for working with Figma designs" },
1637
1005
  () => ({
1638
1006
  messages: [{
1639
1007
  role: "assistant",
@@ -1643,7 +1011,7 @@ function registerPrompts(server2) {
1643
1011
 
1644
1012
  1. Understand Before Creating:
1645
1013
  - Use get_document_info() to see pages and current page
1646
- - Use get_styles() and get_local_variables() to discover existing design tokens
1014
+ - Use styles(method: "list") and get_local_variables() to discover existing design tokens
1647
1015
  - Plan layout hierarchy before creating elements
1648
1016
 
1649
1017
  2. Use Design Tokens \u2014 Never Hardcode:
@@ -1660,7 +1028,7 @@ function registerPrompts(server2) {
1660
1028
 
1661
1029
  4. Naming Conventions:
1662
1030
  - Use descriptive, semantic names for all elements
1663
- - Name components with Property=Value pattern (e.g. "Size=Small") before combine_as_variants
1031
+ - Name components with Property=Value pattern (e.g. "Size=Small") before components(method: "create", type: "variant_set")
1664
1032
 
1665
1033
  5. Variable Modes:
1666
1034
  - Use set_explicit_variable_mode() to pin a frame to a specific mode (e.g. Dark)
@@ -1672,16 +1040,16 @@ function registerPrompts(server2) {
1672
1040
  * no-text-style: text without a text style applied
1673
1041
  * no-autolayout: frames with children but no auto-layout
1674
1042
  * default-name: nodes still named "Frame", "Rectangle", etc.
1675
- - Use lint_fix_autolayout() and lint_fix_replace_shape_with_frame() to auto-fix
1043
+ - Use lint_fix_autolayout() to auto-fix layout issues
1676
1044
  - Lint early and often \u2014 it is cheaper to fix issues during creation than after`
1677
1045
  }
1678
1046
  }],
1679
1047
  description: "Best practices for working with Figma designs"
1680
1048
  })
1681
1049
  );
1682
- server2.prompt(
1050
+ server2.registerPrompt(
1683
1051
  "read_design_strategy",
1684
- "Best practices for reading Figma designs",
1052
+ { description: "Best practices for reading Figma designs" },
1685
1053
  () => ({
1686
1054
  messages: [{
1687
1055
  role: "assistant",
@@ -1690,7 +1058,7 @@ function registerPrompts(server2) {
1690
1058
  text: `When reading Figma designs, follow these best practices:
1691
1059
 
1692
1060
  1. Start with selection:
1693
- - First use read_my_design() to understand the current selection
1061
+ - First use get_selection() to understand the current selection
1694
1062
  - If no selection ask user to select single or multiple nodes
1695
1063
  `
1696
1064
  }
@@ -1698,9 +1066,9 @@ function registerPrompts(server2) {
1698
1066
  description: "Best practices for reading Figma designs"
1699
1067
  })
1700
1068
  );
1701
- server2.prompt(
1069
+ server2.registerPrompt(
1702
1070
  "text_replacement_strategy",
1703
- "Systematic approach for replacing text in Figma designs",
1071
+ { description: "Systematic approach for replacing text in Figma designs" },
1704
1072
  () => ({
1705
1073
  messages: [{
1706
1074
  role: "assistant",
@@ -1825,9 +1193,9 @@ Remember that text is never just text\u2014it's a core design element that must
1825
1193
  description: "Systematic approach for replacing text in Figma designs"
1826
1194
  })
1827
1195
  );
1828
- server2.prompt(
1196
+ server2.registerPrompt(
1829
1197
  "swap_overrides_instances",
1830
- "Guide to swap instance overrides between instances",
1198
+ { description: "Guide to swap instance overrides between instances" },
1831
1199
  () => ({
1832
1200
  messages: [{
1833
1201
  role: "assistant",
@@ -1845,12 +1213,12 @@ Transfer content overrides from a source instance to target instances.
1845
1213
  - Use \`search_nodes(types: ["INSTANCE"])\` to find instances on the page
1846
1214
 
1847
1215
  ### 2. Extract Source Overrides
1848
- - \`get_instance_overrides(nodeId: "source-instance-id")\`
1216
+ - \`instances(method: "get", id: "source-instance-id")\`
1849
1217
  - Returns mainComponentId and per-child override fields (characters, fills, fontSize, etc.)
1850
1218
 
1851
1219
  ### 3. Apply to Targets
1852
1220
  - For text overrides: use \`set_text_content\` on matching child node IDs
1853
- - For style overrides: use \`set_fill_color\`, \`apply_style_to_node\`, etc.
1221
+ - For style overrides: use \`patch_nodes\` with fill/stroke/text/effects styleName fields
1854
1222
  - Match children by name path \u2014 source and target instances share the same internal structure
1855
1223
 
1856
1224
  ### 4. Verify
@@ -1864,24 +1232,25 @@ Transfer content overrides from a source instance to target instances.
1864
1232
  }
1865
1233
 
1866
1234
  // src/tools/mcp-registry.ts
1867
- function registerAllTools(server2, sendCommand) {
1868
- registerMcpTools(server2, sendCommand);
1869
- registerMcpTools2(server2, sendCommand);
1870
- registerMcpTools3(server2, sendCommand);
1871
- registerMcpTools4(server2, sendCommand);
1872
- registerMcpTools5(server2, sendCommand);
1873
- registerMcpTools6(server2, sendCommand);
1874
- registerMcpTools7(server2, sendCommand);
1875
- registerMcpTools8(server2, sendCommand);
1876
- registerMcpTools9(server2, sendCommand);
1877
- registerMcpTools10(server2, sendCommand);
1878
- registerMcpTools11(server2, sendCommand);
1879
- registerMcpTools12(server2, sendCommand);
1880
- registerMcpTools13(server2, sendCommand);
1881
- registerMcpTools14(server2, sendCommand);
1882
- registerMcpTools15(server2, sendCommand);
1883
- registerMcpTools16(server2, sendCommand);
1884
- registerMcpTools17(server2, sendCommand);
1235
+ var allTools = [
1236
+ ...tools,
1237
+ ...tools2,
1238
+ ...tools3,
1239
+ ...tools4,
1240
+ ...tools5,
1241
+ ...tools6,
1242
+ ...tools7,
1243
+ ...tools8,
1244
+ ...tools9,
1245
+ ...tools10,
1246
+ ...tools11,
1247
+ ...tools12,
1248
+ ...tools13,
1249
+ ...tools14,
1250
+ ...tools15
1251
+ ];
1252
+ function registerAllTools(server2, sendCommand, caps2) {
1253
+ registerTools(server2, sendCommand, caps2, allTools);
1885
1254
  registerPrompts(server2);
1886
1255
  }
1887
1256
 
@@ -1927,6 +1296,10 @@ var portArg = args.find((a) => a.startsWith("--port="));
1927
1296
  var serverUrl = serverArg ? serverArg.split("=")[1] : "localhost";
1928
1297
  if (portArg) activePort = parseInt(portArg.split("=")[1]);
1929
1298
  var WS_URL = serverUrl === "localhost" ? `ws://${serverUrl}` : `wss://${serverUrl}`;
1299
+ var caps = {
1300
+ create: args.includes("--create") || args.includes("--edit"),
1301
+ edit: args.includes("--edit")
1302
+ };
1930
1303
  function connectToFigma(port = activePort) {
1931
1304
  activePort = port;
1932
1305
  if (ws && ws.readyState === import_ws.default.OPEN) {
@@ -2094,10 +1467,12 @@ var server = new import_mcp.McpServer({
2094
1467
  name: "VibmaMCP",
2095
1468
  version: "1.0.0"
2096
1469
  });
2097
- server.tool(
1470
+ server.registerTool(
2098
1471
  "join_channel",
2099
- "REQUIRED FIRST STEP: Join a channel before using any other tool. The channel name is shown in the Figma plugin UI (defaults to 'vibma' if not customised). After joining, call `ping` to verify the Figma plugin is connected. All subsequent commands are sent through this channel.",
2100
- { channel: import_zod19.z.string().describe("The channel name displayed in the Figma plugin panel. Defaults to 'vibma' if omitted.").default("vibma") },
1472
+ {
1473
+ description: "REQUIRED FIRST STEP: Join a channel before using any other tool. The channel name is shown in the Figma plugin UI (defaults to 'vibma' if not customised). After joining, call `ping` to verify the Figma plugin is connected. All subsequent commands are sent through this channel.",
1474
+ inputSchema: { channel: import_zod18.z.string().describe("The channel name displayed in the Figma plugin panel. Defaults to 'vibma' if omitted.").default("vibma") }
1475
+ },
2101
1476
  async ({ channel }) => {
2102
1477
  try {
2103
1478
  await joinChannel(channel);
@@ -2120,10 +1495,11 @@ See "Version mismatch" in CARRYME.md or DRAGME.md for update steps.`;
2120
1495
  }
2121
1496
  }
2122
1497
  );
2123
- server.tool(
1498
+ server.registerTool(
2124
1499
  "channel_info",
2125
- "Debug: inspect which clients (MCP, plugin) are connected to each relay channel. Useful for diagnosing connection issues. Does not require an active channel.",
2126
- {},
1500
+ {
1501
+ description: "Debug: inspect which clients (MCP, plugin) are connected to each relay channel. Useful for diagnosing connection issues. Does not require an active channel."
1502
+ },
2127
1503
  async () => {
2128
1504
  try {
2129
1505
  const url = serverUrl === "localhost" ? `http://localhost:${activePort}/channels` : `https://${serverUrl}/channels`;
@@ -2143,11 +1519,13 @@ server.tool(
2143
1519
  }
2144
1520
  }
2145
1521
  );
2146
- server.tool(
1522
+ server.registerTool(
2147
1523
  "reset_tunnel",
2148
- "DESTRUCTIVE: Factory-reset a channel on the relay via HTTP, disconnecting ALL occupants (MCP + Figma plugin). Only use this when the channel is stuck or occupied by another MCP \u2014 do NOT use it just to reconnect yourself (use `join_channel` instead). After reset, ask the user to reopen the Vibma plugin in Figma, then call `join_channel` and `ping`.",
2149
1524
  {
2150
- channel: import_zod19.z.string().describe("Channel to reset. Defaults to 'vibma'.").default("vibma")
1525
+ description: "DESTRUCTIVE: Factory-reset a channel on the relay via HTTP, disconnecting ALL occupants (MCP + Figma plugin). Only use this when the channel is stuck or occupied by another MCP \u2014 do NOT use it just to reconnect yourself (use `join_channel` instead). After reset, ask the user to reopen the Vibma plugin in Figma, then call `join_channel` and `ping`.",
1526
+ inputSchema: {
1527
+ channel: import_zod18.z.string().describe("Channel to reset. Defaults to 'vibma'.").default("vibma")
1528
+ }
2151
1529
  },
2152
1530
  async ({ channel }) => {
2153
1531
  const targetChannel = channel || currentChannel || "vibma";
@@ -2191,7 +1569,7 @@ IMPORTANT: The Figma plugin was also disconnected. Ask the user to reopen the Vi
2191
1569
  }
2192
1570
  }
2193
1571
  );
2194
- registerAllTools(server, sendCommandToFigma);
1572
+ registerAllTools(server, sendCommandToFigma, caps);
2195
1573
  function cleanup() {
2196
1574
  if (ws && ws.readyState === import_ws.default.OPEN) {
2197
1575
  ws.close(1e3, "MCP server shutting down");