Skip to main content
Glama
README.md
# Figma MCP Server

A powerful MCP (Model Context Protocol) server that connects AI applications to the Figma API, enabling seamless access to Figma designs, automatic HTML/CSS generation, and screenshot capture.

## ๐Ÿš€ Features

### Available MCP Tools

| Tool | Description | Use Case |
|------|-------------|----------|
| **getFile** | Fetch complete Figma file data | Get entire file structure and metadata |
| **getNode** | Fetch specific node from a file | Access individual components or frames |
| **analyzeDesign** | Extract and analyze design properties | Understand component structure and styling |
| **generateCSS** | Generate CSS from Figma nodes | Convert Figma styles to CSS code |
| **generateHTML** | Generate HTML structure | Create semantic HTML from designs |
| **generateFullDesign** | Generate complete HTML/CSS file | Convert entire designs to working code |
| **getImage** | Capture screenshots/renders | Export designs as PNG, JPG, SVG, or PDF |
| **generateDesignWithScreenshot** | Generate HTML/CSS with screenshot reference | More accurate design-to-code with visual context |
| **generateBootstrapDesign** โญ | Generate Bootstrap 5 + SCSS from Figma | Production-ready responsive designs |

### What You Can Do

- ๐Ÿ“Š **Extract Design Data** - Access complete design specifications
- ๐ŸŽจ **Generate CSS** - Convert Figma styles to production-ready CSS
- ๐Ÿ—๏ธ **Create HTML** - Generate semantic HTML structure from designs
- ๐Ÿ“ธ **Capture Screenshots** - Export designs as images in multiple formats
- ๐Ÿ” **Analyze Components** - Understand design properties and hierarchy
- โšก **Automate Workflows** - Integrate with AI tools like Claude Desktop
- ๐Ÿš€ **Bootstrap Integration** โญ NEW - Generate responsive designs with Bootstrap 5 + SCSS

## ๐Ÿ“‹ Prerequisites

- **Node.js** v17 or higher
- **Figma Personal Access Token** (not a file access token)

## ๐Ÿ› ๏ธ Installation

### 1. Clone and Install

```bash
git clone <your-repo-url>
cd figma-mcp
npm install
```

### 2. Configure Figma Token

Create a `.env` file in the root directory:

```bash
FIGMA_TOKEN=your_personal_access_token_here
```

