@muloka/figma-console-mcp 0.6.5 → 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 +12 -5
- 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/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-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.map +1 -1
- package/dist/core/figma-api.js +2 -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 +39 -38
- 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-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 +6 -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 +76 -147
- 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,8 +20,7 @@ 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
26
|
import { attachCacheInvalidation, attachWriteInvalidation } from "./core/cache-invalidation.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";
|
|
@@ -96,41 +97,6 @@ function readJsonBody(req) {
|
|
|
96
97
|
req.on("error", reject);
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Copy plugin files to a stable directory (~/.figma-console-mcp/plugin/).
|
|
101
|
-
* This gives users a permanent, predictable path to import from instead of
|
|
102
|
-
* the volatile npx cache path that changes between updates.
|
|
103
|
-
*
|
|
104
|
-
* Returns the stable manifest path, or null if copy failed.
|
|
105
|
-
*/
|
|
106
|
-
function setupStablePluginDir(sourcePluginDir) {
|
|
107
|
-
try {
|
|
108
|
-
const stableDir = join(homedir(), ".figma-console-mcp", "plugin");
|
|
109
|
-
mkdirSync(stableDir, { recursive: true });
|
|
110
|
-
const filesToCopy = ["manifest.json", "code.js", "ui.html"];
|
|
111
|
-
for (const file of filesToCopy) {
|
|
112
|
-
const src = join(sourcePluginDir, file);
|
|
113
|
-
const dest = join(stableDir, file);
|
|
114
|
-
if (existsSync(src)) {
|
|
115
|
-
copyFileSync(src, dest);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Write a version marker so we can detect stale copies
|
|
119
|
-
try {
|
|
120
|
-
const pkg = JSON.parse(readFileSync(join(sourcePluginDir, "..", "package.json"), "utf-8"));
|
|
121
|
-
writeFileSync(join(stableDir, ".version"), pkg.version, "utf-8");
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
// Non-critical — version marker is for diagnostics only
|
|
125
|
-
}
|
|
126
|
-
logger.info({ stableDir }, "Plugin files copied to stable directory");
|
|
127
|
-
return join(stableDir, "manifest.json");
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
logger.warn({ error }, "Could not set up stable plugin directory (non-critical)");
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
100
|
/**
|
|
135
101
|
* Server version reported in the MCP handshake's serverInfo.version — read from
|
|
136
102
|
* package.json (not hardcoded) so a client's status check can detect
|
|
@@ -155,6 +121,7 @@ Then tell the user to run \`npx @muloka/figma-console-mcp --print-path\` and imp
|
|
|
155
121
|
manifest.json in Figma: Plugins → Development → Import plugin from manifest. On macOS that
|
|
156
122
|
folder is hidden, so the file dialog will not show it: tell them to press Cmd+Shift+G in the
|
|
157
123
|
dialog and paste the path. (On Windows the folder is visible; navigate to it normally.)
|
|
124
|
+
Then run it: Plugins → Development → ${PLUGIN_NAME}.
|
|
158
125
|
|
|
159
126
|
### VISUAL VALIDATION WORKFLOW (Required)
|
|
160
127
|
After creating or modifying ANY visual design elements:
|
|
@@ -316,7 +283,7 @@ class LocalFigmaConsoleMCP {
|
|
|
316
283
|
}
|
|
317
284
|
const wsPort = this.wsActualPort || this.wsPreferredPort || DEFAULT_WS_PORT;
|
|
318
285
|
const err = new Error("Cannot connect to Figma Desktop.\n\n" +
|
|
319
|
-
"Open the
|
|
286
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma (" + PLUGIN_MENU_PATH + ").\n" +
|
|
320
287
|
`The plugin will connect automatically to ws://localhost:${wsPort}.\n` +
|
|
321
288
|
"No special launch flags needed.");
|
|
322
289
|
// Attach structured connection error for programmatic agent recovery
|
|
@@ -375,7 +342,7 @@ class LocalFigmaConsoleMCP {
|
|
|
375
342
|
type: 'BRIDGE_COMMAND_TIMEOUT',
|
|
376
343
|
canRetry: true,
|
|
377
344
|
recoverySteps: [
|
|
378
|
-
"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",
|
|
379
346
|
"If the issue persists, restart Figma Desktop",
|
|
380
347
|
"Call figma_get_status with probe:true to verify the connection",
|
|
381
348
|
],
|
|
@@ -387,7 +354,7 @@ class LocalFigmaConsoleMCP {
|
|
|
387
354
|
canRetry: !isNoClient,
|
|
388
355
|
recoverySteps: [
|
|
389
356
|
"Open Figma Desktop with your target file",
|
|
390
|
-
"Go to
|
|
357
|
+
"Go to " + PLUGIN_MENU_PATH,
|
|
391
358
|
"Click 'Run' to open the plugin",
|
|
392
359
|
"Wait 3 seconds, then call figma_get_status with probe:true to verify",
|
|
393
360
|
],
|
|
@@ -424,13 +391,13 @@ class LocalFigmaConsoleMCP {
|
|
|
424
391
|
// Not available yet — log guidance but don't throw
|
|
425
392
|
// The user may open the plugin later
|
|
426
393
|
logger.warn(`WebSocket transport not available yet.\n\n` +
|
|
427
|
-
`Open the
|
|
394
|
+
`Open the ${PLUGIN_NAME} plugin in Figma (${PLUGIN_MENU_PATH}).\n` +
|
|
428
395
|
`No special launch flags needed — the plugin connects automatically.`);
|
|
429
396
|
}
|
|
430
397
|
}
|
|
431
398
|
/**
|
|
432
399
|
* Resolve the path to the Desktop Bridge plugin manifest.
|
|
433
|
-
* Prefers the
|
|
400
|
+
* Prefers the plugin's own import directory (see pluginImportDir) over the npx cache path.
|
|
434
401
|
*/
|
|
435
402
|
getPluginPath() {
|
|
436
403
|
// Prefer stable path — consistent across npx updates
|
|
@@ -485,7 +452,7 @@ class LocalFigmaConsoleMCP {
|
|
|
485
452
|
source = "websocket";
|
|
486
453
|
}
|
|
487
454
|
else {
|
|
488
|
-
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.");
|
|
489
456
|
}
|
|
490
457
|
const responseData = {
|
|
491
458
|
logs,
|
|
@@ -497,12 +464,12 @@ class LocalFigmaConsoleMCP {
|
|
|
497
464
|
};
|
|
498
465
|
if (source === "websocket") {
|
|
499
466
|
responseData.ai_instruction =
|
|
500
|
-
"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.";
|
|
501
468
|
}
|
|
502
469
|
if (logs.length === 0) {
|
|
503
470
|
if (source === "websocket") {
|
|
504
471
|
responseData.ai_instruction =
|
|
505
|
-
"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.";
|
|
506
473
|
}
|
|
507
474
|
else {
|
|
508
475
|
const isMonitoring = status.isMonitoring;
|
|
@@ -536,8 +503,8 @@ class LocalFigmaConsoleMCP {
|
|
|
536
503
|
error: errorMessage,
|
|
537
504
|
message: "Failed to retrieve console logs.",
|
|
538
505
|
troubleshooting: [
|
|
539
|
-
"Open the
|
|
540
|
-
"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",
|
|
541
508
|
],
|
|
542
509
|
}),
|
|
543
510
|
},
|
|
@@ -551,12 +518,12 @@ class LocalFigmaConsoleMCP {
|
|
|
551
518
|
// token, and reflects the current runtime state (no cloud-sync lag).
|
|
552
519
|
// Note: For screenshots of specific components, use figma_get_component_image instead
|
|
553
520
|
server.registerTool("figma_take_screenshot", {
|
|
554
|
-
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.`,
|
|
555
522
|
inputSchema: z.object({
|
|
556
523
|
nodeId: z
|
|
557
524
|
.string()
|
|
558
525
|
.optional()
|
|
559
|
-
.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)."),
|
|
560
527
|
scale: z
|
|
561
528
|
.number()
|
|
562
529
|
.min(0.01)
|
|
@@ -623,7 +590,7 @@ class LocalFigmaConsoleMCP {
|
|
|
623
590
|
format,
|
|
624
591
|
byteLength: result.image.byteLength,
|
|
625
592
|
source: "desktop_bridge",
|
|
626
|
-
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.",
|
|
627
594
|
}),
|
|
628
595
|
},
|
|
629
596
|
{
|
|
@@ -643,7 +610,7 @@ class LocalFigmaConsoleMCP {
|
|
|
643
610
|
// Get current URL to extract file key and node ID if not provided
|
|
644
611
|
const currentUrl = this.getCurrentFileUrl();
|
|
645
612
|
if (!currentUrl) {
|
|
646
|
-
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.");
|
|
647
614
|
}
|
|
648
615
|
const fileKey = extractFileKey(currentUrl);
|
|
649
616
|
if (!fileKey) {
|
|
@@ -728,8 +695,8 @@ class LocalFigmaConsoleMCP {
|
|
|
728
695
|
error: errorMessage,
|
|
729
696
|
message: "Failed to capture screenshot via Figma API",
|
|
730
697
|
hint: isAuthError
|
|
731
|
-
? "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
|
|
732
|
-
: "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.",
|
|
733
700
|
}),
|
|
734
701
|
},
|
|
735
702
|
],
|
|
@@ -754,7 +721,7 @@ class LocalFigmaConsoleMCP {
|
|
|
754
721
|
}),
|
|
755
722
|
}, async ({ duration, level }) => {
|
|
756
723
|
if (!this.wsServer?.isClientConnected()) {
|
|
757
|
-
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.");
|
|
758
725
|
}
|
|
759
726
|
const startTime = Date.now();
|
|
760
727
|
const startLogCount = this.wsServer.getConsoleStatus().logCount;
|
|
@@ -816,7 +783,7 @@ class LocalFigmaConsoleMCP {
|
|
|
816
783
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
817
784
|
}
|
|
818
785
|
else {
|
|
819
|
-
throw new Error("No connection available. Open the
|
|
786
|
+
throw new Error("No connection available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.");
|
|
820
787
|
}
|
|
821
788
|
const responseData = {
|
|
822
789
|
status: "reloaded",
|
|
@@ -851,8 +818,8 @@ class LocalFigmaConsoleMCP {
|
|
|
851
818
|
error: String(error),
|
|
852
819
|
message: "Failed to reload plugin",
|
|
853
820
|
troubleshooting: [
|
|
854
|
-
"Open the
|
|
855
|
-
"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",
|
|
856
823
|
],
|
|
857
824
|
}),
|
|
858
825
|
},
|
|
@@ -875,7 +842,7 @@ class LocalFigmaConsoleMCP {
|
|
|
875
842
|
transport = "websocket";
|
|
876
843
|
}
|
|
877
844
|
else {
|
|
878
|
-
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.");
|
|
879
846
|
}
|
|
880
847
|
const responseData = {
|
|
881
848
|
status: "cleared",
|
|
@@ -918,7 +885,7 @@ class LocalFigmaConsoleMCP {
|
|
|
918
885
|
});
|
|
919
886
|
// Tool 6: Navigate / switch active file
|
|
920
887
|
server.registerTool("figma_navigate", {
|
|
921
|
-
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.",
|
|
922
889
|
inputSchema: z.object({
|
|
923
890
|
url: z
|
|
924
891
|
.string()
|
|
@@ -1035,19 +1002,19 @@ class LocalFigmaConsoleMCP {
|
|
|
1035
1002
|
isActive: f.isActive,
|
|
1036
1003
|
})),
|
|
1037
1004
|
requestedFileKey,
|
|
1038
|
-
message: "The requested file is not connected via WebSocket. Open the
|
|
1039
|
-
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.",
|
|
1040
1007
|
}),
|
|
1041
1008
|
},
|
|
1042
1009
|
],
|
|
1043
1010
|
};
|
|
1044
1011
|
}
|
|
1045
|
-
throw new Error("No connection available. Open the
|
|
1012
|
+
throw new Error("No connection available. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.");
|
|
1046
1013
|
}
|
|
1047
1014
|
// If we got here, the WebSocket plugin bridge wasn't connected.
|
|
1048
1015
|
// Tell the user how to recover — local mode has no Puppeteer
|
|
1049
1016
|
// fallback after the Phase 3 CDP cleanup.
|
|
1050
|
-
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.");
|
|
1051
1018
|
}
|
|
1052
1019
|
catch (error) {
|
|
1053
1020
|
logger.error({ error }, "Failed to navigate to Figma");
|
|
@@ -1060,8 +1027,8 @@ class LocalFigmaConsoleMCP {
|
|
|
1060
1027
|
error: errorMessage,
|
|
1061
1028
|
message: "Failed to navigate to Figma URL",
|
|
1062
1029
|
troubleshooting: [
|
|
1063
|
-
"In WebSocket mode: navigate manually in Figma and ensure
|
|
1064
|
-
"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",
|
|
1065
1032
|
],
|
|
1066
1033
|
}),
|
|
1067
1034
|
},
|
|
@@ -1072,7 +1039,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1072
1039
|
});
|
|
1073
1040
|
// Tool 7: Get Status (with setup validation)
|
|
1074
1041
|
server.registerTool("figma_get_status", {
|
|
1075
|
-
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.",
|
|
1076
1043
|
inputSchema: z.object({
|
|
1077
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."),
|
|
1078
1045
|
}),
|
|
@@ -1151,7 +1118,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1151
1118
|
]
|
|
1152
1119
|
: [
|
|
1153
1120
|
"Open Figma Desktop with your target file",
|
|
1154
|
-
"Go to
|
|
1121
|
+
"Go to " + PLUGIN_MENU_PATH,
|
|
1155
1122
|
"Click 'Run' to open the plugin",
|
|
1156
1123
|
"Wait 3 seconds for the WebSocket connection to establish",
|
|
1157
1124
|
"Call figma_get_status with probe:true to verify the connection",
|
|
@@ -1163,7 +1130,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1163
1130
|
text: JSON.stringify({
|
|
1164
1131
|
mode: "local",
|
|
1165
1132
|
currentFileName: currentFileName ||
|
|
1166
|
-
"(unable to retrieve -
|
|
1133
|
+
"(unable to retrieve - the " + PLUGIN_NAME_WITH_OLD + " plugin may need to be opened)",
|
|
1167
1134
|
currentFileKey: currentFileKey || undefined,
|
|
1168
1135
|
editorType: this.wsServer?.getEditorType() || "figma",
|
|
1169
1136
|
monitoredPageUrl: currentUrl,
|
|
@@ -1216,6 +1183,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1216
1183
|
pluginVersion: wsFileInfo.pluginVersion ?? undefined,
|
|
1217
1184
|
forkPluginRevision: wsFileInfo.forkPluginRevision ?? null,
|
|
1218
1185
|
pluginUpdateAvailable: wsFileInfo.pluginUpdateAvailable || undefined,
|
|
1186
|
+
pluginUpdateHint: wsFileInfo.pluginUpdateAvailable
|
|
1187
|
+
? pluginUpdateHint(wsFileInfo.forkPluginRevision, this.getPluginPath())
|
|
1188
|
+
: undefined,
|
|
1219
1189
|
} : undefined,
|
|
1220
1190
|
connectedFiles: (() => {
|
|
1221
1191
|
const files = this.wsServer?.getConnectedFiles();
|
|
@@ -1231,6 +1201,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1231
1201
|
pluginVersion: f.pluginVersion ?? undefined,
|
|
1232
1202
|
forkPluginRevision: f.forkPluginRevision ?? null,
|
|
1233
1203
|
pluginUpdateAvailable: f.pluginUpdateAvailable || undefined,
|
|
1204
|
+
pluginUpdateHint: f.pluginUpdateAvailable
|
|
1205
|
+
? pluginUpdateHint(f.forkPluginRevision, this.getPluginPath())
|
|
1206
|
+
: undefined,
|
|
1234
1207
|
}));
|
|
1235
1208
|
})(),
|
|
1236
1209
|
currentSelection: (() => {
|
|
@@ -1258,7 +1231,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1258
1231
|
: this.wsStartupError?.code === "EADDRINUSE"
|
|
1259
1232
|
? `❌ All WebSocket ports ${this.wsPreferredPort}-${this.wsPreferredPort + 9} are in use`
|
|
1260
1233
|
: this.wsActualPort !== null && this.wsActualPort !== this.wsPreferredPort
|
|
1261
|
-
? `❌ 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.`
|
|
1262
1235
|
: "❌ No connection to Figma Desktop",
|
|
1263
1236
|
setupInstructions: !setupValid
|
|
1264
1237
|
? this.wsStartupError?.code === "EADDRINUSE"
|
|
@@ -1267,15 +1240,15 @@ class LocalFigmaConsoleMCP {
|
|
|
1267
1240
|
fix: "Close some of the other Claude Desktop tabs or terminal sessions running the MCP server, then restart this one.",
|
|
1268
1241
|
}
|
|
1269
1242
|
: {
|
|
1270
|
-
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() : ''}`,
|
|
1271
1244
|
}
|
|
1272
1245
|
: undefined,
|
|
1273
1246
|
ai_instruction: !setupValid
|
|
1274
1247
|
? this.wsStartupError?.code === "EADDRINUSE"
|
|
1275
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.`
|
|
1276
1249
|
: this.wsActualPort !== null && this.wsActualPort !== this.wsPreferredPort
|
|
1277
|
-
? `Server is running on fallback port ${this.wsActualPort} (port ${this.wsPreferredPort} was taken by another instance). The
|
|
1278
|
-
: `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() : ''}`
|
|
1279
1252
|
: activeTransport === "websocket"
|
|
1280
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.`
|
|
1281
1254
|
: "All tools are ready to use.",
|
|
@@ -1321,7 +1294,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1321
1294
|
// success criterion here.
|
|
1322
1295
|
if (!this.wsServer?.isClientConnected()) {
|
|
1323
1296
|
throw new Error("Cannot connect to Figma Desktop.\n\n" +
|
|
1324
|
-
"Open the
|
|
1297
|
+
"Open the " + PLUGIN_NAME + " plugin in Figma (" + PLUGIN_MENU_PATH + ").");
|
|
1325
1298
|
}
|
|
1326
1299
|
const connector = await this.getDesktopConnector();
|
|
1327
1300
|
const probe = async () => connector.executeCodeViaUI("return { fileName: figma.root.name, fileKey: figma.fileKey }", 5000);
|
|
@@ -1347,9 +1320,9 @@ class LocalFigmaConsoleMCP {
|
|
|
1347
1320
|
}
|
|
1348
1321
|
}
|
|
1349
1322
|
if (!fileInfo.success) {
|
|
1350
|
-
const probeErr = new Error("
|
|
1323
|
+
const probeErr = new Error("The " + PLUGIN_NAME + " plugin's socket is open but it is not responding to commands " +
|
|
1351
1324
|
"(automatic plugin reload was attempted and did not help). " +
|
|
1352
|
-
"Close and reopen the
|
|
1325
|
+
"Close and reopen the " + PLUGIN_NAME + " plugin in Figma Desktop (" + PLUGIN_MENU_PATH + ").");
|
|
1353
1326
|
probeErr.connectionError = this.buildConnectionError(probeErr);
|
|
1354
1327
|
throw probeErr;
|
|
1355
1328
|
}
|
|
@@ -1382,7 +1355,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1382
1355
|
text: JSON.stringify({
|
|
1383
1356
|
error: error instanceof Error ? error.message : String(error),
|
|
1384
1357
|
message: "Failed to reconnect to Figma Desktop",
|
|
1385
|
-
hint: "Open the
|
|
1358
|
+
hint: "Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma",
|
|
1386
1359
|
connectionError: this.buildConnectionError(error),
|
|
1387
1360
|
}),
|
|
1388
1361
|
},
|
|
@@ -1396,7 +1369,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1396
1369
|
// ============================================================================
|
|
1397
1370
|
// Tool: Get current user selection in Figma
|
|
1398
1371
|
server.registerTool("figma_get_selection", {
|
|
1399
|
-
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.",
|
|
1400
1373
|
inputSchema: z.object({
|
|
1401
1374
|
verbose: z
|
|
1402
1375
|
.boolean()
|
|
@@ -1412,7 +1385,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1412
1385
|
content: [{
|
|
1413
1386
|
type: "text",
|
|
1414
1387
|
text: JSON.stringify({
|
|
1415
|
-
error: "WebSocket not connected. Open the
|
|
1388
|
+
error: "WebSocket not connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.",
|
|
1416
1389
|
selection: null,
|
|
1417
1390
|
}),
|
|
1418
1391
|
}],
|
|
@@ -1492,7 +1465,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1492
1465
|
});
|
|
1493
1466
|
// Tool: Get recent design changes
|
|
1494
1467
|
server.registerTool("figma_get_design_changes", {
|
|
1495
|
-
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.",
|
|
1496
1469
|
inputSchema: z.object({
|
|
1497
1470
|
since: z
|
|
1498
1471
|
.number()
|
|
@@ -1515,7 +1488,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1515
1488
|
content: [{
|
|
1516
1489
|
type: "text",
|
|
1517
1490
|
text: JSON.stringify({
|
|
1518
|
-
error: "WebSocket not connected. Open the
|
|
1491
|
+
error: "WebSocket not connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.",
|
|
1519
1492
|
changes: [],
|
|
1520
1493
|
}),
|
|
1521
1494
|
}],
|
|
@@ -1572,7 +1545,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1572
1545
|
});
|
|
1573
1546
|
// Tool: List all open files connected via WebSocket
|
|
1574
1547
|
server.registerTool("figma_list_open_files", {
|
|
1575
|
-
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.",
|
|
1576
1549
|
inputSchema: z.object({}),
|
|
1577
1550
|
}, async () => {
|
|
1578
1551
|
try {
|
|
@@ -1581,7 +1554,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1581
1554
|
content: [{
|
|
1582
1555
|
type: "text",
|
|
1583
1556
|
text: JSON.stringify({
|
|
1584
|
-
error: "No files connected. Open the
|
|
1557
|
+
error: "No files connected. Open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma to connect files.",
|
|
1585
1558
|
files: [],
|
|
1586
1559
|
}),
|
|
1587
1560
|
}],
|
|
@@ -1657,10 +1630,10 @@ class LocalFigmaConsoleMCP {
|
|
|
1657
1630
|
...result,
|
|
1658
1631
|
warning: [
|
|
1659
1632
|
componentsError
|
|
1660
|
-
? `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.`
|
|
1661
1634
|
: null,
|
|
1662
1635
|
variablesError
|
|
1663
|
-
? `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.`
|
|
1664
1637
|
: null,
|
|
1665
1638
|
]
|
|
1666
1639
|
.filter(Boolean)
|
|
@@ -1683,7 +1656,6 @@ class LocalFigmaConsoleMCP {
|
|
|
1683
1656
|
}),
|
|
1684
1657
|
}, async ({ forceRefresh }) => {
|
|
1685
1658
|
try {
|
|
1686
|
-
const { getCategories, getTokenSummary } = await import("./core/design-system-manifest.js");
|
|
1687
1659
|
const { cacheEntry, fileKey, wasLoaded, componentsError, variablesError } = await ensureDesignSystemCache({ forceRefresh });
|
|
1688
1660
|
const categories = getCategories(cacheEntry.manifest);
|
|
1689
1661
|
const tokenSummary = getTokenSummary(cacheEntry.manifest);
|
|
@@ -1729,10 +1701,10 @@ class LocalFigmaConsoleMCP {
|
|
|
1729
1701
|
warnings: componentsError || variablesError
|
|
1730
1702
|
? [
|
|
1731
1703
|
componentsError
|
|
1732
|
-
? `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.`
|
|
1733
1705
|
: null,
|
|
1734
1706
|
variablesError
|
|
1735
|
-
? `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.`
|
|
1736
1708
|
: null,
|
|
1737
1709
|
].filter(Boolean)
|
|
1738
1710
|
: undefined,
|
|
@@ -1750,7 +1722,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1750
1722
|
type: "text",
|
|
1751
1723
|
text: JSON.stringify({
|
|
1752
1724
|
error: error instanceof Error ? error.message : String(error),
|
|
1753
|
-
hint: "Make sure the
|
|
1725
|
+
hint: "Make sure the " + PLUGIN_NAME_WITH_OLD + " plugin is running in Figma",
|
|
1754
1726
|
}),
|
|
1755
1727
|
},
|
|
1756
1728
|
],
|
|
@@ -1799,7 +1771,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
1799
1771
|
// Determine if this is a library search or local search
|
|
1800
1772
|
let resolvedLibraryKey = libraryFileKey;
|
|
1801
1773
|
if (!resolvedLibraryKey && libraryFileUrl) {
|
|
1802
|
-
const { extractFileKey } = await import("./core/figma-api.js");
|
|
1803
1774
|
resolvedLibraryKey = extractFileKey(libraryFileUrl) ?? undefined;
|
|
1804
1775
|
}
|
|
1805
1776
|
// LIBRARY SEARCH PATH: Use REST API for cross-file access
|
|
@@ -1920,23 +1891,8 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
1920
1891
|
};
|
|
1921
1892
|
}
|
|
1922
1893
|
// LOCAL SEARCH PATH: Use cached design system manifest (existing behavior)
|
|
1923
|
-
const { searchComponents } = await import("./core/design-system-manifest.js");
|
|
1924
1894
|
// Auto-load design system cache if needed (no error returned to user)
|
|
1925
1895
|
const { cacheEntry, warning: cacheWarning } = await ensureDesignSystemCache();
|
|
1926
|
-
if (!cacheEntry) {
|
|
1927
|
-
return {
|
|
1928
|
-
content: [
|
|
1929
|
-
{
|
|
1930
|
-
type: "text",
|
|
1931
|
-
text: JSON.stringify({
|
|
1932
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
1933
|
-
hint: "If you're trying to search a published library from another file, pass the libraryFileKey or libraryFileUrl parameter.",
|
|
1934
|
-
}),
|
|
1935
|
-
},
|
|
1936
|
-
],
|
|
1937
|
-
isError: true,
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
1896
|
const effectiveLimit = Math.min(limit || 10, 25);
|
|
1941
1897
|
const results = searchComponents(cacheEntry.manifest, query || "", {
|
|
1942
1898
|
category,
|
|
@@ -2013,19 +1969,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2013
1969
|
}
|
|
2014
1970
|
// Auto-load design system cache if needed
|
|
2015
1971
|
const { cacheEntry, warning } = await ensureDesignSystemCache();
|
|
2016
|
-
if (!cacheEntry) {
|
|
2017
|
-
return {
|
|
2018
|
-
content: [
|
|
2019
|
-
{
|
|
2020
|
-
type: "text",
|
|
2021
|
-
text: JSON.stringify({
|
|
2022
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
2023
|
-
}),
|
|
2024
|
-
},
|
|
2025
|
-
],
|
|
2026
|
-
isError: true,
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
1972
|
// Search for the component
|
|
2030
1973
|
let component = null;
|
|
2031
1974
|
let isComponentSet = false;
|
|
@@ -2121,19 +2064,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2121
2064
|
try {
|
|
2122
2065
|
// Auto-load design system cache if needed
|
|
2123
2066
|
const { cacheEntry, warning } = await ensureDesignSystemCache();
|
|
2124
|
-
if (!cacheEntry) {
|
|
2125
|
-
return {
|
|
2126
|
-
content: [
|
|
2127
|
-
{
|
|
2128
|
-
type: "text",
|
|
2129
|
-
text: JSON.stringify({
|
|
2130
|
-
error: "Could not load design system data. Make sure the Desktop Bridge plugin is running.",
|
|
2131
|
-
}),
|
|
2132
|
-
},
|
|
2133
|
-
],
|
|
2134
|
-
isError: true,
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
2067
|
const tokens = cacheEntry.manifest.tokens;
|
|
2138
2068
|
const effectiveLimit = Math.min(limit || 50, 100);
|
|
2139
2069
|
const filterLower = filter?.toLowerCase();
|
|
@@ -2245,7 +2175,6 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2245
2175
|
// Resolve file key from URL or direct key
|
|
2246
2176
|
let fileKey = libraryFileKey;
|
|
2247
2177
|
if (!fileKey && libraryFileUrl) {
|
|
2248
|
-
const { extractFileKey } = await import("./core/figma-api.js");
|
|
2249
2178
|
fileKey = extractFileKey(libraryFileUrl) ?? undefined;
|
|
2250
2179
|
if (!fileKey) {
|
|
2251
2180
|
return {
|
|
@@ -2531,6 +2460,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2531
2460
|
},
|
|
2532
2461
|
getBundledPluginVersion,
|
|
2533
2462
|
getBundledForkPluginRevision,
|
|
2463
|
+
getPluginPath: () => this.getPluginPath(),
|
|
2534
2464
|
getPluginState: () => {
|
|
2535
2465
|
if (!this.wsServer)
|
|
2536
2466
|
return null;
|
|
@@ -2568,7 +2498,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2568
2498
|
registerTokenBrowserApp(server, async (fileUrl) => {
|
|
2569
2499
|
const url = fileUrl || this.getCurrentFileUrl();
|
|
2570
2500
|
if (!url) {
|
|
2571
|
-
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.");
|
|
2572
2502
|
}
|
|
2573
2503
|
const urlInfo = extractFigmaUrlInfo(url);
|
|
2574
2504
|
if (!urlInfo) {
|
|
@@ -2649,7 +2579,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2649
2579
|
const api = await this.getFigmaAPI();
|
|
2650
2580
|
const { local, localError } = await api.getAllVariables(fileKey);
|
|
2651
2581
|
if (localError) {
|
|
2652
|
-
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}`);
|
|
2653
2583
|
}
|
|
2654
2584
|
// Cache in the shared array shape, unless the cache was invalidated while it was read
|
|
2655
2585
|
const restData = restVariablesCacheData(fileKey, local);
|
|
@@ -2666,7 +2596,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2666
2596
|
registerDesignSystemDashboardApp(server, async (fileUrl) => {
|
|
2667
2597
|
const url = fileUrl || this.getCurrentFileUrl();
|
|
2668
2598
|
if (!url) {
|
|
2669
|
-
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.");
|
|
2670
2600
|
}
|
|
2671
2601
|
const urlInfo = extractFigmaUrlInfo(url);
|
|
2672
2602
|
if (!urlInfo) {
|
|
@@ -2756,19 +2686,19 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2756
2686
|
if (!variablesAvailable) {
|
|
2757
2687
|
if (desktopBridgeFailed && restApiFailed) {
|
|
2758
2688
|
variableError =
|
|
2759
|
-
"
|
|
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.";
|
|
2760
2690
|
}
|
|
2761
2691
|
else if (desktopBridgeFailed) {
|
|
2762
2692
|
variableError =
|
|
2763
|
-
"
|
|
2693
|
+
"The " + PLUGIN_NAME + " plugin is not connected. Please open the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma to enable variable/token analysis.";
|
|
2764
2694
|
}
|
|
2765
2695
|
else if (restApiFailed) {
|
|
2766
2696
|
variableError =
|
|
2767
|
-
"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.";
|
|
2768
2698
|
}
|
|
2769
2699
|
else if (!desktopBridgeAttempted && !restApiAttempted) {
|
|
2770
2700
|
variableError =
|
|
2771
|
-
"No variable fetch methods available. Connect the
|
|
2701
|
+
"No variable fetch methods available. Connect the " + PLUGIN_NAME_WITH_OLD + " plugin in Figma.";
|
|
2772
2702
|
}
|
|
2773
2703
|
}
|
|
2774
2704
|
// Fetch file metadata, components, component sets, and styles via REST API
|
|
@@ -2987,7 +2917,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2987
2917
|
bundledPluginVersion: getBundledPluginVersion(),
|
|
2988
2918
|
config: this.config,
|
|
2989
2919
|
}, `Starting Figma Console MCP v${SERVER_VERSION} (Local Mode)`);
|
|
2990
|
-
// Copy plugin files to
|
|
2920
|
+
// Copy plugin files to the plugin's own import directory
|
|
2991
2921
|
// so users have a permanent import path that survives npx cache changes.
|
|
2992
2922
|
try {
|
|
2993
2923
|
const thisFile = fileURLToPath(import.meta.url);
|
|
@@ -3265,12 +3195,11 @@ if (currentFile === entryFile) {
|
|
|
3265
3195
|
"Import plugin from manifest). The MCP server refreshes the\n" +
|
|
3266
3196
|
"plugin files in this directory on every startup.\n" +
|
|
3267
3197
|
"\n" +
|
|
3268
|
-
"
|
|
3269
|
-
"
|
|
3270
|
-
"
|
|
3271
|
-
"
|
|
3272
|
-
"
|
|
3273
|
-
"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");
|
|
3274
3203
|
process.exit(0);
|
|
3275
3204
|
}
|
|
3276
3205
|
// Fallback to npm package path
|
|
@@ -3281,7 +3210,7 @@ if (currentFile === entryFile) {
|
|
|
3281
3210
|
}
|
|
3282
3211
|
// Last resort: print the stable dir path even if it doesn't exist yet
|
|
3283
3212
|
// (the server will create it on first startup)
|
|
3284
|
-
const stableDir = join(
|
|
3213
|
+
const stableDir = join(pluginImportDir(), "manifest.json");
|
|
3285
3214
|
console.log(stableDir);
|
|
3286
3215
|
console.error("\nNote: This path will be populated when the MCP server starts.");
|
|
3287
3216
|
process.exit(0);
|