|
| 1 | +--- |
| 2 | +title: MCP Server |
| 3 | +description: Expose your Panda CSS design system to AI assistants using the Model Context Protocol (MCP). |
| 4 | +--- |
| 5 | + |
| 6 | +The Panda MCP Server allows AI assistants like Claude, Cursor, VS Code Copilot, Windsurf, and Codex to understand and |
| 7 | +work with your project's design system. It provides tools for querying tokens, recipes, patterns, conditions, and more. |
| 8 | + |
| 9 | +## What is MCP? |
| 10 | + |
| 11 | +The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is an open standard for connecting AI assistants to |
| 12 | +external tools and data sources. Panda's MCP server exposes your design system through a set of specialized tools that |
| 13 | +AI assistants can use to: |
| 14 | + |
| 15 | +- Look up design tokens and their values |
| 16 | +- Understand available component recipes and variants |
| 17 | +- Query layout patterns and their properties |
| 18 | +- Analyze token and recipe usage across your codebase |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +### 1. Initialize MCP Configuration |
| 23 | + |
| 24 | +Run the interactive setup command in your project: |
| 25 | + |
| 26 | +```bash |
| 27 | +pnpm panda init-mcp |
| 28 | +``` |
| 29 | + |
| 30 | +This will prompt you to select which AI clients to configure: |
| 31 | + |
| 32 | +``` |
| 33 | +◆ Panda MCP Setup |
| 34 | +│ |
| 35 | +◆ Select AI clients to configure: |
| 36 | +│ ◻ Claude (.mcp.json) |
| 37 | +│ ◻ Cursor (.cursor/mcp.json) |
| 38 | +│ ◻ VS Code (.vscode/mcp.json) |
| 39 | +│ ◻ Windsurf (.windsurf/mcp.json) |
| 40 | +│ ◻ Codex (.codex/mcp.json) |
| 41 | +``` |
| 42 | + |
| 43 | +### 2. Use with Your AI Assistant |
| 44 | + |
| 45 | +Once configured, your AI assistant will automatically have access to Panda CSS tools. You can ask questions like: |
| 46 | + |
| 47 | +- "What color tokens are available in my design system?" |
| 48 | +- "Show me the button recipe variants" |
| 49 | +- "Which tokens are unused in my codebase?" |
| 50 | +- "What breakpoints are defined?" |
| 51 | + |
| 52 | +## CLI Commands |
| 53 | + |
| 54 | +### init-mcp |
| 55 | + |
| 56 | +Initialize MCP configuration for one or more AI clients. |
| 57 | + |
| 58 | +```bash |
| 59 | +# Interactive mode - select clients from a list |
| 60 | +pnpm panda init-mcp |
| 61 | + |
| 62 | +# Configure specific clients directly |
| 63 | +pnpm panda init-mcp --client claude,cursor |
| 64 | + |
| 65 | +# Specify working directory |
| 66 | +pnpm panda init-mcp --cwd ./my-project |
| 67 | +``` |
| 68 | + |
| 69 | +| Flag | Description | |
| 70 | +| ------------------ | ----------------------------------------- | |
| 71 | +| `--client <names>` | AI clients to configure (comma-separated) | |
| 72 | +| `--cwd <path>` | Current working directory | |
| 73 | + |
| 74 | +### mcp |
| 75 | + |
| 76 | +Start the MCP server manually (usually not needed - clients start it automatically). |
| 77 | + |
| 78 | +```bash |
| 79 | +pnpm panda mcp |
| 80 | + |
| 81 | +# With custom config path |
| 82 | +pnpm panda mcp --config ./panda.config.ts |
| 83 | + |
| 84 | +# Specify working directory |
| 85 | +pnpm panda mcp --cwd ./my-project |
| 86 | +``` |
| 87 | + |
| 88 | +| Flag | Description | |
| 89 | +| --------------------- | ------------------------- | |
| 90 | +| `--config, -c <path>` | Path to Panda config file | |
| 91 | +| `--cwd <path>` | Current working directory | |
| 92 | + |
| 93 | +## Supported AI Clients |
| 94 | + |
| 95 | +The MCP server supports the following AI assistants: |
| 96 | + |
| 97 | +| Client | Config Path | Description | |
| 98 | +| -------- | -------------------- | ------------------------------ | |
| 99 | +| Claude | `.mcp.json` | Claude Code and Claude Desktop | |
| 100 | +| Cursor | `.cursor/mcp.json` | Cursor IDE | |
| 101 | +| VS Code | `.vscode/mcp.json` | VS Code with Copilot | |
| 102 | +| Windsurf | `.windsurf/mcp.json` | Windsurf IDE | |
| 103 | +| Codex | `.codex/mcp.json` | OpenAI Codex CLI | |
| 104 | + |
| 105 | +## Available Tools |
| 106 | + |
| 107 | +The MCP server exposes these tools to AI assistants: |
| 108 | + |
| 109 | +| Tool | Description | Input | |
| 110 | +| ---------------------- | ------------------------------------------------------------------- | ----------------------------------------- | |
| 111 | +| `get_tokens` | Get design tokens with values, CSS variables, and usage examples | `category?` - filter by token category | |
| 112 | +| `get_semantic_tokens` | Get semantic tokens with conditional values (dark mode, responsive) | `category?` - filter by token category | |
| 113 | +| `get_color_palette` | Get the complete color palette | - | |
| 114 | +| `get_recipes` | Get component recipes with variants and default values | `name?` - filter by recipe name | |
| 115 | +| `get_patterns` | Get layout patterns with properties and usage examples | `name?` - filter by pattern name | |
| 116 | +| `get_conditions` | Get all conditions (breakpoints, pseudo-classes, color modes) | - | |
| 117 | +| `get_keyframes` | Get keyframe animations defined in the theme | - | |
| 118 | +| `get_text_styles` | Get text style compositions for typography | - | |
| 119 | +| `get_layer_styles` | Get layer style compositions for visual styling | - | |
| 120 | +| `get_animation_styles` | Get animation style compositions | - | |
| 121 | +| `get_config` | Get the resolved Panda CSS configuration | - | |
| 122 | +| `get_usage_report` | Analyze token/recipe usage across the codebase | `scope?` - `'all'`, `'token'`, `'recipe'` | |
| 123 | + |
| 124 | +The `get_usage_report` tool is particularly useful for auditing your design system, identifying unused tokens/recipes, |
| 125 | +and finding missing definitions. |
| 126 | + |
| 127 | +## Generated Configuration |
| 128 | + |
| 129 | +When you run `panda init-mcp`, the following configuration is generated for each selected client: |
| 130 | + |
| 131 | +```json |
| 132 | +{ |
| 133 | + "mcpServers": { |
| 134 | + "panda": { |
| 135 | + "command": "npx", |
| 136 | + "args": ["panda", "mcp"] |
| 137 | + } |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +The server automatically loads your `panda.config.ts` from the current working directory when started. |
| 143 | + |
| 144 | +## Manual Configuration |
| 145 | + |
| 146 | +If you prefer to configure MCP manually, create the appropriate config file for your AI client: |
| 147 | + |
| 148 | +### Claude |
| 149 | + |
| 150 | +Create `.mcp.json` in your project root: |
| 151 | + |
| 152 | +```json |
| 153 | +{ |
| 154 | + "mcpServers": { |
| 155 | + "panda": { |
| 156 | + "command": "npx", |
| 157 | + "args": ["panda", "mcp"] |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +### Cursor |
| 164 | + |
| 165 | +Create `.cursor/mcp.json`: |
| 166 | + |
| 167 | +```json |
| 168 | +{ |
| 169 | + "mcpServers": { |
| 170 | + "panda": { |
| 171 | + "command": "npx", |
| 172 | + "args": ["panda", "mcp"] |
| 173 | + } |
| 174 | + } |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +### VS Code |
| 179 | + |
| 180 | +Create `.vscode/mcp.json`: |
| 181 | + |
| 182 | +```json |
| 183 | +{ |
| 184 | + "servers": { |
| 185 | + "panda": { |
| 186 | + "command": "npx", |
| 187 | + "args": ["panda", "mcp"] |
| 188 | + } |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +### Custom Config Path |
| 194 | + |
| 195 | +If your Panda config is not in the default location, specify it explicitly: |
| 196 | + |
| 197 | +```json |
| 198 | +{ |
| 199 | + "mcpServers": { |
| 200 | + "panda": { |
| 201 | + "command": "npx", |
| 202 | + "args": ["panda", "mcp", "--config", "./path/to/panda.config.ts"] |
| 203 | + } |
| 204 | + } |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +## Example Interactions |
| 209 | + |
| 210 | +Here are some example prompts you can use with AI assistants once MCP is configured: |
| 211 | + |
| 212 | +### Exploring Tokens |
| 213 | + |
| 214 | +> "What spacing tokens are available?" |
| 215 | +
|
| 216 | +The AI will use `get_tokens` with `category: "spacing"` to show you all spacing values. |
| 217 | + |
| 218 | +### Understanding Recipes |
| 219 | + |
| 220 | +> "How do I use the button recipe with a destructive variant?" |
| 221 | +
|
| 222 | +The AI will use `get_recipes` with `name: "button"` to show variants and usage. |
| 223 | + |
| 224 | +### Finding Unused Tokens |
| 225 | + |
| 226 | +> "Which design tokens are not being used in my codebase?" |
| 227 | +
|
| 228 | +The AI will use `get_usage_report` with `scope: "token"` to identify unused tokens. |
| 229 | + |
| 230 | +### Checking Conditions |
| 231 | + |
| 232 | +> "What responsive breakpoints are defined?" |
| 233 | +
|
| 234 | +The AI will use `get_conditions` to show all available breakpoints. |
| 235 | + |
| 236 | +## Troubleshooting |
| 237 | + |
| 238 | +### Server Not Starting |
| 239 | + |
| 240 | +If the MCP server fails to start: |
| 241 | + |
| 242 | +1. Ensure Panda CSS is installed: `pnpm add -D @pandacss/dev` |
| 243 | +2. Verify you have a valid `panda.config.ts` in your project |
| 244 | +3. Check that `npx panda mcp` runs without errors |
| 245 | + |
| 246 | +### Tools Not Available |
| 247 | + |
| 248 | +If tools aren't showing up in your AI assistant: |
| 249 | + |
| 250 | +1. Restart the AI assistant after adding the MCP configuration |
| 251 | +2. Verify the config file is in the correct location |
| 252 | +3. Check the AI assistant's MCP documentation for any additional setup steps |
| 253 | + |
| 254 | +### Usage Report Empty |
| 255 | + |
| 256 | +If `get_usage_report` returns empty results: |
| 257 | + |
| 258 | +1. Ensure your `include` paths in `panda.config.ts` cover your source files |
| 259 | +2. Run `pnpm panda codegen` to ensure the project is properly set up |
| 260 | +3. Verify files contain Panda CSS usage (css(), styled(), etc.) |
0 commit comments