@muloka/figma-console-mcp 0.5.5 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/core/http-request-guard.d.ts.map +1 -1
- package/dist/core/http-request-guard.js +11 -13
- package/dist/core/http-request-guard.js.map +1 -1
- package/dist/core/port-discovery.d.ts.map +1 -1
- package/dist/core/port-discovery.js +151 -52
- package/dist/core/port-discovery.js.map +1 -1
- package/dist/core/websocket-server.d.ts +39 -2
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +147 -19
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/core/write-tools.d.ts +18 -1
- package/dist/core/write-tools.d.ts.map +1 -1
- package/dist/core/write-tools.js +138 -89
- package/dist/core/write-tools.js.map +1 -1
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +39 -6
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/code.js +10 -2
- package/figma-desktop-bridge/ui.html +82 -8
- package/package.json +1 -1
package/dist/core/write-tools.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { createChildLogger } from "./logger.js";
|
|
3
3
|
const logger = createChildLogger({ component: "write-tools" });
|
|
4
4
|
/**
|
|
5
|
-
* Optional target file (TECH-32), on
|
|
5
|
+
* Optional target file (TECH-32), on all write tools. Without it a tool
|
|
6
6
|
* runs in the active file, as before. With it, the connector is built for that
|
|
7
7
|
* file and every command it sends goes only to that file's plugin.
|
|
8
8
|
*/
|
|
@@ -12,13 +12,50 @@ const fileKeyArg = z
|
|
|
12
12
|
.describe("Run in this file (its fileKey, as figma_list_open_files reports it) instead of the active file. " +
|
|
13
13
|
"Fails if that file's Desktop Bridge plugin is not connected; never falls back to the active file. " +
|
|
14
14
|
"Ignores the active file and the target lock. Leave it out to use the active file.");
|
|
15
|
+
/**
|
|
16
|
+
* Shared inline JS helper embedded in batch variable scripts.
|
|
17
|
+
* Validates 3/4/6/8-digit hex strings instead of silently producing NaN channels.
|
|
18
|
+
*/
|
|
19
|
+
const HEX_TO_RGBA_HELPER = `function hexToRgba(hex) {
|
|
20
|
+
if (typeof hex !== 'string') throw new Error('Invalid color value: expected hex string, got ' + typeof hex);
|
|
21
|
+
let h = hex.trim().replace(/^#/, '');
|
|
22
|
+
if (h.length === 3 || h.length === 4) h = h.split('').map(c => c + c).join('');
|
|
23
|
+
if (!/^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(h)) {
|
|
24
|
+
throw new Error('Invalid hex color: "' + hex + '" (expected #RGB, #RGBA, #RRGGBB, or #RRGGBBAA)');
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
r: parseInt(h.substring(0, 2), 16) / 255,
|
|
28
|
+
g: parseInt(h.substring(2, 4), 16) / 255,
|
|
29
|
+
b: parseInt(h.substring(4, 6), 16) / 255,
|
|
30
|
+
a: h.length === 8 ? parseInt(h.substring(6, 8), 16) / 255 : 1
|
|
31
|
+
};
|
|
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
|
+
}
|
|
15
52
|
/**
|
|
16
53
|
* Register write/manipulation tools that require a Desktop Bridge connector.
|
|
17
54
|
* Used by both local mode (src/local.ts) and cloud mode (src/index.ts).
|
|
18
55
|
* `getDesktopConnector(fileKey)` returns a connector bound to that file;
|
|
19
56
|
* with no key, one that follows the active file.
|
|
20
57
|
*/
|
|
21
|
-
export function registerWriteTools(server, getDesktopConnector) {
|
|
58
|
+
export function registerWriteTools(server, getDesktopConnector, options) {
|
|
22
59
|
// ============================================================================
|
|
23
60
|
// EXECUTION TOOL
|
|
24
61
|
// ============================================================================
|
|
@@ -106,9 +143,10 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
106
143
|
.string()
|
|
107
144
|
.optional()
|
|
108
145
|
.describe("Set the variable's description (the 'How to use this variable' field; exported as DTCG $description). Pass an empty string to clear it."),
|
|
109
|
-
|
|
146
|
+
fileKey: fileKeyArg,
|
|
147
|
+
}, async ({ variableId, modeId, value, description, fileKey }) => {
|
|
110
148
|
try {
|
|
111
|
-
const connector = await getDesktopConnector();
|
|
149
|
+
const connector = await getDesktopConnector(fileKey);
|
|
112
150
|
const hasValueUpdate = modeId !== undefined && value !== undefined;
|
|
113
151
|
const hasDescriptionUpdate = description !== undefined;
|
|
114
152
|
if ((modeId !== undefined) !== (value !== undefined)) {
|
|
@@ -140,6 +178,7 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
140
178
|
variable = result.variable || variable;
|
|
141
179
|
updated.push("description");
|
|
142
180
|
}
|
|
181
|
+
options?.onVariableWrite?.();
|
|
143
182
|
return {
|
|
144
183
|
content: [
|
|
145
184
|
{
|
|
@@ -190,9 +229,10 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
190
229
|
.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
|
|
191
230
|
.optional()
|
|
192
231
|
.describe("Optional initial values by mode ID. Example: { '1:0': '#FF0000', '1:1': '#0000FF' }"),
|
|
193
|
-
|
|
232
|
+
fileKey: fileKeyArg,
|
|
233
|
+
}, async ({ name, collectionId, resolvedType, description, valuesByMode, fileKey, }) => {
|
|
194
234
|
try {
|
|
195
|
-
const connector = await getDesktopConnector();
|
|
235
|
+
const connector = await getDesktopConnector(fileKey);
|
|
196
236
|
const result = await connector.createVariable(name, collectionId, resolvedType, {
|
|
197
237
|
description,
|
|
198
238
|
valuesByMode,
|
|
@@ -200,6 +240,7 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
200
240
|
if (!result.success) {
|
|
201
241
|
throw new Error(result.error || "Failed to create variable");
|
|
202
242
|
}
|
|
243
|
+
options?.onVariableWrite?.();
|
|
203
244
|
return {
|
|
204
245
|
content: [
|
|
205
246
|
{
|
|
@@ -244,9 +285,10 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
244
285
|
.array(z.string())
|
|
245
286
|
.optional()
|
|
246
287
|
.describe("Additional mode names to create. Example: ['Dark', 'High Contrast']"),
|
|
247
|
-
|
|
288
|
+
fileKey: fileKeyArg,
|
|
289
|
+
}, async ({ name, initialModeName, additionalModes, fileKey }) => {
|
|
248
290
|
try {
|
|
249
|
-
const connector = await getDesktopConnector();
|
|
291
|
+
const connector = await getDesktopConnector(fileKey);
|
|
250
292
|
const result = await connector.createVariableCollection(name, {
|
|
251
293
|
initialModeName,
|
|
252
294
|
additionalModes,
|
|
@@ -254,6 +296,7 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
254
296
|
if (!result.success) {
|
|
255
297
|
throw new Error(result.error || "Failed to create variable collection");
|
|
256
298
|
}
|
|
299
|
+
options?.onVariableWrite?.();
|
|
257
300
|
return {
|
|
258
301
|
content: [
|
|
259
302
|
{
|
|
@@ -298,6 +341,7 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
298
341
|
if (!result.success) {
|
|
299
342
|
throw new Error(result.error || "Failed to delete variable");
|
|
300
343
|
}
|
|
344
|
+
options?.onVariableWrite?.();
|
|
301
345
|
return {
|
|
302
346
|
content: [
|
|
303
347
|
{
|
|
@@ -335,13 +379,15 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
335
379
|
collectionId: z
|
|
336
380
|
.string()
|
|
337
381
|
.describe("The collection ID to delete (e.g., 'VariableCollectionId:123:456'). Get this from figma_get_variables."),
|
|
338
|
-
|
|
382
|
+
fileKey: fileKeyArg,
|
|
383
|
+
}, async ({ collectionId, fileKey }) => {
|
|
339
384
|
try {
|
|
340
|
-
const connector = await getDesktopConnector();
|
|
385
|
+
const connector = await getDesktopConnector(fileKey);
|
|
341
386
|
const result = await connector.deleteVariableCollection(collectionId);
|
|
342
387
|
if (!result.success) {
|
|
343
388
|
throw new Error(result.error || "Failed to delete variable collection");
|
|
344
389
|
}
|
|
390
|
+
options?.onVariableWrite?.();
|
|
345
391
|
return {
|
|
346
392
|
content: [
|
|
347
393
|
{
|
|
@@ -390,6 +436,7 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
390
436
|
if (!result.success) {
|
|
391
437
|
throw new Error(result.error || "Failed to rename variable");
|
|
392
438
|
}
|
|
439
|
+
options?.onVariableWrite?.();
|
|
393
440
|
return {
|
|
394
441
|
content: [
|
|
395
442
|
{
|
|
@@ -430,15 +477,17 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
430
477
|
modeName: z
|
|
431
478
|
.string()
|
|
432
479
|
.describe("The name for the new mode (e.g., 'Dark', 'Mobile', 'High Contrast')."),
|
|
433
|
-
|
|
480
|
+
fileKey: fileKeyArg,
|
|
481
|
+
}, async ({ collectionId, modeName, fileKey }) => {
|
|
434
482
|
try {
|
|
435
|
-
const connector = await getDesktopConnector();
|
|
483
|
+
const connector = await getDesktopConnector(fileKey);
|
|
436
484
|
const result = await connector.addMode(collectionId, modeName);
|
|
437
485
|
// Keep the plugin's error text intact — for a plan-limit failure it
|
|
438
486
|
// carries the file's real ceiling ("in addMode: Limited to N modes only").
|
|
439
487
|
if (!result.success) {
|
|
440
488
|
throw new Error(result.error || "Failed to add mode");
|
|
441
489
|
}
|
|
490
|
+
options?.onVariableWrite?.();
|
|
442
491
|
return {
|
|
443
492
|
content: [
|
|
444
493
|
{
|
|
@@ -482,13 +531,15 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
482
531
|
newName: z
|
|
483
532
|
.string()
|
|
484
533
|
.describe("The new name for the mode (e.g., 'Dark Theme', 'Tablet')."),
|
|
485
|
-
|
|
534
|
+
fileKey: fileKeyArg,
|
|
535
|
+
}, async ({ collectionId, modeId, newName, fileKey }) => {
|
|
486
536
|
try {
|
|
487
|
-
const connector = await getDesktopConnector();
|
|
537
|
+
const connector = await getDesktopConnector(fileKey);
|
|
488
538
|
const result = await connector.renameMode(collectionId, modeId, newName);
|
|
489
539
|
if (!result.success) {
|
|
490
540
|
throw new Error(result.error || "Failed to rename mode");
|
|
491
541
|
}
|
|
542
|
+
options?.onVariableWrite?.();
|
|
492
543
|
return {
|
|
493
544
|
content: [
|
|
494
545
|
{
|
|
@@ -556,19 +607,10 @@ Layers: If your code creates helper frames, placeholder nodes, or intermediate l
|
|
|
556
607
|
const connector = await getDesktopConnector(fileKey);
|
|
557
608
|
const script = `
|
|
558
609
|
const results = [];
|
|
559
|
-
const collectionId = ${JSON.stringify(collectionId)};
|
|
560
|
-
const vars = ${JSON.stringify(variables)};
|
|
610
|
+
const collectionId = ${sandboxSafeJson(JSON.stringify(collectionId))};
|
|
611
|
+
const vars = ${sandboxSafeJson(JSON.stringify(variables))};
|
|
561
612
|
|
|
562
|
-
|
|
563
|
-
hex = hex.replace('#', '');
|
|
564
|
-
if (hex.length === 3) hex = hex.split('').map(c => c + c).join('');
|
|
565
|
-
return {
|
|
566
|
-
r: parseInt(hex.substring(0, 2), 16) / 255,
|
|
567
|
-
g: parseInt(hex.substring(2, 4), 16) / 255,
|
|
568
|
-
b: parseInt(hex.substring(4, 6), 16) / 255,
|
|
569
|
-
a: hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1
|
|
570
|
-
};
|
|
571
|
-
}
|
|
613
|
+
${HEX_TO_RGBA_HELPER}
|
|
572
614
|
|
|
573
615
|
const collection = await figma.variables.getVariableCollectionByIdAsync(collectionId);
|
|
574
616
|
if (!collection) return { created: 0, failed: vars.length, results: vars.map(v => ({ success: false, name: v.name, error: 'Collection not found: ' + collectionId })) };
|
|
@@ -622,6 +664,7 @@ return {
|
|
|
622
664
|
isError: true,
|
|
623
665
|
};
|
|
624
666
|
}
|
|
667
|
+
options?.onVariableWrite?.();
|
|
625
668
|
return {
|
|
626
669
|
content: [
|
|
627
670
|
{
|
|
@@ -667,7 +710,7 @@ return {
|
|
|
667
710
|
.describe("Mode ID (e.g., '1:0')"),
|
|
668
711
|
value: z
|
|
669
712
|
.union([z.string(), z.number(), z.boolean()])
|
|
670
|
-
.describe("New value. COLOR: hex like '#FF0000'. FLOAT: number. STRING: text. BOOLEAN: true/false."),
|
|
713
|
+
.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."),
|
|
671
714
|
}))
|
|
672
715
|
.min(1)
|
|
673
716
|
.max(100)
|
|
@@ -678,25 +721,20 @@ return {
|
|
|
678
721
|
const connector = await getDesktopConnector(fileKey);
|
|
679
722
|
const script = `
|
|
680
723
|
const results = [];
|
|
681
|
-
const updates = ${JSON.stringify(updates)};
|
|
724
|
+
const updates = ${sandboxSafeJson(JSON.stringify(updates))};
|
|
682
725
|
|
|
683
|
-
|
|
684
|
-
hex = hex.replace('#', '');
|
|
685
|
-
if (hex.length === 3) hex = hex.split('').map(c => c + c).join('');
|
|
686
|
-
return {
|
|
687
|
-
r: parseInt(hex.substring(0, 2), 16) / 255,
|
|
688
|
-
g: parseInt(hex.substring(2, 4), 16) / 255,
|
|
689
|
-
b: parseInt(hex.substring(4, 6), 16) / 255,
|
|
690
|
-
a: hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1
|
|
691
|
-
};
|
|
692
|
-
}
|
|
726
|
+
${HEX_TO_RGBA_HELPER}
|
|
693
727
|
|
|
694
728
|
for (const u of updates) {
|
|
695
729
|
try {
|
|
696
730
|
const variable = await figma.variables.getVariableByIdAsync(u.variableId);
|
|
697
731
|
if (!variable) throw new Error('Variable not found: ' + u.variableId);
|
|
698
|
-
|
|
699
|
-
|
|
732
|
+
let processed = u.value;
|
|
733
|
+
if (typeof u.value === 'string' && u.value.startsWith('VariableID:')) {
|
|
734
|
+
processed = { type: 'VARIABLE_ALIAS', id: u.value };
|
|
735
|
+
} else if (variable.resolvedType === 'COLOR' && typeof u.value === 'string') {
|
|
736
|
+
processed = hexToRgba(u.value);
|
|
737
|
+
}
|
|
700
738
|
variable.setValueForMode(u.modeId, processed);
|
|
701
739
|
results.push({ success: true, variableId: u.variableId, name: variable.name });
|
|
702
740
|
} catch (err) {
|
|
@@ -726,6 +764,7 @@ return {
|
|
|
726
764
|
isError: true,
|
|
727
765
|
};
|
|
728
766
|
}
|
|
767
|
+
options?.onVariableWrite?.();
|
|
729
768
|
return {
|
|
730
769
|
content: [
|
|
731
770
|
{
|
|
@@ -793,20 +832,11 @@ return {
|
|
|
793
832
|
try {
|
|
794
833
|
const connector = await getDesktopConnector(fileKey);
|
|
795
834
|
const script = `
|
|
796
|
-
const collectionName = ${JSON.stringify(collectionName)};
|
|
797
|
-
const modeNames = ${JSON.stringify(modes)};
|
|
798
|
-
const tokenDefs = ${JSON.stringify(tokens)};
|
|
835
|
+
const collectionName = ${sandboxSafeJson(JSON.stringify(collectionName))};
|
|
836
|
+
const modeNames = ${sandboxSafeJson(JSON.stringify(modes))};
|
|
837
|
+
const tokenDefs = ${sandboxSafeJson(JSON.stringify(tokens))};
|
|
799
838
|
|
|
800
|
-
|
|
801
|
-
hex = hex.replace('#', '');
|
|
802
|
-
if (hex.length === 3) hex = hex.split('').map(c => c + c).join('');
|
|
803
|
-
return {
|
|
804
|
-
r: parseInt(hex.substring(0, 2), 16) / 255,
|
|
805
|
-
g: parseInt(hex.substring(2, 4), 16) / 255,
|
|
806
|
-
b: parseInt(hex.substring(4, 6), 16) / 255,
|
|
807
|
-
a: hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1
|
|
808
|
-
};
|
|
809
|
-
}
|
|
839
|
+
${HEX_TO_RGBA_HELPER}
|
|
810
840
|
|
|
811
841
|
// Step 1: Create collection
|
|
812
842
|
const collection = figma.variables.createVariableCollection(collectionName);
|
|
@@ -1015,6 +1045,7 @@ return {
|
|
|
1015
1045
|
isError: true,
|
|
1016
1046
|
};
|
|
1017
1047
|
}
|
|
1048
|
+
options?.onVariableWrite?.();
|
|
1018
1049
|
return {
|
|
1019
1050
|
content: [
|
|
1020
1051
|
{
|
|
@@ -1089,12 +1120,13 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1089
1120
|
.string()
|
|
1090
1121
|
.optional()
|
|
1091
1122
|
.describe("Parent node ID to append the instance to"),
|
|
1092
|
-
|
|
1123
|
+
fileKey: fileKeyArg,
|
|
1124
|
+
}, async ({ componentKey, nodeId, variant, overrides, position, parentId, fileKey, }) => {
|
|
1093
1125
|
try {
|
|
1094
1126
|
if (!componentKey && !nodeId) {
|
|
1095
1127
|
throw new Error("Either componentKey or nodeId is required");
|
|
1096
1128
|
}
|
|
1097
|
-
const connector = await getDesktopConnector();
|
|
1129
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1098
1130
|
const result = await connector.instantiateComponent(componentKey || "", {
|
|
1099
1131
|
nodeId,
|
|
1100
1132
|
position,
|
|
@@ -1154,9 +1186,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1154
1186
|
.string()
|
|
1155
1187
|
.optional()
|
|
1156
1188
|
.describe("Optional rich text description using markdown formatting"),
|
|
1157
|
-
|
|
1189
|
+
fileKey: fileKeyArg,
|
|
1190
|
+
}, async ({ nodeId, description, descriptionMarkdown, fileKey }) => {
|
|
1158
1191
|
try {
|
|
1159
|
-
const connector = await getDesktopConnector();
|
|
1192
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1160
1193
|
const result = await connector.setNodeDescription(nodeId, description, descriptionMarkdown);
|
|
1161
1194
|
if (!result.success) {
|
|
1162
1195
|
throw new Error(result.error || "Failed to set description");
|
|
@@ -1214,9 +1247,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1214
1247
|
}))
|
|
1215
1248
|
.optional()
|
|
1216
1249
|
.describe("Preferred components (INSTANCE_SWAP and SLOT only)"),
|
|
1217
|
-
|
|
1250
|
+
fileKey: fileKeyArg,
|
|
1251
|
+
}, async ({ nodeId, propertyName, type, defaultValue, description, preferredValues, fileKey }) => {
|
|
1218
1252
|
try {
|
|
1219
|
-
const connector = await getDesktopConnector();
|
|
1253
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1220
1254
|
const options = {};
|
|
1221
1255
|
if (description)
|
|
1222
1256
|
options.description = description;
|
|
@@ -1294,9 +1328,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1294
1328
|
.describe("Preferred values (INSTANCE_SWAP only)"),
|
|
1295
1329
|
})
|
|
1296
1330
|
.describe("Object with the values to update"),
|
|
1297
|
-
|
|
1331
|
+
fileKey: fileKeyArg,
|
|
1332
|
+
}, async ({ nodeId, propertyName, newValue, fileKey }) => {
|
|
1298
1333
|
try {
|
|
1299
|
-
const connector = await getDesktopConnector();
|
|
1334
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1300
1335
|
const result = await connector.editComponentProperty(nodeId, propertyName, newValue);
|
|
1301
1336
|
if (!result.success) {
|
|
1302
1337
|
throw new Error(result.error || "Failed to edit property");
|
|
@@ -1335,9 +1370,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1335
1370
|
propertyName: z
|
|
1336
1371
|
.string()
|
|
1337
1372
|
.describe("The full property name with suffix (e.g., 'Show Icon#123:456')"),
|
|
1338
|
-
|
|
1373
|
+
fileKey: fileKeyArg,
|
|
1374
|
+
}, async ({ nodeId, propertyName, fileKey }) => {
|
|
1339
1375
|
try {
|
|
1340
|
-
const connector = await getDesktopConnector();
|
|
1376
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1341
1377
|
const result = await connector.deleteComponentProperty(nodeId, propertyName);
|
|
1342
1378
|
if (!result.success) {
|
|
1343
1379
|
throw new Error(result.error || "Failed to delete property");
|
|
@@ -1383,9 +1419,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1383
1419
|
.optional()
|
|
1384
1420
|
.default(true)
|
|
1385
1421
|
.describe("Whether to apply child constraints during resize (default: true)"),
|
|
1386
|
-
|
|
1422
|
+
fileKey: fileKeyArg,
|
|
1423
|
+
}, async ({ nodeId, width, height, withConstraints, fileKey }) => {
|
|
1387
1424
|
try {
|
|
1388
|
-
const connector = await getDesktopConnector();
|
|
1425
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1389
1426
|
const result = await connector.resizeNode(nodeId, width, height, withConstraints);
|
|
1390
1427
|
if (!result.success) {
|
|
1391
1428
|
throw new Error(result.error || "Failed to resize node");
|
|
@@ -1423,9 +1460,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1423
1460
|
nodeId: z.string().describe("The node ID to move"),
|
|
1424
1461
|
x: z.number().describe("New X position"),
|
|
1425
1462
|
y: z.number().describe("New Y position"),
|
|
1426
|
-
|
|
1463
|
+
fileKey: fileKeyArg,
|
|
1464
|
+
}, async ({ nodeId, x, y, fileKey }) => {
|
|
1427
1465
|
try {
|
|
1428
|
-
const connector = await getDesktopConnector();
|
|
1466
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1429
1467
|
const result = await connector.moveNode(nodeId, x, y);
|
|
1430
1468
|
if (!result.success) {
|
|
1431
1469
|
throw new Error(result.error || "Failed to move node");
|
|
@@ -1480,9 +1518,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1480
1518
|
.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."),
|
|
1481
1519
|
}))
|
|
1482
1520
|
.describe("Array of fill objects"),
|
|
1483
|
-
|
|
1521
|
+
fileKey: fileKeyArg,
|
|
1522
|
+
}, async ({ nodeId, fills, fileKey }) => {
|
|
1484
1523
|
try {
|
|
1485
|
-
const connector = await getDesktopConnector();
|
|
1524
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1486
1525
|
const result = await connector.setNodeFills(nodeId, fills);
|
|
1487
1526
|
if (!result.success) {
|
|
1488
1527
|
throw new Error(result.error || "Failed to set fills");
|
|
@@ -1522,9 +1561,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1522
1561
|
nodeIds: z.array(z.string()).describe("Array of node IDs to apply the image fill to"),
|
|
1523
1562
|
imageData: z.string().describe("Base64-encoded image data (JPEG/PNG)"),
|
|
1524
1563
|
scaleMode: z.enum(["FILL", "FIT", "CROP", "TILE"]).optional().describe("How the image fills the node (default: FILL)"),
|
|
1525
|
-
|
|
1564
|
+
fileKey: fileKeyArg,
|
|
1565
|
+
}, async ({ nodeIds, imageData, scaleMode, fileKey }) => {
|
|
1526
1566
|
try {
|
|
1527
|
-
const connector = await getDesktopConnector();
|
|
1567
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1528
1568
|
const result = await connector.setImageFill(nodeIds, imageData, scaleMode || "FILL");
|
|
1529
1569
|
if (!result.success) {
|
|
1530
1570
|
throw new Error(result.error || "Failed to set image fill");
|
|
@@ -1579,9 +1619,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1579
1619
|
.number()
|
|
1580
1620
|
.optional()
|
|
1581
1621
|
.describe("Stroke thickness in pixels"),
|
|
1582
|
-
|
|
1622
|
+
fileKey: fileKeyArg,
|
|
1623
|
+
}, async ({ nodeId, strokes, strokeWeight, fileKey }) => {
|
|
1583
1624
|
try {
|
|
1584
|
-
const connector = await getDesktopConnector();
|
|
1625
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1585
1626
|
const result = await connector.setNodeStrokes(nodeId, strokes, strokeWeight);
|
|
1586
1627
|
if (!result.success) {
|
|
1587
1628
|
throw new Error(result.error || "Failed to set strokes");
|
|
@@ -1617,9 +1658,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1617
1658
|
// Tool: Clone Node
|
|
1618
1659
|
server.tool("figma_clone_node", "Duplicate a node. The clone is placed at a slight offset from the original.", {
|
|
1619
1660
|
nodeId: z.string().describe("The node ID to clone"),
|
|
1620
|
-
|
|
1661
|
+
fileKey: fileKeyArg,
|
|
1662
|
+
}, async ({ nodeId, fileKey }) => {
|
|
1621
1663
|
try {
|
|
1622
|
-
const connector = await getDesktopConnector();
|
|
1664
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1623
1665
|
const result = await connector.cloneNode(nodeId);
|
|
1624
1666
|
if (!result.success) {
|
|
1625
1667
|
throw new Error(result.error || "Failed to clone node");
|
|
@@ -1655,9 +1697,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1655
1697
|
// Tool: Delete Node
|
|
1656
1698
|
server.tool("figma_delete_node", "Delete a node from the canvas. WARNING: This is a destructive operation (can be undone with Figma's undo).", {
|
|
1657
1699
|
nodeId: z.string().describe("The node ID to delete"),
|
|
1658
|
-
|
|
1700
|
+
fileKey: fileKeyArg,
|
|
1701
|
+
}, async ({ nodeId, fileKey }) => {
|
|
1659
1702
|
try {
|
|
1660
|
-
const connector = await getDesktopConnector();
|
|
1703
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1661
1704
|
const result = await connector.deleteNode(nodeId);
|
|
1662
1705
|
if (!result.success) {
|
|
1663
1706
|
throw new Error(result.error || "Failed to delete node");
|
|
@@ -1743,9 +1786,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1743
1786
|
.string()
|
|
1744
1787
|
.optional()
|
|
1745
1788
|
.describe("Optional font style/weight to apply (e.g., 'Bold', 'Semi Bold'). No-space variants like 'SemiBold' are auto-corrected."),
|
|
1746
|
-
|
|
1789
|
+
fileKey: fileKeyArg,
|
|
1790
|
+
}, async ({ nodeId, text, fontSize, fontFamily, fontStyle, fileKey }) => {
|
|
1747
1791
|
try {
|
|
1748
|
-
const connector = await getDesktopConnector();
|
|
1792
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1749
1793
|
const result = await connector.setTextContent(nodeId, text, fontSize || fontFamily || fontStyle
|
|
1750
1794
|
? { fontSize, fontFamily, fontStyle }
|
|
1751
1795
|
: undefined);
|
|
@@ -1808,9 +1852,10 @@ After instantiating components, use figma_take_screenshot to verify the result l
|
|
|
1808
1852
|
})
|
|
1809
1853
|
.optional()
|
|
1810
1854
|
.describe("Properties for the new node"),
|
|
1811
|
-
|
|
1855
|
+
fileKey: fileKeyArg,
|
|
1856
|
+
}, async ({ parentId, nodeType, properties, fileKey }) => {
|
|
1812
1857
|
try {
|
|
1813
|
-
const connector = await getDesktopConnector();
|
|
1858
|
+
const connector = await getDesktopConnector(fileKey);
|
|
1814
1859
|
const result = await connector.createChildNode(parentId, nodeType, properties);
|
|
1815
1860
|
if (!result.success) {
|
|
1816
1861
|
throw new Error(result.error || "Failed to create node");
|
|
@@ -2326,9 +2371,10 @@ Non-destructive: rearranges the existing variants in place (grid positions on th
|
|
|
2326
2371
|
})
|
|
2327
2372
|
.optional()
|
|
2328
2373
|
.describe("Layout options"),
|
|
2329
|
-
|
|
2374
|
+
fileKey: fileKeyArg,
|
|
2375
|
+
}, async ({ componentSetId, componentSetName, options, fileKey }) => {
|
|
2330
2376
|
try {
|
|
2331
|
-
const connector = await getDesktopConnector();
|
|
2377
|
+
const connector = await getDesktopConnector(fileKey);
|
|
2332
2378
|
const code = buildArrangeComponentSetCode(componentSetId ?? null, componentSetName ?? null, options);
|
|
2333
2379
|
const result = await connector.executeCodeViaUI(code, 25000);
|
|
2334
2380
|
if (!result.success) {
|
|
@@ -2418,7 +2464,8 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
|
|
|
2418
2464
|
})
|
|
2419
2465
|
.optional()
|
|
2420
2466
|
.describe("Grid layout options, used when autoArrange is true."),
|
|
2421
|
-
|
|
2467
|
+
fileKey: fileKeyArg,
|
|
2468
|
+
}, async ({ baseComponentId, properties, componentIds, variantProperties, name, parentId, position, autoArrange, arrangeOptions, fileKey, }) => {
|
|
2422
2469
|
try {
|
|
2423
2470
|
if (!baseComponentId && (!componentIds || componentIds.length === 0)) {
|
|
2424
2471
|
throw new Error("Provide either baseComponentId + properties (generate variants from a base) or componentIds (combine existing components)");
|
|
@@ -2442,7 +2489,7 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
|
|
|
2442
2489
|
const sizeWarning = requestedVariantCount > 40
|
|
2443
2490
|
? `${requestedVariantCount} variants requested — large sets are slow to build (timeout scales automatically, ~1.2s/variant, 2min cap) and heavy base components may still time out. Consider splitting into multiple sets (e.g. one per Size).`
|
|
2444
2491
|
: undefined;
|
|
2445
|
-
const connector = await getDesktopConnector();
|
|
2492
|
+
const connector = await getDesktopConnector(fileKey);
|
|
2446
2493
|
const result = await connector.createComponentSet({
|
|
2447
2494
|
baseComponentId,
|
|
2448
2495
|
properties,
|
|
@@ -2539,9 +2586,10 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
|
|
|
2539
2586
|
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']."),
|
|
2540
2587
|
maxDepth: z.number().optional().describe("Maximum tree depth to traverse (default: 10)"),
|
|
2541
2588
|
maxFindings: z.number().optional().describe("Maximum findings before stopping (default: 100)"),
|
|
2542
|
-
|
|
2589
|
+
fileKey: fileKeyArg,
|
|
2590
|
+
}, async ({ nodeId, rules, maxDepth, maxFindings, fileKey }) => {
|
|
2543
2591
|
try {
|
|
2544
|
-
const connector = await getDesktopConnector();
|
|
2592
|
+
const connector = await getDesktopConnector(fileKey);
|
|
2545
2593
|
const result = await connector.lintDesign(nodeId, rules || ['wcag', 'design-system', 'layout'], maxDepth || 10, maxFindings || 100);
|
|
2546
2594
|
if (!result.success) {
|
|
2547
2595
|
throw new Error(result.error || "Lint failed");
|
|
@@ -2580,9 +2628,10 @@ SIZE GUIDANCE: hard cap 100 variants. The timeout auto-scales with variant count
|
|
|
2580
2628
|
"Requires Desktop Bridge plugin.", {
|
|
2581
2629
|
nodeId: z.string().optional().describe("Node ID of a COMPONENT_SET, COMPONENT, or INSTANCE to audit. Falls back to current selection if omitted."),
|
|
2582
2630
|
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."),
|
|
2583
|
-
|
|
2631
|
+
fileKey: fileKeyArg,
|
|
2632
|
+
}, async ({ nodeId, targetSize, fileKey }) => {
|
|
2584
2633
|
try {
|
|
2585
|
-
const connector = await getDesktopConnector();
|
|
2634
|
+
const connector = await getDesktopConnector(fileKey);
|
|
2586
2635
|
const result = await connector.auditComponentAccessibility(nodeId, targetSize);
|
|
2587
2636
|
if (!result.success) {
|
|
2588
2637
|
throw new Error(result.error || "Audit failed");
|