figme-mcp 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -15
- package/dist/mcp/create.d.ts +1 -5
- package/dist/mcp/create.js +28 -3
- package/dist/mcp/tools/context.d.ts +1 -1
- package/dist/mcp/tools/context.js +5 -5
- package/dist/mcp/tools/find.js +1 -1
- package/dist/mcp/tools/image.js +1 -1
- package/dist/mcp/tools/instance.js +1 -1
- package/dist/mcp/tools/node.js +1 -1
- package/dist/mcp/tools/render.js +1 -1
- package/dist/mcp/tools/style.js +1 -1
- package/dist/mcp/tools/text.js +1 -1
- package/dist/mcp/tools/tree.js +1 -1
- package/dist/model/tree.d.ts +11 -0
- package/dist/model/tree.js +29 -0
- package/dist/render/index.js +5 -5
- package/package.json +66 -65
package/README.md
CHANGED
|
@@ -51,42 +51,221 @@ These are deliberate, permanent limits — not missing features:
|
|
|
51
51
|
- Runtime dependencies: `@modelcontextprotocol/sdk` and `zod`. The parser itself uses only
|
|
52
52
|
Node built-ins.
|
|
53
53
|
|
|
54
|
-
## Install
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
`figme` is published on npm, so there is nothing to clone and nothing to build — your MCP
|
|
57
|
+
client downloads it on first start with `npx`.
|
|
58
|
+
|
|
59
|
+
You need two things:
|
|
60
|
+
|
|
61
|
+
- **Node.js >= 22.15** (see Requirements above).
|
|
62
|
+
- **A `.fig` file on disk.** This server reads a local file and never contacts figma.com, so
|
|
63
|
+
there is no account, token or sign-in — but there is also nothing to read until you save
|
|
64
|
+
one. In Figma: `File -> Save local copy...`.
|
|
65
|
+
|
|
66
|
+
### The part every client shares
|
|
67
|
+
|
|
68
|
+
Nearly every MCP client spawns a stdio server from the same two fields:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{ "command": "npx", "args": ["-y", "figme-mcp"] }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
On **Windows**, some clients cannot resolve `npx` on their own. If the server fails to start,
|
|
75
|
+
route it through `cmd`:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{ "command": "cmd", "args": ["/c", "npx", "-y", "figme-mcp"] }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Claude Code
|
|
55
82
|
|
|
56
83
|
```bash
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
claude mcp add figme -- npx -y figme-mcp # this project
|
|
85
|
+
claude mcp add -s user figme -- npx -y figme-mcp # every project
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or commit a `.mcp.json` at the repository root so collaborators get it too:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"mcpServers": {
|
|
93
|
+
"figme": {
|
|
94
|
+
"command": "npx",
|
|
95
|
+
"args": ["-y", "figme-mcp"]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
60
99
|
```
|
|
61
100
|
|
|
62
|
-
|
|
101
|
+
The Claude Code **extensions for VS Code and JetBrains** run Claude Code underneath and share
|
|
102
|
+
its configuration: register the server once with the command above and the extension sees it.
|
|
103
|
+
They do not read the editor's own MCP settings.
|
|
104
|
+
|
|
105
|
+
### Cursor
|
|
63
106
|
|
|
64
|
-
|
|
107
|
+
`~/.cursor/mcp.json` for every project, or `.cursor/mcp.json` for a single one:
|
|
65
108
|
|
|
66
109
|
```json
|
|
67
110
|
{
|
|
68
111
|
"mcpServers": {
|
|
69
112
|
"figme": {
|
|
70
|
-
"command": "
|
|
71
|
-
"args": ["
|
|
113
|
+
"command": "npx",
|
|
114
|
+
"args": ["-y", "figme-mcp"]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### VS Code — GitHub Copilot agent mode
|
|
121
|
+
|
|
122
|
+
VS Code uses its own key, `servers` rather than `mcpServers`, in `.vscode/mcp.json`:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"servers": {
|
|
127
|
+
"figme": {
|
|
128
|
+
"type": "stdio",
|
|
129
|
+
"command": "npx",
|
|
130
|
+
"args": ["-y", "figme-mcp"]
|
|
72
131
|
}
|
|
73
132
|
}
|
|
74
133
|
}
|
|
75
134
|
```
|
|
76
135
|
|
|
77
|
-
|
|
136
|
+
The same entry works in your user `settings.json` under `"mcp"`. From a terminal:
|
|
78
137
|
|
|
79
138
|
```bash
|
|
80
|
-
|
|
139
|
+
code --add-mcp '{"name":"figme","command":"npx","args":["-y","figme-mcp"]}'
|
|
81
140
|
```
|
|
82
141
|
|
|
83
|
-
|
|
142
|
+
Then pick **Agent** mode in the Chat view.
|
|
143
|
+
|
|
144
|
+
### Windsurf
|
|
145
|
+
|
|
146
|
+
`~/.codeium/windsurf/mcp_config.json`:
|
|
84
147
|
|
|
85
|
-
|
|
86
|
-
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"figme": {
|
|
152
|
+
"command": "npx",
|
|
153
|
+
"args": ["-y", "figme-mcp"]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Anything else
|
|
160
|
+
|
|
161
|
+
Spawn `npx -y figme-mcp` and talk MCP over stdio.
|
|
162
|
+
|
|
163
|
+
> Client UIs and config paths move between releases. The `command` and `args` pair above is the
|
|
164
|
+
> stable part; if a path here does not match what you see, check that client's own MCP
|
|
165
|
+
> documentation.
|
|
166
|
+
|
|
167
|
+
### Two things to know before the first call
|
|
168
|
+
|
|
169
|
+
**Use absolute paths.** A `file` argument may be relative, but it resolves against the server's
|
|
170
|
+
working directory — whichever directory your client happened to launch it from. An absolute
|
|
171
|
+
path removes the guesswork:
|
|
172
|
+
|
|
173
|
+
> Using figme, run `fig_overview` on /Users/me/Desktop/design.fig
|
|
174
|
+
|
|
175
|
+
**Watch memory.** `--max-files N` (default 4) caps how many parsed files stay cached. A 39 MB
|
|
176
|
+
`.fig` decodes to roughly 900 MB of live objects, so lower it on a small machine and raise it
|
|
177
|
+
only with memory to spare:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{ "command": "npx", "args": ["-y", "figme-mcp", "--max-files", "1"] }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## From a Figma link
|
|
184
|
+
|
|
185
|
+
The usual job: *implement this component from our design*, starting from a link someone pasted
|
|
186
|
+
into a ticket.
|
|
187
|
+
|
|
188
|
+
### 1. Save the file locally
|
|
189
|
+
|
|
190
|
+
This server reads a `.fig` on your disk and never contacts figma.com, so a link by itself is not
|
|
191
|
+
enough. Open it in Figma and use `File -> Save local copy...`. For a Community file, click
|
|
192
|
+
**Open in Figma** first — that duplicates it into your drafts, which is what makes the copy
|
|
193
|
+
possible.
|
|
194
|
+
|
|
195
|
+
### 2. Take the node id from the link
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
https://www.figma.com/design/<file key>/<slug>?node-id=3017-121&t=<share token>
|
|
199
|
+
~~~~~~~~~~ ~~~~~~~~
|
|
200
|
+
which file which node
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Figma writes node ids with a **dash** in links; the `.fig` format uses a **colon**, so
|
|
204
|
+
`node-id=3017-121` is guid `3017:121`. You do not have to convert it yourself — every guid
|
|
205
|
+
argument accepts all of these:
|
|
206
|
+
|
|
207
|
+
| You pass | Server reads |
|
|
208
|
+
|---|---|
|
|
209
|
+
| `3017:121` | `3017:121` |
|
|
210
|
+
| `3017-121` | `3017:121` |
|
|
211
|
+
| `3017%3A121` | `3017:121` |
|
|
212
|
+
| `node-id=3017-121` | `3017:121` |
|
|
213
|
+
| the whole `https://www.figma.com/design/...?node-id=3017-121` | `3017:121` |
|
|
214
|
+
|
|
215
|
+
Anything else is passed through untouched, so a typo still fails loudly rather than being
|
|
216
|
+
guessed at.
|
|
217
|
+
|
|
218
|
+
The file key is a cloud identifier with no counterpart in the saved file, so nothing can work
|
|
219
|
+
out which local `.fig` a link refers to. Always give the path yourself.
|
|
220
|
+
|
|
221
|
+
### 3. Ask for the component
|
|
222
|
+
|
|
223
|
+
> Using figme, read `/abs/path/UX Case Study Template.fig` and implement node `3017:121` as a
|
|
224
|
+
> React component.
|
|
225
|
+
|
|
226
|
+
A good agent then works roughly in this order:
|
|
227
|
+
|
|
228
|
+
1. **`fig_render`** — see it. The fastest orientation there is; check the `approximated` and
|
|
229
|
+
`unsupported` lists before trusting fine detail.
|
|
230
|
+
2. **`fig_node`** — size, corner radii, auto-layout, constraints, children.
|
|
231
|
+
3. **`fig_style`** — resolved fills, strokes, effects and typography, already shaped for code.
|
|
232
|
+
4. **`fig_text`** — the exact copy, including per-run styling.
|
|
233
|
+
5. **`fig_instance`** — if the node is an INSTANCE, what it came from and what is overridden.
|
|
234
|
+
This is what decides *reusable component* against *one-off*.
|
|
235
|
+
6. **`fig_variables`** — token names, so the code references your theme instead of raw hex.
|
|
236
|
+
7. **`fig_render` again**, and compare it against a screenshot of what you built.
|
|
237
|
+
|
|
238
|
+
That last step is why the renderer exists: you get a pixel oracle, not just a description.
|
|
239
|
+
|
|
240
|
+
### If the guid does not resolve
|
|
241
|
+
|
|
242
|
+
Node ids are intrinsic to the document, so the id in the link should be the id in the saved
|
|
243
|
+
file. If it is reported missing anyway you are most likely in the wrong file — compare
|
|
244
|
+
`fig_overview`'s document name with the link's slug — or find the layer by name with `fig_find`,
|
|
245
|
+
or browse the page with `fig_tree`.
|
|
246
|
+
|
|
247
|
+
### Do not let an agent fetch the link
|
|
248
|
+
|
|
249
|
+
A Figma URL is auth-gated and rendered by JavaScript, so fetching it yields nothing useful.
|
|
250
|
+
Worse, the slug reads like a description, which is enough for a model to invent a plausible
|
|
251
|
+
component and present it with confidence. The server says as much to every agent at connect
|
|
252
|
+
time; if yours reaches for the web regardless, tell it not to.
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
## From source
|
|
256
|
+
|
|
257
|
+
For development, or to run a revision that is not published yet:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
git clone https://github.com/ntson9p/figme-mcp.git
|
|
261
|
+
cd figme-mcp
|
|
262
|
+
npm install
|
|
263
|
+
npm run build # tsc -> dist/
|
|
264
|
+
npm test # builds, then runs the full node:test suite
|
|
265
|
+
```
|
|
87
266
|
|
|
88
|
-
|
|
89
|
-
|
|
267
|
+
Register `node /abs/path/to/figme-mcp/dist/mcp/server.js` in place of `npx -y figme-mcp`. This
|
|
268
|
+
repository ships a `.mcp.json` that already does so for Claude Code.
|
|
90
269
|
|
|
91
270
|
---
|
|
92
271
|
|
package/dist/mcp/create.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server factory, kept separate from the stdio entry point so tests (and any other transport)
|
|
3
|
-
* can build a fully-registered server without connecting to a process's stdin/stdout.
|
|
4
|
-
*/
|
|
5
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
2
|
import type { ToolContext } from './tools/context.js';
|
|
7
3
|
export declare const SERVER_NAME = "figme";
|
|
8
|
-
export declare const SERVER_VERSION
|
|
4
|
+
export declare const SERVER_VERSION: string;
|
|
9
5
|
export declare const INSTRUCTIONS: string;
|
|
10
6
|
export declare function createServer(ctx: ToolContext): McpServer;
|
|
11
7
|
export declare function createContext(maxFiles?: number): ToolContext;
|
package/dist/mcp/create.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Server factory, kept separate from the stdio entry point so tests (and any other transport)
|
|
3
3
|
* can build a fully-registered server without connecting to a process's stdin/stdout.
|
|
4
4
|
*/
|
|
5
|
+
import * as fs from 'node:fs';
|
|
5
6
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
7
|
import { FileCache } from '../cache.js';
|
|
7
8
|
import * as overview from './tools/overview.js';
|
|
@@ -17,7 +18,18 @@ import * as image from './tools/image.js';
|
|
|
17
18
|
import * as blob from './tools/blob.js';
|
|
18
19
|
import * as render from './tools/render.js';
|
|
19
20
|
export const SERVER_NAME = 'figme';
|
|
20
|
-
|
|
21
|
+
/** Read from package.json so the reported version can never drift from the published one. */
|
|
22
|
+
function packageVersion() {
|
|
23
|
+
try {
|
|
24
|
+
const raw = fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8');
|
|
25
|
+
const v = JSON.parse(raw).version;
|
|
26
|
+
return typeof v === 'string' ? v : '0.0.0';
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return '0.0.0';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const SERVER_VERSION = packageVersion();
|
|
21
33
|
export const INSTRUCTIONS = [
|
|
22
34
|
'Read-only access to local Figma .fig / .figma files. No Figma account, API or network is',
|
|
23
35
|
'used, and nothing is ever written back to the file.',
|
|
@@ -30,8 +42,21 @@ export const INSTRUCTIONS = [
|
|
|
30
42
|
'fig_render returns a picture of any node - the fastest way to understand a frame. Always',
|
|
31
43
|
'check its approximated/unsupported lists before trusting fine visual detail.',
|
|
32
44
|
'',
|
|
33
|
-
'Node guids are "sessionID:localID" strings such as "2:1339".
|
|
34
|
-
'
|
|
45
|
+
'Node guids are "sessionID:localID" strings such as "2:1339". A Figma link spells the same',
|
|
46
|
+
'id with a dash - node-id=3017-121 is guid "3017:121" - and every guid argument also accepts',
|
|
47
|
+
'that form, the percent-encoded form, or the whole link, so pass along whatever the user had.',
|
|
48
|
+
'',
|
|
49
|
+
'These tools read a .fig saved on disk and cannot open a figma.com URL. Given a link but no',
|
|
50
|
+
'file path, ask the user for the path. Never fetch the link, and never infer the design from',
|
|
51
|
+
'the words in it - the slug is a file name, not a specification.',
|
|
52
|
+
'',
|
|
53
|
+
'To implement a component: fig_render it first to see it, then fig_node for layout and size,',
|
|
54
|
+
'fig_style for resolved fills, strokes and type, fig_text for the exact copy, fig_instance if',
|
|
55
|
+
'it is an INSTANCE (it tells you whether to build something reusable), and fig_variables so',
|
|
56
|
+
'the code uses token names instead of literal values. Render again at the end and compare.',
|
|
57
|
+
'',
|
|
58
|
+
'Responses are budgeted: when one is cut you get truncated:true plus an opaque nextCursor to',
|
|
59
|
+
'pass back.',
|
|
35
60
|
].join('\n');
|
|
36
61
|
export function createServer(ctx) {
|
|
37
62
|
const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION }, { instructions: INSTRUCTIONS });
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import type { FileCache, CacheEntry } from '../../cache.js';
|
|
7
7
|
import type { FileIndex } from '../../model/index.js';
|
|
8
|
-
import type
|
|
8
|
+
import { type TreeNode } from '../../model/tree.js';
|
|
9
9
|
import { type CallToolResult } from '../respond.js';
|
|
10
10
|
export interface ToolContext {
|
|
11
11
|
readonly cache: FileCache;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* reporting. Tool handlers stay small and never touch bytes directly.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { canonicalGuid, guidNotFound } from '../../model/tree.js';
|
|
6
7
|
import { errorResult } from '../respond.js';
|
|
7
8
|
export const fileArg = z
|
|
8
9
|
.string()
|
|
@@ -15,11 +16,10 @@ export function load(ctx, file) {
|
|
|
15
16
|
return ctx.cache.get(file);
|
|
16
17
|
}
|
|
17
18
|
export function requireNode(index, guid) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
const key = canonicalGuid(guid);
|
|
20
|
+
const t = index.node(key);
|
|
21
|
+
if (!t)
|
|
22
|
+
throw new Error(guidNotFound(guid, key));
|
|
23
23
|
return t;
|
|
24
24
|
}
|
|
25
25
|
/** Resolve an optional scope argument to a subtree root, defaulting to the DOCUMENT. */
|
package/dist/mcp/tools/find.js
CHANGED
|
@@ -24,7 +24,7 @@ export function register(server, ctx) {
|
|
|
24
24
|
.optional()
|
|
25
25
|
.describe('Case-insensitive substring matched against layer names AND text content.'),
|
|
26
26
|
types: z.array(z.string()).optional().describe('Restrict to node types, e.g. ["TEXT"].'),
|
|
27
|
-
scope: z.string().optional().describe('Only search inside this guid subtree.'),
|
|
27
|
+
scope: z.string().optional().describe('Only search inside this guid subtree. A Figma node-id or link works too.'),
|
|
28
28
|
limit: z.number().int().min(1).max(300).optional().describe(`Default ${DEFAULT_LIMIT}.`),
|
|
29
29
|
cursor: cursorArg,
|
|
30
30
|
},
|
package/dist/mcp/tools/image.js
CHANGED
|
@@ -28,7 +28,7 @@ export function register(server, ctx) {
|
|
|
28
28
|
.string()
|
|
29
29
|
.optional()
|
|
30
30
|
.describe('40-hex image hash, or the literal "thumbnail" for thumbnail.png.'),
|
|
31
|
-
guid: z.string().optional().describe('Node guid; uses the image fills on that node.'),
|
|
31
|
+
guid: z.string().optional().describe('Node guid; uses the image fills on that node. A Figma node-id or link works too.'),
|
|
32
32
|
savePath: z
|
|
33
33
|
.string()
|
|
34
34
|
.optional()
|
|
@@ -17,7 +17,7 @@ export function register(server, ctx) {
|
|
|
17
17
|
description: DESCRIPTION,
|
|
18
18
|
inputSchema: {
|
|
19
19
|
file: fileArg,
|
|
20
|
-
guid: z.string().describe('Guid of an INSTANCE node, e.g. "2:1329".'),
|
|
20
|
+
guid: z.string().describe('Guid of an INSTANCE node, e.g. "2:1329". A Figma node-id or link works too.'),
|
|
21
21
|
},
|
|
22
22
|
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
23
23
|
}, handler((args) => {
|
package/dist/mcp/tools/node.js
CHANGED
|
@@ -16,7 +16,7 @@ export function register(server, ctx) {
|
|
|
16
16
|
description: DESCRIPTION,
|
|
17
17
|
inputSchema: {
|
|
18
18
|
file: fileArg,
|
|
19
|
-
guid: z.string().describe('Node guid, "sessionID:localID", e.g. "2:1339".'),
|
|
19
|
+
guid: z.string().describe('Node guid, "sessionID:localID", e.g. "2:1339". A Figma node-id or link works too.'),
|
|
20
20
|
detail: z.enum(['summary', 'full', 'raw']).optional().describe('Default "full".'),
|
|
21
21
|
includeChildren: z
|
|
22
22
|
.boolean()
|
package/dist/mcp/tools/render.js
CHANGED
|
@@ -45,7 +45,7 @@ export function register(server, ctx) {
|
|
|
45
45
|
file: fileArg,
|
|
46
46
|
guid: z
|
|
47
47
|
.string()
|
|
48
|
-
.describe('Node to render, e.g. "2:1339". A page guid renders the whole page, downscaled to fit maxSize.'),
|
|
48
|
+
.describe('Node to render, e.g. "2:1339"; a Figma node-id or link works too. A page guid renders the whole page, downscaled to fit maxSize.'),
|
|
49
49
|
format: z
|
|
50
50
|
.enum(['png', 'svg'])
|
|
51
51
|
.optional()
|
package/dist/mcp/tools/style.js
CHANGED
|
@@ -18,7 +18,7 @@ export function register(server, ctx) {
|
|
|
18
18
|
description: DESCRIPTION,
|
|
19
19
|
inputSchema: {
|
|
20
20
|
file: fileArg,
|
|
21
|
-
guid: z.string().describe('Node guid, e.g. "2:1339".'),
|
|
21
|
+
guid: z.string().describe('Node guid, e.g. "2:1339". A Figma node-id or link works too.'),
|
|
22
22
|
includeRuns: z
|
|
23
23
|
.boolean()
|
|
24
24
|
.optional()
|
package/dist/mcp/tools/text.js
CHANGED
|
@@ -18,7 +18,7 @@ export function register(server, ctx) {
|
|
|
18
18
|
description: DESCRIPTION,
|
|
19
19
|
inputSchema: {
|
|
20
20
|
file: fileArg,
|
|
21
|
-
scope: z.string().optional().describe('Only collect text inside this guid subtree.'),
|
|
21
|
+
scope: z.string().optional().describe('Only collect text inside this guid subtree. A Figma node-id or link works too.'),
|
|
22
22
|
includeRuns: z
|
|
23
23
|
.boolean()
|
|
24
24
|
.optional()
|
package/dist/mcp/tools/tree.js
CHANGED
|
@@ -22,7 +22,7 @@ export function register(server, ctx) {
|
|
|
22
22
|
root: z
|
|
23
23
|
.string()
|
|
24
24
|
.optional()
|
|
25
|
-
.describe('Guid to start from, e.g. "2:1339". Defaults to the DOCUMENT node.'),
|
|
25
|
+
.describe('Guid to start from, e.g. "2:1339"; a Figma node-id or link works too. Defaults to the DOCUMENT node.'),
|
|
26
26
|
depth: z
|
|
27
27
|
.number()
|
|
28
28
|
.int()
|
package/dist/model/tree.d.ts
CHANGED
|
@@ -13,6 +13,17 @@ export interface Guid {
|
|
|
13
13
|
}
|
|
14
14
|
/** Canonical guid string used at every API boundary: `"2:1339"`. */
|
|
15
15
|
export declare function guidKey(g: Guid | undefined): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Canonical guid for a reference supplied by a user or an agent.
|
|
18
|
+
*
|
|
19
|
+
* Figma writes node ids with a dash in links (`node-id=3017-121`), older links percent-encode
|
|
20
|
+
* the colon, and people paste the whole link. A guid is always two integers, so `3017-121` can
|
|
21
|
+
* never be a valid one itself and rewriting it is unambiguous. Anything unrecognised is handed
|
|
22
|
+
* back untouched, so a genuine typo still fails loudly instead of being guessed at.
|
|
23
|
+
*/
|
|
24
|
+
export declare function canonicalGuid(input: string): string;
|
|
25
|
+
/** One wording for a missing guid, shared by the MCP tools and the renderer. */
|
|
26
|
+
export declare function guidNotFound(input: string, key: string): string;
|
|
16
27
|
export declare function readGuid(obj: KiwiObject | undefined, field: string): string | undefined;
|
|
17
28
|
export interface TreeNode {
|
|
18
29
|
readonly key: string;
|
package/dist/model/tree.js
CHANGED
|
@@ -4,6 +4,35 @@ export function guidKey(g) {
|
|
|
4
4
|
return undefined;
|
|
5
5
|
return `${g.sessionID}:${g.localID}`;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Canonical guid for a reference supplied by a user or an agent.
|
|
9
|
+
*
|
|
10
|
+
* Figma writes node ids with a dash in links (`node-id=3017-121`), older links percent-encode
|
|
11
|
+
* the colon, and people paste the whole link. A guid is always two integers, so `3017-121` can
|
|
12
|
+
* never be a valid one itself and rewriting it is unambiguous. Anything unrecognised is handed
|
|
13
|
+
* back untouched, so a genuine typo still fails loudly instead of being guessed at.
|
|
14
|
+
*/
|
|
15
|
+
export function canonicalGuid(input) {
|
|
16
|
+
const raw = input.trim();
|
|
17
|
+
const inLink = /(?:^|[?&#])node-id=([^&#\s]+)/i.exec(raw);
|
|
18
|
+
const pair = /^(\d+)[:-](\d+)$/.exec(decode(inLink ? inLink[1] : raw).trim());
|
|
19
|
+
return pair ? `${pair[1]}:${pair[2]}` : raw;
|
|
20
|
+
}
|
|
21
|
+
function decode(s) {
|
|
22
|
+
try {
|
|
23
|
+
return decodeURIComponent(s);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return s;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** One wording for a missing guid, shared by the MCP tools and the renderer. */
|
|
30
|
+
export function guidNotFound(input, key) {
|
|
31
|
+
const read = key === input.trim() ? '' : ` (read as ${JSON.stringify(key)})`;
|
|
32
|
+
return (`no node with guid ${JSON.stringify(input)}${read} in this file. ` +
|
|
33
|
+
'Guids look like "2:1339"; a Figma link spells the same id "node-id=3017-121", and ' +
|
|
34
|
+
'that form, or the whole link, is accepted. Use fig_find or fig_tree to find guids.');
|
|
35
|
+
}
|
|
7
36
|
export function readGuid(obj, field) {
|
|
8
37
|
return guidKey(obj?.[field]);
|
|
9
38
|
}
|
package/dist/render/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canonicalGuid, guidNotFound } from '../model/tree.js';
|
|
1
2
|
import { str } from '../model/access.js';
|
|
2
3
|
import { pageBackground } from './color.js';
|
|
3
4
|
import { DEFAULT_MAX_NODES, HARD_MAX_NODES, MAX_SVG_BYTES, exportSubtree, } from './export.js';
|
|
@@ -7,11 +8,10 @@ export const DEFAULT_SCALE = 2;
|
|
|
7
8
|
export const DEFAULT_MAX_SIZE = 1568;
|
|
8
9
|
export const HARD_MAX_SIZE = 4096;
|
|
9
10
|
function resolveRoot(entry, guid) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
11
|
+
const key = canonicalGuid(guid);
|
|
12
|
+
const t = entry.index.node(key);
|
|
13
|
+
if (!t)
|
|
14
|
+
throw new Error(guidNotFound(guid, key));
|
|
15
15
|
if (nodeType(t.node) === 'DOCUMENT') {
|
|
16
16
|
throw new Error('cannot render the DOCUMENT node — render a page or a node inside one');
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "figme-mcp",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"test
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"visual
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"@types/
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "figme-mcp",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"mcpName": "io.github.ntson9p/figme-mcp",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "MCP server that reads local Figma .fig files, fully offline",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mcp",
|
|
9
|
+
"model-context-protocol",
|
|
10
|
+
"figma",
|
|
11
|
+
"fig",
|
|
12
|
+
"design",
|
|
13
|
+
"ai-agent",
|
|
14
|
+
"offline"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/ntson9p/figme-mcp#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ntson9p/figme-mcp/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ntson9p/figme-mcp.git"
|
|
23
|
+
},
|
|
24
|
+
"author": "ntson9p",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.15"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"figme-mcp": "dist/mcp/server.js"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"!dist/**/*.map",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"prepublishOnly": "npm run build",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
42
|
+
"test": "npm run build && node --test",
|
|
43
|
+
"test:fast": "node --test",
|
|
44
|
+
"start": "node dist/mcp/server.js",
|
|
45
|
+
"smoke": "node scripts/smoke.mjs",
|
|
46
|
+
"crosscheck": "node --max-old-space-size=8192 scripts/crosscheck.mjs",
|
|
47
|
+
"render": "node scripts/render.mjs",
|
|
48
|
+
"visual": "node scripts/visual.mjs",
|
|
49
|
+
"visual:update": "node scripts/visual.mjs --update"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
53
|
+
"zod": "^4.5.4"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^26.4.0",
|
|
57
|
+
"@types/pngjs": "^6.0.5",
|
|
58
|
+
"kiwi-schema": "^0.5.0",
|
|
59
|
+
"pixelmatch": "^7.2.0",
|
|
60
|
+
"pngjs": "^7.0.0",
|
|
61
|
+
"typescript": "^7.0.2"
|
|
62
|
+
},
|
|
63
|
+
"optionalDependencies": {
|
|
64
|
+
"@resvg/resvg-wasm": "2.6.2"
|
|
65
|
+
}
|
|
66
|
+
}
|