@muloka/figma-console-mcp 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/core/design-code-tools.js +2 -2
- package/dist/core/design-code-tools.js.map +1 -1
- package/dist/core/design-system-manifest.d.ts +37 -2
- package/dist/core/design-system-manifest.d.ts.map +1 -1
- package/dist/core/design-system-manifest.js +85 -0
- package/dist/core/design-system-manifest.js.map +1 -1
- package/dist/core/diagnose-tool.d.ts +4 -0
- package/dist/core/diagnose-tool.d.ts.map +1 -1
- package/dist/core/diagnose-tool.js +6 -1
- package/dist/core/diagnose-tool.js.map +1 -1
- package/dist/core/figma-connector.d.ts +14 -3
- package/dist/core/figma-connector.d.ts.map +1 -1
- package/dist/core/figma-tools.d.ts.map +1 -1
- package/dist/core/figma-tools.js +53 -18
- package/dist/core/figma-tools.js.map +1 -1
- package/dist/core/identity.d.ts +30 -6
- package/dist/core/identity.d.ts.map +1 -1
- package/dist/core/identity.js +60 -10
- package/dist/core/identity.js.map +1 -1
- package/dist/core/tokens-tools.d.ts.map +1 -1
- package/dist/core/tokens-tools.js +4 -8
- package/dist/core/tokens-tools.js.map +1 -1
- package/dist/core/tool-annotations.d.ts +53 -0
- package/dist/core/tool-annotations.d.ts.map +1 -0
- package/dist/core/tool-annotations.js +214 -0
- package/dist/core/tool-annotations.js.map +1 -0
- package/dist/core/variable-resolver.d.ts.map +1 -1
- package/dist/core/variable-resolver.js +1 -4
- package/dist/core/variable-resolver.js.map +1 -1
- package/dist/core/websocket-connector.d.ts +2 -4
- package/dist/core/websocket-connector.d.ts.map +1 -1
- package/dist/core/websocket-connector.js +26 -36
- package/dist/core/websocket-connector.js.map +1 -1
- package/dist/core/websocket-server.d.ts +36 -2
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +69 -8
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/local.d.ts +1 -0
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +67 -111
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/code.js +23 -2
- package/package.json +2 -2
package/dist/local.js
CHANGED
|
@@ -37,21 +37,27 @@ import { registerAccessibilityTools } from "./core/accessibility-tools.js";
|
|
|
37
37
|
import { registerDiagnoseTool } from "./core/diagnose-tool.js";
|
|
38
38
|
import { registerWriteTools } from "./core/write-tools.js";
|
|
39
39
|
import { registerTokensTools } from "./core/tokens-tools.js";
|
|
40
|
-
import { withToolIdentity } from "./core/identity.js";
|
|
40
|
+
import { MAX_TOOL_RESPONSE_BYTES, withToolIdentity } from "./core/identity.js";
|
|
41
41
|
import { PACKAGE_ROOT } from "./core/resolve-package-root.js";
|
|
42
|
-
import { FigmaWebSocketServer, getBundledPluginVersion, heldPinStatusWarning, } from "./core/websocket-server.js";
|
|
42
|
+
import { FigmaWebSocketServer, getBundledPluginVersion, getBundledForkPluginRevision, heldPinStatusWarning, } from "./core/websocket-server.js";
|
|
43
43
|
import { WebSocketConnector } from "./core/websocket-connector.js";
|
|
44
|
+
import { invalidateAfterVariableWrite } from "./core/design-system-manifest.js";
|
|
44
45
|
import { DEFAULT_WS_PORT, getPortRange, advertisePort, unadvertisePort, registerPortCleanup, startPeriodicReaper, discoverActiveInstances, cleanupStalePortFiles, cleanupOrphanedProcesses, evictOldestInstance, refreshPortAdvertisement, setAdvertisedMcpHttpPort, HEARTBEAT_INTERVAL_MS, } from "./core/port-discovery.js";
|
|
45
46
|
import { registerTokenBrowserApp } from "./apps/token-browser/server.js";
|
|
46
47
|
import { registerDesignSystemDashboardApp } from "./apps/design-system-dashboard/server.js";
|
|
47
48
|
import { registerFigJamTools } from "./core/figjam-tools.js";
|
|
48
49
|
import { registerSlidesTools } from "./core/slides-tools.js";
|
|
49
50
|
import { registerSlotTools } from "./core/slot-tools.js";
|
|
51
|
+
import { applyToolAnnotations } from "./core/tool-annotations.js";
|
|
50
52
|
const logger = createChildLogger({ component: "local-server" });
|
|
51
53
|
// Every McpServer this process builds (stdio and per-request HTTP) stamps tool
|
|
52
54
|
// responses and thrown errors with our MCP identity, so LLMs can attribute
|
|
53
55
|
// output unambiguously when several Figma-related MCPs are connected.
|
|
54
56
|
const IdentifiedMcpServer = withToolIdentity(McpServer);
|
|
57
|
+
// stdio additionally withholds a result above MAX_TOOL_RESPONSE_BYTES: an MCP
|
|
58
|
+
// client drops the connection when one message gets too large. HTTP is not
|
|
59
|
+
// capped (IdentifiedMcpServer).
|
|
60
|
+
const StdioMcpServer = withToolIdentity(McpServer, { maxResponseBytes: MAX_TOOL_RESPONSE_BYTES });
|
|
55
61
|
/** Largest JSON-RPC body the MCP_HTTP_PORT endpoint reads (both protocol eras). */
|
|
56
62
|
const MAX_HTTP_BODY_BYTES = 4 * 1024 * 1024;
|
|
57
63
|
/** Read and parse a JSON request body, refusing oversized or malformed ones. */
|
|
@@ -214,10 +220,13 @@ class LocalFigmaConsoleMCP {
|
|
|
214
220
|
* to ensure the next figma_get_variables call returns fresh data.
|
|
215
221
|
*/
|
|
216
222
|
invalidateVariablesCache() {
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
// Also drops every cached design-system manifest: a variable write that
|
|
224
|
+
// touches no node fires no documentChange, so nothing else would, and the
|
|
225
|
+
// summary / token-value tools would serve pre-write tokens (#14).
|
|
226
|
+
const hadVariables = this.variablesCache.size > 0;
|
|
227
|
+
invalidateAfterVariableWrite(this.variablesCache);
|
|
228
|
+
if (hadVariables)
|
|
219
229
|
logger.info('Variables cache invalidated after write operation');
|
|
220
|
-
}
|
|
221
230
|
}
|
|
222
231
|
constructor() {
|
|
223
232
|
this.figmaAPI = null;
|
|
@@ -243,7 +252,7 @@ class LocalFigmaConsoleMCP {
|
|
|
243
252
|
this.variablesCache = new Map();
|
|
244
253
|
/** Stable plugin directory path (set during startup) */
|
|
245
254
|
this.stablePluginPath = null;
|
|
246
|
-
this.server = new
|
|
255
|
+
this.server = new StdioMcpServer({
|
|
247
256
|
name: "Figma Console MCP (Local)",
|
|
248
257
|
version: SERVER_VERSION,
|
|
249
258
|
}, {
|
|
@@ -1148,6 +1157,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1148
1157
|
// connected files compares against THIS, not the server
|
|
1149
1158
|
// version (which can be newer on server-only releases).
|
|
1150
1159
|
bundledPluginVersion: getBundledPluginVersion(),
|
|
1160
|
+
bundledForkPluginRevision: getBundledForkPluginRevision(),
|
|
1151
1161
|
port: this.wsActualPort ? String(this.wsActualPort) : null,
|
|
1152
1162
|
preferredPort: String(this.wsPreferredPort),
|
|
1153
1163
|
...(this.wsServer?.loopbackFallback
|
|
@@ -1183,6 +1193,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1183
1193
|
currentPage: wsFileInfo.currentPage,
|
|
1184
1194
|
connectedAt: new Date(wsFileInfo.connectedAt).toISOString(),
|
|
1185
1195
|
pluginVersion: wsFileInfo.pluginVersion ?? undefined,
|
|
1196
|
+
forkPluginRevision: wsFileInfo.forkPluginRevision ?? null,
|
|
1186
1197
|
pluginUpdateAvailable: wsFileInfo.pluginUpdateAvailable || undefined,
|
|
1187
1198
|
} : undefined,
|
|
1188
1199
|
connectedFiles: (() => {
|
|
@@ -1197,6 +1208,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1197
1208
|
isActive: f.isActive,
|
|
1198
1209
|
connectedAt: new Date(f.connectedAt).toISOString(),
|
|
1199
1210
|
pluginVersion: f.pluginVersion ?? undefined,
|
|
1211
|
+
forkPluginRevision: f.forkPluginRevision ?? null,
|
|
1200
1212
|
pluginUpdateAvailable: f.pluginUpdateAvailable || undefined,
|
|
1201
1213
|
}));
|
|
1202
1214
|
})(),
|
|
@@ -1612,7 +1624,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1612
1624
|
// then get details for specific components.
|
|
1613
1625
|
// Helper function to ensure design system cache is loaded (auto-loads if needed)
|
|
1614
1626
|
const ensureDesignSystemCache = async () => {
|
|
1615
|
-
const { DesignSystemManifestCache, createEmptyManifest,
|
|
1627
|
+
const { DesignSystemManifestCache, createEmptyManifest, loadManifestVariables, } = await import("./core/design-system-manifest.js");
|
|
1616
1628
|
const cache = DesignSystemManifestCache.getInstance();
|
|
1617
1629
|
const currentUrl = this.getCurrentFileUrl();
|
|
1618
1630
|
// extractFileKey is branch-aware: on /design/KEY/branch/BRANCH_KEY/…
|
|
@@ -1630,48 +1642,12 @@ class LocalFigmaConsoleMCP {
|
|
|
1630
1642
|
const connector = await this.getDesktopConnector();
|
|
1631
1643
|
const manifest = createEmptyManifest(fileKey);
|
|
1632
1644
|
manifest.fileUrl = currentUrl || undefined;
|
|
1633
|
-
// Get variables (tokens)
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
manifest.collections.push({
|
|
1640
|
-
id: collection.id,
|
|
1641
|
-
name: collection.name,
|
|
1642
|
-
modes: collection.modes.map((m) => ({
|
|
1643
|
-
modeId: m.modeId,
|
|
1644
|
-
name: m.name,
|
|
1645
|
-
})),
|
|
1646
|
-
defaultModeId: collection.defaultModeId,
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
for (const variable of variablesResult.data.variables || []) {
|
|
1650
|
-
const tokenName = variable.name;
|
|
1651
|
-
const defaultModeId = manifest.collections.find((c) => c.id === variable.variableCollectionId)?.defaultModeId;
|
|
1652
|
-
const defaultValue = defaultModeId
|
|
1653
|
-
? variable.valuesByMode?.[defaultModeId]
|
|
1654
|
-
: undefined;
|
|
1655
|
-
if (variable.resolvedType === "COLOR") {
|
|
1656
|
-
manifest.tokens.colors[tokenName] = {
|
|
1657
|
-
name: tokenName,
|
|
1658
|
-
value: figmaColorToHex(defaultValue),
|
|
1659
|
-
variableId: variable.id,
|
|
1660
|
-
scopes: variable.scopes,
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
|
-
else if (variable.resolvedType === "FLOAT") {
|
|
1664
|
-
manifest.tokens.spacing[tokenName] = {
|
|
1665
|
-
name: tokenName,
|
|
1666
|
-
value: typeof defaultValue === "number" ? defaultValue : 0,
|
|
1667
|
-
variableId: variable.id,
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
catch (error) {
|
|
1674
|
-
logger.warn({ error }, "Could not fetch variables during auto-load");
|
|
1645
|
+
// Get variables (tokens). A failed read is reported, and the manifest
|
|
1646
|
+
// is not cached, so a transient plugin error can't serve "0 tokens"
|
|
1647
|
+
// for the full TTL.
|
|
1648
|
+
const variablesFetchError = await loadManifestVariables(manifest, () => connector.readVariables(fileKey));
|
|
1649
|
+
if (variablesFetchError) {
|
|
1650
|
+
logger.warn({ error: variablesFetchError }, "Could not fetch variables during auto-load");
|
|
1675
1651
|
}
|
|
1676
1652
|
// Get components
|
|
1677
1653
|
// Maps are keyed by component key (unique) rather than name — same-named
|
|
@@ -1731,6 +1707,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1731
1707
|
colorPalette: Object.keys(manifest.tokens.colors).slice(0, 10),
|
|
1732
1708
|
spacingScale: Object.values(manifest.tokens.spacing)
|
|
1733
1709
|
.map((s) => s.value)
|
|
1710
|
+
.filter((v) => typeof v === "number")
|
|
1734
1711
|
.sort((a, b) => a - b)
|
|
1735
1712
|
.slice(0, 10),
|
|
1736
1713
|
typographyScale: [],
|
|
@@ -1739,7 +1716,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1739
1716
|
// Cache the result — but never cache a manifest built from a FAILED
|
|
1740
1717
|
// components fetch: serving an empty manifest as "cached" for the full
|
|
1741
1718
|
// TTL is exactly the "search returns 0 components" poisoning bug.
|
|
1742
|
-
if (!componentsFetchError) {
|
|
1719
|
+
if (!componentsFetchError && !variablesFetchError) {
|
|
1743
1720
|
cache.set(fileKey, manifest, rawComponents);
|
|
1744
1721
|
cacheEntry = cache.get(fileKey);
|
|
1745
1722
|
}
|
|
@@ -1755,9 +1732,16 @@ class LocalFigmaConsoleMCP {
|
|
|
1755
1732
|
cacheEntry,
|
|
1756
1733
|
fileKey,
|
|
1757
1734
|
wasLoaded: true,
|
|
1758
|
-
warning:
|
|
1759
|
-
|
|
1760
|
-
|
|
1735
|
+
warning: [
|
|
1736
|
+
componentsFetchError
|
|
1737
|
+
? `Components fetch failed (${componentsFetchError}) — results may be incomplete and were NOT cached; retry after checking the Desktop Bridge plugin.`
|
|
1738
|
+
: null,
|
|
1739
|
+
variablesFetchError
|
|
1740
|
+
? `Variables fetch failed (${variablesFetchError}) — tokens are missing and the result was NOT cached; retry after checking the Desktop Bridge plugin.`
|
|
1741
|
+
: null,
|
|
1742
|
+
]
|
|
1743
|
+
.filter(Boolean)
|
|
1744
|
+
.join(" ") || undefined,
|
|
1761
1745
|
};
|
|
1762
1746
|
};
|
|
1763
1747
|
// ============================================================================
|
|
@@ -1776,7 +1760,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1776
1760
|
}),
|
|
1777
1761
|
}, async ({ forceRefresh }) => {
|
|
1778
1762
|
try {
|
|
1779
|
-
const { DesignSystemManifestCache, createEmptyManifest,
|
|
1763
|
+
const { DesignSystemManifestCache, createEmptyManifest, loadManifestVariables, getCategories, getTokenSummary, } = await import("./core/design-system-manifest.js");
|
|
1780
1764
|
const cache = DesignSystemManifestCache.getInstance();
|
|
1781
1765
|
const currentUrl = this.getCurrentFileUrl();
|
|
1782
1766
|
const fileKeyMatch = currentUrl?.match(/\/(file|design|board|slides)\/([a-zA-Z0-9]+)/);
|
|
@@ -1812,49 +1796,8 @@ class LocalFigmaConsoleMCP {
|
|
|
1812
1796
|
const connector = await this.getDesktopConnector();
|
|
1813
1797
|
const manifest = createEmptyManifest(fileKey);
|
|
1814
1798
|
manifest.fileUrl = currentUrl || undefined;
|
|
1815
|
-
// Get variables (tokens)
|
|
1816
|
-
|
|
1817
|
-
const variablesResult = await connector.getVariables(fileKey);
|
|
1818
|
-
if (variablesResult.success && variablesResult.data) {
|
|
1819
|
-
for (const collection of variablesResult.data
|
|
1820
|
-
.variableCollections || []) {
|
|
1821
|
-
manifest.collections.push({
|
|
1822
|
-
id: collection.id,
|
|
1823
|
-
name: collection.name,
|
|
1824
|
-
modes: collection.modes.map((m) => ({
|
|
1825
|
-
modeId: m.modeId,
|
|
1826
|
-
name: m.name,
|
|
1827
|
-
})),
|
|
1828
|
-
defaultModeId: collection.defaultModeId,
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
|
-
for (const variable of variablesResult.data.variables || []) {
|
|
1832
|
-
const tokenName = variable.name;
|
|
1833
|
-
const defaultModeId = manifest.collections.find((c) => c.id === variable.variableCollectionId)?.defaultModeId;
|
|
1834
|
-
const defaultValue = defaultModeId
|
|
1835
|
-
? variable.valuesByMode?.[defaultModeId]
|
|
1836
|
-
: undefined;
|
|
1837
|
-
if (variable.resolvedType === "COLOR") {
|
|
1838
|
-
manifest.tokens.colors[tokenName] = {
|
|
1839
|
-
name: tokenName,
|
|
1840
|
-
value: figmaColorToHex(defaultValue),
|
|
1841
|
-
variableId: variable.id,
|
|
1842
|
-
scopes: variable.scopes,
|
|
1843
|
-
};
|
|
1844
|
-
}
|
|
1845
|
-
else if (variable.resolvedType === "FLOAT") {
|
|
1846
|
-
manifest.tokens.spacing[tokenName] = {
|
|
1847
|
-
name: tokenName,
|
|
1848
|
-
value: typeof defaultValue === "number" ? defaultValue : 0,
|
|
1849
|
-
variableId: variable.id,
|
|
1850
|
-
};
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
catch (error) {
|
|
1856
|
-
logger.warn({ error }, "Could not fetch variables");
|
|
1857
|
-
}
|
|
1799
|
+
// Get variables (tokens); see ensureDesignSystemCache for the failure guard.
|
|
1800
|
+
const variablesFetchError = await loadManifestVariables(manifest, () => connector.readVariables(fileKey));
|
|
1858
1801
|
// Get components (can be slow for large files)
|
|
1859
1802
|
// Keyed by component key (unique) — name keys drop same-named
|
|
1860
1803
|
// components on other pages.
|
|
@@ -1913,6 +1856,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1913
1856
|
colorPalette: Object.keys(manifest.tokens.colors).slice(0, 10),
|
|
1914
1857
|
spacingScale: Object.values(manifest.tokens.spacing)
|
|
1915
1858
|
.map((s) => s.value)
|
|
1859
|
+
.filter((v) => typeof v === "number")
|
|
1916
1860
|
.sort((a, b) => a - b)
|
|
1917
1861
|
.slice(0, 10),
|
|
1918
1862
|
typographyScale: [],
|
|
@@ -1920,7 +1864,7 @@ class LocalFigmaConsoleMCP {
|
|
|
1920
1864
|
};
|
|
1921
1865
|
// Cache the result — never cache a manifest built from a failed
|
|
1922
1866
|
// components fetch (would serve empty results for the full TTL).
|
|
1923
|
-
if (!componentsFetchError) {
|
|
1867
|
+
if (!componentsFetchError && !variablesFetchError) {
|
|
1924
1868
|
cache.set(fileKey, manifest, rawComponents);
|
|
1925
1869
|
}
|
|
1926
1870
|
const categories = getCategories(manifest);
|
|
@@ -1940,10 +1884,15 @@ class LocalFigmaConsoleMCP {
|
|
|
1940
1884
|
componentSets: manifest.summary.totalComponentSets,
|
|
1941
1885
|
tokens: manifest.summary.totalTokens,
|
|
1942
1886
|
},
|
|
1943
|
-
warnings: componentsFetchError
|
|
1887
|
+
warnings: componentsFetchError || variablesFetchError
|
|
1944
1888
|
? [
|
|
1945
|
-
|
|
1946
|
-
|
|
1889
|
+
componentsFetchError
|
|
1890
|
+
? `Components fetch failed (${componentsFetchError}) — component data is incomplete and was NOT cached. Check the Desktop Bridge plugin and retry.`
|
|
1891
|
+
: null,
|
|
1892
|
+
variablesFetchError
|
|
1893
|
+
? `Variables fetch failed (${variablesFetchError}) — tokens are missing and the result was NOT cached. Check the Desktop Bridge plugin and retry.`
|
|
1894
|
+
: null,
|
|
1895
|
+
].filter(Boolean)
|
|
1947
1896
|
: undefined,
|
|
1948
1897
|
hint: "Use figma_search_components to find specific components by name or category.",
|
|
1949
1898
|
}),
|
|
@@ -2352,7 +2301,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2352
2301
|
if (count >= effectiveLimit)
|
|
2353
2302
|
break;
|
|
2354
2303
|
if (!filterLower || name.toLowerCase().includes(filterLower)) {
|
|
2355
|
-
colors[name] = { value: token.value, scopes: token.scopes };
|
|
2304
|
+
colors[name] = { value: token.value, scopes: token.scopes, ...(token.aliasOf ? { aliasOf: token.aliasOf } : {}) };
|
|
2356
2305
|
count++;
|
|
2357
2306
|
}
|
|
2358
2307
|
}
|
|
@@ -2365,7 +2314,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2365
2314
|
if (count >= effectiveLimit)
|
|
2366
2315
|
break;
|
|
2367
2316
|
if (!filterLower || name.toLowerCase().includes(filterLower)) {
|
|
2368
|
-
spacing[name] = { value: token.value };
|
|
2317
|
+
spacing[name] = { value: token.value, ...(token.aliasOf ? { aliasOf: token.aliasOf } : {}) };
|
|
2369
2318
|
count++;
|
|
2370
2319
|
}
|
|
2371
2320
|
}
|
|
@@ -2732,6 +2681,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2732
2681
|
}
|
|
2733
2682
|
},
|
|
2734
2683
|
getBundledPluginVersion,
|
|
2684
|
+
getBundledForkPluginRevision,
|
|
2735
2685
|
getPluginState: () => {
|
|
2736
2686
|
if (!this.wsServer)
|
|
2737
2687
|
return null;
|
|
@@ -2746,6 +2696,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2746
2696
|
port: this.wsActualPort ?? undefined,
|
|
2747
2697
|
portFallbackFrom: this.wsPreferredPort,
|
|
2748
2698
|
pluginVersion: fileInfo?.pluginVersion,
|
|
2699
|
+
forkPluginRevision: fileInfo?.forkPluginRevision ?? null,
|
|
2749
2700
|
pluginUpdateAvailable: fileInfo?.pluginUpdateAvailable,
|
|
2750
2701
|
};
|
|
2751
2702
|
},
|
|
@@ -2827,7 +2778,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2827
2778
|
// Priority 1: Try Desktop Bridge via transport-agnostic connector
|
|
2828
2779
|
try {
|
|
2829
2780
|
const connector = await this.getDesktopConnector();
|
|
2830
|
-
const desktopResult = await connector.
|
|
2781
|
+
const desktopResult = await connector.readVariables(fileKey);
|
|
2831
2782
|
if (desktopResult.success && desktopResult.variables) {
|
|
2832
2783
|
// Cache the desktop result
|
|
2833
2784
|
this.variablesCache.set(fileKey, {
|
|
@@ -2910,7 +2861,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
2910
2861
|
desktopBridgeAttempted = true;
|
|
2911
2862
|
try {
|
|
2912
2863
|
const connector = await this.getDesktopConnector();
|
|
2913
|
-
const desktopResult = await connector.
|
|
2864
|
+
const desktopResult = await connector.readVariables(fileKey);
|
|
2914
2865
|
if (desktopResult.success && desktopResult.variables) {
|
|
2915
2866
|
this.variablesCache.set(fileKey, {
|
|
2916
2867
|
data: {
|
|
@@ -3059,14 +3010,19 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3059
3010
|
() => this.getCurrentFileUrl());
|
|
3060
3011
|
logger.info("MCP Apps registered (ENABLE_MCP_APPS=true)");
|
|
3061
3012
|
}
|
|
3013
|
+
const unclassified = applyToolAnnotations(server);
|
|
3014
|
+
if (unclassified.length > 0)
|
|
3015
|
+
logger.warn({ unclassified }, "Tools registered without annotation hints");
|
|
3062
3016
|
logger.info("All MCP tools registered successfully (including write operations)");
|
|
3063
3017
|
}
|
|
3064
3018
|
/**
|
|
3065
3019
|
* A fresh, fully registered server: one per MCP_HTTP_PORT request (either
|
|
3066
3020
|
* era), or for a stdio connection that serveStdio re-pins to another era.
|
|
3021
|
+
* Only stdio servers cap oversized results.
|
|
3067
3022
|
*/
|
|
3068
|
-
createRequestServer() {
|
|
3069
|
-
const
|
|
3023
|
+
createRequestServer(transport) {
|
|
3024
|
+
const ServerClass = transport === "stdio" ? StdioMcpServer : IdentifiedMcpServer;
|
|
3025
|
+
const server = new ServerClass({ name: "Figma Console MCP (Local)", version: SERVER_VERSION }, { instructions: MCP_SERVER_INSTRUCTIONS });
|
|
3070
3026
|
this.registerTools(server);
|
|
3071
3027
|
return server;
|
|
3072
3028
|
}
|
|
@@ -3087,14 +3043,14 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3087
3043
|
}
|
|
3088
3044
|
// Both protocol eras are served at /mcp, each by a fresh server per request
|
|
3089
3045
|
// (IdentifiedMcpServer: every handler gets `_mcp` tagging and
|
|
3090
|
-
// `[figma-console-mcp]` error prefixing):
|
|
3046
|
+
// `[figma-console-mcp]` error prefixing, and results are never capped):
|
|
3091
3047
|
// - 2026-07-28 requests (per-request `_meta`, no initialize) go to the SDK's
|
|
3092
3048
|
// createMcpHandler. `legacy: "reject"` keeps its own stateless fallback
|
|
3093
3049
|
// from ever answering 2025-era traffic, which is routed below instead.
|
|
3094
3050
|
// - 2025-era requests keep this endpoint's stateless Streamable HTTP
|
|
3095
3051
|
// contract: no session id, one transport per request.
|
|
3096
3052
|
const reportModernError = (error) => logger.warn({ err: error.message }, "HTTP MCP (2026-07-28) request error");
|
|
3097
|
-
this.modernHttpHandler = createMcpHandler(() => this.createRequestServer(), {
|
|
3053
|
+
this.modernHttpHandler = createMcpHandler(() => this.createRequestServer("http"), {
|
|
3098
3054
|
legacy: "reject",
|
|
3099
3055
|
onerror: reportModernError,
|
|
3100
3056
|
maxRequestBodySize: MAX_HTTP_BODY_BYTES,
|
|
@@ -3138,7 +3094,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3138
3094
|
const transport = new NodeStreamableHTTPServerTransport({
|
|
3139
3095
|
sessionIdGenerator: undefined,
|
|
3140
3096
|
});
|
|
3141
|
-
const reqServer = this.createRequestServer();
|
|
3097
|
+
const reqServer = this.createRequestServer("http");
|
|
3142
3098
|
await reqServer.connect(transport);
|
|
3143
3099
|
res.once("close", () => {
|
|
3144
3100
|
reqServer.close().catch(() => { });
|
|
@@ -3381,7 +3337,7 @@ Without libraryFileKey/libraryFileUrl, searches the currently open file (local c
|
|
|
3381
3337
|
let stdioServerHandedOut = false;
|
|
3382
3338
|
serveStdio(() => {
|
|
3383
3339
|
if (stdioServerHandedOut)
|
|
3384
|
-
return this.createRequestServer();
|
|
3340
|
+
return this.createRequestServer("stdio");
|
|
3385
3341
|
stdioServerHandedOut = true;
|
|
3386
3342
|
return this.server;
|
|
3387
3343
|
}, { onerror: (error) => logger.error({ error }, "stdio transport error") });
|