You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mcp/tools/storefront-next-figma-to-component-workflow.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ Workflow orchestrator for converting Figma designs to Storefront Next components
11
11
When you provide a Figma design URL, your AI assistant uses this tool to extract the file and node identifiers, then follows the workflow to fetch design data, analyze your codebase, and produce recommendations. The assistant will:
12
12
13
13
- Fetch design context and screenshots from Figma
14
+
-**Ask for your approval before exporting images** — when the design contains image assets (photos, logos, icons), the assistant presents the list and waits for you to confirm before exporting
14
15
- Discover similar components in your project
15
16
- Recommend whether to REUSE, EXTEND, or CREATE a component
16
17
- Map Figma design tokens to your theme variables
@@ -118,6 +119,18 @@ The workflow relies on your AI assistant having access to Figma MCP tools to fet
118
119
-**get_screenshot** - Provides a visual reference image of the design
4. Ask once: "Should I export these N image assets now? (yes/no)"
130
+
5. Wait for your explicit "yes" before calling `get_design_context` with `dirForAssetWrites` to export
131
+
132
+
You are prompted **once per batch**—not per image. This ensures you control when assets are written to disk. Logo and brand assets are explicitly included in the identification criteria so they are not missed.
133
+
121
134
Ensure the Figma MCP server is enabled in your MCP client. See [Figma-to-Component Tools Setup](../figma-tools-setup) for configuration and the [Figma MCP Server Documentation](https://developers.figma.com/docs/figma-mcp-server) for official setup and tool details.
Copy file name to clipboardExpand all lines: packages/b2c-dx-mcp/src/tools/storefrontnext/figma/figma-to-component/index.ts
+25-7Lines changed: 25 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,9 @@ This workflow guides through converting a Figma design into a StorefrontNext-com
46
46
### Key Principles
47
47
1. Review workflow plan and list out todos to user before fetching designs
48
48
2. ALWAYS fetch design context and visual reference from Figma MCP tools first. Do not attempt to generate code without retrieving at minimum the design context and screenshot. Metadata is optional
49
+
2a. **NEVER pass dirForAssetWrites on the initial get_design_context call.** Call it first WITHOUT that parameter to inspect the response. Only pass dirForAssetWrites after the user has explicitly approved image export.
50
+
2b. **MANDATORY GATE - Image export requires user approval:** Do NOT call get_design_context with dirForAssetWrites for ANY node until you have: (1) identified all image-containing nodes, (2) presented the list to the user, (3) asked "Should I export these N image assets now? (yes/no)", and (4) received an explicit "yes". Do NOT export images automatically.
51
+
2c. **Single prompt per batch:** Ask ONCE for the entire batch of image nodes. After the user says "yes", export all of them (via one or more get_design_context calls with dirForAssetWrites). Do NOT prompt again for each individual image.
49
52
3. Only call the Figma MCP tools listed in this workflow. If a tool is not available or not enabled, inform the user
50
53
4. ALWAYS discover similar components before creating new ones. Use Glob/Grep/Read to search the codebase
51
54
5. ALWAYS call generate-component tool with discovered components to get REUSE/EXTEND/CREATE recommendation
@@ -56,9 +59,24 @@ This workflow guides through converting a Figma design into a StorefrontNext-com
56
59
57
60
### Figma MCP Tools
58
61
When calling these tools, always include: clientLanguages="typescript", clientFrameworks="react"
59
-
- mcp__figma__get_design_context (REQUIRED): Generates UI code and returns asset URLs
62
+
- mcp__figma__get_design_context (REQUIRED): Generates UI code and returns asset URLs. **Initial call: do NOT pass dirForAssetWrites.** Call first without it to inspect the response. Only pass dirForAssetWrites after user has approved export (see Image and Asset Export below).
60
63
- mcp__figma__get_screenshot (REQUIRED): Provides visual reference of the design
61
-
- mcp__figma__get_metadata (OPTIONAL): Retrieves node hierarchy, layer types, names, positions, and sizes. Use only if you need detailed structural information
64
+
- mcp__figma__get_metadata (REQUIRED when node is a section): Retrieves node hierarchy, layer types, names, positions, and sizes. Use when get_design_context returns sparse metadata (section nodes do not export assets)
65
+
66
+
### Image and Asset Export (REQUIRED)
67
+
**MANDATORY GATE: Do not call get_design_context with dirForAssetWrites until the user has approved. You MUST ask ONCE for the entire batch—never prompt per image.**
68
+
69
+
Section nodes return sparse metadata and do NOT export images. You MUST:
70
+
71
+
1. **Initial probe (no export)**: Call get_design_context WITHOUT dirForAssetWrites first. Never pass dirForAssetWrites on the first call.
72
+
2. **Detect sparse response**: If get_design_context returns "sparse metadata" or "section node", call get_metadata with the same nodeId to retrieve the XML with child node IDs
73
+
3. **Identify image-containing nodes**: From the metadata XML (or from the initial response if it's a leaf with images), find nodes that contain images. Include: RECTANGLE with fills; nodes named with image-like names (e.g., photo, image, banner, hero); logos and brand assets (nodes named "logo", "Logo", "brand", "icon", "header", "footer", or similar); vector/component instances that represent logos or icons; frames that visually contain photos/illustrations; any node the screenshot suggests contains a logo or brand asset
74
+
4. **STOP and ask for approval (MANDATORY)**: Present the list of identified nodes (names and node IDs) to the user. Ask explicitly: "I found N image-containing nodes. Should I export these assets now? (yes/no)". STOP and wait for the user to respond. Do NOT call get_design_context with dirForAssetWrites for any node until the user confirms "yes". If you proceed without user confirmation, you have violated this workflow
75
+
5. **Download image nodes** (ONLY after user says "yes"): For each identified image-containing node, call get_design_context with:
76
+
- nodeId: the node ID from metadata or initial selection (e.g., "3351:1234")
77
+
- dirForAssetWrites: absolute path to the project's public images folder (e.g., \`{workspace}/packages/template-retail-rsc-app/public/images/figma-exports\`)
78
+
6. **Track downloaded assets**: Note which exported file path corresponds to which node/component (e.g., hero banner → hero-banner.webp, logo → nettle-logo.webp, category card 1 → infused-beverages.webp)
79
+
7. **Set image URLs in implementation**: When implementing the component, use the downloaded file paths for any img src or imageUrl props. Replace placeholder paths with the actual exported asset paths (e.g., \`/images/figma-exports/hero-banner.webp\`)
62
80
63
81
### StorefrontNext MCP Tools (REQUIRED)
64
82
- generate-component: Analyzes Figma design and discovered components, recommends REUSE/EXTEND/CREATE strategy. MUST be called with discoveredComponents parameter
@@ -134,9 +152,9 @@ Before calling generate-component, you must discover similar components using yo
134
152
135
153
**Create and present to the user a task plan that reflects these steps while keeping the Workflow Guidelines in mind. Wait for approval before proceeding.**
136
154
137
-
1. REQUIRED: Retrieve design context and generated code using mcp__figma__get_design_context with the provided fileKey and nodeId
155
+
1. REQUIRED: Retrieve design context using mcp__figma__get_design_context with fileKey and nodeId. **Do NOT pass dirForAssetWrites on this initial call.** If the response is sparse (section node): call get_metadata, identify image-containing nodes, then STOP and ask the user "Should I export these N image assets now? (yes/no)". WAIT for user to respond. Only after user says "yes", call get_design_context for each image-containing node with dirForAssetWrites
138
156
2. REQUIRED: Retrieve visual reference using mcp__figma__get_screenshot with the provided fileKey and nodeId
139
-
3. OPTIONAL: Retrieve design metadata using mcp__figma__get_metadata with the provided fileKey and nodeId (only if you need detailed structural information about the design hierarchy)
157
+
3. REQUIRED when sparse: If get_design_context returns sparse metadata (section node), call mcp__figma__get_metadata to get child node IDs, identify image-containing nodes, then STOP and ask user for approval. Do NOT call get_design_context with dirForAssetWrites until user confirms "yes"
140
158
4. REQUIRED: Discover similar components in the codebase:
141
159
- Use Glob to find component files in common directories
142
160
- Use Grep to search for components with similar names or structure
@@ -238,9 +256,9 @@ This tool has provided workflow instructions only. You MUST now execute ALL step
238
256
239
257
### Step 1: Fetch Figma Design Data (Parallel Calls)
240
258
Call these Figma MCP tools with the parameters above:
241
-
- \`mcp__figma__get_design_context\` (REQUIRED) - Get generated React code
259
+
- \`mcp__figma__get_design_context\` (REQUIRED) - **Do NOT pass dirForAssetWrites on the initial call.** Call first without it to inspect the response. If response is sparse (section node): call get_metadata to get child node IDs, identify image-containing nodes, then STOP and present the list to the user. Ask "Should I export these N image assets now? (yes/no)" and WAIT for user response. Only after user says "yes", call get_design_context per image-containing node with dirForAssetWrites
242
260
- \`mcp__figma__get_screenshot\` (REQUIRED) - Get visual reference
243
-
- \`mcp__figma__get_metadata\` (OPTIONAL) - Get node structure and hierarchy if needed
261
+
- \`mcp__figma__get_metadata\` (REQUIRED when sparse) - Use when get_design_context returns sparse metadata. After identifying image nodes: STOP, present list to user, wait for "yes" before exporting
244
262
245
263
### Step 2: Discover Similar Components
246
264
Use your tools to find existing components:
@@ -264,7 +282,7 @@ You MUST call \`map_tokens_to_theme\` tool with tokens extracted from Figma desi
264
282
This tool returns the token mapping summary that MUST be shown to the user.
265
283
266
284
### Step 5: Implement
267
-
After showing the recommendation and token mapping to the user, wait for approval then implement the code changes.
285
+
After showing the recommendation and token mapping to the user, wait for approval then implement the code changes. Use the downloaded asset paths from Step 1 for any img src or imageUrl props—do not use placeholder paths.
268
286
269
287
**DO NOT STOP until you have called generate_component AND map_tokens_to_theme and shown their outputs to the user.**
0 commit comments