sketch-design-mcp 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dist/index.js +2642 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# sketch-design-mcp
|
|
2
|
+
|
|
3
|
+
MCP server for high-fidelity implementation from Sketch spec pages (无敌Sketch标注插件导出), optimized for Claude Code.
|
|
4
|
+
|
|
5
|
+
## Version 3 Direction
|
|
6
|
+
|
|
7
|
+
v3 is the only supported pipeline and focuses on implementation fidelity:
|
|
8
|
+
|
|
9
|
+
1. `get_artboard_manifest`: choose the right entry artboard
|
|
10
|
+
2. `get_scene_graph`: reconstruct hierarchy + constraints from flat layers
|
|
11
|
+
3. `get_blueprint`: generate implementation contract (`layout/tokens/components/interactions`)
|
|
12
|
+
4. `get_interaction_graph`: build `trigger -> condition -> action` graph with target binding
|
|
13
|
+
5. `validate_implementation`: compare expected contract vs actual implementation snapshot
|
|
14
|
+
|
|
15
|
+
This enables a practical loop: `extract -> code -> screenshot/json snapshot -> validate -> fix`.
|
|
16
|
+
|
|
17
|
+
## Architecture
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
src/
|
|
21
|
+
├── index.ts # MCP protocol entry (official SDK, stdio transport)
|
|
22
|
+
├── engine.ts # Engine export facade
|
|
23
|
+
├── engine/ # Engine internals (core/output/v3-tools)
|
|
24
|
+
├── v3/ # v3 modules: scene / blueprint / interaction / validate / manifest
|
|
25
|
+
├── rules.ts # Configurable recognition rules (supports external JSON override)
|
|
26
|
+
├── aggregator.ts # Shared low-level layer helpers used by v3
|
|
27
|
+
├── aggregator/ # Shared low-level layer helpers
|
|
28
|
+
└── types.ts # Type definitions
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Tools
|
|
32
|
+
|
|
33
|
+
| Tool | Purpose |
|
|
34
|
+
|------|---------|
|
|
35
|
+
| `get_artboard_manifest` | Artboard list + complexity score + recommended pages (supports paging) |
|
|
36
|
+
| `get_scene_graph` | Hierarchical nodes, constraints, sections, styles (supports paging) |
|
|
37
|
+
| `get_blueprint` | Code-generation contract for Claude Code (supports component paging) |
|
|
38
|
+
| `get_interaction_graph` | Structured interaction edges with target binding (supports paging) |
|
|
39
|
+
| `validate_implementation` | Scoring + findings for layout/style/interaction |
|
|
40
|
+
|
|
41
|
+
## Setup
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install
|
|
45
|
+
npm run build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage with Claude Code
|
|
49
|
+
|
|
50
|
+
Add to `~/.claude.json`:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"sketch-design": {
|
|
56
|
+
"type": "stdio",
|
|
57
|
+
"command": "node",
|
|
58
|
+
"args": ["/path/to/sketch-design-mcp/dist/index.js"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Recommended Claude Workflow
|
|
65
|
+
|
|
66
|
+
1. Call `get_artboard_manifest` and choose a `recommended=true` artboard.
|
|
67
|
+
2. Call `get_blueprint` for the target Y range.
|
|
68
|
+
3. Generate front-end code from blueprint.
|
|
69
|
+
4. Call `get_interaction_graph` to complete behavior logic.
|
|
70
|
+
5. Feed expected/actual JSON into `validate_implementation`.
|
|
71
|
+
6. Iterate until score reaches your target.
|
|
72
|
+
|
|
73
|
+
## Large Payload Behavior
|
|
74
|
+
|
|
75
|
+
- v3 tools **no longer silently truncate** large responses.
|
|
76
|
+
- If payload exceeds limit, tool returns an explicit error with guidance.
|
|
77
|
+
- Use `offset/limit/cursor` to fetch in pages.
|
|
78
|
+
- Cursor format is `offset:N` (example: `offset:300`).
|
|
79
|
+
- For very large blueprints, set `include_interactions=false` and fetch interactions via `get_interaction_graph`.
|
|
80
|
+
|
|
81
|
+
## Configurable Rules
|
|
82
|
+
|
|
83
|
+
- Default recognition rules are built in `src/rules.ts`.
|
|
84
|
+
- Built-in profiles:
|
|
85
|
+
- `shadow_zh`: optimized for current Chinese intranet Sketch annotation style.
|
|
86
|
+
- `generic`: broader language/label matching for mixed teams.
|
|
87
|
+
- MCP now auto-detects profile from the selected artboard layers.
|
|
88
|
+
- You can force profile selection:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
export SKETCH_MCP_RULESET_PROFILE=generic
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- You can still override keyword/pattern rules without changing TypeScript code:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export SKETCH_MCP_RULESET_PATH=/absolute/path/to/ruleset.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- Example rules file: `docs/ruleset.example.json`.
|
|
101
|
+
- Supported override keys include:
|
|
102
|
+
- `annotationNamePrefixes`, `annotationFontIncludes`, `anchorNamePrefixes`
|
|
103
|
+
- `specFontIncludes`, `marginNumberedItemPattern`, `marginSpecPatterns`
|
|
104
|
+
- `interactionStepPatterns.trigger/condition/action`
|
|
105
|
+
- Every tool output now includes runtime rule metadata in `meta`:
|
|
106
|
+
- `ruleProfile`
|
|
107
|
+
- `ruleConfidence`
|
|
108
|
+
- `ruleSource` (`auto` / `forced_env` / `default`)
|
|
109
|
+
|
|
110
|
+
## AI Interaction Understanding
|
|
111
|
+
|
|
112
|
+
- `get_interaction_graph` supports model-driven semantic understanding for interaction blocks via Anthropic Messages API.
|
|
113
|
+
- Configuration via 4 environment variables:
|
|
114
|
+
- `SKETCH_MCP_INTERACTION_PROVIDER` — `anthropic` (default) or `fallback` to disable AI
|
|
115
|
+
- `SKETCH_MCP_INTERACTION_MODEL` — model name (e.g. `glm-5.1`)
|
|
116
|
+
- `SKETCH_MCP_AUTH_TOKEN` — API key for the provider
|
|
117
|
+
- `SKETCH_MCP_BASE_URL` — API base URL (e.g. `https://open.bigmodel.cn/api/anthropic`)
|
|
118
|
+
- When `SKETCH_MCP_AUTH_TOKEN` is empty or provider is `fallback`, falls back to rule-based analysis.
|
|
119
|
+
- AI output also feeds `visualHints` into `get_blueprint`, so interaction-derived visual states can be carried into implementation.
|
|
120
|
+
|
|
121
|
+
Example MCP server config:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"env": {
|
|
126
|
+
"SKETCH_MCP_INTERACTION_PROVIDER": "anthropic",
|
|
127
|
+
"SKETCH_MCP_INTERACTION_MODEL": "glm-5.1",
|
|
128
|
+
"SKETCH_MCP_AUTH_TOKEN": "your-api-key",
|
|
129
|
+
"SKETCH_MCP_BASE_URL": "https://open.bigmodel.cn/api/anthropic"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Notes
|
|
135
|
+
|
|
136
|
+
- Pure TypeScript runtime, no Python dependency.
|
|
137
|
+
- Internal-network cache: `/tmp/sketch_design_cache`.
|
|
138
|
+
- `NODE_TLS_REJECT_UNAUTHORIZED=0` is enabled for intranet HTTPS edge cases.
|