sketch-design-mcp
v3.0.0
Published
MCP Server for extracting structured UI design details from Sketch design specs (exported via 无敌Sketch标注插件) — no vision model required.
Maintainers
Readme
sketch-design-mcp
MCP server for high-fidelity implementation from Sketch spec pages (无敌Sketch标注插件导出), optimized for Claude Code.
Version 3 Direction
v3 is the only supported pipeline and focuses on implementation fidelity:
get_artboard_manifest: choose the right entry artboardget_scene_graph: reconstruct hierarchy + constraints from flat layersget_blueprint: generate implementation contract (layout/tokens/components/interactions)get_interaction_graph: buildtrigger -> condition -> actiongraph with target bindingvalidate_implementation: compare expected contract vs actual implementation snapshot
This enables a practical loop: extract -> code -> screenshot/json snapshot -> validate -> fix.
Architecture
src/
├── index.ts # MCP protocol entry (official SDK, stdio transport)
├── engine.ts # Engine export facade
├── engine/ # Engine internals (core/output/v3-tools)
├── v3/ # v3 modules: scene / blueprint / interaction / validate / manifest
├── rules.ts # Configurable recognition rules (supports external JSON override)
├── aggregator.ts # Shared low-level layer helpers used by v3
├── aggregator/ # Shared low-level layer helpers
└── types.ts # Type definitionsTools
| Tool | Purpose |
|------|---------|
| get_artboard_manifest | Artboard list + complexity score + recommended pages (supports paging) |
| get_scene_graph | Hierarchical nodes, constraints, sections, styles (supports paging) |
| get_blueprint | Code-generation contract for Claude Code (supports component paging) |
| get_interaction_graph | Structured interaction edges with target binding (supports paging) |
| validate_implementation | Scoring + findings for layout/style/interaction |
Setup
npm install
npm run buildUsage with Claude Code
Add to ~/.claude.json:
{
"mcpServers": {
"sketch-design": {
"type": "stdio",
"command": "node",
"args": ["/path/to/sketch-design-mcp/dist/index.js"]
}
}
}Recommended Claude Workflow
- Call
get_artboard_manifestand choose arecommended=trueartboard. - Call
get_blueprintfor the target Y range. - Generate front-end code from blueprint.
- Call
get_interaction_graphto complete behavior logic. - Feed expected/actual JSON into
validate_implementation. - Iterate until score reaches your target.
Large Payload Behavior
- v3 tools no longer silently truncate large responses.
- If payload exceeds limit, tool returns an explicit error with guidance.
- Use
offset/limit/cursorto fetch in pages. - Cursor format is
offset:N(example:offset:300). - For very large blueprints, set
include_interactions=falseand fetch interactions viaget_interaction_graph.
Configurable Rules
- Default recognition rules are built in
src/rules.ts. - Built-in profiles:
shadow_zh: optimized for current Chinese intranet Sketch annotation style.generic: broader language/label matching for mixed teams.
- MCP now auto-detects profile from the selected artboard layers.
- You can force profile selection:
export SKETCH_MCP_RULESET_PROFILE=generic- You can still override keyword/pattern rules without changing TypeScript code:
export SKETCH_MCP_RULESET_PATH=/absolute/path/to/ruleset.json- Example rules file:
docs/ruleset.example.json. - Supported override keys include:
annotationNamePrefixes,annotationFontIncludes,anchorNamePrefixesspecFontIncludes,marginNumberedItemPattern,marginSpecPatternsinteractionStepPatterns.trigger/condition/action
- Every tool output now includes runtime rule metadata in
meta:ruleProfileruleConfidenceruleSource(auto/forced_env/default)
AI Interaction Understanding
get_interaction_graphsupports model-driven semantic understanding for interaction blocks via Anthropic Messages API.- Configuration via 4 environment variables:
SKETCH_MCP_INTERACTION_PROVIDER—anthropic(default) orfallbackto disable AISKETCH_MCP_INTERACTION_MODEL— model name (e.g.glm-5.1)SKETCH_MCP_AUTH_TOKEN— API key for the providerSKETCH_MCP_BASE_URL— API base URL (e.g.https://open.bigmodel.cn/api/anthropic)
- When
SKETCH_MCP_AUTH_TOKENis empty or provider isfallback, falls back to rule-based analysis. - AI output also feeds
visualHintsintoget_blueprint, so interaction-derived visual states can be carried into implementation.
Example MCP server config:
{
"env": {
"SKETCH_MCP_INTERACTION_PROVIDER": "anthropic",
"SKETCH_MCP_INTERACTION_MODEL": "glm-5.1",
"SKETCH_MCP_AUTH_TOKEN": "your-api-key",
"SKETCH_MCP_BASE_URL": "https://open.bigmodel.cn/api/anthropic"
}
}Notes
- Pure TypeScript runtime, no Python dependency.
- Internal-network cache:
/tmp/sketch_design_cache. NODE_TLS_REJECT_UNAUTHORIZED=0is enabled for intranet HTTPS edge cases.
