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