
Product
Introducing Socket Scanning for VS Code Marketplace Extensions
Socket now scans VS Code extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
@xiehuan123/figma-mcp-server
Advanced tools
将 Figma API 数据处理成 AI 友好格式的 MCP 服务器,专为 AI 代码生成场景优化。
cd figma-mcp-server
npm install
Figma → Settings → Personal Access Tokens → 创建 token
{
"mcpServers": {
"figma": {
"command": "npx",
"args": ["-y", "@xiehuan123/figma-mcp-server"],
"env": {
"FIGMA_TOKEN": "figd_你的token"
}
}
}
}
{
"mcpServers": {
"figma": {
"command": "node",
"args": ["/path/to/figma-mcp-server/src/index.js"],
"env": {
"FIGMA_TOKEN": "figd_你的token"
}
}
}
}
从 Figma 文件 URL 中提取:figma.com/design/这一段就是fileKey/...
| 工具 | 用途 | 关键参数 |
|---|---|---|
get_file_structure | 获取文件页面和顶层 frame 概览 | fileKey |
get_node | 获取节点 AI 友好数据(压缩/JSON),自动导出 SVG | fileKey, nodeId, format, maxTokens |
get_components | 获取所有组件列表 | fileKey |
get_component_detail | 获取组件变体属性和内部结构 | fileKey, nodeId |
get_styles | 获取颜色/文字/效果样式 | fileKey |
get_variables | 获取 Design Tokens (Variables) | fileKey |
get_node_css | 生成 CSS 或 Tailwind 类名 | fileKey, nodeId, mode, recursive |
get_page_for_codegen | 一站式代码生成上下文,自动导出 SVG | fileKey, nodeId, depth |
get_images | 获取节点图片导出 URL | fileKey, nodeIds, format, scale |
export_svg | 手动导出指定节点为 SVG | fileKey, nodeIds |
1. get_file_structure → 了解文件有哪些页面和 frame
2. get_node → 获取目标节点的压缩格式结构(图标自动导出 SVG)
3. get_page_for_codegen → 一站式获取代码生成完整上下文
4. get_node_css (tailwind) → 直接输出带类名的组件结构
5. export_svg → 手动导出特定节点的 SVG
当调用 get_node 或 get_page_for_codegen 时,系统会自动检测节点树中的可导出元素:
检测规则:
/^(icon|ico|Icons|Basics)\b/i 的节点导出行为:
.figma-temp/svg/ 目录手动导出:
使用 export_svg 工具可以指定任意节点 ID 进行 SVG 导出。
每次 Figma API 调用和数据转换都会记录到 .figma-temp/logs/ 目录:
.figma-temp/logs/
2026-05-09T10-30-45-123Z_api_raw.json # Figma API 原始响应
2026-05-09T10-30-45-456Z_get_node_optimized.json # 优化后的数据
所有临时数据存储在项目根目录的 .figma-temp/ 中:
.figma-temp/
raw/ # Figma API 原始响应数据
optimized/ # 优化后的 AI 友好数据
svg/ # 导出的 SVG 文件
icons/ # 图标索引 (index.json)
logs/ # API 调用日志
生命周期规则:
.figma-temp/ 目录默认输出格式,比 JSON 节省 60%+ token:
[HEADER "TopNav" 1440x64 bg:#ffffff flex-row center p:0,24 gap:32 <header>]
[IMG "Logo" 120x32 <img>]
[NAV "MainNav" flex-row gap:24 <nav>]
[TEXT "Products" 14px/500 #374151 "Products"]
格式说明:
[TYPE "名称" 宽x高 样式... "文本内容"]<tag> 为建议的 HTML 元素自动识别 28 种语义角色:
HEADER, FOOTER, SIDEBAR, NAV, CARD, BUTTON, INPUT, DIALOG,
AVATAR, BADGE, ICON, IMG, LIST, FORM, SECTION, DIVIDER,
LINK, TABLE, SELECT, CHECKBOX, RADIO, TOGGLE, TOOLTIP,
BREADCRUMB, PAGINATION, PROGRESS, ALERT, COMPONENT
get_node_css 设置 mode: "tailwind", recursive: true 输出带类名的 HTML:
<button class="flex flex-row w-[96px] h-[36px] bg-[#4f46e5] rounded-[6px] justify-center items-center">
<span class="text-[14px] font-[600] text-[#ffffff]">Sign Up</span>
</button>
get_node 的 maxTokens 参数(默认 4000)自动控制输出大小,超预算时智能降低深度而非粗暴截断。
| 处理 | 说明 |
|---|---|
| 去噪 | 移除 pluginData、exportSettings、不可见节点 |
| 颜色扁平化 | RGBA 对象 → #hex 或 rgba() |
| 布局语义化 | Auto Layout → flex-row/flex-col、start/center/end |
| Padding 压缩 | 四边相同压缩为单值 |
| 响应式提示 | 基于 constraints 生成 stretch-x、fluid-width 等建议 |
| 深度控制 | 可配置递归深度 + token 预算自动截断 |
| 缓存 | 60s 内存缓存减少重复 API 调用 |
src/
index.js # MCP Server 主入口,工具定义
figma-client.js # Figma REST API 客户端(带缓存和日志钩子)
transformer.js # 数据转换器(简化、压缩格式、CSS/Tailwind 生成)
temp-manager.js # 临时目录生命周期管理
logger.js # 日志系统
svg-exporter.js # SVG 检测、导出、下载
npm run dev # 带 watch 模式运行
npm start # 正常运行
FAQs
Figma MCP Server - 将 Figma API 数据处理成 AI 友好格式
We found that @xiehuan123/figma-mcp-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Product
Socket now scans VS Code extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Research
/Security News
Socket uncovered two malicious VS Code themes in a GlassWorm-linked cluster with thousands of installs across VS Code Marketplace and Open VSX.

Security News
/Company News
Capital One is partnering with Socket to proactively secure its open source supply chain.