@tempad-dev/mcp 0.10.0 → 0.11.0
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 +20 -4
- package/README.zh-Hans.md +16 -3
- package/dist/cli.mjs +1 -1
- package/dist/hub.mjs +86 -31
- package/dist/hub.mjs.map +1 -1
- package/dist/{shared-Dh112Muy.mjs → shared-FHsVNIOk.mjs} +57 -18
- package/dist/shared-FHsVNIOk.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/shared-Dh112Muy.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -43,17 +43,33 @@ Supported tools/resources:
|
|
|
43
43
|
resolves, validates, diffs, applies, and structurally verifies the result.
|
|
44
44
|
- `upload_asset`: A bounded Hub-only bridge from a programmatically composed generated PNG/JPEG/GIF
|
|
45
45
|
data URL to a content-addressed `assetHash` for `apply_canvas`; encoded bytes are never returned.
|
|
46
|
-
- `get_screenshot`: A bounded rendered PNG for selective visual validation.
|
|
47
|
-
- `get_structure`: Hierarchy/geometry outline for an exact node, page, or
|
|
46
|
+
- `get_screenshot`: A bounded rendered PNG per requested node for selective visual validation.
|
|
47
|
+
- `get_structure`: Hierarchy/geometry outline for an exact node, page, or one or more visible selected nodes, including stable authoring keys on
|
|
48
48
|
TemPad-managed nodes and optional native mask, IMAGE paint, layout-grid, and frame-guide read-back.
|
|
49
49
|
|
|
50
50
|
Notes:
|
|
51
51
|
|
|
52
|
+
- `get_code`, `get_structure`, and `get_screenshot` accept `nodeIds` or the current multi-selection.
|
|
53
|
+
Single `nodeId` calls retain their existing result shape. Code and screenshots return independent
|
|
54
|
+
`{ nodeId, result }` or `{ nodeId, error }` entries for batches; continue `remainingNodeIds` with
|
|
55
|
+
exact `nodeIds` and unchanged options. Structure retains exact roots, reports failed roots in
|
|
56
|
+
`errors`, and supports `options.depth: 0` for roots only. Node-set reads require matching Hub and
|
|
57
|
+
extension builds using bridge protocol 15; older peers cannot silently ignore the new selectors.
|
|
58
|
+
- `get_code.resolveTokens` controls code only. Both settings return token definitions with all
|
|
59
|
+
modes and aliases. Enabled resolution uses each actual consumer's effective Figma modes;
|
|
60
|
+
unresolved references remain in code with `token-resolution` warnings. Missing or ambiguous
|
|
61
|
+
definitions produce `token-definition` warnings. Warnings are bounded per node result.
|
|
62
|
+
This replaces older responses that flattened `tokens` when resolution was enabled; legacy
|
|
63
|
+
extensions must upgrade to use `resolveTokens: true`.
|
|
52
64
|
- Tool responses use a shared `64 KiB` inline budget measured on the `CallToolResult` body. When a selection is too large for the `get_code` budget, TemPad Dev may return a shell response instead of failing. The shell keeps the current node wrapper and lists omitted direct child ids in an inline code comment so agents can request them one by one. The accompanying warning stays lightweight and only points agents to that comment.
|
|
53
65
|
- `apply_canvas` is available whenever MCP access is enabled and the current Figma Design file is
|
|
54
66
|
editable. Dev Mode and view-only files remain read-only.
|
|
55
|
-
- MCP **0.
|
|
56
|
-
|
|
67
|
+
- MCP **0.11.0** pairs with extension **0.23.0** and Agent Plugin **0.4.0**.
|
|
68
|
+
The node-set and token-definition semantics above require matching protocol 15 Hub and extension
|
|
69
|
+
builds. Extension 0.22.0 remains supported through protocol 13 for existing reads, sessions,
|
|
70
|
+
tasks, and canvas writes. New read options prompt an upgrade, and responses identify older
|
|
71
|
+
selection/token semantics. Update the extension and reload Figma for the new capabilities, update
|
|
72
|
+
the plugin or installed skills, replace any alpha-pinned MCP configuration with `@tempad-dev/mcp@latest`,
|
|
57
73
|
then reconnect the MCP client and start a new task. See the
|
|
58
74
|
[upgrade guide](https://github.com/ecomfe/tempad-dev/tree/main/agent-plugin/src#upgrading).
|
|
59
75
|
- Assets are ephemeral and tool-linked. Local stdio clients receive `asset.localPath` when the Hub
|
package/README.zh-Hans.md
CHANGED
|
@@ -38,16 +38,29 @@ TemPad Dev 的 MCP server 将 coding agent 连接到浏览器中打开的 Figma
|
|
|
38
38
|
扩展会在本地解析、验证、计算与实时画布的差异、应用修改并校验结构。
|
|
39
39
|
- `upload_asset`:Hub 内的受限桥梁,把程序化串联生成的 PNG/JPEG/GIF data URL 存成供
|
|
40
40
|
`apply_canvas` 使用的 content-addressed `assetHash`,且不会返回编码后的图片字节。
|
|
41
|
-
- `get_screenshot
|
|
42
|
-
- `get_structure
|
|
41
|
+
- `get_screenshot`:为每个请求的节点返回有大小限制的渲染 PNG,用于按需视觉验证。
|
|
42
|
+
- `get_structure`:精确节点、页面或当前选中的一个或多个可见节点的层级/几何结构信息,并返回 TemPad 已管理节点的稳定 authoring key;
|
|
43
43
|
还可按需读回原生遮罩、IMAGE paint、布局网格与画框参考线。
|
|
44
44
|
|
|
45
45
|
说明:
|
|
46
46
|
|
|
47
|
+
- `get_code`、`get_structure` 和 `get_screenshot` 接受 `nodeIds` 或当前多选,单个 `nodeId`
|
|
48
|
+
调用保留原有返回格式。代码和截图批量返回 `{ nodeId, result }` 或 `{ nodeId, error }`,
|
|
49
|
+
使用返回的 `remainingNodeIds` 作为 `nodeIds`,并保留原参数,即可继续读取。结构读取保留
|
|
50
|
+
真实根节点,在 `errors` 中报告失败节点;`options.depth: 0` 只读取根节点。多节点读取要求
|
|
51
|
+
Hub 和扩展使用匹配的 bridge protocol 15 构建,旧版不会静默忽略新的节点选择参数。
|
|
52
|
+
- `get_code.resolveTokens` 只控制代码;无论是否启用,`tokens` 都保留定义、全部模式和 alias。
|
|
53
|
+
启用后按每个实际消费节点的 Figma 有效模式解析;无法解析的引用保留在代码中,并返回
|
|
54
|
+
`token-resolution` warning。定义缺失或名称有歧义时返回 `token-definition` warning;
|
|
55
|
+
warning 按节点独立去重并限制大小。旧版启用该选项时会把 `tokens` 展开为字面量,
|
|
56
|
+
旧扩展需要升级才能使用 `resolveTokens: true`。
|
|
47
57
|
- 工具响应共用 `64 KiB` 的 inline budget,按 `CallToolResult` 整体响应体积计算。若选区过大而超出 `get_code` 的预算,TemPad Dev 可能返回 shell response 而不是直接失败。shell 会保留当前节点的包裹结构,并在内联代码注释中列出被省略的直接子节点 id,方便 agent 逐个继续拉取;配套 warning 只保留最小化的提示信息,用来指向这条注释。
|
|
48
58
|
- 启用 MCP access 且当前 Figma Design 文件可编辑时,`apply_canvas` 即可使用;Dev Mode 和
|
|
49
59
|
只读文件仍不可写。
|
|
50
|
-
- MCP **0.
|
|
60
|
+
- MCP **0.11.0** 配套扩展 **0.23.0** 和 Agent Plugin **0.4.0**。
|
|
61
|
+
上述多节点读取与 token 定义语义要求 Hub 和扩展均使用匹配的 protocol 15 构建。
|
|
62
|
+
扩展 0.22.0 仍通过 protocol 13 支持既有读取、会话、任务和画布写入。新版读取选项会提示升级,响应会标注旧版选区和 token 语义。
|
|
63
|
+
请更新扩展并重新加载 Figma 以启用新版能力,再更新 plugin 或已安装的 skill,
|
|
51
64
|
将固定 alpha 版本的 MCP 配置改为 `@tempad-dev/mcp@latest`,然后重新连接 MCP client 并新建任务。
|
|
52
65
|
详见[升级指南](https://github.com/ecomfe/tempad-dev/blob/main/agent-plugin/src/README.zh-Hans.md#升级)。
|
|
53
66
|
- 资源是临时且与工具调用关联的。本地 stdio client 在 Hub 持有字节时会收到
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as runtimeIdentity, c as RUNTIME_DIR, l as SOCK_PATH, o as LOCK_PATH, p as log, s as PACKAGE_VERSION, u as ensureDir } from "./shared-
|
|
2
|
+
import { _ as runtimeIdentity, c as RUNTIME_DIR, l as SOCK_PATH, o as LOCK_PATH, p as log, s as PACKAGE_VERSION, u as ensureDir } from "./shared-FHsVNIOk.mjs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { connect } from "node:net";
|
|
5
5
|
import { join } from "node:path";
|
package/dist/hub.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TEMPAD_MCP_BRIDGE_SUBPROTOCOL, A as GetScreenshotParametersSchema, B as MCP_GET_CODE_TIMEOUT_MS, C as DesignTaskSchema, D as GetCodeParametersSchema, E as GetAssetsResultSchema, G as MCP_NODE_READ_BATCH_WORK_BUDGET_MS, H as MCP_MAX_ASSET_BYTES, I as MCP_APPLY_CANVAS_TIMEOUT_MS, J as MCP_TOOL_TIMEOUT_MS, K as MCP_PORT_CANDIDATES, L as MCP_ASSET_TTL_MS, M as GetTokenDefsParametersSchema, N as LegacyMessageFromExtensionSchema, O as GetDesignSystemParametersSchema, P as LegacyToolCallPayloadSchema, Q as SetDesignAnchorParametersSchema, R as MCP_AUTO_ACTIVATE_GRACE_MS, S as DesignTaskIdSchema, T as GetAssetsParametersSchema, U as MCP_MAX_ASSET_STORE_BYTES, V as MCP_GET_DESIGN_SYSTEM_TIMEOUT_MS, W as MCP_MAX_PAYLOAD_BYTES, X as MessageFromExtensionSchema, Y as ManageDesignTaskParametersSchema, Z as RESUMABLE_DESIGN_TASK_STATUSES, a as HUB_RUNTIME_IDENTITY_PATH, at as buildGetAssetsToolResult, b as ApplyCanvasResultSchema, c as RUNTIME_DIR, ct as buildGetScreenshotToolResult, d as ensureFile, dt as buildUploadAssetToolResult, et as TEMPAD_MCP_BRIDGE_SUPPORTED_PROTOCOL_VERSIONS, f as getRecordProperty, ft as formatDesignFeedback, g as clientDescriptor, h as bindRequestMetadata, i as HUB_LOCK_UPDATE_MS, it as buildApplyCanvasToolResult, j as GetStructureParametersSchema, k as GetDesignSystemResultSchema, l as SOCK_PATH, lt as buildGetStructureToolResult, m as ClientEventSchema, mt as utf8Bytes, n as HUB_LOCK_PATH, nt as UploadAssetParametersSchema, ot as buildGetCodeToolResult, p as log, pt as measureCallToolResultBytes, q as MCP_TOOL_INLINE_BUDGET_BYTES, r as HUB_LOCK_STALE_MS, rt as UploadAssetResultSchema, s as PACKAGE_VERSION, st as buildGetDesignSystemToolResult, t as ASSET_DIR, tt as TEMPAD_MCP_ERROR_CODES, u as ensureDir, ut as buildGetTokenDefsToolResult, v as AGENT_CLIENTS, w as FigmaSessionSchema, x as DesignAnchorSchema, y as ApplyCanvasParametersSchema } from "./shared-FHsVNIOk.mjs";
|
|
2
2
|
import { execFile, spawn } from "node:child_process";
|
|
3
3
|
import { connect, createServer } from "node:net";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -240,7 +240,7 @@ async function codexQueueExecutable() {
|
|
|
240
240
|
"-o",
|
|
241
241
|
"comm="
|
|
242
242
|
], { timeout: 3e3 });
|
|
243
|
-
const paths = [...new Set(stdout.split(/\r?\n/).map((path) => path.trim()))].filter((path) => /[/\\]resources[/\\]codex(?:\.exe)?$/i.test(path));
|
|
243
|
+
const paths = [...new Set(stdout.split(/\r?\n/).map((path) => path.trim()))].filter((path) => /[/\\]resources[/\\](?:codex-cli[/\\]CodexCLI\.app[/\\]Contents[/\\]MacOS[/\\])?codex(?:\.exe)?$/i.test(path));
|
|
244
244
|
if (paths.length !== 1) throw new Error("The running Codex desktop executable could not be identified.");
|
|
245
245
|
return paths[0];
|
|
246
246
|
}
|
|
@@ -2479,7 +2479,7 @@ var DesignTaskStore = class {
|
|
|
2479
2479
|
//#endregion
|
|
2480
2480
|
//#region src/legacy-extension.ts
|
|
2481
2481
|
function extensionUpgradeRequired() {
|
|
2482
|
-
return Object.assign(/* @__PURE__ */ new Error("This operation requires TemPad Dev extension
|
|
2482
|
+
return Object.assign(/* @__PURE__ */ new Error("This operation requires a current TemPad Dev extension compatible with this Hub. Update the extension in Chrome, then reload the Figma tab and reconnect Agent integration. Until then, get_code, get_screenshot, and node-based get_structure remain available without a design task."), { code: TEMPAD_MCP_ERROR_CODES.EXTENSION_UPGRADE_REQUIRED });
|
|
2483
2483
|
}
|
|
2484
2484
|
function legacyToolPayload(name, args) {
|
|
2485
2485
|
const result = LegacyToolCallPayloadSchema.safeParse({
|
|
@@ -2487,6 +2487,7 @@ function legacyToolPayload(name, args) {
|
|
|
2487
2487
|
args
|
|
2488
2488
|
});
|
|
2489
2489
|
if (!result.success) throw extensionUpgradeRequired();
|
|
2490
|
+
if (result.data.name === "get_code" && result.data.args?.resolveTokens) throw Object.assign(/* @__PURE__ */ new Error("resolveTokens requires matching current Hub and extension builds. Update the extension, then reload the Figma tab and reconnect Agent integration. Older extensions flatten token definitions and cannot return consumer-aware code with preserved aliases."), { code: TEMPAD_MCP_ERROR_CODES.EXTENSION_UPGRADE_REQUIRED });
|
|
2490
2491
|
return result.data;
|
|
2491
2492
|
}
|
|
2492
2493
|
//#endregion
|
|
@@ -3013,7 +3014,7 @@ function attachExtensionSocket(ws, options) {
|
|
|
3013
3014
|
options.onConnected?.(extension.id);
|
|
3014
3015
|
const registered = {
|
|
3015
3016
|
id: extension.id,
|
|
3016
|
-
protocolVersion:
|
|
3017
|
+
protocolVersion: 15,
|
|
3017
3018
|
supportedProtocolVersions: [...TEMPAD_MCP_BRIDGE_SUPPORTED_PROTOCOL_VERSIONS],
|
|
3018
3019
|
type: "registered"
|
|
3019
3020
|
};
|
|
@@ -3074,20 +3075,29 @@ function attachExtensionSocket(ws, options) {
|
|
|
3074
3075
|
if (message.error !== void 0) options.onToolError(message.id, extension.id, message.error);
|
|
3075
3076
|
else options.onToolResult(message.id, extension.id, message.payload);
|
|
3076
3077
|
break;
|
|
3077
|
-
case "runtimeHello":
|
|
3078
|
-
|
|
3078
|
+
case "runtimeHello": {
|
|
3079
|
+
const protocolVersion = message.protocolVersion ?? 13;
|
|
3080
|
+
if (!TEMPAD_MCP_BRIDGE_SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
3081
|
+
ws.close(1008, "Unsupported extension bridge protocol.");
|
|
3082
|
+
break;
|
|
3083
|
+
}
|
|
3084
|
+
if (extension.runtime && (extension.runtime.version !== message.extensionVersion || extension.runtime.fingerprint !== message.extensionRuntimeFingerprint || extension.runtime.protocolVersion !== protocolVersion)) {
|
|
3079
3085
|
options.onProtocolWarning?.({
|
|
3080
3086
|
error: /* @__PURE__ */ new Error("Extension changed runtime identity on an open connection."),
|
|
3081
3087
|
extensionId: extension.id,
|
|
3082
3088
|
kind: "schema"
|
|
3083
3089
|
});
|
|
3090
|
+
ws.close(1008, "Extension changed runtime identity.");
|
|
3084
3091
|
break;
|
|
3085
3092
|
}
|
|
3086
3093
|
extension.runtime = {
|
|
3094
|
+
protocolVersion,
|
|
3087
3095
|
version: message.extensionVersion,
|
|
3088
3096
|
fingerprint: message.extensionRuntimeFingerprint
|
|
3089
3097
|
};
|
|
3090
3098
|
options.onRuntimeHello?.(extension);
|
|
3099
|
+
break;
|
|
3100
|
+
}
|
|
3091
3101
|
}
|
|
3092
3102
|
});
|
|
3093
3103
|
ws.on("error", (error) => {
|
|
@@ -3294,7 +3304,7 @@ const CONNECTIVITY_TROUBLESHOOTING_LINES = [
|
|
|
3294
3304
|
"- Badge-default reads require the intended tab's active MCP badge. Exact sessionId reads require that session in list_design_sessions; browser focus does not select a default.",
|
|
3295
3305
|
"- If the connection is missing or reports a protocol mismatch, rebuild the affected runtime layers, reload the installed TemPad Dev browser extension, reload the same Figma tab, and start a fresh task."
|
|
3296
3306
|
];
|
|
3297
|
-
const
|
|
3307
|
+
const MULTI_SELECTION_TROUBLESHOOTING_LINE = "Tip: Select one or more visible nodes, or pass nodeIds (nodeId for a single node).";
|
|
3298
3308
|
const VERIFICATION_TROUBLESHOOTING_LINE = "Tip: TemPad rolls verification failures back. Correct the reported desired-state mismatch and retry the affected root while preserving unrelated design intent.";
|
|
3299
3309
|
function isRecord(value) {
|
|
3300
3310
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3341,7 +3351,7 @@ const TOOL_DEFS = [
|
|
|
3341
3351
|
}),
|
|
3342
3352
|
extTool({
|
|
3343
3353
|
name: "get_code",
|
|
3344
|
-
description: "Read implementation evidence for
|
|
3354
|
+
description: "Read implementation evidence for exact nodeId/nodeIds or the current selection as JSX/Vue markup, classes, tokens, assets, codegen facts, and bounded warnings. Multi-selection and explicit nodeIds return independent results keyed by nodeId, including per-node errors. Continue remainingNodeIds with nodeIds and the same options. Single-node calls retain the flat result.",
|
|
3345
3355
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
3346
3356
|
parameters: GetCodeParametersSchema,
|
|
3347
3357
|
target: "extension",
|
|
@@ -3365,7 +3375,7 @@ const TOOL_DEFS = [
|
|
|
3365
3375
|
}),
|
|
3366
3376
|
extTool({
|
|
3367
3377
|
name: "get_token_defs",
|
|
3368
|
-
description: "
|
|
3378
|
+
description: "Read definitions for canonical token names referenced by get_code, preserving aliases and optionally all modes. Consumer-specific literal values belong to get_code with resolveTokens enabled.",
|
|
3369
3379
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
3370
3380
|
parameters: GetTokenDefsParametersSchema,
|
|
3371
3381
|
target: "extension",
|
|
@@ -3374,7 +3384,7 @@ const TOOL_DEFS = [
|
|
|
3374
3384
|
}),
|
|
3375
3385
|
extTool({
|
|
3376
3386
|
name: "get_screenshot",
|
|
3377
|
-
description: "Capture
|
|
3387
|
+
description: "Capture a bounded rendered PNG per exact nodeId/nodeIds or selected node. Multi-selection and explicit nodeIds return independent results keyed by nodeId, including per-node errors. Continue remainingNodeIds with nodeIds. Single-node calls retain the flat result. Open each returned PNG to visually verify it.",
|
|
3378
3388
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
3379
3389
|
parameters: GetScreenshotParametersSchema,
|
|
3380
3390
|
target: "extension",
|
|
@@ -3382,7 +3392,7 @@ const TOOL_DEFS = [
|
|
|
3382
3392
|
}),
|
|
3383
3393
|
extTool({
|
|
3384
3394
|
name: "get_structure",
|
|
3385
|
-
description: "Read a compact hierarchy and geometry outline for
|
|
3395
|
+
description: "Read a compact hierarchy and geometry outline for exact nodeId/nodeIds, exact page id/key, or the current selection. Exact roots are preserved before descendants consume the budget; options.depth: 0 returns roots only. Inspect errors and continue remainingNodeIds with nodeIds. Every x/y is relative to the node's actual Figma parent; page-query roots are page-relative. Includes stable keys on TemPad-managed nodes and exact page context for page queries. Set options.native for selected native read-back; this does not provide rendered pixels or general appearance.",
|
|
3386
3396
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
3387
3397
|
parameters: GetStructureParametersSchema,
|
|
3388
3398
|
target: "extension",
|
|
@@ -3438,7 +3448,7 @@ function createToolErrorResponse(toolName, error) {
|
|
|
3438
3448
|
function buildTroubleshootingText(code, message) {
|
|
3439
3449
|
const help = [];
|
|
3440
3450
|
if (isConnectivityToolError(code, message)) help.push(...CONNECTIVITY_TROUBLESHOOTING_LINES);
|
|
3441
|
-
if (isSelectionToolError(code, message)) help.push(
|
|
3451
|
+
if (isSelectionToolError(code, message)) help.push(MULTI_SELECTION_TROUBLESHOOTING_LINE);
|
|
3442
3452
|
if (code === TEMPAD_MCP_ERROR_CODES.INVALID_CANVAS_SPEC && /verification failed/i.test(message)) help.push(VERIFICATION_TROUBLESHOOTING_LINE);
|
|
3443
3453
|
return help.length ? `\n\n${help.join("\n")}` : "";
|
|
3444
3454
|
}
|
|
@@ -3446,10 +3456,10 @@ function isConnectivityToolError(code, message) {
|
|
|
3446
3456
|
return (code ? CONNECTIVITY_ERROR_CODES.has(code) : false) || /no active tempad dev extension/i.test(message) || /asset server url is not configured/i.test(message) || /\bwebsocket (?:connection )?(?:closed|disconnected|failed|unavailable|error)\b/i.test(message);
|
|
3447
3457
|
}
|
|
3448
3458
|
function isSelectionToolError(code, message) {
|
|
3449
|
-
return (code ? SELECTION_ERROR_CODES.has(code) : false) || /select exactly one visible node/i.test(message) || /no visible node found/i.test(message);
|
|
3459
|
+
return (code ? SELECTION_ERROR_CODES.has(code) : false) || /select exactly one visible node/i.test(message) || /select one or more visible nodes/i.test(message) || /no visible node found/i.test(message);
|
|
3450
3460
|
}
|
|
3451
3461
|
function createCodeToolResponse(payload) {
|
|
3452
|
-
return formatToolResult("get_code", payload, isCodeResult, buildGetCodeToolResult);
|
|
3462
|
+
return formatToolResult("get_code", payload, (value) => isCodeResult(value) || isNodeReadBatchResult(value, isCodeResult), buildGetCodeToolResult);
|
|
3453
3463
|
}
|
|
3454
3464
|
function createDesignSystemToolResponse(payload) {
|
|
3455
3465
|
return formatToolResult("get_design_system", payload, isDesignSystemResult, buildGetDesignSystemToolResult);
|
|
@@ -3464,7 +3474,7 @@ function createTokenDefsToolResponse(payload) {
|
|
|
3464
3474
|
return formatToolResult("get_token_defs", payload, isTokenDefsResult, buildGetTokenDefsToolResult);
|
|
3465
3475
|
}
|
|
3466
3476
|
function createScreenshotToolResponse(payload) {
|
|
3467
|
-
return formatToolResult("get_screenshot", payload, isScreenshotResult, buildGetScreenshotToolResult);
|
|
3477
|
+
return formatToolResult("get_screenshot", payload, (value) => isScreenshotResult(value) || isNodeReadBatchResult(value, isScreenshotResult), buildGetScreenshotToolResult);
|
|
3468
3478
|
}
|
|
3469
3479
|
function formatToolResult(toolName, payload, isValid, build) {
|
|
3470
3480
|
if (!isValid(payload)) throw new Error(`Invalid ${toolName} payload received from extension.`);
|
|
@@ -3482,6 +3492,9 @@ function isApplyCanvasResult(payload) {
|
|
|
3482
3492
|
function isCodeResult(payload) {
|
|
3483
3493
|
return isRecord(payload) && typeof payload.code === "string" && typeof payload.lang === "string" && (payload.assets === void 0 || Array.isArray(payload.assets));
|
|
3484
3494
|
}
|
|
3495
|
+
function isNodeReadBatchResult(payload, isResult) {
|
|
3496
|
+
return isRecord(payload) && Array.isArray(payload.results) && (payload.remainingNodeIds === void 0 || Array.isArray(payload.remainingNodeIds) && payload.remainingNodeIds.every((id) => typeof id === "string" && id.length > 0)) && payload.results.every((entry) => isRecord(entry) && typeof entry.nodeId === "string" && entry.nodeId.length > 0 && (entry.error === void 0 ? isResult(entry.result) : entry.result === void 0 && isRecord(entry.error) && typeof entry.error.message === "string" && (entry.error.code === void 0 || isTempadMcpErrorCode(entry.error.code))));
|
|
3497
|
+
}
|
|
3485
3498
|
function isStructureResult(payload) {
|
|
3486
3499
|
return isRecord(payload) && Array.isArray(payload.roots);
|
|
3487
3500
|
}
|
|
@@ -3553,6 +3566,24 @@ function getBudgetRetryGuidance(toolName) {
|
|
|
3553
3566
|
}
|
|
3554
3567
|
}
|
|
3555
3568
|
//#endregion
|
|
3569
|
+
//#region src/versioned-extension.ts
|
|
3570
|
+
const NODE_READS = /* @__PURE__ */ new Set([
|
|
3571
|
+
"get_code",
|
|
3572
|
+
"get_screenshot",
|
|
3573
|
+
"get_structure"
|
|
3574
|
+
]);
|
|
3575
|
+
/** Preserve protocol 13's wire arguments; never silently strip a newer read option. */
|
|
3576
|
+
function assertVersionedToolSupport(protocolVersion, name, args) {
|
|
3577
|
+
if (protocolVersion !== 13) return;
|
|
3578
|
+
if (!(NODE_READS.has(name) && getRecordProperty(args, "nodeIds") !== void 0 || name === "get_structure" && getRecordProperty(getRecordProperty(args, "options"), "depth") === 0 || name === "get_code" && getRecordProperty(args, "resolveTokens") === true)) return;
|
|
3579
|
+
throw Object.assign(/* @__PURE__ */ new Error("This read option requires TemPad Dev extension 0.23.0 or later. Update the extension and reload the Figma tab. Until then, use individual nodeId reads, positive structure depths, and unresolved token references. Existing sessions, design tasks, and canvas writes remain available."), { code: TEMPAD_MCP_ERROR_CODES.EXTENSION_UPGRADE_REQUIRED });
|
|
3580
|
+
}
|
|
3581
|
+
function versionedReadNotice(protocolVersion, name) {
|
|
3582
|
+
if (protocolVersion !== 13) return void 0;
|
|
3583
|
+
if (name === "get_code" || name === "get_token_defs") return "Protocol 13 compatibility: token metadata uses the installed extension’s original semantics; complete modes and alias dependencies are not guaranteed. Use exact nodeId reads for code. Upgrade the extension and reload Figma for consumer-aware resolution and complete definitions.";
|
|
3584
|
+
if (name === "get_structure" || name === "get_screenshot") return "Protocol 13 compatibility: omitted nodeId uses the installed extension’s original selection behavior; structure may use a common ancestor. Use exact nodeId reads to preserve each requested root.";
|
|
3585
|
+
}
|
|
3586
|
+
//#endregion
|
|
3556
3587
|
//#region src/websocket-server.ts
|
|
3557
3588
|
async function startExtensionWebSocketServer({ maxPayloadBytes, maxConnections, originPolicy, portCandidates, onPortInUse, onConnectionLimit, onRejectedHandshake }) {
|
|
3558
3589
|
for (const candidate of portCandidates) {
|
|
@@ -3996,6 +4027,7 @@ function registerProxiedTool(mcp, tool, ownerId) {
|
|
|
3996
4027
|
else if (tool.name === "get_design_system" && getRecordProperty(parsedArgs, "scope") !== "fonts" && getRecordProperty(parsedArgs, "scope") !== "pages" && !getRecordProperty(parsedArgs, "catalogId")) timeoutMs = getDesignSystemTimeoutMs;
|
|
3997
4028
|
else if (tool.name === "get_structure" && (getRecordProperty(parsedArgs, "pageId") || getRecordProperty(parsedArgs, "pageKey"))) timeoutMs = pageStructureTimeoutMs;
|
|
3998
4029
|
else if (tool.name === "apply_canvas") timeoutMs = applyCanvasTimeoutMs;
|
|
4030
|
+
if ((tool.name === "get_code" || tool.name === "get_screenshot") && !getRecordProperty(parsedArgs, "nodeId")) timeoutMs += MCP_NODE_READ_BATCH_WORK_BUDGET_MS;
|
|
3999
4031
|
const legacy = !taskId && !explicitSessionId ? extensionRegistry.getActive() : void 0;
|
|
4000
4032
|
if (legacy?.legacy) {
|
|
4001
4033
|
const payload = legacyToolPayload(tool.name, parsed);
|
|
@@ -4016,6 +4048,8 @@ function registerProxiedTool(mcp, tool, ownerId) {
|
|
|
4016
4048
|
const runtimeIssues = getExtensionRuntimeIssues(activeExt.runtime);
|
|
4017
4049
|
if (runtimeIssues.length) throw createCodedError(TEMPAD_MCP_ERROR_CODES.RUNTIME_IDENTITY_MISMATCH, `${runtimeIssues.join("; ")}. Rebuild/reload the extension and start a fresh agent task.`);
|
|
4018
4050
|
const runtime = tool.name === "apply_canvas" ? buildAuthoringRuntimeEvidence(activeExt) : void 0;
|
|
4051
|
+
const protocolVersion = activeExt.runtime.protocolVersion;
|
|
4052
|
+
assertVersionedToolSupport(protocolVersion, tool.name, parsedArgs);
|
|
4019
4053
|
if (runtime && utf8Bytes({ runtime }) > 2048) throw createCodedError(TEMPAD_MCP_ERROR_CODES.RUNTIME_IDENTITY_MISMATCH, "Runtime evidence exceeds the reserved response budget. No canvas write was dispatched.");
|
|
4020
4054
|
designTasks.checkOperation(ownerId, session, taskId, tool.name === "apply_canvas");
|
|
4021
4055
|
const registration = register(activeExt.id, timeoutMs, { waitForDefinitiveResult: tool.name === "apply_canvas" });
|
|
@@ -4060,7 +4094,10 @@ function registerProxiedTool(mcp, tool, ownerId) {
|
|
|
4060
4094
|
if (typeof pageId === "string") designTasks.updatePage(taskId, pageId);
|
|
4061
4095
|
}
|
|
4062
4096
|
}
|
|
4063
|
-
return createToolResponse(tool.name, payload,
|
|
4097
|
+
return createToolResponse(tool.name, payload, {
|
|
4098
|
+
runtime,
|
|
4099
|
+
compatibilityNotice: versionedReadNotice(protocolVersion, tool.name)
|
|
4100
|
+
});
|
|
4064
4101
|
} catch (error) {
|
|
4065
4102
|
const normalized = coerceToolError(error);
|
|
4066
4103
|
log.error({
|
|
@@ -4109,21 +4146,18 @@ function registerLocalTool(mcp, tool, ownerId) {
|
|
|
4109
4146
|
};
|
|
4110
4147
|
registerToolFn(tool.name, registrationOptions, registerHandler);
|
|
4111
4148
|
}
|
|
4112
|
-
function createToolResponse(toolName, payload, runtime, includeLocalAssetPaths = true) {
|
|
4149
|
+
function createToolResponse(toolName, payload, { runtime, includeLocalAssetPaths = true, compatibilityNotice } = {}) {
|
|
4113
4150
|
const enrichedPayload = (() => {
|
|
4114
|
-
if (toolName === "
|
|
4115
|
-
const
|
|
4116
|
-
return {
|
|
4117
|
-
...
|
|
4118
|
-
|
|
4151
|
+
if (includeLocalAssetPaths && (toolName === "get_code" || toolName === "get_screenshot")) {
|
|
4152
|
+
const read = payload;
|
|
4153
|
+
if ("results" in read) return {
|
|
4154
|
+
...read,
|
|
4155
|
+
results: read.results.map((entry) => entry.result ? {
|
|
4156
|
+
...entry,
|
|
4157
|
+
result: addReadLocalAssetPaths(entry.result)
|
|
4158
|
+
} : entry)
|
|
4119
4159
|
};
|
|
4120
|
-
|
|
4121
|
-
if (toolName === "get_code" && includeLocalAssetPaths) {
|
|
4122
|
-
const code = payload;
|
|
4123
|
-
return code.assets ? {
|
|
4124
|
-
...code,
|
|
4125
|
-
assets: code.assets.map((asset) => addLocalAssetPath(asset))
|
|
4126
|
-
} : code;
|
|
4160
|
+
return addReadLocalAssetPaths(read);
|
|
4127
4161
|
}
|
|
4128
4162
|
if (toolName === "apply_canvas" && runtime) return {
|
|
4129
4163
|
...payload,
|
|
@@ -4144,9 +4178,20 @@ function createToolResponse(toolName, payload, runtime, includeLocalAssetPaths =
|
|
|
4144
4178
|
rawResult = coercePayloadToToolResponse(enrichedPayload);
|
|
4145
4179
|
}
|
|
4146
4180
|
else rawResult = coercePayloadToToolResponse(enrichedPayload);
|
|
4181
|
+
if (compatibilityNotice) rawResult = {
|
|
4182
|
+
...rawResult,
|
|
4183
|
+
content: [{
|
|
4184
|
+
type: "text",
|
|
4185
|
+
text: compatibilityNotice
|
|
4186
|
+
}, ...rawResult.content]
|
|
4187
|
+
};
|
|
4147
4188
|
const resultBytes = measureCallToolResultBytes(rawResult);
|
|
4148
4189
|
if (resultBytes > 65536) {
|
|
4149
|
-
if (includeLocalAssetPaths && (toolName === "get_code" || toolName === "get_screenshot")) return createToolResponse(toolName, payload,
|
|
4190
|
+
if (includeLocalAssetPaths && (toolName === "get_code" || toolName === "get_screenshot")) return createToolResponse(toolName, payload, {
|
|
4191
|
+
runtime,
|
|
4192
|
+
compatibilityNotice,
|
|
4193
|
+
includeLocalAssetPaths: false
|
|
4194
|
+
});
|
|
4150
4195
|
log.warn({
|
|
4151
4196
|
tool: toolName,
|
|
4152
4197
|
resultBytes,
|
|
@@ -4161,7 +4206,7 @@ function buildAuthoringRuntimeEvidence(extension) {
|
|
|
4161
4206
|
const issues = getExtensionRuntimeIssues(runtime);
|
|
4162
4207
|
if (!hubRuntimeIdentity) issues.unshift("Hub runtime identity is unavailable");
|
|
4163
4208
|
return {
|
|
4164
|
-
protocolVersion:
|
|
4209
|
+
protocolVersion: 15,
|
|
4165
4210
|
locked: false,
|
|
4166
4211
|
valid: issues.length === 0,
|
|
4167
4212
|
issues,
|
|
@@ -4177,6 +4222,16 @@ function buildAuthoringRuntimeEvidence(extension) {
|
|
|
4177
4222
|
}
|
|
4178
4223
|
};
|
|
4179
4224
|
}
|
|
4225
|
+
function addReadLocalAssetPaths(result) {
|
|
4226
|
+
if ("asset" in result) return {
|
|
4227
|
+
...result,
|
|
4228
|
+
asset: addLocalAssetPath(result.asset)
|
|
4229
|
+
};
|
|
4230
|
+
return result.assets ? {
|
|
4231
|
+
...result,
|
|
4232
|
+
assets: result.assets.map(addLocalAssetPath)
|
|
4233
|
+
} : result;
|
|
4234
|
+
}
|
|
4180
4235
|
function addLocalAssetPath(asset) {
|
|
4181
4236
|
const record = assetStore.get(asset.hash);
|
|
4182
4237
|
return record && existsSync(record.filePath) ? {
|