Figma MCP Server: Build a React Component From a Frame, Then Write It Back
The Figma MCP server lets a coding agent read real frames, variables and Code Connect mappings instead of guessing from a screenshot. Build a TaskCard component from named tokens, render it with Vite, then write it back into Figma as a new frame.
What you will learn
- Connect the remote Figma MCP server to VS Code or Claude Code
- Name the three read tools the agent calls to turn a frame into a component
- Map Figma variables to Tailwind CSS 4 tokens so no hex colour lands in a component
- Write a component back into Figma as a new frame bound to the same variables
Before you start
- What Is MCP? Host, Client and Server
- Basic React components and props
Give a cook a blurry photo of a recipe and they squint and guess the amounts. Put the recipe book open on the counter and they read the exact numbers. Pasting a screenshot of a design into an AI tool is the photo: the colours and the spacing get guessed. The Figma MCP server is the open book. The agent reads your frames, your variables and your component mappings straight from the file.
In this lesson the agent works in both directions in one session. It reads a Figma frame and builds a React component from it, and then it writes a component from code back into Figma as a new frame. The project is a small React 19, Vite and Tailwind CSS 4 app. We type in VS Code, but any editor works.
If MCP is new to you, read What Is MCP? Host, Client and Server first.
Connect the server once
This is an example setup. Figma changes these steps from time to time, so check Figma's developer docs for the current version before you start. You also need a Figma account with a Dev or Full seat.
In VS Code the server is one entry in .vscode/mcp.json. The url points at Figma's hosted server and the type is http. That's the whole entry.
{
"inputs": [],
"servers": {
"figma": {
"url": "https://mcp.figma.com/mcp",
"type": "http"
}
}
}
In Claude Code one command does the same job:
claude mcp add --transport http figma https://mcp.figma.com/mcp
Then start a new session, run /mcp, choose figma and authenticate. You sign in to Figma once, in the browser. For more on scopes and on fixing a server that won't connect, see Configuring MCP Servers in Claude Code.
Design to code: the agent reads
The Figma file has a TaskCard frame, a few variables (surface, brand, text-secondary, radius-card) and a Button component. Select the frame in Figma, copy its link, and ask the agent:
Using the Figma MCP server, read the TaskCard frame I selected (design context,
variables and the Code Connect mapping). Build it as a React 19 + Tailwind CSS 4
component called TaskCard with props title, owner, due and done. Use the named
variables as Tailwind theme tokens, not hex colours, and reuse my existing
Button component.
The agent makes three read calls. The values below come from the lecture's simplified mock-up, so treat them as examples:
| Tool | What it returns | Example |
|---|---|---|
get_design_context | The structure of the frame | TaskCard, 320 x 190, auto layout, padding 20, radius 16 |
get_variable_defs | The variables the frame uses, with values | surface #FFFFFF, brand #4F46E5, text-secondary #64748B |
get_code_connect_map | Which Figma components already exist in your code | Button maps to src/Button.tsx |
The third call matters more than it looks. Code Connect tells the agent that the "View task" button already lives in src/Button.tsx, so it reuses that file instead of inventing a second button.
Variables become tokens
Each Figma variable turns into a CSS token, and Tailwind turns the token into a class:
| Figma variable | CSS token | Tailwind class |
|---|---|---|
| surface | --color-surface | bg-surface |
| brand | --color-brand | bg-brand |
| text-secondary | --color-text-secondary | text-text-secondary |
| radius-card | --radius-card | rounded-card |
Yes, text-text-secondary looks funny. It's correct: text- is the Tailwind prefix and text-secondary is the token name. The tokens live in one @theme block in src/index.css:
@import "tailwindcss";
/* Variables that were read from the Figma file (get_variable_defs) */
@theme {
--color-surface: #ffffff;
--color-surface-muted: #f1f5f9;
--color-text-primary: #0f172a;
--color-text-secondary: #64748b;
--color-brand: #4f46e5;
--color-brand-soft: #e0e7ff;
--color-success: #059669;
--radius-card: 16px;
--spacing-card: 20px;
}
body { margin: 0; font-family: system-ui, sans-serif; background: var(--color-surface-muted); }
The point is that no hex colour ends up inside the component. When the designer changes a variable, every card changes with it. Names, not numbers. The idea of tokens is covered in more depth in Components, Variants and Variables.
TaskCard.tsx: built from names
This is the component a session like that produces:
import { Button } from './Button'
type Props = {
title: string
owner: string
due: string
done?: boolean
}
export function TaskCard({ title, owner, due, done }: Props) {
return (
<article className="w-80 rounded-card bg-surface p-card shadow-md">
<div className="flex items-center justify-between">
<h3 className="text-lg font-bold text-text-primary">{title}</h3>
<span
className={`rounded-full px-3 py-1 text-xs font-semibold ${
done ? 'bg-success text-white' : 'bg-brand-soft text-brand'
}`}
>
{done ? 'Done' : 'Open'}
</span>
</div>
<p className="mt-2 text-sm text-text-secondary">Owner: {owner}</p>
<p className="text-sm text-text-secondary">Due: {due}</p>
<Button className="mt-4 w-full">View task</Button>
</article>
)
}
Look at the classes on the article: rounded-card, bg-surface, p-card. Every one is a named variable. The badge shows Done or Open depending on the done prop, and the last line is your own Button, which was already in the codebase:
import type { ButtonHTMLAttributes } from 'react'
// Already in the codebase. Code Connect maps the Figma "Button" component to this file.
export function Button({ className = '', ...props }: ButtonHTMLAttributes<HTMLButtonElement>) {
return (
<button
className={`rounded-lg bg-brand px-4 py-2 text-sm font-semibold text-white hover:opacity-90 ${className}`}
{...props}
/>
)
}
The card, rendered
App.tsx renders two cards from the same component:
import { TaskCard } from './TaskCard'
export default function App() {
return (
<main className="flex flex-wrap gap-6 p-8">
<TaskCard title="Write report" owner="Emma" due="Friday" />
<TaskCard title="Email Jack" owner="Priya" due="Monday" done />
</main>
)
}
Run it with npm install and npm run dev, then open the address Vite prints (http://localhost:5173).

done prop, and both buttons are the existing Button.Try the token idea yourself: change --color-brand in src/index.css and watch every card follow.
Code to design: write it back
Now the other direction. Start from src/TaskCard.tsx and ask:
Take src/TaskCard.tsx and write it into my Figma file as a new frame named
TaskCard, with layers for the title, the badge and the button. Bind the colours
and radius to the matching Figma variables.
The agent uses a write tool. Which one depends on the task: use_figma creates and edits content in a file, and generate_figma_design sends a web page into Figma as layers. The result is a new frame on the canvas with layers for the title, the badge and the button. Because the same names go back, the frame stays bound to the variables.
| Direction | Tools | Result |
|---|---|---|
| Design to code | get_design_context, get_variable_defs | A component in your repo |
| Code to design | use_figma, generate_figma_design | A new frame in Figma |
| Keeps them aligned | get_code_connect_map, add_code_connect_map | Frame and file point to each other |
Common mistakes
- Pasting a screenshot when the file is available. The agent guesses colours and spacing from pixels. Through MCP it reads the real values.
- Vague variable names. Clear names like
text-secondarygive the agent better answers thangrey-2. - Accepting hex colours in the component. If you see
#4F46E5inTaskCard.tsx, ask the agent to use the token. - Skipping the review. An agent can make mistakes in both directions. Check the component and the new frame.
- Expecting write-back on any seat. Writing needs the remote server and the right Figma seat.
Quick recap
| Step | What happens |
|---|---|
| Connect | .vscode/mcp.json or claude mcp add --transport http figma ..., then sign in once |
| Read | Design context, variable definitions and the Code Connect map |
| Build | A component made of named tokens that reuses your own Button |
| Write back | A new Figma frame bound to the same variables |
Try it yourself
Add a priority variable in Figma, ask the agent to show it as a second badge on the card, then write the updated card back into Figma and check that the new layer is bound to the variable.
The project files and sample prompts for this lesson are in the StudyEasy AI Community, free to join.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
