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