Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions external_plugins/figma-mcp/.mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mcpServers": {
"figma-desktop": {
"type": "http",
"url": "http://127.0.0.1:3845/mcp",
"enabled": true,
"timeoutMs": 120000
},
"figma-remote": {
"type": "http",
"url": "https://mcp.figma.com/mcp",
"enabled": false,
"timeoutMs": 120000
}
}
}
26 changes: 26 additions & 0 deletions external_plugins/figma-mcp/.zcode-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "figma-mcp",
"version": "0.1.2",
"description": "Read and write Figma designs from ZCode through the Figma desktop MCP server: design context, variables, screenshots, motion and Code Connect.",
"description_i18n": {
"en": "Read and write Figma designs from ZCode through the Figma desktop MCP server: design context, variables, screenshots, motion and Code Connect.",
"zh-CN": "在 ZCode 中通过 Figma 桌面版 MCP 服务器读写 Figma 设计:设计上下文、变量、截图、动效与 Code Connect。"
},
"author": {
"name": "devcustrom",
"url": "https://github.com/devcustrom"
},
"keywords": [
"figma",
"mcp",
"design",
"design-to-code",
"dev-mode",
"code-connect",
"figjam",
"motion"
],
"mcpServers": "./.mcp.json",
"skills": "./skills",
"commands": "./commands"
}
97 changes: 97 additions & 0 deletions external_plugins/figma-mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# figma-mcp

[中文文档](./README_CN.md)

Connects ZCode to Figma through the Figma MCP server, so the agent can read a design file, implement UI from it, and map Figma components onto real code.

The plugin enables the local MCP server of the Figma desktop app: no account linking, no token, no cloud round-trip. Figma's hosted remote endpoint is shipped disabled, because Figma currently rejects OAuth client registration from third-party clients (see [The remote server](#the-remote-server)).

## What the plugin provides

