@muloka/figma-console-mcp 0.6.4 → 0.6.6
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 +18 -6
- package/dist/apps/design-system-dashboard/mcp-app.html +20 -20
- package/dist/apps/design-system-dashboard/scoring/accessibility.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/accessibility.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/accessibility.js.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.js.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js.map +1 -1
- package/dist/apps/design-system-dashboard/server.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/server.js +2 -1
- package/dist/apps/design-system-dashboard/server.js.map +1 -1
- package/dist/core/annotation-tools.d.ts.map +1 -1
- package/dist/core/annotation-tools.js +7 -6
- package/dist/core/annotation-tools.js.map +1 -1
- package/dist/core/cache-invalidation.d.ts +18 -2
- package/dist/core/cache-invalidation.d.ts.map +1 -1
- package/dist/core/cache-invalidation.js +51 -0
- package/dist/core/cache-invalidation.js.map +1 -1
- package/dist/core/call-context.d.ts +13 -0
- package/dist/core/call-context.d.ts.map +1 -0
- package/dist/core/call-context.js +20 -0
- package/dist/core/call-context.js.map +1 -0
- package/dist/core/comment-tools.d.ts.map +1 -1
- package/dist/core/comment-tools.js +4 -3
- package/dist/core/comment-tools.js.map +1 -1
- package/dist/core/deep-component-tools.d.ts.map +1 -1
- package/dist/core/deep-component-tools.js +5 -4
- package/dist/core/deep-component-tools.js.map +1 -1
- package/dist/core/design-code-tools.d.ts.map +1 -1
- package/dist/core/design-code-tools.js +4 -3
- package/dist/core/design-code-tools.js.map +1 -1
- package/dist/core/design-system-manifest.d.ts +7 -3
- package/dist/core/design-system-manifest.d.ts.map +1 -1
- package/dist/core/design-system-manifest.js +14 -5
- package/dist/core/design-system-manifest.js.map +1 -1
- package/dist/core/design-system-tools.d.ts.map +1 -1
- package/dist/core/design-system-tools.js +2 -1
- package/dist/core/design-system-tools.js.map +1 -1
- package/dist/core/diagnose-tool.d.ts +2 -0
- package/dist/core/diagnose-tool.d.ts.map +1 -1
- package/dist/core/diagnose-tool.js +6 -5
- package/dist/core/diagnose-tool.js.map +1 -1
- package/dist/core/figjam-tools.d.ts.map +1 -1
- package/dist/core/figjam-tools.js +5 -4
- package/dist/core/figjam-tools.js.map +1 -1
- package/dist/core/figma-api.d.ts +12 -0
- package/dist/core/figma-api.d.ts.map +1 -1
- package/dist/core/figma-api.js +17 -1
- package/dist/core/figma-api.js.map +1 -1
- package/dist/core/figma-tools.d.ts.map +1 -1
- package/dist/core/figma-tools.js +42 -53
- package/dist/core/figma-tools.js.map +1 -1
- package/dist/core/library-tools.d.ts.map +1 -1
- package/dist/core/library-tools.js +7 -6
- package/dist/core/library-tools.js.map +1 -1
- package/dist/core/logger.d.ts +11 -0
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +13 -1
- package/dist/core/logger.js.map +1 -1
- package/dist/core/plugin-import-dir.d.ts +9 -0
- package/dist/core/plugin-import-dir.d.ts.map +1 -0
- package/dist/core/plugin-import-dir.js +47 -0
- package/dist/core/plugin-import-dir.js.map +1 -0
- package/dist/core/plugin-name.d.ts +26 -0
- package/dist/core/plugin-name.d.ts.map +1 -0
- package/dist/core/plugin-name.js +35 -0
- package/dist/core/plugin-name.js.map +1 -0
- package/dist/core/port-discovery.d.ts +2 -2
- package/dist/core/port-discovery.d.ts.map +1 -1
- package/dist/core/port-discovery.js +8 -6
- package/dist/core/port-discovery.js.map +1 -1
- package/dist/core/slides-tools.d.ts.map +1 -1
- package/dist/core/slides-tools.js +2 -1
- package/dist/core/slides-tools.js.map +1 -1
- package/dist/core/slot-tools.d.ts.map +1 -1
- package/dist/core/slot-tools.js +3 -2
- package/dist/core/slot-tools.js.map +1 -1
- package/dist/core/tokens/schemas.d.ts +1 -1
- package/dist/core/tokens-tools.d.ts.map +1 -1
- package/dist/core/tokens-tools.js +2 -1
- package/dist/core/tokens-tools.js.map +1 -1
- package/dist/core/variable-resolver.d.ts.map +1 -1
- package/dist/core/variable-resolver.js +3 -2
- package/dist/core/variable-resolver.js.map +1 -1
- package/dist/core/version-tools.d.ts.map +1 -1
- package/dist/core/version-tools.js +9 -8
- package/dist/core/version-tools.js.map +1 -1
- package/dist/core/websocket-connector.d.ts.map +1 -1
- package/dist/core/websocket-connector.js +3 -2
- package/dist/core/websocket-connector.js.map +1 -1
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +8 -5
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/core/write-tools.d.ts.map +1 -1
- package/dist/core/write-tools.js +283 -232
- package/dist/core/write-tools.js.map +1 -1
- package/dist/local.d.ts +1 -1
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +114 -190
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/README.md +15 -63
- package/figma-desktop-bridge/code.js +31 -29
- package/figma-desktop-bridge/manifest.json +5 -9
- package/figma-desktop-bridge/ui.html +768 -924
- package/package.json +1 -1
package/dist/local.js
CHANGED
|
@@ -20,13 +20,12 @@ import { guardLocalHttpRequest } from "./core/http-request-guard.js";
|
|
|
20
20
|
import { z } from "zod";
|
|
21
21
|
import { fileURLToPath } from "url";
|
|
22
22
|
import { dirname, resolve, join } from "path";
|
|
23
|
-
import { realpathSync, existsSync, readFileSync
|
|
24
|
-
import { homedir } from "os";
|
|
23
|
+
import { realpathSync, existsSync, readFileSync } from "fs";
|
|
25
24
|
import { getConfig } from "./core/config.js";
|
|
26
25
|
import { createChildLogger } from "./core/logger.js";
|
|
27
|
-
import { attachCacheInvalidation } from "./core/cache-invalidation.js";
|
|
26
|
+
import { attachCacheInvalidation, attachWriteInvalidation } from "./core/cache-invalidation.js";
|
|
28
27
|
import { onStdinClosed } from "./core/stdin-lifecycle.js";
|
|
29
|
-
import { FigmaAPI, extractFileKey, extractFigmaUrlInfo,
|
|
28
|
+
import { FigmaAPI, extractFileKey, extractFigmaUrlInfo, restVariablesCacheData, } from "./core/figma-api.js";
|
|
30
29
|
import { registerFigmaAPITools } from "./core/figma-tools.js";
|
|
31
30
|
import { registerDesignCodeTools } from "./core/design-code-tools.js";
|
|
32
31
|
import { registerCommentTools } from "./core/comment-tools.js";
|
|
@@ -37,13 +36,15 @@ import { registerDesignSystemTools } from "./core/design-system-tools.js";
|
|
|
37
36
|
import { registerLibraryTools, registerLibraryVariableTools } from "./core/library-tools.js";
|
|
38
37
|
import { registerAccessibilityTools } from "./core/accessibility-tools.js";
|
|
39
38
|
import { registerDiagnoseTool } from "./core/diagnose-tool.js";
|
|
39
|
+
import { PLUGIN_MENU_PATH, PLUGIN_NAME, PLUGIN_NAME_WITH_OLD, OLD_PLUGIN_NAME, pluginUpdateHint } from "./core/plugin-name.js";
|
|
40
|
+
import { pluginImportDir, setupStablePluginDir } from "./core/plugin-import-dir.js";
|
|
40
41
|
import { registerWriteTools } from "./core/write-tools.js";
|
|
41
42
|
import { registerTokensTools } from "./core/tokens-tools.js";
|
|
42
43
|
import { MAX_TOOL_RESPONSE_BYTES, withToolIdentity } from "./core/identity.js";
|
|
43
44
|
import { PACKAGE_ROOT } from "./core/resolve-package-root.js";
|
|
44
45
|
import { FigmaWebSocketServer, getBundledPluginVersion, getBundledForkPluginRevision, heldPinStatusWarning, } from "./core/websocket-server.js";
|
|
45
46
|
import { WebSocketConnector } from "./core/websocket-connector.js";
|
|
46
|
-
import { DesignSystemManifestCache, invalidateAfterVariableWrite } from "./core/design-system-manifest.js";
|
|
47
|
+
import { DesignSystemManifestCache, getCategories, getTokenSummary, invalidateAfterVariableWrite, searchComponents, } from "./core/design-system-manifest.js";
|
|
47
48
|
import { ensureManifest } from "./core/manifest-build.js";
|
|
48
49
|
import { VariablesCache, cacheGeneration, setCacheIfCurrent } from "./core/variables-cache.js";
|
|
49
50
|
import { DEFAULT_WS_PORT, getPortRange, advertisePort, unadvertisePort, registerPortCleanup, startPeriodicReaper, discoverActiveInstances, cleanupStalePortFiles, cleanupOrphanedProcesses, evictOldestInstance, refreshPortAdvertisement, setAdvertisedMcpHttpPort, HEARTBEAT_INTERVAL_MS, } from "./core/port-discovery.js";
|
|
@@ -53,6 +54,7 @@ import { registerFigJamTools } from "./core/figjam-tools.js";
|
|
|
53
54
|
import { registerSlidesTools } from "./core/slides-tools.js";
|
|
54
55
|
import { registerSlotTools } from "./core/slot-tools.js";
|
|
55
56
|
import { applyToolAnnotations } from "./core/tool-annotations.js";
|
|
57
|
+
import { currentCallFiles } from "./core/call-context.js";
|
|
56
58
|
const logger = createChildLogger({ component: "local-server" });
|
|
57
59
|
// Every McpServer this process builds (stdio and per-request HTTP) stamps tool
|
|
58
60
|
// responses and thrown errors with our MCP identity, so LLMs can attribute
|
|
@@ -95,41 +97,6 @@ function readJsonBody(req) {
|
|
|
95
97
|
req.on("error", reject);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Copy plugin files to a stable directory (~/.figma-console-mcp/plugin/).
|
|
100
|
-
* This gives users a permanent, predictable path to import from instead of
|
|
101
|
-
* the volatile npx cache path that changes between updates.
|
|
102
|
-
*
|
|
103
|
-
* Returns the stable manifest path, or null if copy failed.
|
|
104
|
-
*/
|
|
105
|
-
function setupStablePluginDir(sourcePluginDir) {
|
|
106
|
-
try {
|
|
107
|
-
const stableDir = join(homedir(), ".figma-console-mcp", "plugin");
|
|
108
|
-
mkdirSync(stableDir, { recursive: true });
|
|
109
|
-
const filesToCopy = ["manifest.json", "code.js", "ui.html"];
|
|
110
|
-
for (const file of filesToCopy) {
|
|
111
|
-
const src = join(sourcePluginDir, file);
|
|
112
|
-
const dest = join(stableDir, file);
|
|
113
|
-
if (existsSync(src)) {
|
|
114
|
-
copyFileSync(src, dest);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Write a version marker so we can detect stale copies
|
|
118
|
-
try {
|
|
119
|
-
const pkg = JSON.parse(readFileSync(join(sourcePluginDir, "..", "package.json"), "utf-8"));
|
|
120
|
-
writeFileSync(join(stableDir, ".version"), pkg.version, "utf-8");
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// Non-critical — version marker is for diagnostics only
|
|
124
|
-
}
|
|
125
|
-
logger.info({ stableDir }, "Plugin files copied to stable directory");
|
|
126
|
-
return join(stableDir, "manifest.json");
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
logger.warn({ error }, "Could not set up stable plugin directory (non-critical)");
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
100
|
/**
|
|
134
101
|
* Server version reported in the MCP handshake's serverInfo.version — read from
|
|
135
102
|
* package.json (not hardcoded) so a client's status check can detect
|
|
@@ -154,6 +121,7 @@ Then tell the user to run \`npx @muloka/figma-console-mcp --print-path\` and imp
|
|
|
154
121
|
manifest.json in Figma: Plugins → Development → Import plugin from manifest. On macOS that
|
|
155
122
|
folder is hidden, so the file dialog will not show it: tell them to press Cmd+Shift+G in the
|
|
156
123
|
dialog and paste the path. (On Windows the folder is visible; navigate to it normally.)
|
|
124
|
+
Then run it: Plugins → Development → ${PLUGIN_NAME}.
|
|
157
125
|
|
|
158
126
|
### VISUAL VALIDATION WORKFLOW (Required)
|
|
159
127
|
After creating or modifying ANY visual design elements:
|
|
@@ -224,13 +192,19 @@ class LocalFigmaConsoleMCP {
|
|
|
224
192
|
* to ensure the next figma_get_variables call returns fresh data.
|
|
225
193
|
*/
|
|
226
194
|
invalidateVariablesCache() {
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
195
|
+
// Inside a tool call, clears only the files that call reached; outside
|
|
196
|
+
// one, every file. Also drops the design-system manifests: a variable
|
|
197
|
+
// write that touches no node fires no documentChange, so nothing else
|
|
198
|
+
// would, and the summary / token-value tools would serve pre-write
|
|
199
|
+
// tokens (#14).
|
|
200
|
+
const files = currentCallFiles();
|
|
201
|
+
invalidateAfterVariableWrite(this.variablesCache, this.manifestCache, files);
|
|
202
|
+
if (!files) {
|
|
203
|
+
logger.info('Caches invalidated after write operation: all files');
|
|
204
|
+
}
|
|
205
|
+
else if (files.size > 0) {
|
|
206
|
+
logger.info({ files: [...files] }, 'Caches invalidated after write operation');
|
|
207
|
+
}
|
|
234
208
|
}
|
|
235
209
|
constructor() {
|
|
236
210
|
this.figmaAPI = null;
|
|
@@ -258,9 +232,9 @@ class LocalFigmaConsoleMCP {
|
|
|
258
232
|
// Every invalidation also ends in-flight read sharing, for the files it
|
|
259
233
|
// invalidates: a read that starts after the invalidation must not join a
|
|
260
234
|
// read that started before it, or it would store pre-change data under the
|
|
261
|
-
// new generation.
|
|
262
|
-
//
|
|
263
|
-
//
|
|
235
|
+
// new generation. Writes, document changes and disconnects invalidate per
|
|
236
|
+
// file (a variable write outside a tool call, every file), through
|
|
237
|
+
// src/core/cache-invalidation.ts, and end only those files' shared reads.
|
|
264
238
|
this.variablesCache = new VariablesCache((fileKey) => this.wsServer?.forgetSharedReads(fileKey));
|
|
265
239
|
// Design-system manifests, one per file; its invalidations end shared reads the same way.
|
|
266
240
|
this.manifestCache = new DesignSystemManifestCache((fileKey) => this.wsServer?.forgetSharedReads(fileKey));
|
|
@@ -309,7 +283,7 @@ class LocalFigmaConsoleMCP {
|
|
|
309
283
|
}
|
|
310
284
|
const wsPort = this.wsActualPort || this.wsPreferredPort || DEFAULT_WS_PORT;
|
|
311
285
|
const err = new Error("Cannot connect to Figma Desktop.\n\n" +
|
|
312
|
-
"Open the
|
|
286
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma (" + PLUGIN_MENU_PATH + ").\n" +
|
|
313
287
|
`The plugin will connect automatically to ws://localhost:${wsPort}.\n` +
|
|
314
288
|
"No special launch flags needed.");
|
|
315
289
|
// Attach structured connection error for programmatic agent recovery
|
|
@@ -368,7 +342,7 @@ class LocalFigmaConsoleMCP {
|
|
|
368
342
|
type: 'BRIDGE_COMMAND_TIMEOUT',
|
|
369
343
|
canRetry: true,
|
|
370
344
|
recoverySteps: [
|
|
371
|
-
"The plugin may be unresponsive — close and reopen the
|
|
345
|
+
"The plugin may be unresponsive — close and reopen the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma",
|
|
372
346
|
"If the issue persists, restart Figma Desktop",
|
|
373
347
|
"Call figma_get_status with probe:true to verify the connection",
|
|
374
348
|
],
|
|
@@ -380,7 +354,7 @@ class LocalFigmaConsoleMCP {
|
|
|
380
354
|
canRetry: !isNoClient,
|
|
381
355
|
recoverySteps: [
|
|
382
356
|
"Open Figma Desktop with your target file",
|
|
383
|
-
"Go to
|
|
357
|
+
"Go to " + PLUGIN_MENU_PATH,
|
|
384
358
|
"Click 'Run' to open the plugin",
|
|
385
359
|
"Wait 3 seconds, then call figma_get_status with probe:true to verify",
|
|
386
360
|
],
|
|
@@ -417,13 +391,13 @@ class LocalFigmaConsoleMCP {
|
|
|
417
391
|
// Not available yet — log guidance but don't throw
|
|
418
392
|
// The user may open the plugin later
|
|
419
393
|
logger.warn(`WebSocket transport not available yet.\n\n` +
|
|
420
|
-
`Open the
|
|
394
|
+
`Open the ${PLUGIN_NAME} plugin in Figma (${PLUGIN_MENU_PATH}).\n` +
|
|
421
395
|
`No special launch flags needed — the plugin connects automatically.`);
|
|
422
396
|
}
|
|
423
397
|
}
|
|
424
398
|
/**
|
|
425
399
|
* Resolve the path to the Desktop Bridge plugin manifest.
|
|
426
|
-
* Prefers the
|
|
400
|
+
* Prefers the plugin's own import directory (see pluginImportDir) over the npx cache path.
|
|
427
401
|
*/
|
|
428
402
|
getPluginPath() {
|
|
429
403
|
// Prefer stable path — consistent across npx updates
|
|
@@ -478,7 +452,7 @@ class LocalFigmaConsoleMCP {
|
|
|
478
452
|
source = "websocket";
|
|
479
453
|
}
|
|
480
454
|
else {
|
|
481
|
-
throw new Error("No console monitoring available. Open the
|
|
455
|
+
throw new Error("No console monitoring available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma for console capture.");
|
|
482
456
|
}
|
|
483
457
|
const responseData = {
|
|
484
458
|
logs,
|
|
@@ -490,12 +464,12 @@ class LocalFigmaConsoleMCP {
|
|
|
490
464
|
};
|
|
491
465
|
if (source === "websocket") {
|
|
492
466
|
responseData.ai_instruction =
|
|
493
|
-
"Console logs captured via WebSocket Bridge (plugin sandbox only). These logs include output from the
|
|
467
|
+
"Console logs captured via WebSocket Bridge (plugin sandbox only). These logs include output from the " + PLUGIN_NAME + " plugin's code.js context.";
|
|
494
468
|
}
|
|
495
469
|
if (logs.length === 0) {
|
|
496
470
|
if (source === "websocket") {
|
|
497
471
|
responseData.ai_instruction =
|
|
498
|
-
"No console logs captured yet via WebSocket. The
|
|
472
|
+
"No console logs captured yet via WebSocket. The " + PLUGIN_NAME + " plugin is connected and monitoring. Plugin console output (console.log/warn/error from code.js) will appear here automatically. Try running a design operation that triggers plugin logging.";
|
|
499
473
|
}
|
|
500
474
|
else {
|
|
501
475
|
const isMonitoring = status.isMonitoring;
|
|
@@ -529,8 +503,8 @@ class LocalFigmaConsoleMCP {
|
|
|
529
503
|
error: errorMessage,
|
|
530
504
|
message: "Failed to retrieve console logs.",
|
|
531
505
|
troubleshooting: [
|
|
532
|
-
"Open the
|
|
533
|
-
"Ensure the
|
|
506
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma for WebSocket-based console capture",
|
|
507
|
+
"Ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is open and connected in Figma",
|
|
534
508
|
],
|
|
535
509
|
}),
|
|
536
510
|
},
|
|
@@ -544,12 +518,12 @@ class LocalFigmaConsoleMCP {
|
|
|
544
518
|
// token, and reflects the current runtime state (no cloud-sync lag).
|
|
545
519
|
// Note: For screenshots of specific components, use figma_get_component_image instead
|
|
546
520
|
server.registerTool("figma_take_screenshot", {
|
|
547
|
-
description: `Export an image of the current Figma page or specific node. Uses the
|
|
521
|
+
description: `Export an image of the current Figma page or specific node. Uses the ${PLUGIN_NAME} plugin (exportAsync) when connected — works on any plan, no REST token needed, reflects current runtime state. Falls back to the Figma REST API when the bridge is unavailable or for PDF format. Use for visual validation after design changes — check alignment, spacing, proportions. Pass nodeId to target specific elements. For components, prefer figma_get_component_image.`,
|
|
548
522
|
inputSchema: z.object({
|
|
549
523
|
nodeId: z
|
|
550
524
|
.string()
|
|
551
525
|
.optional()
|
|
552
|
-
.describe("Optional node ID to screenshot (e.g., '123:456'). If omitted, uses the node-id from the
|
|
526
|
+
.describe("Optional node ID to screenshot (e.g., '123:456'). If omitted, uses the node-id from the " + PLUGIN_NAME + " plugin's reported file URL when present. To screenshot what the user is currently looking at on the canvas, prefer figma_capture_screenshot (uses the plugin's exportAsync and reflects the current state)."),
|
|
553
527
|
scale: z
|
|
554
528
|
.number()
|
|
555
529
|
.min(0.01)
|
|
@@ -616,7 +590,7 @@ class LocalFigmaConsoleMCP {
|
|
|
616
590
|
format,
|
|
617
591
|
byteLength: result.image.byteLength,
|
|
618
592
|
source: "desktop_bridge",
|
|
619
|
-
note: "Screenshot captured via the
|
|
593
|
+
note: "Screenshot captured via the " + PLUGIN_NAME + " plugin (current runtime state, no REST token required). The image is included below for visual analysis.",
|
|
620
594
|
}),
|
|
621
595
|
},
|
|
622
596
|
{
|
|
@@ -636,7 +610,7 @@ class LocalFigmaConsoleMCP {
|
|
|
636
610
|
// Get current URL to extract file key and node ID if not provided
|
|
637
611
|
const currentUrl = this.getCurrentFileUrl();
|
|
638
612
|
if (!currentUrl) {
|
|
639
|
-
throw new Error("No Figma file open. Either provide a nodeId parameter, call figma_navigate, or ensure the
|
|
613
|
+
throw new Error("No Figma file open. Either provide a nodeId parameter, call figma_navigate, or ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is connected.");
|
|
640
614
|
}
|
|
641
615
|
const fileKey = extractFileKey(currentUrl);
|
|
642
616
|
if (!fileKey) {
|
|
@@ -721,8 +695,8 @@ class LocalFigmaConsoleMCP {
|
|
|
721
695
|
error: errorMessage,
|
|
722
696
|
message: "Failed to capture screenshot via Figma API",
|
|
723
697
|
hint: isAuthError
|
|
724
|
-
? "Your FIGMA_ACCESS_TOKEN is expired or invalid. Generate a new personal access token at figma.com → Settings → Security → Personal access tokens, then update FIGMA_ACCESS_TOKEN in your MCP config. Alternatively, open the
|
|
725
|
-
: "Make sure you've called figma_navigate to open a file, or provide a valid nodeId parameter. Tip: with the
|
|
698
|
+
? "Your FIGMA_ACCESS_TOKEN is expired or invalid. Generate a new personal access token at figma.com → Settings → Security → Personal access tokens, then update FIGMA_ACCESS_TOKEN in your MCP config. Alternatively, open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma Desktop — screenshots work through the bridge without any REST token."
|
|
699
|
+
: "Make sure you've called figma_navigate to open a file, or provide a valid nodeId parameter. Tip: with the " + PLUGIN_NAME_WITH_OLD + " plugin open, screenshots don't need a REST token at all.",
|
|
726
700
|
}),
|
|
727
701
|
},
|
|
728
702
|
],
|
|
@@ -747,7 +721,7 @@ class LocalFigmaConsoleMCP {
|
|
|
747
721
|
}),
|
|
748
722
|
}, async ({ duration, level }) => {
|
|
749
723
|
if (!this.wsServer?.isClientConnected()) {
|
|
750
|
-
throw new Error("No console monitoring available. Open the
|
|
724
|
+
throw new Error("No console monitoring available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma for console capture.");
|
|
751
725
|
}
|
|
752
726
|
const startTime = Date.now();
|
|
753
727
|
const startLogCount = this.wsServer.getConsoleStatus().logCount;
|
|
@@ -809,7 +783,7 @@ class LocalFigmaConsoleMCP {
|
|
|
809
783
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
810
784
|
}
|
|
811
785
|
else {
|
|
812
|
-
throw new Error("No connection available. Open the
|
|
786
|
+
throw new Error("No connection available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.");
|
|
813
787
|
}
|
|
814
788
|
const responseData = {
|
|
815
789
|
status: "reloaded",
|
|
@@ -844,8 +818,8 @@ class LocalFigmaConsoleMCP {
|
|
|
844
818
|
error: String(error),
|
|
845
819
|
message: "Failed to reload plugin",
|
|
846
820
|
troubleshooting: [
|
|
847
|
-
"Open the
|
|
848
|
-
"Ensure the
|
|
821
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma for WebSocket-based reload",
|
|
822
|
+
"Ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is open and connected in Figma",
|
|
849
823
|
],
|
|
850
824
|
}),
|
|
851
825
|
},
|
|
@@ -868,7 +842,7 @@ class LocalFigmaConsoleMCP {
|
|
|
868
842
|
transport = "websocket";
|
|
869
843
|
}
|
|
870
844
|
else {
|
|
871
|
-
throw new Error("No console monitoring available. Open the
|
|
845
|
+
throw new Error("No console monitoring available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.");
|
|
872
846
|
}
|
|
873
847
|
const responseData = {
|
|
874
848
|
status: "cleared",
|
|
@@ -911,7 +885,7 @@ class LocalFigmaConsoleMCP {
|
|
|
911
885
|
});
|
|
912
886
|
// Tool 6: Navigate / switch active file
|
|
913
887
|
server.registerTool("figma_navigate", {
|
|
914
|
-
description: "Switch the active Figma file target among files that already have the
|
|
888
|
+
description: "Switch the active Figma file target among files that already have the " + PLUGIN_NAME + " plugin running. Local mode is WebSocket-only — this tool does NOT launch a browser or open files. If the requested URL is already the active file, it confirms the connection. If another connected plugin matches the URL, it switches the active target so subsequent tool calls hit that file. If no connected plugin matches, returns an error with guidance for the user to open the " + PLUGIN_NAME + " plugin in the target file. Use figma_list_open_files to see all connected files.\n\nPass lock: true to PIN this file as the target — new connections, reconnects, and the user's own selection/page changes in other files will no longer move the target. Use this for parallel work (agent edits one file while the user works in another) so commands can't silently route to the wrong file. If the pinned file disconnects, the pin is held (untargeted commands are refused rather than routed elsewhere) until it reconnects, you switch files, or you unlock with lock: false.",
|
|
915
889
|
inputSchema: z.object({
|
|
916
890
|
url: z
|
|
917
891
|
.string()
|
|
@@ -1028,19 +1002,19 @@ class LocalFigmaConsoleMCP {
|
|
|
1028
1002
|
isActive: f.isActive,
|
|
1029
1003
|
})),
|
|
1030
1004
|
requestedFileKey,
|
|
1031
|
-
message: "The requested file is not connected via WebSocket. Open the
|
|
1032
|
-
ai_instruction: "The requested file is not in the connected files list. The user needs to open the
|
|
1005
|
+
message: "The requested file is not connected via WebSocket. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in the target file — it will auto-connect. Use figma_list_open_files to see all connected files.",
|
|
1006
|
+
ai_instruction: "The requested file is not in the connected files list. The user needs to open the " + PLUGIN_NAME_WITH_OLD + " plugin in the target Figma file. Once opened, it will auto-connect and appear in figma_list_open_files. Then use figma_navigate to switch to it.",
|
|
1033
1007
|
}),
|
|
1034
1008
|
},
|
|
1035
1009
|
],
|
|
1036
1010
|
};
|
|
1037
1011
|
}
|
|
1038
|
-
throw new Error("No connection available. Open the
|
|
1012
|
+
throw new Error("No connection available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.");
|
|
1039
1013
|
}
|
|
1040
1014
|
// If we got here, the WebSocket plugin bridge wasn't connected.
|
|
1041
1015
|
// Tell the user how to recover — local mode has no Puppeteer
|
|
1042
1016
|
// fallback after the Phase 3 CDP cleanup.
|
|
1043
|
-
throw new Error("
|
|
1017
|
+
throw new Error("The " + PLUGIN_NAME + " plugin is not connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma Desktop and try again.");
|
|
1044
1018
|
}
|
|
1045
1019
|
catch (error) {
|
|
1046
1020
|
logger.error({ error }, "Failed to navigate to Figma");
|
|
@@ -1053,8 +1027,8 @@ class LocalFigmaConsoleMCP {
|
|
|
1053
1027
|
error: errorMessage,
|
|
1054
1028
|
message: "Failed to navigate to Figma URL",
|
|
1055
1029
|
troubleshooting: [
|
|
1056
|
-
"In WebSocket mode: navigate manually in Figma and ensure
|
|
1057
|
-
"Ensure the
|
|
1030
|
+
"In WebSocket mode: navigate manually in Figma and ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is open",
|
|
1031
|
+
"Ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is open in the target file",
|
|
1058
1032
|
],
|
|
1059
1033
|
}),
|
|
1060
1034
|
},
|
|
@@ -1065,7 +1039,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1065
1039
|
});
|
|
1066
1040
|
// Tool 7: Get Status (with setup validation)
|
|
1067
1041
|
server.registerTool("figma_get_status", {
|
|
1068
|
-
description: "Check connection status to Figma Desktop. Reports transport status and connection health via the
|
|
1042
|
+
description: "Check connection status to Figma Desktop. Reports transport status and connection health via the " + PLUGIN_NAME + " plugin (WebSocket transport). Use probe:true for an active roundtrip verification that the plugin is actually responding.",
|
|
1069
1043
|
inputSchema: z.object({
|
|
1070
1044
|
probe: z.boolean().optional().describe("When true, sends a live roundtrip command to the plugin to verify the connection is actually responsive (not just TCP-open). Returns probeResult with success/latency. Recommended for health checks."),
|
|
1071
1045
|
}),
|
|
@@ -1144,7 +1118,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1144
1118
|
]
|
|
1145
1119
|
: [
|
|
1146
1120
|
"Open Figma Desktop with your target file",
|
|
1147
|
-
"Go to
|
|
1121
|
+
"Go to " + PLUGIN_MENU_PATH,
|
|
1148
1122
|
"Click 'Run' to open the plugin",
|
|
1149
1123
|
"Wait 3 seconds for the WebSocket connection to establish",
|
|
1150
1124
|
"Call figma_get_status with probe:true to verify the connection",
|
|
@@ -1156,7 +1130,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1156
1130
|
text: JSON.stringify({
|
|
1157
1131
|
mode: "local",
|
|
1158
1132
|
currentFileName: currentFileName ||
|
|
1159
|
-
"(unable to retrieve -
|
|
1133
|
+
"(unable to retrieve - the " + PLUGIN_NAME_WITH_OLD + " plugin may need to be opened)",
|
|
1160
1134
|
currentFileKey: currentFileKey || undefined,
|
|
1161
1135
|
editorType: this.wsServer?.getEditorType() || "figma",
|
|
1162
1136
|
monitoredPageUrl: currentUrl,
|
|
@@ -1209,6 +1183,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1209
1183
|
pluginVersion: wsFileInfo.pluginVersion ?? undefined,
|
|
1210
1184
|
forkPluginRevision: wsFileInfo.forkPluginRevision ?? null,
|
|
1211
1185
|
pluginUpdateAvailable: wsFileInfo.pluginUpdateAvailable || undefined,
|
|
1186
|
+
pluginUpdateHint: wsFileInfo.pluginUpdateAvailable
|
|
1187
|
+
? pluginUpdateHint(wsFileInfo.forkPluginRevision, this.getPluginPath())
|
|
1188
|
+
: undefined,
|
|
1212
1189
|
} : undefined,
|
|
1213
1190
|
connectedFiles: (() => {
|
|
1214
1191
|
const files = this.wsServer?.getConnectedFiles();
|
|
@@ -1224,6 +1201,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1224
1201
|
pluginVersion: f.pluginVersion ?? undefined,
|
|
1225
1202
|
forkPluginRevision: f.forkPluginRevision ?? null,
|
|
1226
1203
|
pluginUpdateAvailable: f.pluginUpdateAvailable || undefined,
|
|
1204
|
+
pluginUpdateHint: f.pluginUpdateAvailable
|
|
1205
|
+
? pluginUpdateHint(f.forkPluginRevision, this.getPluginPath())
|
|
1206
|
+
: undefined,
|
|
1227
1207
|
}));
|
|
1228
1208
|
})(),
|
|
1229
1209
|
currentSelection: (() => {
|
|
@@ -1251,7 +1231,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1251
1231
|
: this.wsStartupError?.code === "EADDRINUSE"
|
|
1252
1232
|
? `❌ All WebSocket ports ${this.wsPreferredPort}-${this.wsPreferredPort + 9} are in use`
|
|
1253
1233
|
: this.wsActualPort !== null && this.wsActualPort !== this.wsPreferredPort
|
|
1254
|
-
? `❌ WebSocket server running on port ${this.wsActualPort} (fallback) but no plugin connected. Restart the
|
|
1234
|
+
? `❌ WebSocket server running on port ${this.wsActualPort} (fallback) but no plugin connected. Restart the ${PLUGIN_NAME_WITH_OLD} plugin in Figma to reconnect.`
|
|
1255
1235
|
: "❌ No connection to Figma Desktop",
|
|
1256
1236
|
setupInstructions: !setupValid
|
|
1257
1237
|
? this.wsStartupError?.code === "EADDRINUSE"
|
|
@@ -1260,15 +1240,15 @@ class LocalFigmaConsoleMCP {
|
|
|
1260
1240
|
fix: "Close some of the other Claude Desktop tabs or terminal sessions running the MCP server, then restart this one.",
|
|
1261
1241
|
}
|
|
1262
1242
|
: {
|
|
1263
|
-
instructions: `Open the
|
|
1243
|
+
instructions: `Open the ${PLUGIN_NAME} plugin in Figma (${PLUGIN_MENU_PATH}). No special launch flags needed.${this.getPluginPath() ? ' Plugin manifest: ' + this.getPluginPath() : ''}`,
|
|
1264
1244
|
}
|
|
1265
1245
|
: undefined,
|
|
1266
1246
|
ai_instruction: !setupValid
|
|
1267
1247
|
? this.wsStartupError?.code === "EADDRINUSE"
|
|
1268
1248
|
? `All WebSocket ports in range ${this.wsPreferredPort}-${this.wsPreferredPort + 9} are in use — most likely multiple Claude Desktop tabs or terminal sessions are running the Figma Console MCP server. Ask the user to close some sessions and restart.`
|
|
1269
1249
|
: this.wsActualPort !== null && this.wsActualPort !== this.wsPreferredPort
|
|
1270
|
-
? `Server is running on fallback port ${this.wsActualPort} (port ${this.wsPreferredPort} was taken by another instance). The
|
|
1271
|
-
: `No connection to Figma Desktop. Open the
|
|
1250
|
+
? `Server is running on fallback port ${this.wsActualPort} (port ${this.wsPreferredPort} was taken by another instance). The ${PLUGIN_NAME_WITH_OLD} plugin is not connected. TELL THE USER: Close and reopen the ${PLUGIN_NAME_WITH_OLD} plugin in Figma to reconnect. The plugin scans the whole port range (9223–9232) on launch and will pick up this server automatically.`
|
|
1251
|
+
: `No connection to Figma Desktop. Open the ${PLUGIN_NAME_WITH_OLD} plugin in Figma to connect.${this.getPluginPath() ? ' Plugin manifest: ' + this.getPluginPath() : ''}`
|
|
1272
1252
|
: activeTransport === "websocket"
|
|
1273
1253
|
? `Connected via WebSocket Bridge to "${currentFileName || "unknown file"}" on port ${this.wsActualPort}. All design tools and console monitoring tools are available. Console logs are captured from the plugin sandbox (code.js). IMPORTANT: Always verify the file name before destructive operations when multiple files have the plugin open.`
|
|
1274
1254
|
: "All tools are ready to use.",
|
|
@@ -1314,7 +1294,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1314
1294
|
// success criterion here.
|
|
1315
1295
|
if (!this.wsServer?.isClientConnected()) {
|
|
1316
1296
|
throw new Error("Cannot connect to Figma Desktop.\n\n" +
|
|
1317
|
-
"Open the
|
|
1297
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma (" + PLUGIN_MENU_PATH + ").");
|
|
1318
1298
|
}
|
|
1319
1299
|
const connector = await this.getDesktopConnector();
|
|
1320
1300
|
const probe = async () => connector.executeCodeViaUI("return { fileName: figma.root.name, fileKey: figma.fileKey }", 5000);
|
|
@@ -1340,9 +1320,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1340
1320
|
}
|
|
1341
1321
|
}
|
|
1342
1322
|
if (!fileInfo.success) {
|
|
1343
|
-
const probeErr = new Error("
|
|
1323
|
+
const probeErr = new Error("The " + PLUGIN_NAME + " plugin's socket is open but it is not responding to commands " +
|
|
1344
1324
|
"(automatic plugin reload was attempted and did not help). " +
|
|
1345
|
-
"Close and reopen the
|
|
1325
|
+
"Close and reopen the " + PLUGIN_NAME + " plugin in Figma Desktop (" + PLUGIN_MENU_PATH + ").");
|
|
1346
1326
|
probeErr.connectionError = this.buildConnectionError(probeErr);
|
|
1347
1327
|
throw probeErr;
|
|
1348
1328
|
}
|
|
@@ -1375,7 +1355,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1375
1355
|
text: JSON.stringify({
|
|
1376
1356
|
error: error instanceof Error ? error.message : String(error),
|
|
1377
1357
|
message: "Failed to reconnect to Figma Desktop",
|
|
1378
|
-
hint: "Open the
|
|
1358
|
+
hint: "Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma",
|
|
1379
1359
|
connectionError: this.buildConnectionError(error),
|
|
1380
1360
|
}),
|
|
1381
1361
|
},
|
|
@@ -1389,7 +1369,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1389
1369
|
// ============================================================================
|
|
1390
1370
|
// Tool: Get current user selection in Figma
|
|
1391
1371
|
server.registerTool("figma_get_selection", {
|
|
1392
|
-
description: "Get the currently selected nodes in Figma. Returns node IDs, names, types, and dimensions. WebSocket-only — requires
|
|
1372
|
+
description: "Get the currently selected nodes in Figma. Returns node IDs, names, types, and dimensions. WebSocket-only — requires the " + PLUGIN_NAME + " plugin. Use this to understand what the user is pointing at instead of asking them to describe it.",
|
|
1393
1373
|
inputSchema: z.object({
|
|
1394
1374
|
verbose: z
|
|
1395
1375
|
.boolean()
|
|
@@ -1405,7 +1385,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1405
1385
|
content: [{
|
|
1406
1386
|
type: "text",
|
|
1407
1387
|
text: JSON.stringify({
|
|
1408
|
-
error: "WebSocket not connected. Open the
|
|
1388
|
+
error: "WebSocket not connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.",
|
|
1409
1389
|
selection: null,
|
|
1410
1390
|
}),
|
|
1411
1391
|
}],
|
|
@@ -1485,7 +1465,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1485
1465
|
});
|
|
1486
1466
|
// Tool: Get recent design changes
|
|
1487
1467
|
server.registerTool("figma_get_design_changes", {
|
|
1488
|
-
description: "Get recent document changes detected in Figma. Returns buffered change events including which nodes changed, whether styles were modified, and change counts. WebSocket-only — events are captured via
|
|
1468
|
+
description: "Get recent document changes detected in Figma. Returns buffered change events including which nodes changed, whether styles were modified, and change counts. WebSocket-only — events are captured via the " + PLUGIN_NAME + " plugin. Use this to understand what changed since you last checked.",
|
|
1489
1469
|
inputSchema: z.object({
|
|
1490
1470
|
since: z
|
|
1491
1471
|
.number()
|
|
@@ -1508,7 +1488,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1508
1488
|
content: [{
|
|
1509
1489
|
type: "text",
|
|
1510
1490
|
text: JSON.stringify({
|
|
1511
|
-
error: "WebSocket not connected. Open the
|
|
1491
|
+
error: "WebSocket not connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.",
|
|
1512
1492
|
changes: [],
|
|
1513
1493
|
}),
|
|
1514
1494
|
}],
|
|
@@ -1565,7 +1545,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1565
1545
|
});
|
|
1566
1546
|
// Tool: List all open files connected via WebSocket
|
|
1567
1547
|
server.registerTool("figma_list_open_files", {
|
|
1568
|
-
description: "List all Figma files currently connected via the
|
|
1548
|
+
description: "List all Figma files currently connected via the " + PLUGIN_NAME + " plugin. Shows which files have the plugin open and which one is the active target for tool calls. Use figma_navigate to switch between files. WebSocket multi-client mode — each file with the " + PLUGIN_NAME + " plugin maintains its own connection.",
|
|
1569
1549
|
inputSchema: z.object({}),
|
|
1570
1550
|
}, async () => {
|
|
1571
1551
|
try {
|
|
@@ -1574,7 +1554,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1574
1554
|
content: [{
|
|
1575
1555
|
type: "text",
|
|
1576
1556
|
text: JSON.stringify({
|
|
1577
|
-
error: "No files connected. Open the
|
|
1557
|
+
error: "No files connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma to connect files.",
|
|
1578
1558
|
files: [],
|
|
1579
1559
|
}),
|
|
1580
1560
|
}],
|
|
@@ -1650,10 +1630,10 @@ class LocalFigmaConsoleMCP {
|
|
|
1650
1630
|
...result,
|
|
1651
1631
|
warning: [
|
|
1652
1632
|
componentsError
|
|
1653
|
-
? `Components fetch failed (${componentsError}) — results may be incomplete and were NOT cached; retry after checking the
|
|
1633
|
+
? `Components fetch failed (${componentsError}) — results may be incomplete and were NOT cached; retry after checking the ${PLUGIN_NAME} plugin.`
|
|
1654
1634
|
: null,
|
|
1655
1635
|
variablesError
|
|
1656
|
-
? `Variables fetch failed (${variablesError}) — tokens are missing and the result was NOT cached; retry after checking the
|
|
1636
|
+
? `Variables fetch failed (${variablesError}) — tokens are missing and the result was NOT cached; retry after checking the ${PLUGIN_NAME} plugin.`
|
|
1657
1637
|
: null,
|
|
1658
1638
|
]
|
|
1659
1639
|
.filter(Boolean)
|
|
@@ -1676,7 +1656,6 @@ class LocalFigmaConsoleMCP {
|
|
|
1676
1656
|
}),
|
|
1677
1657
|
}, async ({ forceRefresh }) => {
|
|
1678
1658
|
try {
|
|
1679
|
-
const { getCategories, getTokenSummary } = await import("./core/design-system-manifest.js");
|
|
1680
1659
|
const { cacheEntry, fileKey, wasLoaded, componentsError, variablesError } = await ensureDesignSystemCache({ forceRefresh });
|
|
1681
1660
|
const categories = getCategories(cacheEntry.manifest);
|
|
1682
1661
|
const tokenSummary = getTokenSummary(cacheEntry.manifest);
|
|
@@ -1722,10 +1701,10 @@ class LocalFigmaConsoleMCP {
|
|
|
1722
1701
|
warnings: componentsError || variablesError
|
|
1723
1702
|
? [
|
|
1724
1703
|
componentsError
|
|
1725
|
-
? `Components fetch failed (${componentsError}) — component data is incomplete and was NOT cached. Check the
|
|
1704
|
+
? `Components fetch failed (${componentsError}) — component data is incomplete and was NOT cached. Check the ${PLUGIN_NAME} plugin and retry.`
|
|
1726
1705
|
: null,
|
|
1727
1706
|
variablesError
|
|
1728
|
-
? `Variables fetch failed (${variablesError}) — tokens are missing and the result was NOT cached. Check the
|
|
1707
|
+
? `Variables fetch failed (${variablesError}) — tokens are missing and the result was NOT cached. Check the ${PLUGIN_NAME} plugin and retry.`
|
|
1729
1708
|
: null,
|
|
1730
1709
|
].filter(Boolean)
|
|
1731
1710
|
: undefined,
|
|
@@ -1743,7 +1722,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1743
1722
|
type: "text",
|
|
1744
1723
|
text: JSON.stringify({
|
|
1745
1724
|
error: error instanceof Error ? error.message : String(error),
|
|
1746
|
-
hint: "Make sure the
|
|
1725
|
+
hint: "Make sure the " + PLUGIN_NAME_WITH_OLD + " plugin is running in Figma",
|
|
1747
1726
|
}),
|
|
1748
1727
|
},
|
|
1749
1728
|
],
|
|
@@ -1792,7 +1771,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
1792
1771
|
// Determine if this is a library search or local search
|
|
1793
1772
|
let resolvedLibraryKey = libraryFileKey;
|
|
1794
1773
|
if (!resolvedLibraryKey && libraryFileUrl) {
|
|
1795
|
-
const { extractFileKey } = await import("./core/figma-api.js");
|
|
1796
1774
|
resolvedLibraryKey = extractFileKey(libraryFileUrl) ?? undefined;
|
|
1797
1775
|
}
|
|
1798
1776
|
// LIBRARY SEARCH PATH: Use REST API for cross-file access
|
|
@@ -1913,23 +1891,8 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
1913
1891
|
};
|
|
1914
1892
|
}
|
|
1915
1893
|
// LOCAL SEARCH PATH: Use cached design system manifest (existing behavior)
|
|
1916
|
-
const { searchComponents } = await import("./core/design-system-manifest.js");
|
|
1917
1894
|
// Auto-load design system cache if needed (no error returned to user)
|
|
1918
1895
|
const { cacheEntry, warning: cacheWarning } = await ensureDesignSystemCache();
|
|
1919
|
-
if (!cacheEntry) {
|
|
1920
|
-
return {
|
|
1921
|
-
content: [
|
|
1922
|
-
{
|
|
1923
|
-
type: "text",
|
|
1924
|
-
text: JSON.stringify({
|
|
1925
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
1926
|
-
hint: "If you're trying to search a published library from another file, pass the libraryFileKey or libraryFileUrl parameter.",
|
|
1927
|
-
}),
|
|
1928
|
-
},
|
|
1929
|
-
],
|
|
1930
|
-
isError: true,
|
|
1931
|
-
};
|
|
1932
|
-
}
|
|
1933
1896
|
const effectiveLimit = Math.min(limit || 10, 25);
|
|
1934
1897
|
const results = searchComponents(cacheEntry.manifest, query || "", {
|
|
1935
1898
|
category,
|
|
@@ -2005,20 +1968,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2005
1968
|
};
|
|
2006
1969
|
}
|
|
2007
1970
|
// Auto-load design system cache if needed
|
|
2008
|
-
const { cacheEntry } = await ensureDesignSystemCache();
|
|
2009
|
-
if (!cacheEntry) {
|
|
2010
|
-
return {
|
|
2011
|
-
content: [
|
|
2012
|
-
{
|
|
2013
|
-
type: "text",
|
|
2014
|
-
text: JSON.stringify({
|
|
2015
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
2016
|
-
}),
|
|
2017
|
-
},
|
|
2018
|
-
],
|
|
2019
|
-
isError: true,
|
|
2020
|
-
};
|
|
2021
|
-
}
|
|
1971
|
+
const { cacheEntry, warning } = await ensureDesignSystemCache();
|
|
2022
1972
|
// Search for the component
|
|
2023
1973
|
let component = null;
|
|
2024
1974
|
let isComponentSet = false;
|
|
@@ -2051,6 +2001,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2051
2001
|
text: JSON.stringify({
|
|
2052
2002
|
error: `Component not found: ${componentKey || componentName}`,
|
|
2053
2003
|
hint: "Use figma_search_components to find available components.",
|
|
2004
|
+
warnings: warning ? [warning] : undefined,
|
|
2054
2005
|
}),
|
|
2055
2006
|
},
|
|
2056
2007
|
],
|
|
@@ -2069,6 +2020,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2069
2020
|
key: component.key,
|
|
2070
2021
|
example: `Use figma_instantiate_component with componentKey: "${component.key}"`,
|
|
2071
2022
|
},
|
|
2023
|
+
warnings: warning ? [warning] : undefined,
|
|
2072
2024
|
}),
|
|
2073
2025
|
},
|
|
2074
2026
|
],
|
|
@@ -2111,20 +2063,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2111
2063
|
}, async ({ type, filter, limit }) => {
|
|
2112
2064
|
try {
|
|
2113
2065
|
// Auto-load design system cache if needed
|
|
2114
|
-
const { cacheEntry } = await ensureDesignSystemCache();
|
|
2115
|
-
if (!cacheEntry) {
|
|
2116
|
-
return {
|
|
2117
|
-
content: [
|
|
2118
|
-
{
|
|
2119
|
-
type: "text",
|
|
2120
|
-
text: JSON.stringify({
|
|
2121
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
2122
|
-
}),
|
|
2123
|
-
},
|
|
2124
|
-
],
|
|
2125
|
-
isError: true,
|
|
2126
|
-
};
|
|
2127
|
-
}
|
|
2066
|
+
const { cacheEntry, warning } = await ensureDesignSystemCache();
|
|
2128
2067
|
const tokens = cacheEntry.manifest.tokens;
|
|
2129
2068
|
const effectiveLimit = Math.min(limit || 50, 100);
|
|
2130
2069
|
const filterLower = filter?.toLowerCase();
|
|
@@ -2165,6 +2104,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2165
2104
|
filter: filter || "(none)",
|
|
2166
2105
|
tokens: result,
|
|
2167
2106
|
hint: "Use these exact token names and values when generating designs.",
|
|
2107
|
+
warnings: warning ? [warning] : undefined,
|
|
2168
2108
|
}),
|
|
2169
2109
|
},
|
|
2170
2110
|
],
|
|
@@ -2235,7 +2175,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2235
2175
|
// Resolve file key from URL or direct key
|
|
2236
2176
|
let fileKey = libraryFileKey;
|
|
2237
2177
|
if (!fileKey && libraryFileUrl) {
|
|
2238
|
-
const { extractFileKey } = await import("./core/figma-api.js");
|
|
2239
2178
|
fileKey = extractFileKey(libraryFileUrl) ?? undefined;
|
|
2240
2179
|
if (!fileKey) {
|
|
2241
2180
|
return {
|
|
@@ -2521,6 +2460,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2521
2460
|
},
|
|
2522
2461
|
getBundledPluginVersion,
|
|
2523
2462
|
getBundledForkPluginRevision,
|
|
2463
|
+
getPluginPath: () => this.getPluginPath(),
|
|
2524
2464
|
getPluginState: () => {
|
|
2525
2465
|
if (!this.wsServer)
|
|
2526
2466
|
return null;
|
|
@@ -2558,7 +2498,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2558
2498
|
registerTokenBrowserApp(server, async (fileUrl) => {
|
|
2559
2499
|
const url = fileUrl || this.getCurrentFileUrl();
|
|
2560
2500
|
if (!url) {
|
|
2561
|
-
throw new Error("No Figma file URL available. Either pass a fileUrl, call figma_navigate, or ensure the
|
|
2501
|
+
throw new Error("No Figma file URL available. Either pass a fileUrl, call figma_navigate, or ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is connected.");
|
|
2562
2502
|
}
|
|
2563
2503
|
const urlInfo = extractFigmaUrlInfo(url);
|
|
2564
2504
|
if (!urlInfo) {
|
|
@@ -2599,18 +2539,9 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2599
2539
|
const cacheEntry = this.variablesCache.get(fileKey);
|
|
2600
2540
|
if (cacheEntry && Date.now() - cacheEntry.timestamp < 5 * 60 * 1000) {
|
|
2601
2541
|
const cached = cacheEntry.data;
|
|
2602
|
-
// Desktop Bridge caches arrays directly; REST API data needs formatVariables
|
|
2603
|
-
if (Array.isArray(cached.variables)) {
|
|
2604
|
-
return {
|
|
2605
|
-
variables: cached.variables,
|
|
2606
|
-
collections: cached.variableCollections || [],
|
|
2607
|
-
fileInfo,
|
|
2608
|
-
};
|
|
2609
|
-
}
|
|
2610
|
-
const formatted = formatVariables(cached);
|
|
2611
2542
|
return {
|
|
2612
|
-
variables:
|
|
2613
|
-
collections:
|
|
2543
|
+
variables: cached.variables,
|
|
2544
|
+
collections: cached.variableCollections || [],
|
|
2614
2545
|
fileInfo,
|
|
2615
2546
|
};
|
|
2616
2547
|
}
|
|
@@ -2648,24 +2579,24 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2648
2579
|
const api = await this.getFigmaAPI();
|
|
2649
2580
|
const { local, localError } = await api.getAllVariables(fileKey);
|
|
2650
2581
|
if (localError) {
|
|
2651
|
-
throw new Error(`Could not fetch variables.
|
|
2582
|
+
throw new Error(`Could not fetch variables. The ${PLUGIN_NAME} plugin is unavailable, and the REST API returned: ${localError}`);
|
|
2652
2583
|
}
|
|
2653
|
-
// Cache
|
|
2584
|
+
// Cache in the shared array shape, unless the cache was invalidated while it was read
|
|
2585
|
+
const restData = restVariablesCacheData(fileKey, local);
|
|
2654
2586
|
setCacheIfCurrent(this.variablesCache, fileKey, {
|
|
2655
|
-
data:
|
|
2587
|
+
data: restData,
|
|
2656
2588
|
timestamp: Date.now(),
|
|
2657
2589
|
}, restStartedAt);
|
|
2658
|
-
const formatted = formatVariables(local);
|
|
2659
2590
|
return {
|
|
2660
|
-
variables:
|
|
2661
|
-
collections:
|
|
2591
|
+
variables: restData.variables,
|
|
2592
|
+
collections: restData.variableCollections,
|
|
2662
2593
|
fileInfo,
|
|
2663
2594
|
};
|
|
2664
2595
|
});
|
|
2665
2596
|
registerDesignSystemDashboardApp(server, async (fileUrl) => {
|
|
2666
2597
|
const url = fileUrl || this.getCurrentFileUrl();
|
|
2667
2598
|
if (!url) {
|
|
2668
|
-
throw new Error("No Figma file URL available. Either pass a fileUrl, call figma_navigate, or ensure the
|
|
2599
|
+
throw new Error("No Figma file URL available. Either pass a fileUrl, call figma_navigate, or ensure the " + PLUGIN_NAME_WITH_OLD + " plugin is connected.");
|
|
2669
2600
|
}
|
|
2670
2601
|
const urlInfo = extractFigmaUrlInfo(url);
|
|
2671
2602
|
if (!urlInfo) {
|
|
@@ -2687,15 +2618,8 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2687
2618
|
const cacheEntry = this.variablesCache.get(fileKey);
|
|
2688
2619
|
if (cacheEntry && Date.now() - cacheEntry.timestamp < 5 * 60 * 1000) {
|
|
2689
2620
|
const cached = cacheEntry.data;
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
collections = cached.variableCollections || [];
|
|
2693
|
-
}
|
|
2694
|
-
else {
|
|
2695
|
-
const formatted = formatVariables(cached);
|
|
2696
|
-
variables = formatted.variables;
|
|
2697
|
-
collections = formatted.collections;
|
|
2698
|
-
}
|
|
2621
|
+
variables = cached.variables;
|
|
2622
|
+
collections = cached.variableCollections || [];
|
|
2699
2623
|
variablesAvailable = variables.length > 0;
|
|
2700
2624
|
}
|
|
2701
2625
|
// 2. Try Desktop Bridge via transport-agnostic connector
|
|
@@ -2738,13 +2662,13 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2738
2662
|
const api = await this.getFigmaAPI();
|
|
2739
2663
|
const { local, localError } = await api.getAllVariables(fileKey);
|
|
2740
2664
|
if (!localError && local) {
|
|
2665
|
+
const restData = restVariablesCacheData(fileKey, local);
|
|
2741
2666
|
setCacheIfCurrent(this.variablesCache, fileKey, {
|
|
2742
|
-
data:
|
|
2667
|
+
data: restData,
|
|
2743
2668
|
timestamp: Date.now(),
|
|
2744
2669
|
}, startedAt);
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
collections = formatted.collections;
|
|
2670
|
+
variables = restData.variables;
|
|
2671
|
+
collections = restData.variableCollections;
|
|
2748
2672
|
variablesAvailable = true;
|
|
2749
2673
|
}
|
|
2750
2674
|
else {
|
|
@@ -2762,19 +2686,19 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2762
2686
|
if (!variablesAvailable) {
|
|
2763
2687
|
if (desktopBridgeFailed && restApiFailed) {
|
|
2764
2688
|
variableError =
|
|
2765
|
-
"
|
|
2689
|
+
"The " + PLUGIN_NAME + " plugin is not connected and REST API requires Enterprise plan. Please open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma to enable variable/token analysis.";
|
|
2766
2690
|
}
|
|
2767
2691
|
else if (desktopBridgeFailed) {
|
|
2768
2692
|
variableError =
|
|
2769
|
-
"
|
|
2693
|
+
"The " + PLUGIN_NAME + " plugin is not connected. Please open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma to enable variable/token analysis.";
|
|
2770
2694
|
}
|
|
2771
2695
|
else if (restApiFailed) {
|
|
2772
2696
|
variableError =
|
|
2773
|
-
"REST API requires Figma Enterprise plan. Connect the
|
|
2697
|
+
"REST API requires Figma Enterprise plan. Connect the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma for variable/token access.";
|
|
2774
2698
|
}
|
|
2775
2699
|
else if (!desktopBridgeAttempted && !restApiAttempted) {
|
|
2776
2700
|
variableError =
|
|
2777
|
-
"No variable fetch methods available. Connect the
|
|
2701
|
+
"No variable fetch methods available. Connect the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.";
|
|
2778
2702
|
}
|
|
2779
2703
|
}
|
|
2780
2704
|
// Fetch file metadata, components, component sets, and styles via REST API
|
|
@@ -2855,6 +2779,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2855
2779
|
logger.info("MCP Apps registered (ENABLE_MCP_APPS=true)");
|
|
2856
2780
|
}
|
|
2857
2781
|
const unclassified = applyToolAnnotations(server);
|
|
2782
|
+
attachWriteInvalidation(server, { variablesCache: this.variablesCache, manifestCache: this.manifestCache });
|
|
2858
2783
|
if (unclassified.length > 0)
|
|
2859
2784
|
logger.warn({ unclassified }, "Tools registered without annotation hints");
|
|
2860
2785
|
logger.info("All MCP tools registered successfully (including write operations)");
|
|
@@ -2992,7 +2917,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2992
2917
|
bundledPluginVersion: getBundledPluginVersion(),
|
|
2993
2918
|
config: this.config,
|
|
2994
2919
|
}, `Starting Figma Console MCP v${SERVER_VERSION} (Local Mode)`);
|
|
2995
|
-
// Copy plugin files to
|
|
2920
|
+
// Copy plugin files to the plugin's own import directory
|
|
2996
2921
|
// so users have a permanent import path that survives npx cache changes.
|
|
2997
2922
|
try {
|
|
2998
2923
|
const thisFile = fileURLToPath(import.meta.url);
|
|
@@ -3270,12 +3195,11 @@ if (currentFile === entryFile) {
|
|
|
3270
3195
|
"Import plugin from manifest). The MCP server refreshes the\n" +
|
|
3271
3196
|
"plugin files in this directory on every startup.\n" +
|
|
3272
3197
|
"\n" +
|
|
3273
|
-
"
|
|
3274
|
-
"
|
|
3275
|
-
"
|
|
3276
|
-
"
|
|
3277
|
-
"
|
|
3278
|
-
"level, so re-importing is what makes Figma pick up changes.\n");
|
|
3198
|
+
"In 0.6.6 the plugin was renamed, so importing this manifest\n" +
|
|
3199
|
+
"adds it as a new entry. Then remove the old \"" + OLD_PLUGIN_NAME + "\"\n" +
|
|
3200
|
+
"entry: Plugins → Development → Manage plugins in development.\n" +
|
|
3201
|
+
"Figma caches plugin files at the app level, so importing is\n" +
|
|
3202
|
+
"what makes Figma pick up changes.\n");
|
|
3279
3203
|
process.exit(0);
|
|
3280
3204
|
}
|
|
3281
3205
|
// Fallback to npm package path
|
|
@@ -3286,7 +3210,7 @@ if (currentFile === entryFile) {
|
|
|
3286
3210
|
}
|
|
3287
3211
|
// Last resort: print the stable dir path even if it doesn't exist yet
|
|
3288
3212
|
// (the server will create it on first startup)
|
|
3289
|
-
const stableDir = join(
|
|
3213
|
+
const stableDir = join(pluginImportDir(), "manifest.json");
|
|
3290
3214
|
console.log(stableDir);
|
|
3291
3215
|
console.error("\nNote: This path will be populated when the MCP server starts.");
|
|
3292
3216
|
process.exit(0);
|