@muloka/figma-console-mcp 0.6.1 → 0.6.2
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 +3 -0
- package/dist/core/figma-tools.d.ts.map +1 -1
- package/dist/core/figma-tools.js +49 -4
- package/dist/core/figma-tools.js.map +1 -1
- package/dist/core/identity.d.ts +30 -6
- package/dist/core/identity.d.ts.map +1 -1
- package/dist/core/identity.js +60 -10
- package/dist/core/identity.js.map +1 -1
- package/dist/core/tool-annotations.d.ts +53 -0
- package/dist/core/tool-annotations.d.ts.map +1 -0
- package/dist/core/tool-annotations.js +214 -0
- package/dist/core/tool-annotations.js.map +1 -0
- package/dist/local.d.ts +1 -0
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +18 -8
- package/dist/local.js.map +1 -1
- package/package.json +1 -1
package/dist/core/identity.js
CHANGED
|
@@ -59,21 +59,70 @@ function tagToolResponse(result) {
|
|
|
59
59
|
});
|
|
60
60
|
return { ...r, content: newContent };
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Largest tool result this server will hand to the client, in bytes of content.
|
|
64
|
+
*
|
|
65
|
+
* MCP clients read one JSON-RPC message at a time and defend themselves against
|
|
66
|
+
* runaway output: Claude Code disconnects the server outright once a single
|
|
67
|
+
* message passes 16 MB ("wrote >16MB to stdout without a JSON-RPC message
|
|
68
|
+
* boundary … Disconnecting"). The user sees only "Connection closed" and loses
|
|
69
|
+
* every tool for the rest of the session. 8 MB leaves room for JSON-RPC string
|
|
70
|
+
* escaping, which inflates nested JSON noticeably.
|
|
71
|
+
*/
|
|
72
|
+
export const MAX_TOOL_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
73
|
+
/**
|
|
74
|
+
* Replace an oversized tool result with an actionable error. Returning it would
|
|
75
|
+
* not deliver the data anyway — it would kill the connection.
|
|
76
|
+
*/
|
|
77
|
+
export function capToolResponse(result, maxBytes = MAX_TOOL_RESPONSE_BYTES) {
|
|
78
|
+
if (!result ||
|
|
79
|
+
typeof result !== "object" ||
|
|
80
|
+
!Array.isArray(result.content)) {
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
let bytes = 0;
|
|
84
|
+
for (const item of result
|
|
85
|
+
.content) {
|
|
86
|
+
if (typeof item?.text === "string")
|
|
87
|
+
bytes += Buffer.byteLength(item.text, "utf8");
|
|
88
|
+
if (typeof item?.data === "string")
|
|
89
|
+
bytes += item.data.length; // base64 image/audio
|
|
90
|
+
}
|
|
91
|
+
if (bytes <= maxBytes)
|
|
92
|
+
return result;
|
|
93
|
+
const mb = (n) => (n / (1024 * 1024)).toFixed(1);
|
|
94
|
+
return {
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
text: JSON.stringify({
|
|
99
|
+
_mcp: MCP_NAME,
|
|
100
|
+
error: `${ERROR_PREFIX} This call produced a ${mb(bytes)} MB result, above the ${mb(maxBytes)} MB this server will return. It was withheld because MCP clients disconnect on oversized messages (Claude Code closes the connection above 16 MB), which would have ended this session instead of delivering the data.`,
|
|
101
|
+
resultBytes: bytes,
|
|
102
|
+
note: "Only the RESPONSE was withheld. If this call made changes in Figma, those changes still happened.",
|
|
103
|
+
hint: "Ask for less in one call: return counts or a summary instead of full node data, target fewer nodes, use a smaller depth, or page through the data across several calls.",
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
isError: true,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
62
110
|
const IDENTIFIED = Symbol.for("figma-console-mcp.identifiedToolHandler");
|
|
63
111
|
/**
|
|
64
|
-
* Wrap one tool callback so its result is tagged with `_mcp` and
|
|
65
|
-
* throws carries the `[figma-console-mcp]` prefix. The SDK turns a thrown error
|
|
112
|
+
* Wrap one tool callback so its result is tagged with `_mcp` (and, when
|
|
113
|
+
* `options.maxResponseBytes` is set, capped) and any Error it throws carries the `[figma-console-mcp]` prefix. The SDK turns a thrown error
|
|
66
114
|
* into an `isError` result whose text is the message, so the prefix reaches the
|
|
67
115
|
* client. Idempotent: wrapping twice is a no-op, and tools that already tag
|
|
68
116
|
* themselves (withIdentity, adaptiveResponse) are not double-tagged.
|
|
69
117
|
*/
|
|
70
|
-
export function identifyToolHandler(handler) {
|
|
118
|
+
export function identifyToolHandler(handler, options = {}) {
|
|
71
119
|
if (handler[IDENTIFIED])
|
|
72
120
|
return handler;
|
|
73
121
|
const wrapped = async (...args) => {
|
|
74
122
|
try {
|
|
75
123
|
const result = await handler(...args);
|
|
76
|
-
|
|
124
|
+
const tagged = tagToolResponse(result);
|
|
125
|
+
return options.maxResponseBytes === undefined ? tagged : capToolResponse(tagged, options.maxResponseBytes);
|
|
77
126
|
}
|
|
78
127
|
catch (err) {
|
|
79
128
|
if (err instanceof Error && !err.message.startsWith(ERROR_PREFIX)) {
|
|
@@ -108,10 +157,11 @@ export function identifyToolHandler(handler) {
|
|
|
108
157
|
* Adds attribution coverage to every response path uniformly — see
|
|
109
158
|
* project_lauren_cross_mcp_confusion for why this matters.
|
|
110
159
|
*
|
|
111
|
-
* Ported from upstream southleft/figma-console-mcp 2.3.3
|
|
112
|
-
*
|
|
160
|
+
* Ported from upstream southleft/figma-console-mcp 2.3.3. The response-size
|
|
161
|
+
* cap (upstream 2.5.1) is opt-in via `options.maxResponseBytes` and used for
|
|
162
|
+
* stdio only; the onToolCall hook is not ported.
|
|
113
163
|
*/
|
|
114
|
-
export function withToolIdentity(Base) {
|
|
164
|
+
export function withToolIdentity(Base, options = {}) {
|
|
115
165
|
class IdentifiedServer extends Base {
|
|
116
166
|
}
|
|
117
167
|
const baseProto = Base.prototype;
|
|
@@ -123,20 +173,20 @@ export function withToolIdentity(Base) {
|
|
|
123
173
|
configurable: true,
|
|
124
174
|
writable: true,
|
|
125
175
|
value: function (...args) {
|
|
126
|
-
return original.apply(this, prepareToolRegistration(args));
|
|
176
|
+
return original.apply(this, prepareToolRegistration(args, options));
|
|
127
177
|
},
|
|
128
178
|
});
|
|
129
179
|
}
|
|
130
180
|
return IdentifiedServer;
|
|
131
181
|
}
|
|
132
182
|
/** Apply identity to the callback and quiet record keys in the schemas of one registration call. */
|
|
133
|
-
function prepareToolRegistration(args) {
|
|
183
|
+
function prepareToolRegistration(args, options) {
|
|
134
184
|
if (args.length === 0 || typeof args[args.length - 1] !== "function")
|
|
135
185
|
return args;
|
|
136
186
|
const seen = new WeakSet();
|
|
137
187
|
for (const arg of args.slice(1, -1))
|
|
138
188
|
quietStringRecordKeys(arg, seen);
|
|
139
|
-
return [...args.slice(0, -1), identifyToolHandler(args[args.length - 1])];
|
|
189
|
+
return [...args.slice(0, -1), identifyToolHandler(args[args.length - 1], options)];
|
|
140
190
|
}
|
|
141
191
|
function isZodSchema(value) {
|
|
142
192
|
return (value !== null &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAG,mBAAmB,CAAC;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,QAAQ,GAAG,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC9C,OAAO,IAAI,KAAK,CAAC,GAAG,YAAY,IAAI,OAAO,EAAE,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAO;IAEP,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,MAAe;IACvC,IACC,CAAC,MAAM;QACP,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC;QACtB,CAAC,KAAK,CAAC,OAAO,CAAE,MAAiC,CAAC,OAAO,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,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3B,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,KAA6B,CAAC;YAC7C,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE;gBAC5B,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACvC,aAAa,EAAE,SAAS;aACxB,CAAC,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;YAAE,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC3E,OAAO;IACR,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool annotations (behavior hints) for every tool the server registers.
|
|
3
|
+
*
|
|
4
|
+
* Hosts use these to decide how to treat a call:
|
|
5
|
+
* - readOnlyHint — safe to auto-approve, and Claude Code retries it after a
|
|
6
|
+
* dropped connection.
|
|
7
|
+
* - idempotentHint — calling twice with the same args has no extra effect, so
|
|
8
|
+
* a retry is safe (Claude Code honors this too).
|
|
9
|
+
* - destructiveHint — may delete or overwrite user data; hosts may prompt.
|
|
10
|
+
*
|
|
11
|
+
* One table, applied after registration (`applyToolAnnotations`), so tool files
|
|
12
|
+
* don't each carry their own hints and a new tool can't ship unclassified —
|
|
13
|
+
* `tests/tool-annotations.test.ts` fails when a registered tool is missing here.
|
|
14
|
+
*
|
|
15
|
+
* Convention (the spec's destructiveHint technically covers any overwrite, but
|
|
16
|
+
* hosts treat it as "dangerous"): deletes, replaces, resets and arbitrary code
|
|
17
|
+
* are destructive; "set X to Y" updates are idempotent, non-destructive writes;
|
|
18
|
+
* creates are non-idempotent, non-destructive writes.
|
|
19
|
+
*/
|
|
20
|
+
export type ToolKind =
|
|
21
|
+
/** Reads only — no change to Figma, the filesystem or server state. */
|
|
22
|
+
"read"
|
|
23
|
+
/** Changes session/UI state only (navigation, focus, reconnect). */
|
|
24
|
+
| "session"
|
|
25
|
+
/** Additive write; calling twice creates two things. */
|
|
26
|
+
| "create"
|
|
27
|
+
/** Sets something to a given value; repeating is a no-op. */
|
|
28
|
+
| "update"
|
|
29
|
+
/** Writes local files (may replace an existing file). */
|
|
30
|
+
| "file"
|
|
31
|
+
/** Deletes, replaces, resets, or runs arbitrary code. */
|
|
32
|
+
| "destructive";
|
|
33
|
+
export interface ToolHints {
|
|
34
|
+
readOnlyHint: boolean;
|
|
35
|
+
destructiveHint: boolean;
|
|
36
|
+
idempotentHint: boolean;
|
|
37
|
+
openWorldHint: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Every registered tool, by kind. Grouped by surface for review; order inside
|
|
41
|
+
* a group doesn't matter.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TOOL_KINDS: Record<string, ToolKind>;
|
|
44
|
+
export declare function hintsFor(name: string): ToolHints | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Apply hints to every registered tool. Existing per-tool annotations win
|
|
47
|
+
* (a tool file can still override). Call after all registration and before
|
|
48
|
+
* connect, so no list_changed notification fires.
|
|
49
|
+
*
|
|
50
|
+
* Returns the names of registered tools with no entry in TOOL_KINDS.
|
|
51
|
+
*/
|
|
52
|
+
export declare function applyToolAnnotations(server: object): string[];
|
|
53
|
+
//# sourceMappingURL=tool-annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-annotations.d.ts","sourceRoot":"","sources":["../../src/core/tool-annotations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,QAAQ;AACnB,uEAAuE;AACrE,MAAM;AACR,oEAAoE;GAClE,SAAS;AACX,wDAAwD;GACtD,QAAQ;AACV,6DAA6D;GAC3D,QAAQ;AACV,yDAAyD;GACvD,MAAM;AACR,yDAAyD;GACvD,aAAa,CAAC;AAEjB,MAAM,WAAW,SAAS;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;CACvB;AAWD;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CA6I/C,CAAC;AA2BF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAI5D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAmB7D"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool annotations (behavior hints) for every tool the server registers.
|
|
3
|
+
*
|
|
4
|
+
* Hosts use these to decide how to treat a call:
|
|
5
|
+
* - readOnlyHint — safe to auto-approve, and Claude Code retries it after a
|
|
6
|
+
* dropped connection.
|
|
7
|
+
* - idempotentHint — calling twice with the same args has no extra effect, so
|
|
8
|
+
* a retry is safe (Claude Code honors this too).
|
|
9
|
+
* - destructiveHint — may delete or overwrite user data; hosts may prompt.
|
|
10
|
+
*
|
|
11
|
+
* One table, applied after registration (`applyToolAnnotations`), so tool files
|
|
12
|
+
* don't each carry their own hints and a new tool can't ship unclassified —
|
|
13
|
+
* `tests/tool-annotations.test.ts` fails when a registered tool is missing here.
|
|
14
|
+
*
|
|
15
|
+
* Convention (the spec's destructiveHint technically covers any overwrite, but
|
|
16
|
+
* hosts treat it as "dangerous"): deletes, replaces, resets and arbitrary code
|
|
17
|
+
* are destructive; "set X to Y" updates are idempotent, non-destructive writes;
|
|
18
|
+
* creates are non-idempotent, non-destructive writes.
|
|
19
|
+
*/
|
|
20
|
+
const KIND_HINTS = {
|
|
21
|
+
read: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
|
|
22
|
+
session: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
23
|
+
create: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
24
|
+
update: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
25
|
+
file: { readOnlyHint: false, destructiveHint: true, idempotentHint: true },
|
|
26
|
+
destructive: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Every registered tool, by kind. Grouped by surface for review; order inside
|
|
30
|
+
* a group doesn't matter.
|
|
31
|
+
*/
|
|
32
|
+
export const TOOL_KINDS = {
|
|
33
|
+
// ── Connection, console, status ──────────────────────────────────────────
|
|
34
|
+
figma_get_status: "read",
|
|
35
|
+
figma_diagnose: "read",
|
|
36
|
+
figma_list_open_files: "read",
|
|
37
|
+
figma_get_console_logs: "read",
|
|
38
|
+
figma_watch_console: "read",
|
|
39
|
+
figma_take_screenshot: "read",
|
|
40
|
+
figma_capture_screenshot: "read",
|
|
41
|
+
figma_get_selection: "read",
|
|
42
|
+
// `clear: true` empties the change buffer, so a retry could lose events.
|
|
43
|
+
figma_get_design_changes: "session",
|
|
44
|
+
figma_clear_console: "session",
|
|
45
|
+
figma_navigate: "session",
|
|
46
|
+
figma_reconnect: "session",
|
|
47
|
+
figma_reload_plugin: "session",
|
|
48
|
+
// ── Reads: files, components, tokens, styles ─────────────────────────────
|
|
49
|
+
figma_get_file_data: "read",
|
|
50
|
+
figma_get_file_for_plugin: "read",
|
|
51
|
+
figma_get_variables: "read",
|
|
52
|
+
figma_get_token_values: "read",
|
|
53
|
+
figma_get_styles: "read",
|
|
54
|
+
figma_get_text_styles: "read",
|
|
55
|
+
figma_get_component: "read",
|
|
56
|
+
figma_get_component_details: "read",
|
|
57
|
+
figma_get_component_image: "read",
|
|
58
|
+
figma_get_component_for_development: "read",
|
|
59
|
+
figma_get_component_for_development_deep: "read",
|
|
60
|
+
figma_search_components: "read",
|
|
61
|
+
figma_get_library_components: "read",
|
|
62
|
+
figma_get_library_component_by_key: "read",
|
|
63
|
+
figma_get_library_variables: "read",
|
|
64
|
+
figma_get_design_system_summary: "read",
|
|
65
|
+
figma_get_design_system_kit: "read",
|
|
66
|
+
figma_get_annotations: "read",
|
|
67
|
+
figma_get_annotation_categories: "read",
|
|
68
|
+
figma_get_slots: "read",
|
|
69
|
+
figma_analyze_component_set: "read",
|
|
70
|
+
// ── Audits & reports (compute only) ──────────────────────────────────────
|
|
71
|
+
figma_lint_design: "read",
|
|
72
|
+
figma_audit_component_accessibility: "read",
|
|
73
|
+
figma_scan_code_accessibility: "read",
|
|
74
|
+
figma_check_design_parity: "read",
|
|
75
|
+
figma_audit_design_system: "read",
|
|
76
|
+
ds_dashboard_refresh: "read",
|
|
77
|
+
figma_browse_tokens: "read",
|
|
78
|
+
token_browser_refresh: "read",
|
|
79
|
+
// ── Version history & comments ───────────────────────────────────────────
|
|
80
|
+
figma_get_file_versions: "read",
|
|
81
|
+
figma_get_file_at_version: "read",
|
|
82
|
+
figma_diff_versions: "read",
|
|
83
|
+
figma_get_changes_since_version: "read",
|
|
84
|
+
figma_generate_changelog: "read",
|
|
85
|
+
figma_blame_node: "read",
|
|
86
|
+
figma_get_comments: "read",
|
|
87
|
+
figma_post_comment: "create",
|
|
88
|
+
figma_delete_comment: "destructive",
|
|
89
|
+
// ── Arbitrary code ───────────────────────────────────────────────────────
|
|
90
|
+
figma_execute: "destructive",
|
|
91
|
+
// ── Variables & tokens ───────────────────────────────────────────────────
|
|
92
|
+
figma_create_variable: "create",
|
|
93
|
+
figma_create_variable_collection: "create",
|
|
94
|
+
figma_batch_create_variables: "create",
|
|
95
|
+
figma_setup_design_tokens: "create",
|
|
96
|
+
figma_add_mode: "create",
|
|
97
|
+
figma_update_variable: "update",
|
|
98
|
+
figma_batch_update_variables: "update",
|
|
99
|
+
figma_rename_variable: "update",
|
|
100
|
+
figma_rename_mode: "update",
|
|
101
|
+
figma_import_library_variable: "update",
|
|
102
|
+
figma_delete_variable: "destructive",
|
|
103
|
+
figma_delete_variable_collection: "destructive",
|
|
104
|
+
// strategy "replace" deletes variables missing from the payload.
|
|
105
|
+
figma_import_tokens: "destructive",
|
|
106
|
+
figma_export_tokens: "file",
|
|
107
|
+
// ── Components & properties ──────────────────────────────────────────────
|
|
108
|
+
figma_instantiate_component: "create",
|
|
109
|
+
figma_create_component_set: "create",
|
|
110
|
+
figma_add_component_property: "create",
|
|
111
|
+
figma_edit_component_property: "update",
|
|
112
|
+
figma_set_instance_properties: "update",
|
|
113
|
+
figma_set_description: "update",
|
|
114
|
+
figma_arrange_component_set: "update",
|
|
115
|
+
figma_delete_component_property: "destructive",
|
|
116
|
+
// Upstream writes markdown to outputPath; this fork only suggests the path. Kept as upstream classified it.
|
|
117
|
+
figma_generate_component_doc: "file",
|
|
118
|
+
// ── Nodes & layout ───────────────────────────────────────────────────────
|
|
119
|
+
figma_create_child: "create",
|
|
120
|
+
figma_clone_node: "create",
|
|
121
|
+
figma_resize_node: "update",
|
|
122
|
+
figma_move_node: "update",
|
|
123
|
+
figma_rename_node: "update",
|
|
124
|
+
figma_set_text: "update",
|
|
125
|
+
figma_set_fills: "update",
|
|
126
|
+
figma_set_strokes: "update",
|
|
127
|
+
figma_set_image_fill: "update",
|
|
128
|
+
figma_set_annotations: "update",
|
|
129
|
+
figma_delete_node: "destructive",
|
|
130
|
+
// ── Slots ────────────────────────────────────────────────────────────────
|
|
131
|
+
figma_create_slot: "create",
|
|
132
|
+
figma_add_slot_property: "create",
|
|
133
|
+
figma_append_to_slot: "create",
|
|
134
|
+
figma_reset_slot: "destructive",
|
|
135
|
+
// ── FigJam ───────────────────────────────────────────────────────────────
|
|
136
|
+
figjam_get_board_contents: "read",
|
|
137
|
+
figjam_get_connections: "read",
|
|
138
|
+
figjam_create_sticky: "create",
|
|
139
|
+
figjam_create_stickies: "create",
|
|
140
|
+
figjam_create_connector: "create",
|
|
141
|
+
figjam_create_shape_with_text: "create",
|
|
142
|
+
figjam_create_section: "create",
|
|
143
|
+
figjam_create_table: "create",
|
|
144
|
+
figjam_create_code_block: "create",
|
|
145
|
+
figjam_auto_arrange: "update",
|
|
146
|
+
// ── Slides ───────────────────────────────────────────────────────────────
|
|
147
|
+
figma_list_slides: "read",
|
|
148
|
+
figma_get_slide_content: "read",
|
|
149
|
+
figma_get_slide_grid: "read",
|
|
150
|
+
figma_get_slide_transition: "read",
|
|
151
|
+
figma_get_focused_slide: "read",
|
|
152
|
+
figma_create_slide: "create",
|
|
153
|
+
figma_duplicate_slide: "create",
|
|
154
|
+
figma_add_text_to_slide: "create",
|
|
155
|
+
figma_add_shape_to_slide: "create",
|
|
156
|
+
figma_set_slide_transition: "update",
|
|
157
|
+
figma_set_slide_background: "update",
|
|
158
|
+
figma_skip_slide: "update",
|
|
159
|
+
figma_reorder_slides: "update",
|
|
160
|
+
figma_focus_slide: "session",
|
|
161
|
+
figma_set_slides_view_mode: "session",
|
|
162
|
+
figma_delete_slide: "destructive",
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Open-world tools: each reaches an external system (the Figma REST API).
|
|
166
|
+
* Every other tool only touches the local machine and the user's open Figma file.
|
|
167
|
+
*/
|
|
168
|
+
const OPEN_WORLD_TOOLS = new Set([
|
|
169
|
+
"figma_get_file_data",
|
|
170
|
+
"figma_get_component",
|
|
171
|
+
"figma_get_styles",
|
|
172
|
+
"figma_get_component_image",
|
|
173
|
+
"figma_get_component_for_development",
|
|
174
|
+
"figma_get_file_for_plugin",
|
|
175
|
+
"figma_get_comments",
|
|
176
|
+
"figma_post_comment",
|
|
177
|
+
"figma_delete_comment",
|
|
178
|
+
"figma_get_file_versions",
|
|
179
|
+
"figma_get_file_at_version",
|
|
180
|
+
"figma_diff_versions",
|
|
181
|
+
"figma_get_changes_since_version",
|
|
182
|
+
"figma_generate_changelog",
|
|
183
|
+
"figma_blame_node",
|
|
184
|
+
"figma_get_library_components",
|
|
185
|
+
"figma_get_library_component_by_key",
|
|
186
|
+
"figma_get_design_system_kit",
|
|
187
|
+
]);
|
|
188
|
+
export function hintsFor(name) {
|
|
189
|
+
const kind = TOOL_KINDS[name];
|
|
190
|
+
if (!kind)
|
|
191
|
+
return undefined;
|
|
192
|
+
return { ...KIND_HINTS[kind], openWorldHint: OPEN_WORLD_TOOLS.has(name) };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Apply hints to every registered tool. Existing per-tool annotations win
|
|
196
|
+
* (a tool file can still override). Call after all registration and before
|
|
197
|
+
* connect, so no list_changed notification fires.
|
|
198
|
+
*
|
|
199
|
+
* Returns the names of registered tools with no entry in TOOL_KINDS.
|
|
200
|
+
*/
|
|
201
|
+
export function applyToolAnnotations(server) {
|
|
202
|
+
const registered = server._registeredTools;
|
|
203
|
+
const missing = [];
|
|
204
|
+
for (const [name, tool] of Object.entries(registered ?? {})) {
|
|
205
|
+
const hints = hintsFor(name);
|
|
206
|
+
if (!hints) {
|
|
207
|
+
missing.push(name);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
tool.annotations = { ...hints, ...(tool.annotations ?? {}) };
|
|
211
|
+
}
|
|
212
|
+
return missing;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=tool-annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-annotations.js","sourceRoot":"","sources":["../../src/core/tool-annotations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAuBH,MAAM,UAAU,GAAuD;IACtE,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE;IA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AO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,SAAS;QACV,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/dist/local.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ declare class LocalFigmaConsoleMCP {
|
|
|
91
91
|
/**
|
|
92
92
|
* A fresh, fully registered server: one per MCP_HTTP_PORT request (either
|
|
93
93
|
* era), or for a stdio connection that serveStdio re-pins to another era.
|
|
94
|
+
* Only stdio servers cap oversized results.
|
|
94
95
|
*/
|
|
95
96
|
private createRequestServer;
|
|
96
97
|
/**
|
package/dist/local.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../src/local.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../src/local.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAwOH;;;GAGG;AACH,cAAM,oBAAoB;IACzB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,QAAQ,CAAqC;IACrD,OAAO,CAAC,cAAc,CAA+C;IACrE,uGAAuG;IACvG,OAAO,CAAC,YAAY,CAAuB;IAC3C,6DAA6D;IAC7D,OAAO,CAAC,eAAe,CAA2B;IAClD,2EAA2E;IAC3E,OAAO,CAAC,YAAY,CAA6B;IACjD,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB,CAA+C;IACvE,+EAA+E;IAC/E,OAAO,CAAC,UAAU,CAAgD;IAClE,+DAA+D;IAC/D,OAAO,CAAC,WAAW,CAAuB;IAC1C,qEAAqE;IACrE,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC,MAAM,CAAe;IAI7B,OAAO,CAAC,cAAc,CAMR;IAEd;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;;IAqBhC;;OAEG;YACW,WAAW;IAoBzB;;;;OAIG;YACW,mBAAmB;IAyBjC;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAmBvB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAkD5B;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAezB;;OAEG;YACW,iBAAiB;IAiB/B,wDAAwD;IACxD,OAAO,CAAC,gBAAgB,CAAuB;IAE/C;;;OAGG;IACH,OAAO,CAAC,aAAa;IAkBrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAgjGrB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;;;OAKG;YACW,eAAe;IA4G7B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA+Q5B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAuC/B;AAkGD,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/local.js
CHANGED
|
@@ -37,7 +37,7 @@ import { registerAccessibilityTools } from "./core/accessibility-tools.js";
|
|
|
37
37
|
import { registerDiagnoseTool } from "./core/diagnose-tool.js";
|
|
38
38
|
import { registerWriteTools } from "./core/write-tools.js";
|
|
39
39
|
import { registerTokensTools } from "./core/tokens-tools.js";
|
|
40
|
-
import { withToolIdentity } from "./core/identity.js";
|
|
40
|
+
import { MAX_TOOL_RESPONSE_BYTES, withToolIdentity } from "./core/identity.js";
|
|
41
41
|
import { PACKAGE_ROOT } from "./core/resolve-package-root.js";
|
|
42
42
|
import { FigmaWebSocketServer, getBundledPluginVersion, getBundledForkPluginRevision, heldPinStatusWarning, } from "./core/websocket-server.js";
|
|
43
43
|
import { WebSocketConnector } from "./core/websocket-connector.js";
|
|
@@ -48,11 +48,16 @@ import { registerDesignSystemDashboardApp } from "./apps/design-system-dashboard
|
|
|
48
48
|
import { registerFigJamTools } from "./core/figjam-tools.js";
|
|
49
49
|
import { registerSlidesTools } from "./core/slides-tools.js";
|
|
50
50
|
import { registerSlotTools } from "./core/slot-tools.js";
|
|
51
|
+
import { applyToolAnnotations } from "./core/tool-annotations.js";
|
|
51
52
|
const logger = createChildLogger({ component: "local-server" });
|
|
52
53
|
// Every McpServer this process builds (stdio and per-request HTTP) stamps tool
|
|
53
54
|
// responses and thrown errors with our MCP identity, so LLMs can attribute
|
|
54
55
|
// output unambiguously when several Figma-related MCPs are connected.
|
|
55
56
|
const IdentifiedMcpServer = withToolIdentity(McpServer);
|
|
57
|
+
// stdio additionally withholds a result above MAX_TOOL_RESPONSE_BYTES: an MCP
|
|
58
|
+
// client drops the connection when one message gets too large. HTTP is not
|
|
59
|
+
// capped (IdentifiedMcpServer).
|
|
60
|
+
const StdioMcpServer = withToolIdentity(McpServer, { maxResponseBytes: MAX_TOOL_RESPONSE_BYTES });
|
|
56
61
|
/** Largest JSON-RPC body the MCP_HTTP_PORT endpoint reads (both protocol eras). */
|
|
57
62
|
const MAX_HTTP_BODY_BYTES = 4 * 1024 * 1024;
|
|
58
63
|
/** Read and parse a JSON request body, refusing oversized or malformed ones. */
|
|
@@ -247,7 +252,7 @@ class LocalFigmaConsoleMCP {
|
|
|
247
252
|
this.variablesCache = new Map();
|
|
248
253
|
/** Stable plugin directory path (set during startup) */
|
|
249
254
|
this.stablePluginPath = null;
|
|
250
|
-
this.server = new
|
|
255
|
+
this.server = new StdioMcpServer({
|
|
251
256
|
name: "Figma Console MCP (Local)",
|
|
252
257
|
version: SERVER_VERSION,
|
|
253
258
|
}, {
|
|
@@ -3005,14 +3010,19 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3005
3010
|
() => this.getCurrentFileUrl());
|
|
3006
3011
|
logger.info("MCP Apps registered (ENABLE_MCP_APPS=true)");
|
|
3007
3012
|
}
|
|
3013
|
+
const unclassified = applyToolAnnotations(server);
|
|
3014
|
+
if (unclassified.length > 0)
|
|
3015
|
+
logger.warn({ unclassified }, "Tools registered without annotation hints");
|
|
3008
3016
|
logger.info("All MCP tools registered successfully (including write operations)");
|
|
3009
3017
|
}
|
|
3010
3018
|
/**
|
|
3011
3019
|
* A fresh, fully registered server: one per MCP_HTTP_PORT request (either
|
|
3012
3020
|
* era), or for a stdio connection that serveStdio re-pins to another era.
|
|
3021
|
+
* Only stdio servers cap oversized results.
|
|
3013
3022
|
*/
|
|
3014
|
-
createRequestServer() {
|
|
3015
|
-
const
|
|
3023
|
+
createRequestServer(transport) {
|
|
3024
|
+
const ServerClass = transport === "stdio" ? StdioMcpServer : IdentifiedMcpServer;
|
|
3025
|
+
const server = new ServerClass({ name: "Figma Console MCP (Local)", version: SERVER_VERSION }, { instructions: MCP_SERVER_INSTRUCTIONS });
|
|
3016
3026
|
this.registerTools(server);
|
|
3017
3027
|
return server;
|
|
3018
3028
|
}
|
|
@@ -3033,14 +3043,14 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3033
3043
|
}
|
|
3034
3044
|
// Both protocol eras are served at /mcp, each by a fresh server per request
|
|
3035
3045
|
// (IdentifiedMcpServer: every handler gets `_mcp` tagging and
|
|
3036
|
-
// `[figma-console-mcp]` error prefixing):
|
|
3046
|
+
// `[figma-console-mcp]` error prefixing, and results are never capped):
|
|
3037
3047
|
// - 2026-07-28 requests (per-request `_meta`, no initialize) go to the SDK's
|
|
3038
3048
|
// createMcpHandler. `legacy: "reject"` keeps its own stateless fallback
|
|
3039
3049
|
// from ever answering 2025-era traffic, which is routed below instead.
|
|
3040
3050
|
// - 2025-era requests keep this endpoint's stateless Streamable HTTP
|
|
3041
3051
|
// contract: no session id, one transport per request.
|
|
3042
3052
|
const reportModernError = (error) => logger.warn({ err: error.message }, "HTTP MCP (2026-07-28) request error");
|
|
3043
|
-
this.modernHttpHandler = createMcpHandler(() => this.createRequestServer(), {
|
|
3053
|
+
this.modernHttpHandler = createMcpHandler(() => this.createRequestServer("http"), {
|
|
3044
3054
|
legacy: "reject",
|
|
3045
3055
|
onerror: reportModernError,
|
|
3046
3056
|
maxRequestBodySize: MAX_HTTP_BODY_BYTES,
|
|
@@ -3084,7 +3094,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3084
3094
|
const transport = new NodeStreamableHTTPServerTransport({
|
|
3085
3095
|
sessionIdGenerator: undefined,
|
|
3086
3096
|
});
|
|
3087
|
-
const reqServer = this.createRequestServer();
|
|
3097
|
+
const reqServer = this.createRequestServer("http");
|
|
3088
3098
|
await reqServer.connect(transport);
|
|
3089
3099
|
res.once("close", () => {
|
|
3090
3100
|
reqServer.close().catch(() => { });
|
|
@@ -3327,7 +3337,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3327
3337
|
let stdioServerHandedOut = false;
|
|
3328
3338
|
serveStdio(() => {
|
|
3329
3339
|
if (stdioServerHandedOut)
|
|
3330
|
-
return this.createRequestServer();
|
|
3340
|
+
return this.createRequestServer("stdio");
|
|
3331
3341
|
stdioServerHandedOut = true;
|
|
3332
3342
|
return this.server;
|
|
3333
3343
|
}, { onerror: (error) => logger.error({ error }, "stdio transport error") });
|