@muloka/figma-console-mcp 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +111 -848
  2. package/dist/apps/design-system-dashboard/mcp-app.html +107 -94
  3. package/dist/apps/design-system-dashboard/server.d.ts +1 -1
  4. package/dist/apps/design-system-dashboard/server.d.ts.map +1 -1
  5. package/dist/apps/token-browser/mcp-app.html +95 -82
  6. package/dist/apps/token-browser/server.d.ts +1 -1
  7. package/dist/apps/token-browser/server.d.ts.map +1 -1
  8. package/dist/core/accessibility-tools.d.ts +1 -1
  9. package/dist/core/accessibility-tools.d.ts.map +1 -1
  10. package/dist/core/accessibility-tools.js +18 -15
  11. package/dist/core/accessibility-tools.js.map +1 -1
  12. package/dist/core/annotation-tools.d.ts +1 -1
  13. package/dist/core/annotation-tools.d.ts.map +1 -1
  14. package/dist/core/annotation-tools.js +35 -26
  15. package/dist/core/annotation-tools.js.map +1 -1
  16. package/dist/core/comment-tools.d.ts +2 -2
  17. package/dist/core/comment-tools.d.ts.map +1 -1
  18. package/dist/core/comment-tools.js +60 -51
  19. package/dist/core/comment-tools.js.map +1 -1
  20. package/dist/core/config.d.ts.map +1 -1
  21. package/dist/core/config.js +2 -17
  22. package/dist/core/config.js.map +1 -1
  23. package/dist/core/console-monitor.d.ts +1 -1
  24. package/dist/core/console-monitor.d.ts.map +1 -1
  25. package/dist/core/console-monitor.js +2 -2
  26. package/dist/core/console-monitor.js.map +1 -1
  27. package/dist/core/deep-component-tools.d.ts +1 -1
  28. package/dist/core/deep-component-tools.d.ts.map +1 -1
  29. package/dist/core/deep-component-tools.js +15 -9
  30. package/dist/core/deep-component-tools.js.map +1 -1
  31. package/dist/core/design-code-tools.d.ts +1 -1
  32. package/dist/core/design-code-tools.d.ts.map +1 -1
  33. package/dist/core/design-code-tools.js +51 -45
  34. package/dist/core/design-code-tools.js.map +1 -1
  35. package/dist/core/design-system-tools.d.ts +1 -1
  36. package/dist/core/design-system-tools.d.ts.map +1 -1
  37. package/dist/core/design-system-tools.js +39 -36
  38. package/dist/core/design-system-tools.js.map +1 -1
  39. package/dist/core/diagnose-tool.d.ts +4 -4
  40. package/dist/core/diagnose-tool.d.ts.map +1 -1
  41. package/dist/core/diagnose-tool.js +12 -14
  42. package/dist/core/diagnose-tool.js.map +1 -1
  43. package/dist/core/figjam-tools.d.ts +2 -2
  44. package/dist/core/figjam-tools.d.ts.map +1 -1
  45. package/dist/core/figjam-tools.js +159 -129
  46. package/dist/core/figjam-tools.js.map +1 -1
  47. package/dist/core/figma-tools.d.ts +1 -1
  48. package/dist/core/figma-tools.d.ts.map +1 -1
  49. package/dist/core/figma-tools.js +280 -253
  50. package/dist/core/figma-tools.js.map +1 -1
  51. package/dist/core/identity.d.ts +49 -9
  52. package/dist/core/identity.d.ts.map +1 -1
  53. package/dist/core/identity.js +137 -28
  54. package/dist/core/identity.js.map +1 -1
  55. package/dist/core/library-tools.d.ts +1 -1
  56. package/dist/core/library-tools.d.ts.map +1 -1
  57. package/dist/core/library-tools.js +45 -36
  58. package/dist/core/library-tools.js.map +1 -1
  59. package/dist/core/logger.d.ts +0 -1
  60. package/dist/core/logger.d.ts.map +1 -1
  61. package/dist/core/logger.js +1 -13
  62. package/dist/core/logger.js.map +1 -1
  63. package/dist/core/slides-tools.d.ts +2 -2
  64. package/dist/core/slides-tools.d.ts.map +1 -1
  65. package/dist/core/slides-tools.js +223 -172
  66. package/dist/core/slides-tools.js.map +1 -1
  67. package/dist/core/slot-tools.d.ts +1 -1
  68. package/dist/core/slot-tools.d.ts.map +1 -1
  69. package/dist/core/slot-tools.js +101 -86
  70. package/dist/core/slot-tools.js.map +1 -1
  71. package/dist/core/tokens/config.d.ts +88 -266
  72. package/dist/core/tokens/config.d.ts.map +1 -1
  73. package/dist/core/tokens/config.js +2 -3
  74. package/dist/core/tokens/config.js.map +1 -1
  75. package/dist/core/tokens/schemas.d.ts +104 -113
  76. package/dist/core/tokens/schemas.d.ts.map +1 -1
  77. package/dist/core/tokens/schemas.js +2 -2
  78. package/dist/core/tokens/schemas.js.map +1 -1
  79. package/dist/core/tokens-tools.d.ts +5 -3
  80. package/dist/core/tokens-tools.d.ts.map +1 -1
  81. package/dist/core/tokens-tools.js +9 -2
  82. package/dist/core/tokens-tools.js.map +1 -1
  83. package/dist/core/types/index.d.ts +1 -1
  84. package/dist/core/types/index.d.ts.map +1 -1
  85. package/dist/core/variable-resolver.d.ts +3 -3
  86. package/dist/core/variable-resolver.js +5 -5
  87. package/dist/core/variable-resolver.js.map +1 -1
  88. package/dist/core/version-tools.d.ts +4 -4
  89. package/dist/core/version-tools.d.ts.map +1 -1
  90. package/dist/core/version-tools.js +162 -144
  91. package/dist/core/version-tools.js.map +1 -1
  92. package/dist/core/websocket-connector.d.ts +2 -3
  93. package/dist/core/websocket-connector.d.ts.map +1 -1
  94. package/dist/core/websocket-connector.js +2 -3
  95. package/dist/core/websocket-connector.js.map +1 -1
  96. package/dist/core/websocket-server.d.ts +39 -2
  97. package/dist/core/websocket-server.d.ts.map +1 -1
  98. package/dist/core/websocket-server.js +138 -18
  99. package/dist/core/websocket-server.js.map +1 -1
  100. package/dist/core/write-tools.d.ts +15 -2
  101. package/dist/core/write-tools.d.ts.map +1 -1
  102. package/dist/core/write-tools.js +589 -477
  103. package/dist/core/write-tools.js.map +1 -1
  104. package/dist/local.d.ts +8 -1
  105. package/dist/local.d.ts.map +1 -1
  106. package/dist/local.js +370 -202
  107. package/dist/local.js.map +1 -1
  108. package/package.json +10 -18
@@ -30,9 +30,28 @@ const HEX_TO_RGBA_HELPER = `function hexToRgba(hex) {
30
30
  a: h.length === 8 ? parseInt(h.substring(6, 8), 16) / 255 : 1
31
31
  };
32
32
  }`;
