简介
本文介绍如何在 VS Code 中利用 GitHub Copilot 接入 Figma MCP,实现设计稿到前端代码的还原。
步骤 1:配置 MCP
在 VS Code 中打开项目(例如微信小程序),呼出 GitHub Copilot 对话框,模式选择 Agent,模型建议 Claude 3.7 Sonnet,提问:
https://github.com/GLips/Figma-Context-MCP 如何配置能让你在 vscode 里使用这个 mcp
跟随提示完成配置,插件会自动安装并生成配置说明文档。

运行结果会在项目文件夹最外层创建 .vscode 文件夹,并在 settings.json 中添加配置。如果文件已存在,配置会追加至末尾。
{"mcpServers":{"Framelink Figma MCP":{"command":"cmd","args":["/c","npx","-y","figma-developer-mcp","--figma-api-key=替换为你的密钥","--stdio"]}}}
步骤 2:获取 Figma 密钥
- 打开 Figma 网页,点击左上角头像 -> Settings -> Security -> Generate new token。
- 设置路径可能变化,找到 Generate new token 即可。
- 弹窗中命名 Token(如 mcp),勾选读或写权限(默认无访问权限)。
- 注意:Token 默认 30 天过期,过期后需重新生成。

复制生成的密钥,填入 settings.json 中的 --figma-api-key= 后面。
步骤 3:如何使用
以电商 UI 模板的商品卡片为例:
- 在 Figma 设计图上选中图层,右键点击 Copy link to selection。
- 将链接粘贴到 Copilot 对话框,确保模式为 Agent,测试配置:

出现弹窗说明 Agent 在尝试链接 MCP server,点击继续允许操作。稍后可见描述信息,确认设计图被读取。

现在可以让 AI 写代码:
请根据这个设计图在我的微信小程序里生成商品卡片组件的代码,注意微信小程序中 2rpx=1px,要完全还原设计图的 UI,再建一个测试页面展示这个组件的调用效果,可以参考微信小程序官方文档 https://developers.weixin.qq.com/miniprogram/dev/api

运行开发者工具查看还原效果。如有细节不足,可反馈优化:
看上去有一些 UI 细节不够还原,比如卡片的内边距,还有按钮的布局,请你再仔细检查一下。 商品图片上的三个 icon 按钮应该是水平居中的,learn more 按钮应该是水平居左的。另外你能不能直接下载设计图里的 icon 为 svg 来使用,这样更还原。
经过两轮迭代,还原度显著提升。

人工 Review 生成代码,DOM 结构合理,注释清晰。
<view class="product-card">
<!-- 图片区域 -->
<view class="fixed-height">
<view class="product-cover" style="background-image:url('{{product.coverImage}}');"></view>
<!-- 产品操作按钮 -->
<view class="product-actions">
<view class="action-button like">
<view class="icon"><image class="icon-image" src="/images/icons/like-icon.svg"></image></view>
</view>
<view class="action-button basket">
<view class="icon"><image class="icon-image" src="/images/icons/basket-icon.svg"></image></view>
</view>
<view class="action-button share">
<view class="icon"><image class="icon-image" src="/images/icons/share-icon.svg"></image></view>
</view>
</view>
<!-- 标签 -->
<view class="tag" wx:if="{{product.tag}}">
<text>{{product.tag}}</text>
</view>
</view>
<!-- 产品信息区域 -->
<view class="product-info">
<!-- 类别和评分 -->
<view class="row category-rating">
<view class="category-container"><text class="category">{{product.category}}</text></view>
<view class="rating-container">
<image class="star-icon" src="/images/icons/star-icon.svg"></image>
<text class="rating">{{product.rating}}</text>
</view>
</view>
<!-- 产品标题 -->
<text class="product-title">{{product.title}}</text>
<!-- 产品描述 -->
<text class="product-description">{{product.description}}</text>
<!-- 销售信息 -->
<view class="sales">
<view class="icon"><image class="sales-icon" src="/images/icons/sales-icon.svg"></image></view>
<text class="sales-text">{{product.sales}} Sales</text>
</view>
<!-- 价格信息 -->
<view class="prices">
<text class="original-price" wx:if="{{product.originalPrice}}">¥{{product.originalPrice}}</text>
<text class="current-price">¥{{product.price}}</text>
</view>
<!-- 颜色选项 -->
<view class="product-colors">
<view class="color-dot" wx:for="{{product.colors}}" wx:key="index" style="background-color:{{item}};"></view>
</view>
<!-- 产品特性 -->
<view class="product-features">
<view class="feature">
<view class="icon"><image class="feature-icon" src="/images/icons/calendar-icon.svg"></image></view>
<text class="feature-text">{{product.duration}}</text>
</view>
<view class="feature">
<view class="icon"><image class="feature-icon" src="/images/icons/lessons-icon.svg"></image></view>
<text class="feature-text">{{product.lessons}} Lessons</text>
</view>
<view class="feature">
<view class="icon"><image class="feature-icon" src="/images/icons/progress-icon.svg"></image></view>
<text class="feature-text">Progress</text>
</view>
</view>
<!-- 了解更多按钮 -->
<button class="learn-more-button" hover-class="button-hover">
<text>Learn More</text>
<image class="arrow-icon" src="/images/icons/arrow-right-icon.svg"></image>
</button>
</view>
</view>
调用示例:
<view class="container">
<view class="title">商品卡片组件展示</view>
<view class="card-container">
<product-card product="{{productData}}"></product-card>
</view>
</view>