**Getting Your Token:**
1. Go to [Figma Account Settings](https://www.figma.com/settings)
2. Scroll to "Personal access tokens"
3. Click "Create a new personal access token"
4. Copy the token and add it to `.env`

โš ๏ธ **Important:** Use a **Personal Access Token**, not a file-specific token.

### 3. Build the Project

```bash
npm run build
```

## ๐ŸŽฏ Usage

### With Claude Desktop

Add to your Claude config file:

**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`  
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "figma": {
      "command": "node",
      "args": ["C:\\path\\to\\figma-mcp\\build\\index.js"]
    }
  }
}
```

### With VS Code MCP

Add to `.vscode/mcp.json`:

```json
{
  "servers": {
    "figma-mcp-server": {
      "type": "stdio",
      "command": "npm",
      "args": ["start"]
    }
  }
}
```

## ๐Ÿ“– Tool Usage Examples

### Understanding Figma URLs

For a URL like:
```
https://www.figma.com/design/YwUqmarhRx74Gb4zePtEUx/My-Design?node-id=8384-4
```

- **File Key**: `YwUqmarhRx74Gb4zePtEUx`
- **Node ID**: `8384-4` (or `8384:4` - both formats work)

### 1. Analyze Design Structure

```
Use analyzeDesign with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
```

Returns detailed design properties including:
- Component hierarchy
- Colors and fills
- Typography settings
- Dimensions and positioning

### 2. Generate CSS Styles

```
Use generateCSS with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
- className: .my-component (optional)
```

Generates production-ready CSS with:
- Colors (rgba format)
- Typography (font-family, size, weight)
- Layout (width, height, padding)
- Effects (shadows, borders, border-radius)

### 3. Generate HTML Structure

```
Use generateHTML with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
```

Creates semantic HTML structure matching your Figma hierarchy.

### 4. Generate Complete HTML/CSS Page

```
Use generateFullDesign with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
```

Generates a complete HTML file with:
- Inline CSS styles
- Semantic HTML structure
- Responsive reset styles
- Proper typography and spacing

### 5. Capture Screenshots/Images

```
Use getImage with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
- format: png (or jpg, svg, pdf)
- scale: 2 (optional, 0.01 to 4)
```

**Format Guide:**
- **PNG** - Best for UI designs with transparency (recommended)
- **JPG** - Smaller file size, no transparency
- **SVG** - Vector format, scalable
- **PDF** - Print-ready documents

**Scale Options:**
- `1` - Original size (default)
- `2` - Retina/HiDPI displays (recommended)
- `3-4` - Very high resolution (print quality)
- `0.01-0.99` - Thumbnails/previews

Returns a temporary download URL (valid ~30 minutes).

### 6. Generate Design with Screenshot Reference (Enhanced) โญ

```
Use generateDesignWithScreenshot with:
- fileKey: YwUqmarhRx74Gb4zePtEUx
- nodeId: 8384-4
- includeScreenshot: true (optional, default true)
```

**What makes this special:**
This tool combines both the Figma API data AND a screenshot of the actual design to give you more accurate HTML/CSS generation.

**Benefits:**
- ๐Ÿ“ธ **Visual Reference** - Screenshot URL included in CSS comments
- ๐ŸŽฏ **More Accurate** - Generate code with visual context
- ๐Ÿ’ก **Better Guidance** - Comments suggest how to match the screenshot
- ๐Ÿ”„ **Side-by-side Comparison** - Easily compare output with original

**Perfect for:**
- Pixel-perfect implementations
- Complex layouts requiring visual verification
- When you want to ensure design fidelity
- Learning how designs translate to code

## ๐Ÿงช Testing Tools

Run test scripts from the `tests/` directory. **All outputs are saved to the `output/` folder.**

### Test Bootstrap-Enhanced Generation ๐Ÿš€ RECOMMENDED
```bash
npx tsx tests/test-bootstrap-enhanced.ts
```
Generates production-ready designs with:
- โœ… Bootstrap 5 framework included
- โœ… SCSS source files (editable)
- โœ… Compiled CSS embedded in HTML
- โœ… Semantic class names from Figma
- โœ… Screenshot reference for comparison
- โœ… Responsive, mobile-first layout

**Output:** `output/{component-name}.html`, `output/{component-name}.scss`, `output/{component-name}-screenshot.png`

**Why use this?** Generates designs that actually look like the screenshot!

### Test HTML/CSS Generation
```bash
npx tsx tests/test-tool.ts
```
Generates `output/output.html` with complete HTML/CSS from a Figma design.

### Test Enhanced Generation with Screenshot
```bash
npx tsx tests/test-screenshot-enhanced.ts
```
Generates `output/output-with-screenshot.html` AND downloads a reference screenshot to `output/screenshot-{nodeId}.png`. The HTML includes comments with the screenshot path for easy comparison.

### Test Image Capture
```bash
npx tsx tests/test-image.ts
```
Downloads a screenshot as `output/figma-screenshot-{nodeId}.png`

### Test Token Validation
```bash
npx tsx tests/test-token.ts
```
Validates your Figma API token and permissions.

## ๐Ÿ—๏ธ Project Structure

```
figma-mcp/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ index.ts                     # Main MCP server implementation
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test-bootstrap-enhanced.ts   # ๐Ÿš€ Bootstrap + SCSS generation (RECOMMENDED)
โ”‚   โ”œโ”€โ”€ test-tool.ts                 # HTML/CSS generation test
โ”‚   โ”œโ”€โ”€ test-screenshot-enhanced.ts  # Enhanced generation with screenshot
โ”‚   โ”œโ”€โ”€ test-image.ts                # Image capture test
โ”‚   โ”œโ”€โ”€ test-token.ts                # Token validation test
โ”‚   โ””โ”€โ”€ README.md                    # Test documentation
โ”œโ”€โ”€ output/                          # Generated HTML/CSS and screenshots
โ”‚   โ”œโ”€โ”€ .gitignore                   # Ignores generated files
โ”‚   โ””โ”€โ”€ README.md                    # Output folder guide
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ TROUBLESHOOTING.md           # Common issues and solutions
โ”‚   โ”œโ”€โ”€ CSS-IMPROVEMENTS.md          # CSS generation details
โ”‚   โ”œโ”€โ”€ IMAGE-FEATURE.md             # Screenshot feature guide
โ”‚   โ”œโ”€โ”€ SCREENSHOT-ENHANCED.md       # Enhanced generation guide
โ”‚   โ”œโ”€โ”€ BOOTSTRAP-ENHANCED.md        # ๐Ÿš€ Bootstrap + SCSS guide (NEW)
โ”‚   โ””โ”€โ”€ README.md                    # Documentation index
โ”œโ”€โ”€ build/                           # Compiled JavaScript output
โ”œโ”€โ”€ .env                             # Environment variables (not in git)
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md
```

## ๐Ÿ”ง Development

### Build Commands

```bash
# Build once
npm run build

# Build and watch for changes
npm run build -- --watch

# Start the server
npm start
```

### Supported Figma Properties

**Layout:**
- Width, height, positioning
- Padding and margins
- Border radius

**Typography:**
- Font family, size, weight
- Line height, text alignment
- Text content

**Colors:**
- Fill colors (solid, gradients)
- Stroke/border colors
- Opacity/transparency

**Effects:**
- Drop shadows
- Box shadows
- Border styles

## ๐Ÿ“š Documentation

- **[TROUBLESHOOTING.md](./docs/TROUBLESHOOTING.md)** - Common issues and fixes
- **[CSS-IMPROVEMENTS.md](./docs/CSS-IMPROVEMENTS.md)** - CSS generation details
- **[IMAGE-FEATURE.md](./docs/IMAGE-FEATURE.md)** - Screenshot capabilities

## ๐Ÿ› Troubleshooting

### "Invalid token" Error

โœ… **Solution:** Use a Personal Access Token, not a file access token
- Go to Figma Settings โ†’ Personal access tokens
- Create a new token with full API access
- Update your `.env` file

### Node Not Found

โœ… **Solution:** Check node ID format
- Both `8384-4` and `8384:4` work
- Get node ID from Figma URL or inspect panel

### Class Names Not Working

โœ… **Solution:** Already fixed in latest version
- Class names are normalized (colons โ†’ dashes)
- CSS selectors are valid

See [docs/TROUBLESHOOTING.md](./docs/TROUBLESHOOTING.md) for more solutions.

## ๐Ÿ”’ Security

- โš ๏ธ **Never commit `.env`** - Contains your Figma token
- โœ… Use environment variables for all secrets
- ๐Ÿ” For production, follow [MCP Authorization Best Practices](https://modelcontextprotocol.io/docs/tutorials/security/authorization)

## ๐ŸŒŸ Use Cases

1. **Design-to-Code** - Convert Figma designs to HTML/CSS automatically
2. **Design Systems** - Extract component styles for documentation
3. **Asset Export** - Batch export design elements as images
4. **Design Review** - Capture screenshots for presentations
5. **AI Integration** - Connect Figma to AI tools via MCP
6. **Automation** - Build workflows with Figma data

## ๐Ÿ“– References

- [Model Context Protocol](https://modelcontextprotocol.io)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
- [Figma API Documentation](https://www.figma.com/developers/api)

## ๐Ÿ“„ License

MIT

---

**Made with โค๏ธ for the design-to-code community**