33
+ /**
34
+ * Rewrite serialized JSON before interpolating it into a Figma plugin script.
35
+ *
36
+ * Figma's plugin sandbox refuses a whole script whose source text matches its
37
+ * import-expression scanner (`/^(.*)\bimport\s*(\(|\/\/|\/\*|<!--|-->)/m`),
38
+ * even inside string literals, and older JS parsers reject raw U+2028/U+2029
39
+ * inside string literals. In JSON, `(` and `import` only ever appear inside
40
+ * string literals and neither is part of an escape sequence, so replacing
41
+ * them with unicode escapes is lossless on parse.
42
+ *
43
+ * Adapted from upstream `sandboxSafeJson` (`src/core/assets/plugin-scripts.ts`).
44
+ */
45
+ export function sandboxSafeJson(json) {
46
+ return json
47
+ .replace(/\u2028/g, "\\u2028")
48
+ .replace(/\u2029/g, "\\u2029")
49
+ .replace(/\(/g, "\\u0028")
50
+ .replace(/import/gi, (m) => (m[0] === "i" ? "\\u0069" : "\\u0049") + m.slice(1));
51
+ }
33
52
  /**
34
53
  * Register write/manipulation tools that require a Desktop Bridge connector.
35
- * Used by both local mode (src/local.ts) and cloud mode (src/index.ts).
54
+ * Registered by src/local.ts.
36
55
  * `getDesktopConnector(fileKey)` returns a connector bound to that file;
37
56
  * with no key, one that follows the active file.
38
57
  */
@@ -40,7 +59,8 @@ export function registerWriteTools(server, getDesktopConnector, options) {
40
59
  // ============================================================================
41
60
  // EXECUTION TOOL
42
61
  // ============================================================================
43
- server.tool("figma_execute", `Execute arbitrary JavaScript in Figma's plugin context with full access to the figma API. Use for complex operations not covered by other tools. Requires Desktop Bridge plugin. CAUTION: Can modify your document.
62
+ server.registerTool("figma_execute", {
63
+ description: `Execute arbitrary JavaScript in Figma's plugin context with full access to the figma API. Use for complex operations not covered by other tools. Requires Desktop Bridge plugin. CAUTION: Can modify your document.
44
64
 
45
65
  **COMPONENT INSTANCES:** For instances (node.type === 'INSTANCE'), use figma_set_instance_properties — direct text editing FAILS SILENTLY. Check instance.componentProperties for available props (may have #nodeId suffixes).
46
66
 
@@ -56,17 +76,19 @@ When creating: place inside a named Section, positioned BELOW or AWAY from exist
56
76
  After creating: screenshot to verify clean placement and no overlaps.
57
77
  On failure/retry: DELETE any partial artifacts (empty frames, orphaned layers, blank pages) before retrying. Use node.remove() to clean up.
58
78
  Pages: NEVER create a new page if one with that name already exists — use the existing one. If you created a blank page during a failed attempt, delete it.
59
- Layers: If your code creates helper frames, placeholder nodes, or intermediate layers that aren't part of the final result, remove them.`, {
60
- code: z
61
- .string()
62
- .describe("JavaScript code to execute. Has access to the 'figma' global object. " +
63
- "Example: 'const rect = figma.createRectangle(); rect.resize(100, 100); return { id: rect.id };'"),
64
- timeout: z
65
- .number()
66
- .optional()
67
- .default(5000)
68
- .describe("Execution timeout in milliseconds (default: 5000, max: 30000)"),
69
- fileKey: fileKeyArg,
79
+ Layers: If your code creates helper frames, placeholder nodes, or intermediate layers that aren't part of the final result, remove them.`,
80
+ inputSchema: z.object({
81
+ code: z
82
+ .string()
83
+ .describe("JavaScript code to execute. Has access to the 'figma' global object. " +
84
+ "Example: 'const rect = figma.createRectangle(); rect.resize(100, 100); return { id: rect.id };'"),
85
+ timeout: z
86
+ .number()
87
+ .optional()
88
+ .default(5000)
89
+ .describe("Execution timeout in milliseconds (default: 5000, max: 30000)"),
90
+ fileKey: fileKeyArg,
91
+ }),
70
92
  }, async ({ code, timeout, fileKey }) => {
71
93
  try {
72
94
  const connector = await getDesktopConnector(fileKey);
@@ -108,23 +130,26 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
108
130
  // VARIABLE MANAGEMENT TOOLS
109
131
  // ============================================================================
110
132
  // Tool: Update a variable's value
111
- server.tool("figma_update_variable", "Update a single variable's value and/or its description. Pass modeId+value to change the value in a mode; pass description to set the 'How to use this variable' text shown in the Variables panel (and exported as DTCG $description). At least one of {modeId+value} or {description} is required. For many value updates at once, use figma_batch_update_variables (10-50x faster). Use figma_get_variables first for IDs. COLOR: hex '#FF0000', FLOAT: number, STRING: text, BOOLEAN: true/false. Requires Desktop Bridge plugin.", {
112
- variableId: z
113
- .string()
114
- .describe("The variable ID to update (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
115
- modeId: z
116
- .string()
117
- .optional()
118
- .describe("The mode ID to update the value in (e.g., '1:0'). Required when updating a value. Get this from the variable's collection modes."),
119
- value: z
120
- .union([z.string(), z.number(), z.boolean()])
121
- .optional()
122
- .describe("The new value (requires modeId). For COLOR: hex string like '#FF0000'. For FLOAT: number. For STRING: text. For BOOLEAN: true/false."),
123
- description: z
124
- .string()
125
- .optional()
126
- .describe("Set the variable's description (the 'How to use this variable' field; exported as DTCG $description). Pass an empty string to clear it."),
127
- fileKey: fileKeyArg,
133
+ server.registerTool("figma_update_variable", {
134
+ description: "Update a single variable's value and/or its description. Pass modeId+value to change the value in a mode; pass description to set the 'How to use this variable' text shown in the Variables panel (and exported as DTCG $description). At least one of {modeId+value} or {description} is required. For many value updates at once, use figma_batch_update_variables (10-50x faster). Use figma_get_variables first for IDs. COLOR: hex '#FF0000', FLOAT: number, STRING: text, BOOLEAN: true/false. Requires Desktop Bridge plugin.",
135
+ inputSchema: z.object({
136
+ variableId: z
137
+ .string()
138
+ .describe("The variable ID to update (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
139
+ modeId: z
140
+ .string()
141
+ .optional()
142
+ .describe("The mode ID to update the value in (e.g., '1:0'). Required when updating a value. Get this from the variable's collection modes."),
143
+ value: z
144
+ .union([z.string(), z.number(), z.boolean()])
145
+ .optional()
146
+ .describe("The new value (requires modeId). For COLOR: hex string like '#FF0000'. For FLOAT: number. For STRING: text. For BOOLEAN: true/false."),
147
+ description: z
148
+ .string()
149
+ .optional()
150
+ .describe("Set the variable's description (the 'How to use this variable' field; exported as DTCG $description). Pass an empty string to clear it."),
151
+ fileKey: fileKeyArg,
152
+ }),
128
153
  }, async ({ variableId, modeId, value, description, fileKey }) => {
129
154
  try {
130
155
  const connector = await getDesktopConnector(fileKey);
@@ -192,25 +217,28 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
192
217
  }
193
218
  });
194
219
  // Tool: Create a new variable
195
- server.tool("figma_create_variable", "Create a single Figma variable. For multiple variables, use figma_batch_create_variables instead (10-50x faster). Use figma_get_variables first to get collection IDs. Supports COLOR, FLOAT, STRING, BOOLEAN. Requires Desktop Bridge plugin.", {
196
- name: z
197
- .string()
198
- .describe("Name for the new variable (e.g., 'primary-blue')"),
199
- collectionId: z
200
- .string()
201
- .describe("The collection ID to create the variable in (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
202
- resolvedType: z
203
- .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
204
- .describe("The variable type: COLOR, FLOAT, STRING, or BOOLEAN"),
205
- description: z
206
- .string()
207
- .optional()
208
- .describe("Optional description for the variable"),
209
- valuesByMode: z
210
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
211
- .optional()
212
- .describe("Optional initial values by mode ID. Example: { '1:0': '#FF0000', '1:1': '#0000FF' }"),
213
- fileKey: fileKeyArg,
220
+ server.registerTool("figma_create_variable", {
221
+ description: "Create a single Figma variable. For multiple variables, use figma_batch_create_variables instead (10-50x faster). Use figma_get_variables first to get collection IDs. Supports COLOR, FLOAT, STRING, BOOLEAN. Requires Desktop Bridge plugin.",
222
+ inputSchema: z.object({
223
+ name: z
224
+ .string()
225
+ .describe("Name for the new variable (e.g., 'primary-blue')"),
226
+ collectionId: z
227
+ .string()
228
+ .describe("The collection ID to create the variable in (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
229
+ resolvedType: z
230
+ .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
231
+ .describe("The variable type: COLOR, FLOAT, STRING, or BOOLEAN"),
232
+ description: z
233
+ .string()
234
+ .optional()
235
+ .describe("Optional description for the variable"),
236
+ valuesByMode: z
237
+ .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
238
+ .optional()
239
+ .describe("Optional initial values by mode ID. Example: { '1:0': '#FF0000', '1:1': '#0000FF' }"),
240
+ fileKey: fileKeyArg,
241
+ }),
214
242
  }, async ({ name, collectionId, resolvedType, description, valuesByMode, fileKey, }) => {
215
243
  try {
216
244
  const connector = await getDesktopConnector(fileKey);
@@ -254,19 +282,22 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
254
282
  }
255
283
  });
256
284
  // Tool: Create a new variable collection
257
- server.tool("figma_create_variable_collection", "Create an empty variable collection. To create a collection WITH variables and modes in one step, use figma_setup_design_tokens instead. Requires Desktop Bridge plugin.", {
258
- name: z
259
- .string()
260
- .describe("Name for the new collection (e.g., 'Brand Colors')"),
261
- initialModeName: z
262
- .string()
263
- .optional()
264
- .describe("Name for the initial mode (default mode is created automatically). Example: 'Light'"),
265
- additionalModes: z
266
- .array(z.string())
267
- .optional()
268
- .describe("Additional mode names to create. Example: ['Dark', 'High Contrast']"),
269
- fileKey: fileKeyArg,
285
+ server.registerTool("figma_create_variable_collection", {
286
+ description: "Create an empty variable collection. To create a collection WITH variables and modes in one step, use figma_setup_design_tokens instead. Requires Desktop Bridge plugin.",
287
+ inputSchema: z.object({
288
+ name: z
289
+ .string()
290
+ .describe("Name for the new collection (e.g., 'Brand Colors')"),
291
+ initialModeName: z
292
+ .string()
293
+ .optional()
294
+ .describe("Name for the initial mode (default mode is created automatically). Example: 'Light'"),
295
+ additionalModes: z
296
+ .array(z.string())
297
+ .optional()
298
+ .describe("Additional mode names to create. Example: ['Dark', 'High Contrast']"),
299
+ fileKey: fileKeyArg,
300
+ }),
270
301
  }, async ({ name, initialModeName, additionalModes, fileKey }) => {
271
302
  try {
272
303
  const connector = await getDesktopConnector(fileKey);
@@ -310,11 +341,14 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
310
341
  }
311
342
  });
312
343
  // Tool: Delete a variable
313
- server.tool("figma_delete_variable", "Delete a Figma variable. WARNING: This is a destructive operation that cannot be undone (except with Figma's undo). Use figma_get_variables first to get variable IDs. Requires the Desktop Bridge plugin to be running.", {
314
- variableId: z
315
- .string()
316
- .describe("The variable ID to delete (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
317
- fileKey: fileKeyArg,
344
+ server.registerTool("figma_delete_variable", {
345
+ description: "Delete a Figma variable. WARNING: This is a destructive operation that cannot be undone (except with Figma's undo). Use figma_get_variables first to get variable IDs. Requires the Desktop Bridge plugin to be running.",
346
+ inputSchema: z.object({
347
+ variableId: z
348
+ .string()
349
+ .describe("The variable ID to delete (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
350
+ fileKey: fileKeyArg,
351
+ }),
318
352
  }, async ({ variableId, fileKey }) => {
319
353
  try {
320
354
  const connector = await getDesktopConnector(fileKey);
@@ -356,11 +390,14 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
356
390
  }
357
391
  });
358
392
  // Tool: Delete a variable collection
359
- server.tool("figma_delete_variable_collection", "Delete a Figma variable collection and ALL its variables. WARNING: This is a destructive operation that deletes all variables in the collection and cannot be undone (except with Figma's undo). Requires the Desktop Bridge plugin to be running.", {
360
- collectionId: z
361
- .string()
362
- .describe("The collection ID to delete (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
363
- fileKey: fileKeyArg,
393
+ server.registerTool("figma_delete_variable_collection", {
394
+ description: "Delete a Figma variable collection and ALL its variables. WARNING: This is a destructive operation that deletes all variables in the collection and cannot be undone (except with Figma's undo). Requires the Desktop Bridge plugin to be running.",
395
+ inputSchema: z.object({
396
+ collectionId: z
397
+ .string()
398
+ .describe("The collection ID to delete (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
399
+ fileKey: fileKeyArg,
400
+ }),
364
401
  }, async ({ collectionId, fileKey }) => {
365
402
  try {
366
403
  const connector = await getDesktopConnector(fileKey);
@@ -402,14 +439,17 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
402
439
  }
403
440
  });
404
441
  // Tool: Rename a variable
405
- server.tool("figma_rename_variable", "Rename an existing Figma variable. This updates the variable's name while preserving all its values and settings. Requires the Desktop Bridge plugin to be running.", {
406
- variableId: z
407
- .string()
408
- .describe("The variable ID to rename (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
409
- newName: z
410
- .string()
411
- .describe("The new name for the variable. Can include slashes for grouping (e.g., 'colors/primary/background')."),
412
- fileKey: fileKeyArg,
442
+ server.registerTool("figma_rename_variable", {
443
+ description: "Rename an existing Figma variable. This updates the variable's name while preserving all its values and settings. Requires the Desktop Bridge plugin to be running.",
444
+ inputSchema: z.object({
445
+ variableId: z
446
+ .string()
447
+ .describe("The variable ID to rename (e.g., 'VariableID:123:456'). Get this from figma_get_variables."),
448
+ newName: z
449
+ .string()
450
+ .describe("The new name for the variable. Can include slashes for grouping (e.g., 'colors/primary/background')."),
451
+ fileKey: fileKeyArg,
452
+ }),
413
453
  }, async ({ variableId, newName, fileKey }) => {
414
454
  try {
415
455
  const connector = await getDesktopConnector(fileKey);
@@ -451,14 +491,17 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
451
491
  }
452
492
  });
453
493
  // Tool: Add a mode to a collection
454
- server.tool("figma_add_mode", "Add a new mode to an existing Figma variable collection. Modes allow variables to have different values for different contexts (e.g., Light/Dark themes, device sizes). Requires the Desktop Bridge plugin to be running.", {
455
- collectionId: z
456
- .string()
457
- .describe("The collection ID to add the mode to (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
458
- modeName: z
459
- .string()
460
- .describe("The name for the new mode (e.g., 'Dark', 'Mobile', 'High Contrast')."),
461
- fileKey: fileKeyArg,
494
+ server.registerTool("figma_add_mode", {
495
+ description: "Add a new mode to an existing Figma variable collection. Modes allow variables to have different values for different contexts (e.g., Light/Dark themes, device sizes). Requires the Desktop Bridge plugin to be running.",
496
+ inputSchema: z.object({
497
+ collectionId: z
498
+ .string()
499
+ .describe("The collection ID to add the mode to (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
500
+ modeName: z
501
+ .string()
502
+ .describe("The name for the new mode (e.g., 'Dark', 'Mobile', 'High Contrast')."),
503
+ fileKey: fileKeyArg,
504
+ }),
462
505
  }, async ({ collectionId, modeName, fileKey }) => {
463
506
  try {
464
507
  const connector = await getDesktopConnector(fileKey);
@@ -502,17 +545,20 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
502
545
  }
503
546
  });
504
547
  // Tool: Rename a mode in a collection
505
- server.tool("figma_rename_mode", "Rename an existing mode in a Figma variable collection. Requires the Desktop Bridge plugin to be running.", {
506
- collectionId: z
507
- .string()
508
- .describe("The collection ID containing the mode (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
509
- modeId: z
510
- .string()
511
- .describe("The mode ID to rename (e.g., '123:0'). Get this from the collection's modes array in figma_get_variables."),
512
- newName: z
513
- .string()
514
- .describe("The new name for the mode (e.g., 'Dark Theme', 'Tablet')."),
515
- fileKey: fileKeyArg,
548
+ server.registerTool("figma_rename_mode", {
549
+ description: "Rename an existing mode in a Figma variable collection. Requires the Desktop Bridge plugin to be running.",
550
+ inputSchema: z.object({
551
+ collectionId: z
552
+ .string()
553
+ .describe("The collection ID containing the mode (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
554
+ modeId: z
555
+ .string()
556
+ .describe("The mode ID to rename (e.g., '123:0'). Get this from the collection's modes array in figma_get_variables."),
557
+ newName: z
558
+ .string()
559
+ .describe("The new name for the mode (e.g., 'Dark Theme', 'Tablet')."),
560
+ fileKey: fileKeyArg,
561
+ }),
516
562
  }, async ({ collectionId, modeId, newName, fileKey }) => {
517
563
  try {
518
564
  const connector = await getDesktopConnector(fileKey);
@@ -560,36 +606,39 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
560
606
  // reducing per-operation overhead from ~60-170ms to near-zero.
561
607
  // Use these instead of calling individual tools repeatedly.
562
608
  // Tool: Batch create variables
563
- server.tool("figma_batch_create_variables", "Create multiple variables in one operation. Use instead of calling figma_create_variable repeatedly — up to 50x faster for bulk operations. Get collection IDs from figma_get_variables first. Requires Desktop Bridge plugin.", {
564
- collectionId: z
565
- .string()
566
- .describe("Collection ID to create all variables in (e.g., 'VariableCollectionId:123:456')"),
567
- variables: z
568
- .array(z.object({
569
- name: z.string().describe("Variable name (e.g., 'primary-blue')"),
570
- resolvedType: z
571
- .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
572
- .describe("Variable type"),
573
- description: z
609
+ server.registerTool("figma_batch_create_variables", {
610
+ description: "Create multiple variables in one operation. Use instead of calling figma_create_variable repeatedly — up to 50x faster for bulk operations. Get collection IDs from figma_get_variables first. Requires Desktop Bridge plugin.",
611
+ inputSchema: z.object({
612
+ collectionId: z
574
613
  .string()
575
- .optional()
576
- .describe("Optional description"),
577
- valuesByMode: z
578
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
579
- .optional()
580
- .describe("Values by mode ID. For COLOR: hex like '#FF0000'. Example: { '1:0': '#FF0000' }"),
581
- }))
582
- .min(1)
583
- .max(100)
584
- .describe("Array of variables to create (1-100)"),
585
- fileKey: fileKeyArg,
614
+ .describe("Collection ID to create all variables in (e.g., 'VariableCollectionId:123:456')"),
615
+ variables: z
616
+ .array(z.object({
617
+ name: z.string().describe("Variable name (e.g., 'primary-blue')"),
618
+ resolvedType: z
619
+ .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
620
+ .describe("Variable type"),
621
+ description: z
622
+ .string()
623
+ .optional()
624
+ .describe("Optional description"),
625
+ valuesByMode: z
626
+ .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
627
+ .optional()
628
+ .describe("Values by mode ID. For COLOR: hex like '#FF0000'. Example: { '1:0': '#FF0000' }"),
629
+ }))
630
+ .min(1)
631
+ .max(100)
632
+ .describe("Array of variables to create (1-100)"),
633
+ fileKey: fileKeyArg,
634
+ }),
586
635
  }, async ({ collectionId, variables, fileKey }) => {
587
636
  try {
588
637
  const connector = await getDesktopConnector(fileKey);
589
638
  const script = `
590
639
  const results = [];
591
- const collectionId = ${JSON.stringify(collectionId)};
592
- const vars = ${JSON.stringify(variables)};
640
+ const collectionId = ${sandboxSafeJson(JSON.stringify(collectionId))};
641
+ const vars = ${sandboxSafeJson(JSON.stringify(variables))};
593
642
 
594
643
  ${HEX_TO_RGBA_HELPER}
595
644
 
@@ -680,29 +729,32 @@ return {
680
729
  }
681
730
  });
682
731
  // Tool: Batch update variables
683
- server.tool("figma_batch_update_variables", "Update multiple variable values in one operation. Use instead of calling figma_update_variable repeatedly — up to 50x faster for bulk updates. Get variable/mode IDs from figma_get_variables first. Requires Desktop Bridge plugin.", {
684
- updates: z
685
- .array(z.object({
686
- variableId: z
687
- .string()
688
- .describe("Variable ID (e.g., 'VariableID:123:456')"),
689
- modeId: z
690
- .string()
691
- .describe("Mode ID (e.g., '1:0')"),
692
- value: z
693
- .union([z.string(), z.number(), z.boolean()])
694
- .describe("New value. COLOR: hex like '#FF0000'. FLOAT: number. STRING: text. BOOLEAN: true/false. A string starting with 'VariableID:' (e.g. from figma_get_variables) aliases that variable directly by id."),
695
- }))
696
- .min(1)
697
- .max(100)
698
- .describe("Array of updates to apply (1-100)"),
699
- fileKey: fileKeyArg,
732
+ server.registerTool("figma_batch_update_variables", {
733
+ description: "Update multiple variable values in one operation. Use instead of calling figma_update_variable repeatedly — up to 50x faster for bulk updates. Get variable/mode IDs from figma_get_variables first. Requires Desktop Bridge plugin.",
734
+ inputSchema: z.object({
735
+ updates: z
736
+ .array(z.object({
737
+ variableId: z
738
+ .string()
739
+ .describe("Variable ID (e.g., 'VariableID:123:456')"),
740
+ modeId: z
741
+ .string()
742
+ .describe("Mode ID (e.g., '1:0')"),
743
+ value: z
744
+ .union([z.string(), z.number(), z.boolean()])
745
+ .describe("New value. COLOR: hex like '#FF0000'. FLOAT: number. STRING: text. BOOLEAN: true/false. A string starting with 'VariableID:' (e.g. from figma_get_variables) aliases that variable directly by id."),
746
+ }))
747
+ .min(1)
748
+ .max(100)
749
+ .describe("Array of updates to apply (1-100)"),
750
+ fileKey: fileKeyArg,
751
+ }),
700
752
  }, async ({ updates, fileKey }) => {
701
753
  try {
702
754
  const connector = await getDesktopConnector(fileKey);
703
755
  const script = `
704
756
  const results = [];
705
- const updates = ${JSON.stringify(updates)};
757
+ const updates = ${sandboxSafeJson(JSON.stringify(updates))};
706
758
 
707
759
  ${HEX_TO_RGBA_HELPER}
708
760
 
@@ -780,42 +832,45 @@ return {
780
832
  }
781
833
  });
782
834
  // Tool: Setup design tokens (collection + modes + variables atomically)
783
- server.tool("figma_setup_design_tokens", "Create a complete design token structure in one operation: collection, modes, and all variables. Ideal for importing CSS custom properties or design tokens into Figma. Values may be literals OR DTCG-style brace references ('{color.blue.600}', or set-qualified '{primitives.color.blue.600}') that resolve to variable ALIASES — first against variables created in this same call, then against existing local variables. Unresolvable references skip that value with a per-item warning (the rest of the batch still applies), so semantic collections referencing primitives no longer need raw figma_execute. Requires Desktop Bridge plugin.", {
784
- collectionName: z
785
- .string()
786
- .describe("Name for the token collection (e.g., 'Brand Tokens')"),
787
- modes: z
788
- .array(z.string())
789
- .min(1)
790
- .max(40)
791
- .describe("Mode names (first becomes default). Example: ['Light', 'Dark']. Your Figma plan's per-collection mode limit applies at RUNTIME (e.g. Professional 10, Organization 20) — exceeding it fails cleanly with the file's real ceiling in planModeLimit and no collection left behind."),
792
- tokens: z
793
- .array(z.object({
794
- name: z
835
+ server.registerTool("figma_setup_design_tokens", {
836
+ description: "Create a complete design token structure in one operation: collection, modes, and all variables. Ideal for importing CSS custom properties or design tokens into Figma. Values may be literals OR DTCG-style brace references ('{color.blue.600}', or set-qualified '{primitives.color.blue.600}') that resolve to variable ALIASES — first against variables created in this same call, then against existing local variables. Unresolvable references skip that value with a per-item warning (the rest of the batch still applies), so semantic collections referencing primitives no longer need raw figma_execute. Requires Desktop Bridge plugin.",
837
+ inputSchema: z.object({
838
+ collectionName: z
795
839
  .string()
796
- .describe("Token name (e.g., 'color/primary')"),
797
- resolvedType: z
798
- .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
799
- .describe("Token type"),
800
- description: z
801
- .string()
802
- .optional()
803
- .describe("Optional description"),
804
- values: z
805
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
806
- .describe("Values keyed by mode NAME (not ID). Example: { 'Light': '#FFFFFF', 'Dark': '#000000' }. A string value wrapped in braces is an ALIAS reference resolved to another variable: '{color.blue.600}' matches variable name 'color/blue/600' — first among variables created in THIS call, then existing local variables (exact match, then case-insensitive). Set-qualified references ('{primitives.color.blue.600}') strip the leading collection name. Unresolvable references skip that value and surface in the response's warnings[]. A string starting with 'VariableID:' (e.g. from figma_get_variables) aliases that variable directly by id."),
807
- }))
808
- .min(1)
809
- .max(100)
810
- .describe("Token definitions (1-100)"),
811
- fileKey: fileKeyArg,
840
+ .describe("Name for the token collection (e.g., 'Brand Tokens')"),
841
+ modes: z
842
+ .array(z.string())
843
+ .min(1)
844
+ .max(40)
845
+ .describe("Mode names (first becomes default). Example: ['Light', 'Dark']. Your Figma plan's per-collection mode limit applies at RUNTIME (e.g. Professional 10, Organization 20) — exceeding it fails cleanly with the file's real ceiling in planModeLimit and no collection left behind."),
846
+ tokens: z
847
+ .array(z.object({
848
+ name: z
849
+ .string()
850
+ .describe("Token name (e.g., 'color/primary')"),
851
+ resolvedType: z
852
+ .enum(["COLOR", "FLOAT", "STRING", "BOOLEAN"])
853
+ .describe("Token type"),
854
+ description: z
855
+ .string()
856
+ .optional()
857
+ .describe("Optional description"),
858
+ values: z
859
+ .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
860
+ .describe("Values keyed by mode NAME (not ID). Example: { 'Light': '#FFFFFF', 'Dark': '#000000' }. A string value wrapped in braces is an ALIAS reference resolved to another variable: '{color.blue.600}' matches variable name 'color/blue/600' — first among variables created in THIS call, then existing local variables (exact match, then case-insensitive). Set-qualified references ('{primitives.color.blue.600}') strip the leading collection name. Unresolvable references skip that value and surface in the response's warnings[]. A string starting with 'VariableID:' (e.g. from figma_get_variables) aliases that variable directly by id."),
861
+ }))
862
+ .min(1)
863
+ .max(100)
864
+ .describe("Token definitions (1-100)"),
865
+ fileKey: fileKeyArg,
866
+ }),
812
867
  }, async ({ collectionName, modes, tokens, fileKey }) => {
813
868
  try {
814
869
  const connector = await getDesktopConnector(fileKey);
815
870
  const script = `
816
- const collectionName = ${JSON.stringify(collectionName)};
817
- const modeNames = ${JSON.stringify(modes)};
818
- const tokenDefs = ${JSON.stringify(tokens)};
871
+ const collectionName = ${sandboxSafeJson(JSON.stringify(collectionName))};
872
+ const modeNames = ${sandboxSafeJson(JSON.stringify(modes))};
873
+ const tokenDefs = ${sandboxSafeJson(JSON.stringify(tokens))};
819
874
 
820
875
  ${HEX_TO_RGBA_HELPER}
821
876
 
@@ -1064,7 +1119,8 @@ return {
1064
1119
  // COMPONENT INSTANTIATION & PROPERTY TOOLS
1065
1120
  // ============================================================================
1066
1121
  // Tool: Instantiate Component
1067
- server.tool("figma_instantiate_component", `Create an instance of a component from the design system.
1122
+ server.registerTool("figma_instantiate_component", {
1123
+ description: `Create an instance of a component from the design system.
1068
1124
 
1069
1125
  **CRITICAL: Always pass BOTH componentKey AND nodeId together!**
1070
1126
  Search results return both identifiers. Pass both so the tool can automatically fall back to nodeId if the component isn't published to a library. Most local/unpublished components require nodeId.
@@ -1073,35 +1129,37 @@ Search results return both identifiers. Pass both so the tool can automatically
1073
1129
  NodeIds are session-specific and may be stale from previous conversations. ALWAYS search for components at the start of each design session to get current, valid identifiers.
1074
1130
 
1075
1131
  **VISUAL VALIDATION WORKFLOW:**
1076
- After instantiating components, use figma_take_screenshot to verify the result looks correct. Check placement, sizing, and visual balance.`, {
1077
- componentKey: z
1078
- .string()
1079
- .optional()
1080
- .describe("The component key from search results. Pass this WITH nodeId for automatic fallback."),
1081
- nodeId: z
1082
- .string()
1083
- .optional()
1084
- .describe("The node ID from search results. ALWAYS pass this alongside componentKey - most local components need it."),
1085
- variant: z
1086
- .record(z.string())
1087
- .optional()
1088
- .describe("Variant properties to set (e.g., { Type: 'Simple', State: 'Active' })"),
1089
- overrides: z
1090
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
1091
- .optional()
1092
- .describe("Property overrides (e.g., { 'Button Label': 'Click Me' })"),
1093
- position: z
1094
- .object({
1095
- x: z.number(),
1096
- y: z.number(),
1097
- })
1098
- .optional()
1099
- .describe("Position on canvas (default: 0, 0)"),
1100
- parentId: z
1101
- .string()
1102
- .optional()
1103
- .describe("Parent node ID to append the instance to"),
1104
- fileKey: fileKeyArg,
1132
+ After instantiating components, use figma_take_screenshot to verify the result looks correct. Check placement, sizing, and visual balance.`,
1133
+ inputSchema: z.object({
1134
+ componentKey: z
1135
+ .string()
1136
+ .optional()
1137
+ .describe("The component key from search results. Pass this WITH nodeId for automatic fallback."),
1138
+ nodeId: z
1139
+ .string()
1140
+ .optional()
1141
+ .describe("The node ID from search results. ALWAYS pass this alongside componentKey - most local components need it."),
1142
+ variant: z
1143
+ .record(z.string(), z.string())
1144
+ .optional()
1145
+ .describe("Variant properties to set (e.g., { Type: 'Simple', State: 'Active' })"),
1146
+ overrides: z
1147
+ .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
1148
+ .optional()
1149
+ .describe("Property overrides (e.g., { 'Button Label': 'Click Me' })"),
1150
+ position: z
1151
+ .object({
1152
+ x: z.number(),
1153
+ y: z.number(),
1154
+ })
1155
+ .optional()
1156
+ .describe("Position on canvas (default: 0, 0)"),
1157
+ parentId: z
1158
+ .string()
1159
+ .optional()
1160
+ .describe("Parent node ID to append the instance to"),
1161
+ fileKey: fileKeyArg,
1162
+ }),
1105
1163
  }, async ({ componentKey, nodeId, variant, overrides, position, parentId, fileKey, }) => {
1106
1164
  try {
1107
1165
  if (!componentKey && !nodeId) {
@@ -1158,16 +1216,19 @@ After instantiating components, use figma_take_screenshot to verify the result l
1158
1216
  // Component Property Management Tools
1159
1217
  // ============================================================================
1160
1218
  // Tool: Set Node Description
1161
- server.tool("figma_set_description", "Set the description text on a component, component set, or style. Descriptions appear in Dev Mode and help document design intent. Supports plain text and markdown formatting.", {
1162
- nodeId: z
1163
- .string()
1164
- .describe("The node ID of the component or style to update (e.g., '123:456')"),
1165
- description: z.string().describe("The plain text description to set"),
1166
- descriptionMarkdown: z
1167
- .string()
1168
- .optional()
1169
- .describe("Optional rich text description using markdown formatting"),
1170
- fileKey: fileKeyArg,
1219
+ server.registerTool("figma_set_description", {
1220
+ description: "Set the description text on a component, component set, or style. Descriptions appear in Dev Mode and help document design intent. Supports plain text and markdown formatting.",
1221
+ inputSchema: z.object({
1222
+ nodeId: z
1223
+ .string()
1224
+ .describe("The node ID of the component or style to update (e.g., '123:456')"),
1225
+ description: z.string().describe("The plain text description to set"),
1226
+ descriptionMarkdown: z
1227
+ .string()
1228
+ .optional()
1229
+ .describe("Optional rich text description using markdown formatting"),
1230
+ fileKey: fileKeyArg,
1231
+ }),
1171
1232
  }, async ({ nodeId, description, descriptionMarkdown, fileKey }) => {
1172
1233
  try {
1173
1234
  const connector = await getDesktopConnector(fileKey);
@@ -1205,30 +1266,33 @@ After instantiating components, use figma_take_screenshot to verify the result l
1205
1266
  }
1206
1267
  });
1207
1268
  // Tool: Add Component Property
1208
- server.tool("figma_add_component_property", "Add a new component property to a component or component set. Properties enable dynamic content and behavior in component instances. Supported types: BOOLEAN (toggle), TEXT (string), INSTANCE_SWAP (component swap), VARIANT (variant selection), SLOT (freeform slot — prefer figma_create_slot for new slots).", {
1209
- nodeId: z.string().describe("The component or component set node ID"),
1210
- propertyName: z
1211
- .string()
1212
- .describe("Name for the new property (e.g., 'Show Icon', 'Button Label', 'Content')"),
1213
- type: z
1214
- .enum(["BOOLEAN", "TEXT", "INSTANCE_SWAP", "VARIANT", "SLOT"])
1215
- .describe("Property type: BOOLEAN for toggles, TEXT for strings, INSTANCE_SWAP for component swaps, VARIANT for variant selection, SLOT for freeform slot areas"),
1216
- defaultValue: z
1217
- .union([z.string(), z.number(), z.boolean()])
1218
- .optional()
1219
- .describe("Default value. Required for TEXT (string), INSTANCE_SWAP (component id), and VARIANT (a non-empty variant option name — Figma rejects empty). Optional for BOOLEAN (defaults false). Omit for SLOT."),
1220
- description: z
1221
- .string()
1222
- .optional()
1223
- .describe("Property description (SLOT properties only)"),
1224
- preferredValues: z
1225
- .array(z.object({
1226
- type: z.enum(["COMPONENT", "COMPONENT_SET"]),
1227
- key: z.string(),
1228
- }))
1229
- .optional()
1230
- .describe("Preferred components (INSTANCE_SWAP and SLOT only)"),
1231
- fileKey: fileKeyArg,
1269
+ server.registerTool("figma_add_component_property", {
1270
+ description: "Add a new component property to a component or component set. Properties enable dynamic content and behavior in component instances. Supported types: BOOLEAN (toggle), TEXT (string), INSTANCE_SWAP (component swap), VARIANT (variant selection), SLOT (freeform slot — prefer figma_create_slot for new slots).",
1271
+ inputSchema: z.object({
1272
+ nodeId: z.string().describe("The component or component set node ID"),
1273
+ propertyName: z
1274
+ .string()
1275
+ .describe("Name for the new property (e.g., 'Show Icon', 'Button Label', 'Content')"),
1276
+ type: z
1277
+ .enum(["BOOLEAN", "TEXT", "INSTANCE_SWAP", "VARIANT", "SLOT"])
1278
+ .describe("Property type: BOOLEAN for toggles, TEXT for strings, INSTANCE_SWAP for component swaps, VARIANT for variant selection, SLOT for freeform slot areas"),
1279
+ defaultValue: z
1280
+ .union([z.string(), z.number(), z.boolean()])
1281
+ .optional()
1282
+ .describe("Default value. Required for TEXT (string), INSTANCE_SWAP (component id), and VARIANT (a non-empty variant option name — Figma rejects empty). Optional for BOOLEAN (defaults false). Omit for SLOT."),
1283
+ description: z
1284
+ .string()
1285
+ .optional()
1286
+ .describe("Property description (SLOT properties only)"),
1287
+ preferredValues: z
1288
+ .array(z.object({
1289
+ type: z.enum(["COMPONENT", "COMPONENT_SET"]),
1290
+ key: z.string(),
1291
+ }))
1292
+ .optional()
1293
+ .describe("Preferred components (INSTANCE_SWAP and SLOT only)"),
1294
+ fileKey: fileKeyArg,
1295
+ }),
1232
1296
  }, async ({ nodeId, propertyName, type, defaultValue, description, preferredValues, fileKey }) => {
1233
1297
  try {
1234
1298
  const connector = await getDesktopConnector(fileKey);
@@ -1286,30 +1350,33 @@ After instantiating components, use figma_take_screenshot to verify the result l
1286
1350
  }
1287
1351
  });
1288
1352
  // Tool: Edit Component Property
1289
- server.tool("figma_edit_component_property", "Edit an existing component property. Can change the name, default value, or preferred values (for INSTANCE_SWAP). Use the full property name including the unique suffix.", {
1290
- nodeId: z.string().describe("The component or component set node ID"),
1291
- propertyName: z
1292
- .string()
1293
- .describe("The full property name with suffix (e.g., 'Show Icon#123:456')"),
1294
- newValue: z
1295
- .object({
1296
- name: z.string().optional().describe("New name for the property"),
1297
- defaultValue: z
1298
- .union([z.string(), z.number(), z.boolean()])
1299
- .optional()
1300
- .describe("New default value"),
1301
- preferredValues: z
1302
- .array(z.object({
1303
- type: z
1304
- .enum(["COMPONENT", "COMPONENT_SET"])
1305
- .describe("Type of preferred value"),
1306
- key: z.string().describe("Component or component set key"),
1307
- }))
1308
- .optional()
1309
- .describe("Preferred values (INSTANCE_SWAP only)"),
1310
- })
1311
- .describe("Object with the values to update"),
1312
- fileKey: fileKeyArg,
1353
+ server.registerTool("figma_edit_component_property", {
1354
+ description: "Edit an existing component property. Can change the name, default value, or preferred values (for INSTANCE_SWAP). Use the full property name including the unique suffix.",
1355
+ inputSchema: z.object({
1356
+ nodeId: z.string().describe("The component or component set node ID"),
1357
+ propertyName: z
1358
+ .string()
1359
+ .describe("The full property name with suffix (e.g., 'Show Icon#123:456')"),
1360
+ newValue: z
1361
+ .object({
1362
+ name: z.string().optional().describe("New name for the property"),
1363
+ defaultValue: z
1364
+ .union([z.string(), z.number(), z.boolean()])
1365
+ .optional()
1366
+ .describe("New default value"),
1367
+ preferredValues: z
1368
+ .array(z.object({
1369
+ type: z
1370
+ .enum(["COMPONENT", "COMPONENT_SET"])
1371
+ .describe("Type of preferred value"),
1372
+ key: z.string().describe("Component or component set key"),
1373
+ }))
1374
+ .optional()
1375
+ .describe("Preferred values (INSTANCE_SWAP only)"),
1376
+ })
1377
+ .describe("Object with the values to update"),
1378
+ fileKey: fileKeyArg,
1379
+ }),
1313
1380
  }, async ({ nodeId, propertyName, newValue, fileKey }) => {
1314
1381
  try {
1315
1382
  const connector = await getDesktopConnector(fileKey);
@@ -1346,12 +1413,15 @@ After instantiating components, use figma_take_screenshot to verify the result l
1346
1413
  }
1347
1414
  });
1348
1415
  // Tool: Delete Component Property
1349
- server.tool("figma_delete_component_property", "Delete a component property. Works with BOOLEAN, TEXT, INSTANCE_SWAP, and SLOT properties (not VARIANT). This is a destructive operation.", {
1350
- nodeId: z.string().describe("The component or component set node ID"),
1351
- propertyName: z
1352
- .string()
1353
- .describe("The full property name with suffix (e.g., 'Show Icon#123:456')"),
1354
- fileKey: fileKeyArg,
1416
+ server.registerTool("figma_delete_component_property", {
1417
+ description: "Delete a component property. Works with BOOLEAN, TEXT, INSTANCE_SWAP, and SLOT properties (not VARIANT). This is a destructive operation.",
1418
+ inputSchema: z.object({
1419
+ nodeId: z.string().describe("The component or component set node ID"),
1420
+ propertyName: z
1421
+ .string()
1422
+ .describe("The full property name with suffix (e.g., 'Show Icon#123:456')"),
1423
+ fileKey: fileKeyArg,
1424
+ }),
1355
1425
  }, async ({ nodeId, propertyName, fileKey }) => {
1356
1426
  try {
1357
1427
  const connector = await getDesktopConnector(fileKey);
@@ -1391,16 +1461,19 @@ After instantiating components, use figma_take_screenshot to verify the result l
1391
1461
  // Node Manipulation Tools
1392
1462
  // ============================================================================
1393
1463
  // Tool: Resize Node
1394
- server.tool("figma_resize_node", "Resize a node to specific dimensions. By default respects child constraints; use withConstraints=false to ignore them.", {
1395
- nodeId: z.string().describe("The node ID to resize"),
1396
- width: z.number().describe("New width in pixels"),
1397
- height: z.number().describe("New height in pixels"),
1398
- withConstraints: z
1399
- .boolean()
1400
- .optional()
1401
- .default(true)
1402
- .describe("Whether to apply child constraints during resize (default: true)"),
1403
- fileKey: fileKeyArg,
1464
+ server.registerTool("figma_resize_node", {
1465
+ description: "Resize a node to specific dimensions. By default respects child constraints; use withConstraints=false to ignore them.",
1466
+ inputSchema: z.object({
1467
+ nodeId: z.string().describe("The node ID to resize"),
1468
+ width: z.number().describe("New width in pixels"),
1469
+ height: z.number().describe("New height in pixels"),
1470
+ withConstraints: z
1471
+ .boolean()
1472
+ .optional()
1473
+ .default(true)
1474
+ .describe("Whether to apply child constraints during resize (default: true)"),
1475
+ fileKey: fileKeyArg,
1476
+ }),
1404
1477
  }, async ({ nodeId, width, height, withConstraints, fileKey }) => {
1405
1478
  try {
1406
1479
  const connector = await getDesktopConnector(fileKey);
@@ -1437,11 +1510,14 @@ After instantiating components, use figma_take_screenshot to verify the result l
1437
1510
  }
1438
1511
  });
1439
1512
  // Tool: Move Node
1440
- server.tool("figma_move_node", "Move a node to a new position within its parent.", {
1441
- nodeId: z.string().describe("The node ID to move"),
1442
- x: z.number().describe("New X position"),
1443
- y: z.number().describe("New Y position"),
1444
- fileKey: fileKeyArg,
1513
+ server.registerTool("figma_move_node", {
1514
+ description: "Move a node to a new position within its parent.",
1515
+ inputSchema: z.object({
1516
+ nodeId: z.string().describe("The node ID to move"),
1517
+ x: z.number().describe("New X position"),
1518
+ y: z.number().describe("New Y position"),
1519
+ fileKey: fileKeyArg,
1520
+ }),
1445
1521
  }, async ({ nodeId, x, y, fileKey }) => {
1446
1522
  try {
1447
1523
  const connector = await getDesktopConnector(fileKey);
@@ -1478,28 +1554,31 @@ After instantiating components, use figma_take_screenshot to verify the result l
1478
1554
  }
1479
1555
  });
1480
1556
  // Tool: Set Node Fills
1481
- server.tool("figma_set_fills", "Set the fill colors on a node. Accepts hex color strings (e.g., '#FF0000'). To bind a fill to a design token / color variable, pass that fill's variableId — the variable drives the color and this works on any Figma plan via the bridge (no raw figma_execute needed).", {
1482
- nodeId: z.string().describe("The node ID to modify"),
1483
- fills: z
1484
- .array(z.object({
1485
- type: z
1486
- .literal("SOLID")
1487
- .describe("Fill type (currently only SOLID supported)"),
1488
- color: z
1489
- .string()
1490
- .optional()
1491
- .describe("Hex color string (e.g., '#FF0000', '#FF000080' for transparency). Optional when variableId is provided."),
1492
- opacity: z
1493
- .number()
1494
- .optional()
1495
- .describe("Opacity 0-1 (default: 1)"),
1496
- variableId: z
1497
- .string()
1498
- .optional()
1499
- .describe("Bind this fill's color to a Figma variable by id (e.g. 'VariableID:1:23' from figma_get_variables). When set, the variable drives the color. Import library variables first via figma_import_library_variable."),
1500
- }))
1501
- .describe("Array of fill objects"),
1502
- fileKey: fileKeyArg,
1557
+ server.registerTool("figma_set_fills", {
1558
+ description: "Set the fill colors on a node. Accepts hex color strings (e.g., '#FF0000'). To bind a fill to a design token / color variable, pass that fill's variableId — the variable drives the color and this works on any Figma plan via the bridge (no raw figma_execute needed).",
1559
+ inputSchema: z.object({
1560
+ nodeId: z.string().describe("The node ID to modify"),
1561
+ fills: z
1562
+ .array(z.object({
1563
+ type: z
1564
+ .literal("SOLID")
1565
+ .describe("Fill type (currently only SOLID supported)"),
1566
+ color: z
1567
+ .string()
1568
+ .optional()
1569
+ .describe("Hex color string (e.g., '#FF0000', '#FF000080' for transparency). Optional when variableId is provided."),
1570
+ opacity: z
1571
+ .number()
1572
+ .optional()
1573
+ .describe("Opacity 0-1 (default: 1)"),
1574
+ variableId: z
1575
+ .string()
1576
+ .optional()
1577
+ .describe("Bind this fill's color to a Figma variable by id (e.g. 'VariableID:1:23' from figma_get_variables). When set, the variable drives the color. Import library variables first via figma_import_library_variable."),
1578
+ }))
1579
+ .describe("Array of fill objects"),
1580
+ fileKey: fileKeyArg,
1581
+ }),
1503
1582
  }, async ({ nodeId, fills, fileKey }) => {
1504
1583
  try {
1505
1584
  const connector = await getDesktopConnector(fileKey);
@@ -1536,13 +1615,16 @@ After instantiating components, use figma_take_screenshot to verify the result l
1536
1615
  }
1537
1616
  });
1538
1617
  // Tool: Set Image Fill on nodes
1539
- server.tool("figma_set_image_fill", "Set an image fill on one or more Figma nodes. The imageData parameter accepts a base64-encoded " +
1540
- "image string (JPEG/PNG). The image is decoded in the browser bridge and passed " +
1541
- "as raw bytes to the Figma plugin. Requires Desktop Bridge plugin.", {
1542
- nodeIds: z.array(z.string()).describe("Array of node IDs to apply the image fill to"),
1543
- imageData: z.string().describe("Base64-encoded image data (JPEG/PNG)"),
1544
- scaleMode: z.enum(["FILL", "FIT", "CROP", "TILE"]).optional().describe("How the image fills the node (default: FILL)"),
1545
- fileKey: fileKeyArg,
1618
+ server.registerTool("figma_set_image_fill", {
1619
+ description: "Set an image fill on one or more Figma nodes. The imageData parameter accepts a base64-encoded " +
1620
+ "image string (JPEG/PNG). The image is decoded in the browser bridge and passed " +
1621
+ "as raw bytes to the Figma plugin. Requires Desktop Bridge plugin.",
1622
+ inputSchema: z.object({
1623
+ nodeIds: z.array(z.string()).describe("Array of node IDs to apply the image fill to"),
1624
+ imageData: z.string().describe("Base64-encoded image data (JPEG/PNG)"),
1625
+ scaleMode: z.enum(["FILL", "FIT", "CROP", "TILE"]).optional().describe("How the image fills the node (default: FILL)"),
1626
+ fileKey: fileKeyArg,
1627
+ }),
1546
1628
  }, async ({ nodeIds, imageData, scaleMode, fileKey }) => {
1547
1629
  try {
1548
1630
  const connector = await getDesktopConnector(fileKey);
@@ -1580,27 +1662,30 @@ After instantiating components, use figma_take_screenshot to verify the result l
1580
1662
  }
1581
1663
  });
1582
1664
  // Tool: Set Node Strokes
1583
- server.tool("figma_set_strokes", "Set the stroke (border) on a node. Accepts hex color strings and optional stroke weight. To bind a stroke to a design token / color variable, pass that stroke's variableId — works on any Figma plan via the bridge.", {
1584
- nodeId: z.string().describe("The node ID to modify"),
1585
- strokes: z
1586
- .array(z.object({
1587
- type: z.literal("SOLID").describe("Stroke type"),
1588
- color: z
1589
- .string()
1590
- .optional()
1591
- .describe("Hex color string. Optional when variableId is provided."),
1592
- opacity: z.number().optional().describe("Opacity 0-1"),
1593
- variableId: z
1594
- .string()
1665
+ server.registerTool("figma_set_strokes", {
1666
+ description: "Set the stroke (border) on a node. Accepts hex color strings and optional stroke weight. To bind a stroke to a design token / color variable, pass that stroke's variableId — works on any Figma plan via the bridge.",
1667
+ inputSchema: z.object({
1668
+ nodeId: z.string().describe("The node ID to modify"),
1669
+ strokes: z
1670
+ .array(z.object({
1671
+ type: z.literal("SOLID").describe("Stroke type"),
1672
+ color: z
1673
+ .string()
1674
+ .optional()
1675
+ .describe("Hex color string. Optional when variableId is provided."),
1676
+ opacity: z.number().optional().describe("Opacity 0-1"),
1677
+ variableId: z
1678
+ .string()
1679
+ .optional()
1680
+ .describe("Bind this stroke's color to a Figma variable by id (e.g. 'VariableID:1:23' from figma_get_variables). When set, the variable drives the color."),
1681
+ }))
1682
+ .describe("Array of stroke objects"),
1683
+ strokeWeight: z
1684
+ .number()
1595
1685
  .optional()
1596
- .describe("Bind this stroke's color to a Figma variable by id (e.g. 'VariableID:1:23' from figma_get_variables). When set, the variable drives the color."),
1597
- }))
1598
- .describe("Array of stroke objects"),
1599
- strokeWeight: z
1600
- .number()
1601
- .optional()
1602
- .describe("Stroke thickness in pixels"),
1603
- fileKey: fileKeyArg,
1686
+ .describe("Stroke thickness in pixels"),
1687
+ fileKey: fileKeyArg,
1688
+ }),
1604
1689
  }, async ({ nodeId, strokes, strokeWeight, fileKey }) => {
1605
1690
  try {
1606
1691
  const connector = await getDesktopConnector(fileKey);
@@ -1637,9 +1722,12 @@ After instantiating components, use figma_take_screenshot to verify the result l
1637
1722
  }
1638
1723
  });
1639
1724
  // Tool: Clone Node
1640
- server.tool("figma_clone_node", "Duplicate a node. The clone is placed at a slight offset from the original.", {
1641
- nodeId: z.string().describe("The node ID to clone"),
1642
- fileKey: fileKeyArg,
1725
+ server.registerTool("figma_clone_node", {
1726
+ description: "Duplicate a node. The clone is placed at a slight offset from the original.",
1727
+ inputSchema: z.object({
1728
+ nodeId: z.string().describe("The node ID to clone"),
1729
+ fileKey: fileKeyArg,
1730
+ }),
1643
1731
  }, async ({ nodeId, fileKey }) => {
1644
1732
  try {
1645
1733
  const connector = await getDesktopConnector(fileKey);
@@ -1676,9 +1764,12 @@ After instantiating components, use figma_take_screenshot to verify the result l
1676
1764
  }
1677
1765
  });
1678
1766
  // Tool: Delete Node
1679
- server.tool("figma_delete_node", "Delete a node from the canvas. WARNING: This is a destructive operation (can be undone with Figma's undo).", {
1680
- nodeId: z.string().describe("The node ID to delete"),
1681
- fileKey: fileKeyArg,
1767
+ server.registerTool("figma_delete_node", {
1768
+ description: "Delete a node from the canvas. WARNING: This is a destructive operation (can be undone with Figma's undo).",
1769
+ inputSchema: z.object({
1770
+ nodeId: z.string().describe("The node ID to delete"),
1771
+ fileKey: fileKeyArg,
1772
+ }),
1682
1773
  }, async ({ nodeId, fileKey }) => {
1683
1774
  try {
1684
1775
  const connector = await getDesktopConnector(fileKey);
@@ -1715,10 +1806,13 @@ After instantiating components, use figma_take_screenshot to verify the result l
1715
1806
  }
1716
1807
  });
1717
1808
  // Tool: Rename Node
1718
- server.tool("figma_rename_node", "Rename a node in the layer panel.", {
1719
- nodeId: z.string().describe("The node ID to rename"),
1720
- newName: z.string().describe("The new name for the node"),
1721
- fileKey: fileKeyArg,
1809
+ server.registerTool("figma_rename_node", {
1810
+ description: "Rename a node in the layer panel.",
1811
+ inputSchema: z.object({
1812
+ nodeId: z.string().describe("The node ID to rename"),
1813
+ newName: z.string().describe("The new name for the node"),
1814
+ fileKey: fileKeyArg,
1815
+ }),
1722
1816
  }, async ({ nodeId, newName, fileKey }) => {
1723
1817
  try {
1724
1818
  const connector = await getDesktopConnector(fileKey);
@@ -1755,19 +1849,22 @@ After instantiating components, use figma_take_screenshot to verify the result l
1755
1849
  }
1756
1850
  });
1757
1851
  // Tool: Set Text Content
1758
- server.tool("figma_set_text", "Set the text content of a text node. Optionally adjust font size and the font family/style. Font style names are space-sensitive ('Semi Bold', not 'SemiBold'), but this tool auto-corrects common no-space variants and falls back gracefully — so you don't need raw figma_execute to change typography.", {
1759
- nodeId: z.string().describe("The text node ID"),
1760
- text: z.string().describe("The new text content"),
1761
- fontSize: z.number().optional().describe("Optional font size to set"),
1762
- fontFamily: z
1763
- .string()
1764
- .optional()
1765
- .describe("Optional font family to apply (e.g., 'Inter')"),
1766
- fontStyle: z
1767
- .string()
1768
- .optional()
1769
- .describe("Optional font style/weight to apply (e.g., 'Bold', 'Semi Bold'). No-space variants like 'SemiBold' are auto-corrected."),
1770
- fileKey: fileKeyArg,
1852
+ server.registerTool("figma_set_text", {
1853
+ description: "Set the text content of a text node. Optionally adjust font size and the font family/style. Font style names are space-sensitive ('Semi Bold', not 'SemiBold'), but this tool auto-corrects common no-space variants and falls back gracefully — so you don't need raw figma_execute to change typography.",
1854
+ inputSchema: z.object({
1855
+ nodeId: z.string().describe("The text node ID"),
1856
+ text: z.string().describe("The new text content"),
1857
+ fontSize: z.number().optional().describe("Optional font size to set"),
1858
+ fontFamily: z
1859
+ .string()
1860
+ .optional()
1861
+ .describe("Optional font family to apply (e.g., 'Inter')"),
1862
+ fontStyle: z
1863
+ .string()
1864
+ .optional()
1865
+ .describe("Optional font style/weight to apply (e.g., 'Bold', 'Semi Bold'). No-space variants like 'SemiBold' are auto-corrected."),
1866
+ fileKey: fileKeyArg,
1867
+ }),
1771
1868
  }, async ({ nodeId, text, fontSize, fontFamily, fontStyle, fileKey }) => {
1772
1869
  try {
1773
1870
  const connector = await getDesktopConnector(fileKey);
@@ -1807,33 +1904,36 @@ After instantiating components, use figma_take_screenshot to verify the result l
1807
1904
  }
1808
1905
  });
1809
1906
  // Tool: Create Child Node
1810
- server.tool("figma_create_child", "Create a new child node inside a parent container. Always place inside an existing Section or Frame — never on a bare page. If no suitable parent exists, create a Section first. Clean up any empty or orphaned nodes if the operation fails.", {
1811
- parentId: z.string().describe("The parent node ID"),
1812
- nodeType: z
1813
- .enum(["RECTANGLE", "ELLIPSE", "FRAME", "TEXT", "LINE", "POLYGON", "STAR", "VECTOR"])
1814
- .describe("Type of node to create"),
1815
- properties: z
1816
- .object({
1817
- name: z.string().optional().describe("Name for the new node"),
1818
- x: z.number().optional().describe("X position within parent"),
1819
- y: z.number().optional().describe("Y position within parent"),
1820
- width: z.number().optional().describe("Width (default: 100)"),
1821
- height: z.number().optional().describe("Height (default: 100)"),
1822
- fills: z
1823
- .array(z.object({
1824
- type: z.literal("SOLID"),
1825
- color: z.string(),
1826
- }))
1827
- .optional()
1828
- .describe("Fill colors (hex strings)"),
1829
- text: z
1830
- .string()
1907
+ server.registerTool("figma_create_child", {
1908
+ description: "Create a new child node inside a parent container. Always place inside an existing Section or Frame — never on a bare page. If no suitable parent exists, create a Section first. Clean up any empty or orphaned nodes if the operation fails.",
1909
+ inputSchema: z.object({
1910
+ parentId: z.string().describe("The parent node ID"),
1911
+ nodeType: z
1912
+ .enum(["RECTANGLE", "ELLIPSE", "FRAME", "TEXT", "LINE", "POLYGON", "STAR", "VECTOR"])
1913
+ .describe("Type of node to create"),
1914
+ properties: z
1915
+ .object({
1916
+ name: z.string().optional().describe("Name for the new node"),
1917
+ x: z.number().optional().describe("X position within parent"),
1918
+ y: z.number().optional().describe("Y position within parent"),
1919
+ width: z.number().optional().describe("Width (default: 100)"),
1920
+ height: z.number().optional().describe("Height (default: 100)"),
1921
+ fills: z
1922
+ .array(z.object({
1923
+ type: z.literal("SOLID"),
1924
+ color: z.string(),
1925
+ }))
1926
+ .optional()
1927
+ .describe("Fill colors (hex strings)"),
1928
+ text: z
1929
+ .string()
1930
+ .optional()
1931
+ .describe("Text content (for TEXT nodes only)"),
1932
+ })
1831
1933
  .optional()
1832
- .describe("Text content (for TEXT nodes only)"),
1833
- })
1834
- .optional()
1835
- .describe("Properties for the new node"),
1836
- fileKey: fileKeyArg,
1934
+ .describe("Properties for the new node"),
1935
+ fileKey: fileKeyArg,
1936
+ }),
1837
1937
  }, async ({ parentId, nodeType, properties, fileKey }) => {
1838
1938
  try {
1839
1939
  const connector = await getDesktopConnector(fileKey);
@@ -2322,37 +2422,40 @@ return {
2322
2422
  // Tool: Arrange Component Set (Professional Layout with Native Visualization)
2323
2423
  // Rearranges variants IN PLACE (sets x/y on existing children) so the component
2324
2424
  // set's identity is preserved and placed instances are unaffected
2325
- server.tool("figma_arrange_component_set", `Organize a component set with Figma's native purple dashed visualization. Use after creating variants, adding states (hover/disabled/pressed), or when component sets need cleanup.
2326
-
2327
- Non-destructive: rearranges the existing variants in place (grid positions on the existing set's children), so the component set keeps its node ID and all placed instances remain intact. Arranges variants in a labeled grid (columns = last property like State, rows = other properties like Type+Size) and wraps the set in a white container with title, row/column labels. Safe to run on component sets with placed instances, and safe to re-run.`, {
2328
- componentSetId: z
2329
- .string()
2330
- .optional()
2331
- .describe("Node ID of the component set to arrange. If not provided, will look for a selected component set."),
2332
- componentSetName: z
2333
- .string()
2334
- .optional()
2335
- .describe("Name of the component set to find. Used if componentSetId not provided."),
2336
- options: z
2337
- .object({
2338
- gap: z
2339
- .number()
2340
- .optional()
2341
- .default(24)
2342
- .describe("Gap between grid cells in pixels (default: 24)"),
2343
- cellPadding: z
2344
- .number()
2425
+ server.registerTool("figma_arrange_component_set", {
2426
+ description: `Organize a component set with Figma's native purple dashed visualization. Use after creating variants, adding states (hover/disabled/pressed), or when component sets need cleanup.
2427
+
2428
+ Non-destructive: rearranges the existing variants in place (grid positions on the existing set's children), so the component set keeps its node ID and all placed instances remain intact. Arranges variants in a labeled grid (columns = last property like State, rows = other properties like Type+Size) and wraps the set in a white container with title, row/column labels. Safe to run on component sets with placed instances, and safe to re-run.`,
2429
+ inputSchema: z.object({
2430
+ componentSetId: z
2431
+ .string()
2345
2432
  .optional()
2346
- .default(20)
2347
- .describe("Padding inside each cell around the variant (default: 20)"),
2348
- columnProperty: z
2433
+ .describe("Node ID of the component set to arrange. If not provided, will look for a selected component set."),
2434
+ componentSetName: z
2349
2435
  .string()
2350
2436
  .optional()
2351
- .describe("Property to use for columns (default: auto-detect last property, usually 'State')"),
2352
- })
2353
- .optional()
2354
- .describe("Layout options"),
2355
- fileKey: fileKeyArg,
2437
+ .describe("Name of the component set to find. Used if componentSetId not provided."),
2438
+ options: z
2439
+ .object({
2440
+ gap: z
2441
+ .number()
2442
+ .optional()
2443
+ .default(24)
2444
+ .describe("Gap between grid cells in pixels (default: 24)"),
2445
+ cellPadding: z
2446
+ .number()
2447
+ .optional()
2448
+ .default(20)
2449
+ .describe("Padding inside each cell around the variant (default: 20)"),
2450
+ columnProperty: z
2451
+ .string()
2452
+ .optional()
2453
+ .describe("Property to use for columns (default: auto-detect last property, usually 'State')"),
2454
+ })
2455
+ .optional()
2456
+ .describe("Layout options"),
2457
+ fileKey: fileKeyArg,
2458
+ }),
2356
2459
  }, async ({ componentSetId, componentSetName, options, fileKey }) => {
2357
2460
  try {
2358
2461
  const connector = await getDesktopConnector(fileKey);
@@ -2393,7 +2496,8 @@ Non-destructive: rearranges the existing variants in place (grid positions on th
2393
2496
  });
2394
2497
  // Tool: Create Component Set with variants (structured command — no hand-written
2395
2498
  // figma_execute scripts, no 30s execution-cap juggling for callers)
2396
- server.tool("figma_create_component_set", `Create a component set with variants in one call — replaces hand-written figma.combineAsVariants scripts.
2499
+ server.registerTool("figma_create_component_set", {
2500
+ description: `Create a component set with variants in one call — replaces hand-written figma.combineAsVariants scripts.
2397
2501
 
2398
2502
  Two modes:
2399
2503
  1. **Generate from a base component**: pass baseComponentId + properties (variant axes). The base is cloned for every combination of the axes ({ State: ['default','hover','disabled'], Size: ['sm','lg'] } → 6 variants), each named 'Prop=Value' comma-joined (e.g. 'State=hover, Size=sm'), then combined into a set. The base component itself becomes the FIRST variant (same node ID), so existing instances of the base survive as instances of that variant.
@@ -2403,49 +2507,51 @@ Figma derives the variant property definitions from the names; they live on the
2403
2507
 
2404
2508
  Set autoArrange:true to lay the new set out as a labeled grid inside a white container (same layout as figma_arrange_component_set). Requires Desktop Bridge plugin.
2405
2509
 
2406
- SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count (~1.2s/variant, 30s floor / 2min cap), but above ~40 variants the single-pass clone+combine gets slow and heavy base components may still push the limit — prefer splitting large matrices into multiple sets (e.g. one set per Size).`, {
2407
- baseComponentId: z
2408
- .string()
2409
- .optional()
2410
- .describe("Node ID of an existing COMPONENT to use as the base. Cloned per property combination; becomes the set's first variant (keeps its node ID, so placed instances survive). Mutually exclusive with componentIds."),
2411
- properties: z
2412
- .record(z.string(), z.array(z.string()))
2413
- .optional()
2414
- .describe("Variant property axes — required with baseComponentId. Example: { State: ['default','hover','disabled'], Size: ['sm','lg'] } creates 6 variants. Max 100 combinations. Names and values must not contain '=' or ','."),
2415
- componentIds: z
2416
- .array(z.string())
2417
- .optional()
2418
- .describe("Node IDs of existing COMPONENT nodes to combine as variants. Mutually exclusive with baseComponentId. Components already inside a component set are rejected."),
2419
- variantProperties: z
2420
- .array(z.record(z.string()))
2421
- .optional()
2422
- .describe("Only with componentIds: one property map per component, aligned by index — e.g. [{ State: 'default' }, { State: 'hover' }]. Each component is renamed to 'Prop=Value, ...' before combining. Without this, existing names are kept (names lacking '=' become 'Property 1=<name>')."),
2423
- name: z
2424
- .string()
2425
- .optional()
2426
- .describe("Name for the component set (e.g., 'Button'). Defaults to Figma's derived name."),
2427
- parentId: z
2428
- .string()
2429
- .optional()
2430
- .describe("Node ID of the container (frame/section) to create the set in. Defaults to the current page."),
2431
- position: z
2432
- .object({ x: z.number(), y: z.number() })
2433
- .optional()
2434
- .describe("Position of the set within its parent."),
2435
- autoArrange: z
2436
- .boolean()
2437
- .optional()
2438
- .default(false)
2439
- .describe("If true, arrange the new set in a labeled grid (columns = last property, rows = other properties) inside a white container — same in-place layout as figma_arrange_component_set."),
2440
- arrangeOptions: z
2441
- .object({
2442
- gap: z.number().optional().describe("Gap between grid cells in pixels (default: 24)"),
2443
- cellPadding: z.number().optional().describe("Padding inside each cell around the variant (default: 20)"),
2444
- columnProperty: z.string().optional().describe("Property to use for columns (default: last property)"),
2445
- })
2446
- .optional()
2447
- .describe("Grid layout options, used when autoArrange is true."),
2448
- fileKey: fileKeyArg,
2510
+ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count (~1.2s/variant, 30s floor / 2min cap), but above ~40 variants the single-pass clone+combine gets slow and heavy base components may still push the limit — prefer splitting large matrices into multiple sets (e.g. one set per Size).`,
2511
+ inputSchema: z.object({
2512
+ baseComponentId: z
2513
+ .string()
2514
+ .optional()
2515
+ .describe("Node ID of an existing COMPONENT to use as the base. Cloned per property combination; becomes the set's first variant (keeps its node ID, so placed instances survive). Mutually exclusive with componentIds."),
2516
+ properties: z
2517
+ .record(z.string(), z.array(z.string()))
2518
+ .optional()
2519
+ .describe("Variant property axes — required with baseComponentId. Example: { State: ['default','hover','disabled'], Size: ['sm','lg'] } creates 6 variants. Max 100 combinations. Names and values must not contain '=' or ','."),
2520
+ componentIds: z
2521
+ .array(z.string())
2522
+ .optional()
2523
+ .describe("Node IDs of existing COMPONENT nodes to combine as variants. Mutually exclusive with baseComponentId. Components already inside a component set are rejected."),
2524
+ variantProperties: z
2525
+ .array(z.record(z.string(), z.string()))
2526
+ .optional()
2527
+ .describe("Only with componentIds: one property map per component, aligned by index — e.g. [{ State: 'default' }, { State: 'hover' }]. Each component is renamed to 'Prop=Value, ...' before combining. Without this, existing names are kept (names lacking '=' become 'Property 1=<name>')."),
2528
+ name: z
2529
+ .string()
2530
+ .optional()
2531
+ .describe("Name for the component set (e.g., 'Button'). Defaults to Figma's derived name."),
2532
+ parentId: z
2533
+ .string()
2534
+ .optional()
2535
+ .describe("Node ID of the container (frame/section) to create the set in. Defaults to the current page."),
2536
+ position: z
2537
+ .object({ x: z.number(), y: z.number() })
2538
+ .optional()
2539
+ .describe("Position of the set within its parent."),
2540
+ autoArrange: z
2541
+ .boolean()
2542
+ .optional()
2543
+ .default(false)
2544
+ .describe("If true, arrange the new set in a labeled grid (columns = last property, rows = other properties) inside a white container — same in-place layout as figma_arrange_component_set."),
2545
+ arrangeOptions: z
2546
+ .object({
2547
+ gap: z.number().optional().describe("Gap between grid cells in pixels (default: 24)"),
2548
+ cellPadding: z.number().optional().describe("Padding inside each cell around the variant (default: 20)"),
2549
+ columnProperty: z.string().optional().describe("Property to use for columns (default: last property)"),
2550
+ })
2551
+ .optional()
2552
+ .describe("Grid layout options, used when autoArrange is true."),
2553
+ fileKey: fileKeyArg,
2554
+ }),
2449
2555
  }, async ({ baseComponentId, properties, componentIds, variantProperties, name, parentId, position, autoArrange, arrangeOptions, fileKey, }) => {
2450
2556
  try {
2451
2557
  if (!baseComponentId && (!componentIds || componentIds.length === 0)) {
@@ -2551,23 +2657,26 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
2551
2657
  }
2552
2658
  });
2553
2659
  // Tool: Lint Design for accessibility and quality issues
2554
- server.tool("figma_lint_design", "Run comprehensive accessibility (WCAG 2.2) and design quality checks on the current page or a specific node tree. " +
2555
- "WCAG conformance checks (10 rules): color contrast (AA), non-text contrast (1.4.11), color-only differentiation (1.4.1), " +
2556
- "focus indicators (2.4.7), touch targets (2.5.8), image alt text (1.1.1), heading hierarchy (1.3.1), " +
2557
- "reflow/responsive (1.4.10), reading order (1.3.2), and disabled context (4.1.2). " +
2558
- "Best-practice readability hints (opt-in via rules: ['best-practice'] or ['all']): text sizing, line height, letter spacing, paragraph spacing. " +
2559
- "Note: line/paragraph spacing below 1.5x/2x is NOT a WCAG 1.4.12 failure — 1.4.12 requires supporting user spacing overrides without breaking (a code concern, see figma_scan_code_accessibility), not specific design values — so these are non-normative hints scoped to multi-line text only. " +
2560
- "Design system checks: hardcoded colors, missing text styles, default names, detached components. " +
2561
- "Layout checks: missing auto-layout, empty containers. " +
2562
- "Default audit runs WCAG + design-system + layout (best-practice hints excluded). " +
2563
- "Returns categorized findings with severity levels (critical/warning/info) and WCAG conformance level (a/aa/aaa/best-practice) so teams can filter by target level. " +
2564
- "Use natural language like 'check my design for accessibility issues' or 'lint this page'. " +
2565
- "Requires Desktop Bridge plugin.", {
2566
- nodeId: z.string().optional().describe("Node ID to lint (defaults to current page)"),
2567
- rules: z.array(z.string()).optional().describe("Rule filter. Default (omitted) = ['wcag','design-system','layout'] — real WCAG conformance plus quality checks, with best-practice hints excluded. Groups: ['wcag'] (10 conformance rules), ['best-practice'] (text-size, line-height, letter-spacing, paragraph-spacing), ['all'] (everything incl. best-practice), ['design-system'], ['layout']. Or specific rule IDs like ['wcag-contrast', 'wcag-focus-indicator', 'wcag-disabled-no-context']."),
2568
- maxDepth: z.number().optional().describe("Maximum tree depth to traverse (default: 10)"),
2569
- maxFindings: z.number().optional().describe("Maximum findings before stopping (default: 100)"),
2570
- fileKey: fileKeyArg,
2660
+ server.registerTool("figma_lint_design", {
2661
+ description: "Run comprehensive accessibility (WCAG 2.2) and design quality checks on the current page or a specific node tree. " +
2662
+ "WCAG conformance checks (10 rules): color contrast (AA), non-text contrast (1.4.11), color-only differentiation (1.4.1), " +
2663
+ "focus indicators (2.4.7), touch targets (2.5.8), image alt text (1.1.1), heading hierarchy (1.3.1), " +
2664
+ "reflow/responsive (1.4.10), reading order (1.3.2), and disabled context (4.1.2). " +
2665
+ "Best-practice readability hints (opt-in via rules: ['best-practice'] or ['all']): text sizing, line height, letter spacing, paragraph spacing. " +
2666
+ "Note: line/paragraph spacing below 1.5x/2x is NOT a WCAG 1.4.12 failure — 1.4.12 requires supporting user spacing overrides without breaking (a code concern, see figma_scan_code_accessibility), not specific design values — so these are non-normative hints scoped to multi-line text only. " +
2667
+ "Design system checks: hardcoded colors, missing text styles, default names, detached components. " +
2668
+ "Layout checks: missing auto-layout, empty containers. " +
2669
+ "Default audit runs WCAG + design-system + layout (best-practice hints excluded). " +
2670
+ "Returns categorized findings with severity levels (critical/warning/info) and WCAG conformance level (a/aa/aaa/best-practice) so teams can filter by target level. " +
2671
+ "Use natural language like 'check my design for accessibility issues' or 'lint this page'. " +
2672
+ "Requires Desktop Bridge plugin.",
2673
+ inputSchema: z.object({
2674
+ nodeId: z.string().optional().describe("Node ID to lint (defaults to current page)"),
2675
+ rules: z.array(z.string()).optional().describe("Rule filter. Default (omitted) = ['wcag','design-system','layout'] — real WCAG conformance plus quality checks, with best-practice hints excluded. Groups: ['wcag'] (10 conformance rules), ['best-practice'] (text-size, line-height, letter-spacing, paragraph-spacing), ['all'] (everything incl. best-practice), ['design-system'], ['layout']. Or specific rule IDs like ['wcag-contrast', 'wcag-focus-indicator', 'wcag-disabled-no-context']."),
2676
+ maxDepth: z.number().optional().describe("Maximum tree depth to traverse (default: 10)"),
2677
+ maxFindings: z.number().optional().describe("Maximum findings before stopping (default: 100)"),
2678
+ fileKey: fileKeyArg,
2679
+ }),
2571
2680
  }, async ({ nodeId, rules, maxDepth, maxFindings, fileKey }) => {
2572
2681
  try {
2573
2682
  const connector = await getDesktopConnector(fileKey);
@@ -2601,15 +2710,18 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
2601
2710
  }
2602
2711
  });
2603
2712
  // Tool: Audit Component Accessibility
2604
- server.tool("figma_audit_component_accessibility", "Deep accessibility audit for a specific component or component set. Produces a scorecard covering: " +
2605
- "state coverage (default/hover/focus/disabled/error/active/loading), focus indicator quality and contrast, " +
2606
- "non-color differentiation (WCAG 1.4.1), target size consistency (WCAG 2.5.8), annotation completeness, " +
2607
- "and color-blind simulation (protanopia/deuteranopia/tritanopia). Returns per-category scores (0-100) " +
2608
- "and prioritized recommendations. Use after designing a component to validate accessibility before handoff. " +
2609
- "Requires Desktop Bridge plugin.", {
2610
- nodeId: z.string().optional().describe("Node ID of a COMPONENT_SET, COMPONENT, or INSTANCE to audit. Falls back to current selection if omitted."),
2611
- targetSize: z.number().optional().describe("Minimum touch target size in px (default: 24 per WCAG 2.5.8). Use 44 for iOS or 48 for Android guidelines."),
2612
- fileKey: fileKeyArg,
2713
+ server.registerTool("figma_audit_component_accessibility", {
2714
+ description: "Deep accessibility audit for a specific component or component set. Produces a scorecard covering: " +
2715
+ "state coverage (default/hover/focus/disabled/error/active/loading), focus indicator quality and contrast, " +
2716
+ "non-color differentiation (WCAG 1.4.1), target size consistency (WCAG 2.5.8), annotation completeness, " +
2717
+ "and color-blind simulation (protanopia/deuteranopia/tritanopia). Returns per-category scores (0-100) " +
2718
+ "and prioritized recommendations. Use after designing a component to validate accessibility before handoff. " +
2719
+ "Requires Desktop Bridge plugin.",
2720
+ inputSchema: z.object({
2721
+ nodeId: z.string().optional().describe("Node ID of a COMPONENT_SET, COMPONENT, or INSTANCE to audit. Falls back to current selection if omitted."),
2722
+ targetSize: z.number().optional().describe("Minimum touch target size in px (default: 24 per WCAG 2.5.8). Use 44 for iOS or 48 for Android guidelines."),
2723
+ fileKey: fileKeyArg,
2724
+ }),
2613
2725
  }, async ({ nodeId, targetSize, fileKey }) => {
2614
2726
  try {
2615
2727
  const connector = await getDesktopConnector(fileKey);