| Component | Name | Purpose |
| --- | --- | --- |
| MCP server | `figma-desktop` | HTTP server of the Figma desktop app at `http://127.0.0.1:3845/mcp`. 10 tools for design context, metadata, variables, screenshots, motion, FigJam and Code Connect. Enabled, no authorization. |
| MCP server | `figma-remote` | Figma-hosted endpoint `https://mcp.figma.com/mcp` (Government: `https://mcp.figma-gov.com/mcp`). Disabled; see [The remote server](#the-remote-server). |
| Skill | `figma-mcp` | How to enable the desktop server, which tool to call, the design-to-code workflow, Code Connect, troubleshooting and the prompt-injection rules for design content. |
| Command | `/figma-setup` | Probes the endpoint, reports which Figma tools are registered, and gives the exact Figma steps when the server is off. |

Run one server at a time: both expose the same tool names, so enabling both duplicates every Figma tool.

## Requirements

- The **Figma desktop app**, up to date. The browser app has no local MCP server.
- A Figma **Design** file open in the app, with **Dev Mode** available (press `Shift+D`).
- A **Dev or Full seat** on a Professional, Education, Organization, Government, or Enterprise plan. Viewers and Collab seats cannot run the server.
- No Node.js, Python or other runtime: the plugin only declares HTTP endpoints.

The desktop server belongs to Figma; it starts and stops with the Figma app and the "Enable desktop MCP server" toggle in the Dev Mode sidebar.

## Getting started

1. Install and enable the plugin in ZCode, then start a new session so the MCP server connects.
2. In Figma: open a design file, press `Shift+D` with nothing selected, find **MCP server** in the right sidebar and click **Enable desktop MCP server**.
3. In ZCode, run `/figma-setup`. It should report the endpoint as listening and list the Figma tools. Check **Settings → MCP** if the server is missing.
4. Ask for work with a Figma URL, for example: `Implement this frame in our Vue app and reuse the existing Button component: https://www.figma.com/design/<fileKey>/<name>?node-id=12-345`.

The Figma app serves whichever file is currently open; a `nodeId` selects the subtree. Without a `nodeId`, calls use the current selection, so keep the intended frame selected or pass the URL.

## The remote server

Figma recommends `https://mcp.figma.com/mcp` for design-to-code work, and it is the better endpoint when it is available: no desktop app, all Figma plans. Its OAuth flow is standard — the endpoint returns `401` with `resource_metadata`, `https://api.figma.com` publishes authorization and token endpoints plus a dynamic client registration endpoint, scope `mcp:connect`, PKCE `S256`.

ZCode implements that flow: **Settings → MCP** shows **Authorization required → Open authorization** for plugin MCP servers. With Figma it cannot finish, because Figma's registration endpoint returns `403 Forbidden` for clients it does not recognise:

```text
POST https://api.figma.com/v1/oauth/mcp/register -> 403 Forbidden
```

Without a client registration there is no authorization URL, so ZCode never shows a prompt. The entry stays disabled, and `figma-desktop` is the supported path. If Figma opens registration to third-party clients, enabling `figma-remote` and authorizing once will be enough — no code change is needed.

There is no per-user allowlist to request: Figma admits MCP **clients**, not individual accounts, and the list is the [Figma MCP catalog](https://www.figma.com/mcp-catalog). ZCode is not in it. A client vendor can join Figma's [new-client waitlist](https://form.asana.com/?k=kBG-ejRQTdY8x_H6a4vM3Q&d=10497086658021) or apply to register for remote access through their Figma account team. Until that happens, no configuration on the user side can make the remote endpoint authorize.

## Tools

Verified against Figma Dev Mode MCP Server 1.0.0. Names and schemas change between Figma releases; use the tools the session actually registers.

| Tool | Purpose |
| --- | --- |
| `get_design_context` | Primary design-to-code call for one node: reference code, screenshot and metadata. |
| `get_metadata` | XML overview of a node or page: ids, types, names, positions, sizes. |
| `get_variable_defs` | Design variables and styles for a node. |
| `get_screenshot` | Renders a node from a Design file, FigJam board or Slides deck. |
| `get_motion_context` | Keyframe data, easing, CSS `@keyframes` and motion.dev snippets. |
| `get_code_connect_map` | Existing node-to-component mappings. |
| `add_code_connect_map` | Maps one node to a code component. |
| `get_code_connect_suggestions` | Suggested mapping strategy for a node. |
| `send_code_connect_mappings` | Saves approved mappings in bulk. |
| `get_figjam` | UI code or content from a FigJam node. |

`get_design_context` requires design-to-code guidance to be loaded first. The skill prefers an installed `figma-design-to-code` skill and otherwise reads the `skill://figma/figma-design-to-code/SKILL.md` resource that the server exposes, so the plugin works without that skill installed.

Code Connect tools and motion data depend on the Figma plan and seat; Government plans do not include them. The plugin reports an entitlement error instead of retrying.

## Network access and side effects

- **`figma-desktop` — loopback only.** The plugin sends HTTP requests to `http://127.0.0.1:3845/mcp` on the user's machine. No credentials, no external traffic. The URL is fixed in `.mcp.json`; the skill forbids retargeting it at any other host.
- **`figma-remote` — disabled.** Its endpoint is `https://mcp.figma.com/mcp` (Government: `https://mcp.figma-gov.com/mcp`). It is not contacted while disabled. If enabled without a working client registration, startup fails with the registration error described above.
- **Reads.** Design context, node metadata, variables, screenshots, motion data and Code Connect maps are read from the file open in the Figma app.
- **Writes.** `add_code_connect_map` and `send_code_connect_mappings` write Code Connect data into the Figma file. The skill requires the agent to show suggestions and get the user's approval before saving mappings. No other tool changes the design.
- **Local side effects.** The plugin writes no files, starts no processes and registers no hooks. Figma itself stores the MCP server setting, not the plugin.
- **Untrusted content.** Text, layer names and annotations from a design file are treated as data, never as instructions. The skill tells the agent to report instruction-like design content to the user instead of following it.

No third-party code, binaries or models are bundled. The plugin contains a manifest, an MCP declaration, one skill and one command.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| No Figma tools in the session | Restart the session after installing, then check **Settings → MCP**. |
| Endpoint not listening | Open the Figma desktop app, open a design file, enable Dev Mode, turn on the desktop MCP server. |
| `figma-remote` fails with `Dynamic Client Registration rejected (HTTP 403)` | Expected: Figma does not register this client. Keep it disabled and use `figma-desktop`. |
| Every Figma tool appears twice | Both servers are enabled; disable one. |
| Another process owns port 3845 | Identify it with `netstat -ano | findstr :3845` and close it; the Figma server needs the port. |
| Empty context | Nothing is selected and no `nodeId` was passed; pass the Figma URL. |

## License

Apache-2.0, the license of this repository. See [LICENSE](../../LICENSE).
97 changes: 97 additions & 0 deletions external_plugins/figma-mcp/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# figma-mcp

[English](./README.md)

通过 Figma MCP 服务器把 ZCode 连接到 Figma,让 Agent 读取设计文件、按设计实现 UI,并把 Figma 组件映射到真实代码。

插件启用 Figma 桌面应用自带的本地 MCP 服务器:无需关联账号、无需令牌、不经过云端。Figma 托管的远程端点随插件提供但默认关闭,因为 Figma 目前会拒绝第三方客户端的 OAuth 客户端注册(见[远程服务器](#远程服务器))。

## 插件提供的能力

| 组件 | 名称 | 作用 |
| --- | --- | --- |
| MCP 服务器 | `figma-desktop` | Figma 桌面应用的 HTTP 服务器 `http://127.0.0.1:3845/mcp`,提供设计上下文、元数据、变量、截图、动效、FigJam 与 Code Connect 共 10 个工具。默认启用,无需授权。 |
| MCP 服务器 | `figma-remote` | Figma 托管端点 `https://mcp.figma.com/mcp`(Government 为 `https://mcp.figma-gov.com/mcp`)。默认关闭,见[远程服务器](#远程服务器)。 |
| 技能 | `figma-mcp` | 如何启用桌面服务器、该调用哪个工具、设计到代码的流程、Code Connect、故障排查,以及把设计内容当作不可信数据的规则。 |
| 命令 | `/figma-setup` | 探测端点、报告已注册的 Figma 工具,服务器未开启时给出 Figma 里的具体操作步骤。 |

同一时间只运行一个服务器:两者暴露相同的工具名,同时启用会让每个 Figma 工具出现两次。

## 环境要求

- 最新版 **Figma 桌面应用**。浏览器版没有本地 MCP 服务器。
- 在应用中打开一个 Figma **设计文件**,并可使用**开发模式**(按 `Shift+D`)。
- Professional、Education、Organization、Government 或 Enterprise 计划下的 **Dev 或 Full 席位**。Viewer 和 Collab 席位无法启动该服务器。
- 不需要 Node.js、Python 或其他运行时:插件只声明 HTTP 端点。

桌面服务器属于 Figma,随 Figma 应用启动和停止,并由开发模式侧栏的“Enable desktop MCP server”开关控制。

## 快速开始

1. 在 ZCode 中安装并启用插件,然后新建会话,让 MCP 服务器连接。
2. 在 Figma 中打开设计文件,不选中任何对象按 `Shift+D`,在右侧边栏找到 **MCP server**,点击 **Enable desktop MCP server**。
3. 在 ZCode 中运行 `/figma-setup`,应显示端点正在监听并列出 Figma 工具。若未出现服务器,检查**设置 → MCP**。
4. 用 Figma 链接提出需求,例如:`用我们的 Vue 项目实现这个画板,并复用现有 Button 组件: https://www.figma.com/design/<fileKey>/<name>?node-id=12-345`。

Figma 应用提供当前打开的文件;`nodeId` 用于选中子树,不传时使用当前选区,因此请保持目标画板处于选中状态,或直接传链接。

## 远程服务器

Figma 推荐在设计与代码之间使用 `https://mcp.figma.com/mcp`;可用时它确实更好:不依赖桌面应用,且适用于所有 Figma 计划。它的 OAuth 流程是标准的:端点返回 `401` 并携带 `resource_metadata`,`https://api.figma.com` 公布授权、令牌与动态客户端注册端点,权限为 `mcp:connect`,PKCE `S256`。

ZCode 实现了该流程:**设置 → MCP** 会为插件的 MCP 服务器显示**需要授权 → 打开授权**。但 Figma 无法完成:其注册端点对未识别的客户端返回 `403 Forbidden`:

```text
POST https://api.figma.com/v1/oauth/mcp/register -> 403 Forbidden
```

没有客户端注册就没有授权链接,所以 ZCode 始终不会弹出授权提示。该条目保持关闭,`figma-desktop` 是受支持的路径。若 Figma 将来向第三方客户端开放注册,只需启用 `figma-remote` 并完成一次授权,无需改代码。

这里不存在按用户申请的 allowlist:Figma 放行的是 MCP **客户端**,名单就是 [Figma MCP catalog](https://www.figma.com/mcp-catalog),其中没有 ZCode。客户端厂商可以加入 Figma 的[新客户端 waitlist](https://form.asana.com/?k=kBG-ejRQTdY8x_H6a4vM3Q&d=10497086658021),或通过其 Figma 客户团队申请远程访问注册。在此之前,用户侧任何配置都无法让远程端点完成授权。

## 工具

以下清单基于 Figma Dev Mode MCP Server 1.0.0 实测。工具名与参数会随 Figma 版本变化,以会话实际注册的工具为准。

| 工具 | 作用 |
| --- | --- |
| `get_design_context` | 针对单个节点的主要设计到代码调用:参考代码、截图与元数据。 |
| `get_metadata` | 节点或页面的 XML 概览:id、类型、名称、位置、尺寸。 |
| `get_variable_defs` | 节点使用的设计变量与样式。 |
| `get_screenshot` | 渲染节点,支持设计文件、FigJam 白板和 Slides 演示文稿。 |
| `get_motion_context` | 关键帧、缓动曲线、CSS `@keyframes` 与 motion.dev 代码片段。 |
| `get_code_connect_map` | 已有的节点到组件映射。 |
| `add_code_connect_map` | 把单个节点映射到代码组件。 |
| `get_code_connect_suggestions` | 为节点建议映射方案。 |
| `send_code_connect_mappings` | 批量保存确认后的映射。 |
| `get_figjam` | 从 FigJam 节点获取内容或 UI 代码。 |

调用 `get_design_context` 前必须先加载设计到代码的指导。技能优先使用已安装的 `figma-design-to-code` 技能,否则读取服务器提供的 `skill://figma/figma-design-to-code/SKILL.md` 资源,因此未安装该技能也能使用本插件。

Code Connect 与动效数据取决于 Figma 计划与席位;Government 计划不包含这些能力。插件会直接报告权限错误,不会反复重试。

## 网络访问与副作用

- **`figma-desktop` 仅走本机回环。** 插件向用户机器上的 `http://127.0.0.1:3845/mcp` 发送 HTTP 请求,不带凭据,也不产生外部流量。该 URL 固定写在 `.mcp.json` 中,技能禁止把它指向其他主机。
- **`figma-remote` 默认关闭。** 端点为 `https://mcp.figma.com/mcp`(Government 为 `https://mcp.figma-gov.com/mcp`),关闭时不会被访问。若在没有可用客户端注册的情况下启用,启动会以上述注册错误失败。
- **读取。** 从 Figma 应用当前打开的文件读取设计上下文、节点元数据、变量、截图、动效数据与 Code Connect 映射。
- **写入。** `add_code_connect_map` 与 `send_code_connect_mappings` 会把 Code Connect 数据写入 Figma 文件。技能要求 Agent 先展示建议并取得用户同意后才保存映射;其他工具不修改设计。
- **本地副作用。** 插件不写文件、不启动进程、不注册 hooks。MCP 服务器开关由 Figma 自己保存,与插件无关。
- **不可信内容。** 设计文件中的文本、图层名称与批注一律视为数据而非指令。技能要求 Agent 把类似指令的设计内容报告给用户,而不是执行。

插件不捆绑任何第三方代码、二进制或模型,只包含清单、MCP 声明、一个技能和一个命令。

## 故障排查

| 现象 | 处理 |
| --- | --- |
| 会话中没有 Figma 工具 | 安装后重启会话,再检查**设置 → MCP**。 |
| 端点未监听 | 打开 Figma 桌面应用和设计文件,进入开发模式并开启 desktop MCP server。 |
| `figma-remote` 报 `Dynamic Client Registration rejected (HTTP 403)` | 预期行为:Figma 不注册该客户端。保持关闭并使用 `figma-desktop`。 |
| 每个 Figma 工具出现两次 | 两个服务器都被启用;关闭其中一个。 |
| 端口 3845 被占用 | 用 `netstat -ano | findstr :3845` 找到进程并关闭;Figma 服务器需要该端口。 |
| 返回空上下文 | 没有选中对象且未传 `nodeId`;传入 Figma 链接。 |

## 许可证

Apache-2.0,与本仓库一致。见 [LICENSE](../../LICENSE)。
25 changes: 25 additions & 0 deletions external_plugins/figma-mcp/commands/figma-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
description: Check the Figma MCP connection and walk through enabling the Figma desktop server
argument-hint: "[figma file or node URL to test with]"
---

Diagnose the Figma MCP setup for this user.

1. Use the `figma-mcp` skill of this plugin as the reference.
2. Probe the desktop endpoint without changing anything:

`curl -s -m 4 -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3845/mcp`

Any HTTP status means it is listening; `000` means it is not.
3. Check whether Figma MCP tools (`mcp__*figma*`) are present in this session. Report the actual
server and tool names you see; do not invent them.
4. If tools are missing or the probe failed, give the user the exact Figma desktop steps from the
skill (Figma desktop app → design file → Shift+D Dev Mode → right sidebar "MCP server" →
"Enable desktop MCP server"), plus the seat and plan requirement. Then ask them to restart the
session so ZCode reconnects, and check **Settings → MCP**.
5. If a URL was provided (`$ARGUMENTS`), try a read-only `get_metadata` or `get_design_context`
call on that node and summarize what came back. If no URL was provided, ask for one instead of
searching the user's Figma files.

Report: endpoint status, whether the plugin server is connected, which tools are available, and the
single next action the user must take. Do not edit `~/.zcode` or the Figma file during diagnosis.
Loading