codesign-mcp-next 0.0.0-stage → 0.3.2
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/CHANGELOG.md +121 -0
- package/LICENSE +21 -0
- package/README.md +458 -3
- package/dist/browser/manager.js +204 -0
- package/dist/browser/session.js +62 -0
- package/dist/codesign/cache.js +85 -0
- package/dist/codesign/errors.js +47 -0
- package/dist/codesign/integrity.js +197 -0
- package/dist/codesign/meta.js +57 -0
- package/dist/codesign/parser.js +56 -0
- package/dist/codesign/platform.js +232 -0
- package/dist/codesign/selection.js +205 -0
- package/dist/codesign/sharing.js +153 -0
- package/dist/codesign/slices.js +34 -0
- package/dist/codesign/types.js +1 -0
- package/dist/config.js +94 -0
- package/dist/index.js +16 -0
- package/dist/logger.js +68 -0
- package/dist/mcp/result.js +151 -0
- package/dist/mcp/schema.js +122 -0
- package/dist/mcp/server.js +313 -0
- package/dist/prompts/design-to-code.js +128 -0
- package/dist/resources/workflow.js +33 -0
- package/dist/server.js +61 -0
- package/dist/tools/artboards.js +96 -0
- package/dist/tools/diagnostics.js +192 -0
- package/dist/tools/image.js +134 -0
- package/dist/tools/login.js +136 -0
- package/dist/tools/slices.js +228 -0
- package/dist/tools/spec.js +236 -0
- package/dist/tools/status.js +62 -0
- package/dist/utils/download.js +290 -0
- package/dist/utils/filename.js +16 -0
- package/dist/utils/http.js +54 -0
- package/dist/utils/rate-limit.js +120 -0
- package/dist/utils/redact.js +110 -0
- package/dist/utils/retry.js +97 -0
- package/dist/utils/url.js +98 -0
- package/package.json +58 -6
- package/userscripts/codesign-ai-selection.user.js +445 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.2 - 2026-08-31
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Accepted password-protected sharing-detail responses that expose `screens` at the top level instead of nesting them under `designs`, preventing valid HTTP 200 responses from being reported as `SHARING_NOT_FOUND`. ([#5](https://github.com/DOIT008/codesign-mcp/issues/5))
|
|
8
|
+
- Preserved the existing nested `designs` response shape and sharing-detail diagnostics.
|
|
9
|
+
|
|
10
|
+
### Tests
|
|
11
|
+
|
|
12
|
+
- Added regression coverage for both sharing-detail response shapes and malformed-response diagnostics.
|
|
13
|
+
|
|
14
|
+
## 0.3.1 - 2026-08-29
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Encoded slice `object_id` values as reversible, cross-platform filename components so Windows downloads no longer fail for Figma-style IDs containing reserved characters such as `:`. ([#3](https://github.com/DOIT008/codesign-mcp/issues/3))
|
|
19
|
+
- Preserved existing UUID-style slice filenames while avoiding collisions with identifiers that already contain percent-encoded text.
|
|
20
|
+
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
- Added regression coverage for UUID-style IDs, Windows-incompatible Figma-style IDs, and filename-encoding collisions.
|
|
24
|
+
- Verified real PNG downloads for both a UUID-style slice and the Issue #3 Figma-style slice on Windows.
|
|
25
|
+
|
|
26
|
+
## 0.3.0 - 2026-07-29
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Added a repository-hosted Tampermonkey userscript that copies the active CoDesign screen and layer selection as a structured Agent prompt without including the sharing password.
|
|
31
|
+
- Added `selectionScope` support to `get_artboard_spec`: `layer` preserves the existing single-node response, `subtree` returns strict descendants, and `region` returns all non-ancestor nodes contained by the selected bounds.
|
|
32
|
+
- Added selected-region hierarchy, bounds, relative coordinates, and platform-filtered selection metadata.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- Clarified that semantic document flow is the default design-to-code strategy while an explicit user request for absolute or canvas-style positioning takes precedence.
|
|
37
|
+
- Positioned the userscript action before CoDesign's native inspector action so the existing control keeps its expected placement.
|
|
38
|
+
|
|
39
|
+
### Tests
|
|
40
|
+
|
|
41
|
+
- Added coverage for single-layer, subtree, spatial region, relative coordinate, and missing-layer selection behavior.
|
|
42
|
+
- Added userscript syntax validation to the test command.
|
|
43
|
+
- Verified region selection against a real CoDesign sharing screen, including spatial sibling layers and relative coordinates.
|
|
44
|
+
|
|
45
|
+
## 0.2.0 - 2026-07-02
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
|
|
49
|
+
- Added `targetPlatform` support to `get_artboard_spec` for natural-language platform names such as `web`, `Android`, `安卓`, `iOS`, `微信小程序`, and `mini program`.
|
|
50
|
+
- Added platform presentation metadata under `spec.platformSpec`, including normalized platform id, units, converted rects, unit-adjusted CSS, and conversion details.
|
|
51
|
+
- Added CoDesign-style custom platform settings with `targetUnit`, `customScale`, `customWidth`, and `remBasePx`, including rem conversion for target-width workflows.
|
|
52
|
+
- Updated the design-to-code prompt and workflow resource so agents pass platform, unit, custom width, custom scale, and rem base settings when users provide them in natural language.
|
|
53
|
+
|
|
54
|
+
### Tests
|
|
55
|
+
|
|
56
|
+
- Added platform alias, unit conversion, custom width, rem base, and invalid platform coverage.
|
|
57
|
+
- Verified the real CoDesign sharing link flow with the fuzzy request "设计稿目标宽度 1440px,单位用 rem".
|
|
58
|
+
|
|
59
|
+
## 0.1.10 - 2026-06-09
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- Updated the CoDesign design-to-code prompt and workflow guidance to require semantic page structure and normal document flow before coding.
|
|
64
|
+
- Clarified that Flexbox/Grid should be preferred for page layout, with absolute or fixed positioning reserved for local overlays or intentionally overlapping elements.
|
|
65
|
+
|
|
66
|
+
## 0.1.9 - 2026-05-26
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
- Delayed creation of the default `.codesign-mcp` runtime directory until a tool actually needs local state or artifacts.
|
|
71
|
+
- Kept default startup logging from creating the runtime directory while still honoring an explicit `CODESIGN_LOG_FILE`.
|
|
72
|
+
|
|
73
|
+
### Tests
|
|
74
|
+
|
|
75
|
+
- Added startup coverage to ensure server initialization does not create the default runtime directory.
|
|
76
|
+
|
|
77
|
+
## 0.1.8 - 2026-05-22
|
|
78
|
+
|
|
79
|
+
### Security
|
|
80
|
+
|
|
81
|
+
- Removed runtime dependencies on the MCP SDK, Pino, and Zod to reduce third-party supply-chain exposure.
|
|
82
|
+
- Replaced in-page dynamic fetch calls with Playwright API request calls guarded by CoDesign same-origin checks.
|
|
83
|
+
- Added remote asset allowlisting and CoDesign COS-to-CDN normalization for meta, screen, and slice downloads.
|
|
84
|
+
- Hardened `codesign_logout` so it only clears the configured profile directory, not arbitrary children of a broad data directory.
|
|
85
|
+
- Expanded `debug_collect_network` redaction for sharing IDs, account/team IDs, sensitive headers, query values, CDN path tokens, and response bodies.
|
|
86
|
+
|
|
87
|
+
### Changed
|
|
88
|
+
|
|
89
|
+
- Added a small local MCP stdio implementation and JSON schema validator for the server's current tool, prompt, and resource surface.
|
|
90
|
+
- Replaced Pino with a local JSON-lines file logger.
|
|
91
|
+
- Disabled source map output and excluded generated source maps from published package contents.
|
|
92
|
+
|
|
93
|
+
### Fixed
|
|
94
|
+
|
|
95
|
+
- `prompts/get` now reports invalid prompt arguments as JSON-RPC invalid params instead of internal server errors.
|
|
96
|
+
- Diagnostic response summaries now preserve useful request shape while hiding sensitive values.
|
|
97
|
+
|
|
98
|
+
### Tests
|
|
99
|
+
|
|
100
|
+
- Added coverage for profile deletion safety, diagnostic redaction, same-origin request blocking, and MCP prompt argument validation.
|
|
101
|
+
|
|
102
|
+
## 0.1.7 - 2026-05-21
|
|
103
|
+
|
|
104
|
+
### Added
|
|
105
|
+
|
|
106
|
+
- Added the `implement_codesign_page` MCP prompt for the documented CoDesign design-to-code workflow.
|
|
107
|
+
- Added the `codesign://workflow/design-to-code` read-only MCP resource for workflow guidance.
|
|
108
|
+
- Extended the stdio smoke test to verify tools, prompts, and resources.
|
|
109
|
+
- Added README badges for LobeHub, npm, Node.js, TypeScript, MCP SDK, and license metadata.
|
|
110
|
+
|
|
111
|
+
## 0.1.6 - 2026-05-19
|
|
112
|
+
|
|
113
|
+
### Changed
|
|
114
|
+
|
|
115
|
+
- Invalid scalar environment variables now fail at startup instead of silently using defaults. For example, `CODESIGN_KEEP_BROWSER=maybe` and `CODESIGN_LOG_LEVEL=verbose` will stop the server with a clear configuration error. This is intentional so configuration mistakes are exposed before runtime.
|
|
116
|
+
- Same-origin CoDesign API fetch failures now surface as `SHARING_FETCH_FAILED` instead of being misreported as missing shares.
|
|
117
|
+
- Artifact downloads now reject paths that escape the configured artifacts directory.
|
|
118
|
+
|
|
119
|
+
### Tests
|
|
120
|
+
|
|
121
|
+
- Added coverage for strict environment parsing, same-origin request failures, and artifact path validation.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ccpopy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,458 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# codesign-mcp-next
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/codesign-mcp-next)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://modelcontextprotocol.io/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
English | [简体中文](#简体中文)
|
|
10
|
+
|
|
11
|
+
Local MCP server for Tencent CoDesign sharing links. It exposes artboards, official layer specs, preview images, and designer-exported slices for design-to-code workflows.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Read CoDesign sharing links through MCP tools.
|
|
16
|
+
- List designs and artboards from a sharing URL.
|
|
17
|
+
- Fetch official `meta_url` specs with layers, groups, text, colors, CSS, and coordinates.
|
|
18
|
+
- Download designer-exported slice assets from the official slice manifest.
|
|
19
|
+
- Copy the current CoDesign screen and layer selection to an Agent with the optional Tampermonkey userscript.
|
|
20
|
+
- Keep login state in a persistent local Chromium profile.
|
|
21
|
+
- Store runtime files in the caller workspace by default.
|
|
22
|
+
- Provide a reusable MCP prompt and read-only workflow resource for design-to-code tasks.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Run directly with npm:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx -y codesign-mcp-next
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install globally:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g codesign-mcp-next
|
|
36
|
+
codesign-mcp-next
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## MCP Configuration
|
|
40
|
+
|
|
41
|
+
For most MCP clients, use the zero-config form:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"codesign-mcp-next": {
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["-y", "codesign-mcp-next@latest"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The server detects its workspace in this order:
|
|
55
|
+
|
|
56
|
+
1. `CODESIGN_WORKSPACE_DIR`
|
|
57
|
+
2. `INIT_CWD`, which is normally the directory where `npx` was launched
|
|
58
|
+
3. `process.cwd()`
|
|
59
|
+
|
|
60
|
+
Runtime files are written under the detected workspace:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
<workspace>/.codesign-mcp/profile
|
|
64
|
+
<workspace>/.codesign-mcp/artifacts
|
|
65
|
+
<workspace>/.codesign-mcp/codesign-mcp.log
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The default runtime directory is not created when the MCP server merely starts,
|
|
69
|
+
lists tools, or serves prompts/resources. It is created only when a tool needs
|
|
70
|
+
local state or artifacts, such as `codesign_login`, browser-backed CoDesign
|
|
71
|
+
reads, or downloads. Before that happens, default file logs go to stderr.
|
|
72
|
+
If `CODESIGN_LOG_FILE` is set explicitly, the server treats that path as an
|
|
73
|
+
explicit logging request and creates its parent directory when writing logs.
|
|
74
|
+
|
|
75
|
+
Use the `codesign_status` tool to inspect `workspaceRoot` and `workspaceRootSource`. If your MCP client launches servers from a global application directory instead of the project directory, set one of these explicitly:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"mcpServers": {
|
|
80
|
+
"codesign-mcp-next": {
|
|
81
|
+
"command": "npx",
|
|
82
|
+
"args": ["-y", "codesign-mcp-next@latest"],
|
|
83
|
+
"cwd": "F:/your-project"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or:
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
CODESIGN_WORKSPACE_DIR=F:/your-project
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Optional environment variables:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
CODESIGN_DATA_DIR=F:/your-project/.codesign-mcp
|
|
99
|
+
CODESIGN_PROFILE_DIR=F:/your-project/.codesign-mcp/profile
|
|
100
|
+
CODESIGN_ARTIFACTS_DIR=F:/your-project/.codesign-mcp/artifacts
|
|
101
|
+
CODESIGN_LOG_FILE=F:/your-project/.codesign-mcp/codesign-mcp.log
|
|
102
|
+
CODESIGN_IDLE_MS=600000
|
|
103
|
+
CODESIGN_KEEP_BROWSER=1
|
|
104
|
+
CODESIGN_CACHE_TTL_MS=60000
|
|
105
|
+
CODESIGN_INTEGRITY_STRICT=0
|
|
106
|
+
CODESIGN_RETRY_MAX_ATTEMPTS=3
|
|
107
|
+
CODESIGN_RETRY_BASE_MS=300
|
|
108
|
+
CODESIGN_API_RPS=5
|
|
109
|
+
CODESIGN_CDN_RPS=10
|
|
110
|
+
CODESIGN_LOG_LEVEL=info
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Tools
|
|
114
|
+
|
|
115
|
+
- `codesign_status`: Show runtime paths, browser state, and profile state.
|
|
116
|
+
- `codesign_login`: Open a visible Chromium window for CoDesign QR-code login.
|
|
117
|
+
- `codesign_logout`: Clear the persisted profile.
|
|
118
|
+
- `list_artboards`: Resolve a CoDesign sharing URL into designs and artboards.
|
|
119
|
+
- `get_artboard_spec`: Fetch official CoDesign `meta_url` specs with layers, text, colors, CSS, groups, and slice metadata. Every response includes a `spec.hierarchy` tree built from `parent_id` and `layerIndex`; each node carries `rect` (artboard-absolute), `relativeRect` (relative to the artboard), and `relativeToParent` (relative to its direct parent) so a full-page layout can be mapped to DOM without rebuilding the tree yourself. With `layerObjectId`, `selectionScope` can be `layer`, `subtree`, or `region`; selected responses also include flat layers/groups, selection bounds, and relative coordinates. Optional `targetPlatform` accepts natural-language platform names such as `web`, `Android`, `安卓`, `iOS`, `微信小程序`, or `mini program` and returns platform-adjusted metadata. Optional `targetUnit`, `customScale`, `customWidth`, and `remBasePx` mirror CoDesign's platform settings.
|
|
120
|
+
- `get_artboard_image`: Fetch preview or cover images for visual comparison.
|
|
121
|
+
- `download_slice`: Download designer-exported slice assets from the official slice manifest.
|
|
122
|
+
- `debug_collect_network`: Collect a redacted network summary for diagnosis.
|
|
123
|
+
|
|
124
|
+
## Caching and tool output
|
|
125
|
+
|
|
126
|
+
Sharing details, meta JSON, and slice manifests are cached in memory for 60 seconds (`CODESIGN_CACHE_TTL_MS`, in milliseconds). Concurrent calls for the same resource share a single request. Set the variable to `0` to disable caching. The cache is process-local and is never written to disk.
|
|
127
|
+
|
|
128
|
+
Successful tool results keep the complete payload in `structuredContent`. `content[0].text` contains only a short summary, so the same JSON is not counted twice in the model context. For `get_artboard_spec`, the text summary additionally includes a two-level `hierarchy` skeleton, artboard dimensions, layer/group/slice counts, and any integrity warnings, so clients that ignore `structuredContent` still receive the structural cues needed for design-to-code. If your MCP client does not read `structuredContent`, pass `includeFullText: true` to any data tool (`list_artboards`, `get_artboard_spec`, `get_artboard_image`, `download_slice`) to receive the full JSON as text instead. `debug_collect_network` keeps full records in the text channel because those records are the diagnostic output itself.
|
|
129
|
+
|
|
130
|
+
All headless tools reuse one browser page, so the sharing page is opened only once per session instead of once per tool call. The headed login window uses an exclusive page and mode switches wait for in-flight calls to finish.
|
|
131
|
+
|
|
132
|
+
## Rate limiting and retries
|
|
133
|
+
|
|
134
|
+
Every outbound request (sharing API, meta JSON, slice downloads) passes through a token bucket and a retry wrapper. `CODESIGN_API_RPS` (default `5`) and `CODESIGN_CDN_RPS` (default `10`) are per-host budgets; set either to `0` to disable throttling for that group. Only transient statuses (`408`, `429`, `500`, `502`, `503`, `504`) and network errors are retried, up to `CODESIGN_RETRY_MAX_ATTEMPTS` (default `3`) with exponential backoff and jitter. A `Retry-After` header is honored and capped by `CODESIGN_RETRY_AFTER_MAX_MS` (default `30000`). Exhausted retries return `RATE_LIMITED` with an actionable suggestion instead of a misleading `SHARING_NOT_FOUND`. `codesign_status` exposes the live bucket statistics under `rateLimit`.
|
|
135
|
+
|
|
136
|
+
## Data integrity
|
|
137
|
+
|
|
138
|
+
Responses are validated before they enter the cache, so an incomplete spec, manifest, or sharing detail is never cached or returned as a successful result. `list_artboards`, `get_artboard_spec`, and `download_slice` include an `integrity` field with `ok`, `warnings`, and `stats`. Structural corruption (duplicate layer ids, malformed rects, empty layer trees, missing `screenshot.url`) fails the tool. Ambiguous findings, such as orphaned `parent_id`, are warnings by default; set `CODESIGN_INTEGRITY_STRICT=1` to make warnings fatal.
|
|
139
|
+
|
|
140
|
+
Two CoDesign fields are deliberately **not** used as completeness checks, based on real sharing data: `slices_count` does not equal the number of manifest items, and slice `exportables[].size` is an export multiplier (for example `3`), not a byte count. `download_slice` only uses `screenshot.length` / `screenshot.size` as byte hints when they are present and positive; otherwise it verifies each file against HTTP `Content-Length` (when the response is not compressed), its MIME type, and its magic bytes. Each download result carries `verified` with the byte count, detected format, SHA-256, and encoding. Exportables without a URL are reported in `skipped` instead of being silently dropped, and `requested` / `downloaded` / `reused` counts are returned so partial results are visible.
|
|
141
|
+
|
|
142
|
+
## Security Notes
|
|
143
|
+
|
|
144
|
+
Remote metadata and artifact downloads are restricted to `https://codesign.qq.com` and `https://cdn*.codesign.qq.com`. Unsupported hosts fail explicitly with `REMOTE_URL_NOT_ALLOWED`.
|
|
145
|
+
|
|
146
|
+
`codesign_logout` only clears a profile directory inside the configured runtime directory. Unsafe profile paths fail explicitly with `PROFILE_DIR_UNSAFE`.
|
|
147
|
+
|
|
148
|
+
## Prompts
|
|
149
|
+
|
|
150
|
+
- `implement_codesign_page`: Generate a structured design-to-code prompt for a full page or copied CoDesign selection. It guides an Agent to call `list_artboards`, `get_artboard_spec`, and `download_slice` in the intended order.
|
|
151
|
+
|
|
152
|
+
## Resources
|
|
153
|
+
|
|
154
|
+
- `codesign://workflow/design-to-code`: Read-only workflow guidance for using the MCP tools without cropping preview screenshots or fabricating unavailable CoDesign data.
|
|
155
|
+
|
|
156
|
+
For design-to-code work, prefer this flow:
|
|
157
|
+
|
|
158
|
+
```text
|
|
159
|
+
list_artboards -> get_artboard_spec -> download_slice
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Preview screenshots are for visual comparison, not for production slicing.
|
|
163
|
+
|
|
164
|
+
## CoDesign AI Selection Userscript
|
|
165
|
+
|
|
166
|
+
The optional userscript adds a **Copy for AI** button beside the currently selected CoDesign layer. It reads the active screen and layer identifiers already present in the CoDesign page, then copies a structured Agent prompt. It does not make network requests or copy the sharing password.
|
|
167
|
+
|
|
168
|
+
1. Install [Tampermonkey](https://www.tampermonkey.net/) or another compatible userscript manager.
|
|
169
|
+
2. Open [codesign-ai-selection.user.js](https://raw.githubusercontent.com/DOIT008/codesign-mcp/main/userscripts/codesign-ai-selection.user.js) and confirm installation.
|
|
170
|
+
3. Open a CoDesign sharing page in annotation mode and select a layer or group in the layer tree.
|
|
171
|
+
4. Click **Copy for AI** in the right inspector, then paste the copied prompt into an Agent that has `codesign-mcp-next` connected.
|
|
172
|
+
5. Provide the sharing password separately when the link requires one.
|
|
173
|
+
|
|
174
|
+
The copied reference has this shape:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"type": "codesign-selection",
|
|
179
|
+
"sharingUrl": "https://codesign.qq.com/s/<PROJECT_ID>",
|
|
180
|
+
"screenId": "<SCREEN_ID>",
|
|
181
|
+
"screenName": "<SCREEN_NAME>",
|
|
182
|
+
"layerObjectId": "<LAYER_OBJECT_ID>",
|
|
183
|
+
"layerName": "<LAYER_NAME>",
|
|
184
|
+
"selectionScope": "region"
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`selectionScope=region` returns non-ancestor layers and groups fully contained by the selected bounds, which is useful when visually related elements are siblings rather than strict children. Use `subtree` when only the selected node's strict descendants are wanted. The script reports an explicit error if CoDesign changes the DOM selectors and the current selection cannot be read.
|
|
189
|
+
|
|
190
|
+
## Design-to-Code Workflow Prompt
|
|
191
|
+
|
|
192
|
+
Before asking an Agent to implement a page from CoDesign, make sure the MCP server is connected. If the design requires login, call `codesign_status` first. When the profile does not exist or CoDesign is not logged in, call `codesign_login`, scan the QR code in the opened browser window, and then call `codesign_status` again to confirm the login state.
|
|
193
|
+
|
|
194
|
+
Use this prompt template with your Agent. Replace `<PROJECT_ID>` with the value after `/s/` in the CoDesign sharing URL. If the sharing link does not require a password, remove the password line.
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
Implement this CoDesign design as a page:
|
|
198
|
+
|
|
199
|
+
Link: https://codesign.qq.com/s/<PROJECT_ID>
|
|
200
|
+
Password: <PASSWORD_IF_REQUIRED>
|
|
201
|
+
|
|
202
|
+
Requirements:
|
|
203
|
+
1. First call the codesign-mcp-next list_artboards tool to get the artboard list.
|
|
204
|
+
2. Then call get_artboard_spec to get the official specification data. If the target platform is known, pass it as targetPlatform, for example `Android`, `iOS`, or `微信小程序`. If the user specifies custom platform settings, also pass targetUnit, customScale, customWidth, and remBasePx.
|
|
205
|
+
3. Unless the user explicitly requests an absolute/canvas-style implementation, translate the coordinates into semantic page structure and normal document flow before coding. Prefer Flexbox/Grid for page layout and avoid recreating the whole page as globally absolute-positioned layers. An explicit user layout requirement takes precedence over this default.
|
|
206
|
+
4. If the design contains designer-exported slice assets, prefer download_slice. Do not crop assets from the full-page preview image.
|
|
207
|
+
5. Use preview images only for visual comparison, not as production asset sources.
|
|
208
|
+
6. Implement the page in the target directory specified by the user; if none is given, ask before writing files.
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm install
|
|
215
|
+
npm test
|
|
216
|
+
node scripts/stdio-smoke.mjs
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Publishing
|
|
220
|
+
|
|
221
|
+
This package is intended to be published from GitHub Actions using npm Trusted Publishing. Do not store long-lived npm tokens in the repository.
|
|
222
|
+
|
|
223
|
+
Before first publish:
|
|
224
|
+
|
|
225
|
+
1. Configure npm Trusted Publishing for this GitHub repository and `.github/workflows/publish.yml`.
|
|
226
|
+
2. Enable 2FA on npm for account and publishing protection.
|
|
227
|
+
3. Create and push a version tag matching `package.json`, for example `v0.3.2`, to trigger publication.
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## 简体中文
|
|
236
|
+
|
|
237
|
+
[English](#codesign-mcp-next) | 简体中文
|
|
238
|
+
|
|
239
|
+
面向腾讯 CoDesign 分享链接的本地 MCP 服务器。它为设计还原流程提供画板列表、官方图层标注、预览图以及设计师导出的切图资源。
|
|
240
|
+
|
|
241
|
+
## 功能
|
|
242
|
+
|
|
243
|
+
- 通过 MCP 工具读取 CoDesign 分享链接。
|
|
244
|
+
- 从分享链接获取设计稿和画板列表。
|
|
245
|
+
- 获取官方 `meta_url` 标注数据,包括图层、分组、文字、颜色、CSS 和坐标。
|
|
246
|
+
- 从官方切图清单下载设计师导出的切图资源。
|
|
247
|
+
- 通过可选油猴脚本,把当前 CoDesign 画板和图层选区复制给 Agent。
|
|
248
|
+
- 使用本地 Chromium profile 持久化扫码登录态。
|
|
249
|
+
- 默认把运行数据写入调用方项目目录。
|
|
250
|
+
- 提供可复用的 MCP 提示词和只读流程资源,服务于设计还原任务。
|
|
251
|
+
|
|
252
|
+
## 安装
|
|
253
|
+
|
|
254
|
+
直接通过 npm 运行:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx -y codesign-mcp-next
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
也可以全局安装:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
npm install -g codesign-mcp-next
|
|
264
|
+
codesign-mcp-next
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## MCP 配置
|
|
268
|
+
|
|
269
|
+
大多数 MCP 客户端可以直接使用零配置写法:
|
|
270
|
+
|
|
271
|
+
```json
|
|
272
|
+
{
|
|
273
|
+
"mcpServers": {
|
|
274
|
+
"codesign-mcp-next": {
|
|
275
|
+
"command": "npx",
|
|
276
|
+
"args": ["-y", "codesign-mcp-next@latest"]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
服务器会按这个顺序判断工作区:
|
|
283
|
+
|
|
284
|
+
1. `CODESIGN_WORKSPACE_DIR`
|
|
285
|
+
2. `INIT_CWD`,通常是启动 `npx` 时所在的目录
|
|
286
|
+
3. `process.cwd()`
|
|
287
|
+
|
|
288
|
+
运行数据会写入识别到的工作区:
|
|
289
|
+
|
|
290
|
+
```text
|
|
291
|
+
<workspace>/.codesign-mcp/profile
|
|
292
|
+
<workspace>/.codesign-mcp/artifacts
|
|
293
|
+
<workspace>/.codesign-mcp/codesign-mcp.log
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
MCP 服务仅启动、列出工具或读取提示词/资源时,不会创建默认运行目录。
|
|
297
|
+
只有工具确实需要本地状态或产物时才会创建,例如 `codesign_login`、
|
|
298
|
+
需要浏览器访问 CoDesign 的读取工具,或下载资源工具。在此之前,默认文件
|
|
299
|
+
日志会写到 stderr。如果显式设置了 `CODESIGN_LOG_FILE`,服务会把它视为
|
|
300
|
+
明确的日志写入请求,并在写日志时创建对应父目录。
|
|
301
|
+
|
|
302
|
+
可以通过 `codesign_status` 工具查看 `workspaceRoot` 和 `workspaceRootSource`。如果 MCP 客户端从全局应用目录启动服务器,而不是从项目目录启动,可以显式设置其中一种:
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"mcpServers": {
|
|
307
|
+
"codesign-mcp-next": {
|
|
308
|
+
"command": "npx",
|
|
309
|
+
"args": ["-y", "codesign-mcp-next@latest"],
|
|
310
|
+
"cwd": "F:/your-project"
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
或者:
|
|
317
|
+
|
|
318
|
+
```text
|
|
319
|
+
CODESIGN_WORKSPACE_DIR=F:/your-project
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
可选环境变量:
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
CODESIGN_DATA_DIR=F:/your-project/.codesign-mcp
|
|
326
|
+
CODESIGN_PROFILE_DIR=F:/your-project/.codesign-mcp/profile
|
|
327
|
+
CODESIGN_ARTIFACTS_DIR=F:/your-project/.codesign-mcp/artifacts
|
|
328
|
+
CODESIGN_LOG_FILE=F:/your-project/.codesign-mcp/codesign-mcp.log
|
|
329
|
+
CODESIGN_IDLE_MS=600000
|
|
330
|
+
CODESIGN_KEEP_BROWSER=1
|
|
331
|
+
CODESIGN_CACHE_TTL_MS=60000
|
|
332
|
+
CODESIGN_INTEGRITY_STRICT=0
|
|
333
|
+
CODESIGN_RETRY_MAX_ATTEMPTS=3
|
|
334
|
+
CODESIGN_RETRY_BASE_MS=300
|
|
335
|
+
CODESIGN_API_RPS=5
|
|
336
|
+
CODESIGN_CDN_RPS=10
|
|
337
|
+
CODESIGN_LOG_LEVEL=info
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## 工具
|
|
341
|
+
|
|
342
|
+
- `codesign_status`:查看运行路径、浏览器状态和 profile 状态。
|
|
343
|
+
- `codesign_login`:打开可见 Chromium 窗口,用于扫码登录 CoDesign。
|
|
344
|
+
- `codesign_logout`:清理持久化 profile。
|
|
345
|
+
- `list_artboards`:把 CoDesign 分享链接解析为设计稿和画板列表。
|
|
346
|
+
- `get_artboard_spec`:读取官方 CoDesign `meta_url` 标注数据,包括图层、文字、颜色、CSS、分组和切图元数据。所有结果都包含按 `parent_id` 与 `layerIndex` 构建的 `spec.hierarchy` 层级树;每个节点带 `rect`(相对画板绝对坐标)、`relativeRect`(相对画板)和 `relativeToParent`(相对直接父节点),整页还原可直接映射为 DOM,无需自行拼树。传入 `layerObjectId` 后,`selectionScope` 可设为 `layer`、`subtree` 或 `region`;选区结果还包含扁平图层/分组、选区边界和相对坐标。可选的 `targetPlatform` 支持 `web`、`Android`、`安卓`、`iOS`、`微信小程序`、`mini program` 等自然语言平台名称,并返回平台转换后的标注信息。`targetUnit`、`customScale`、`customWidth`、`remBasePx` 对应 CoDesign 的平台设置。
|
|
347
|
+
- `get_artboard_image`:获取预览图或封面图,主要用于视觉对比。
|
|
348
|
+
- `download_slice`:从官方切图清单下载设计师导出的切图资源。
|
|
349
|
+
- `debug_collect_network`:收集脱敏后的网络摘要,用于诊断。
|
|
350
|
+
|
|
351
|
+
## 缓存与工具输出
|
|
352
|
+
|
|
353
|
+
分享详情、标注 JSON 和切图清单会在内存中缓存 60 秒(`CODESIGN_CACHE_TTL_MS`,单位毫秒),相同资源的并发调用会合并为一次请求。设为 `0` 可关闭缓存。缓存只存在于当前进程,不会写入磁盘。
|
|
354
|
+
|
|
355
|
+
工具成功结果把完整数据放在 `structuredContent` 中,`content[0].text` 只返回简短摘要,避免同一份 JSON 在模型上下文里被计算两次。`get_artboard_spec` 的文本摘要还会带出两层 `hierarchy` 骨架、画板尺寸、图层/分组/切图数量以及完整性告警,因此不读取 `structuredContent` 的客户端也能拿到还原所需的结构信息。如果你的 MCP 客户端不读取 `structuredContent`,可以对任意数据工具(`list_artboards`、`get_artboard_spec`、`get_artboard_image`、`download_slice`)传 `includeFullText: true`,改为接收完整 JSON 文本。`debug_collect_network` 的诊断记录本身就是输出内容,因此仍在文本通道中保留完整记录。
|
|
356
|
+
|
|
357
|
+
所有 headless 工具复用同一个浏览器页面,分享页在每个会话中只打开一次,而不是每次工具调用都打开。登录用的 headed 窗口使用独占页面,模式切换会等待正在进行的调用结束。
|
|
358
|
+
|
|
359
|
+
## 限流与重试
|
|
360
|
+
|
|
361
|
+
所有出站请求(分享接口、标注 JSON、切图下载)都会先经过令牌桶节流再进入重试包装。`CODESIGN_API_RPS`(默认 `5`)和 `CODESIGN_CDN_RPS`(默认 `10`)是按 host 分组的配额,设为 `0` 可关闭对应分组的节流。只有瞬时状态码(`408`、`429`、`500`、`502`、`503`、`504`)和网络错误会重试,最多 `CODESIGN_RETRY_MAX_ATTEMPTS` 次(默认 `3`),采用指数退避加抖动。`Retry-After` 响应头会被遵守,上限由 `CODESIGN_RETRY_AFTER_MAX_MS` 控制(默认 `30000` 毫秒)。重试耗尽后返回 `RATE_LIMITED` 和可操作建议,而不再误报为 `SHARING_NOT_FOUND`。`codesign_status` 会在 `rateLimit` 字段中暴露实时的桶统计。
|
|
362
|
+
|
|
363
|
+
## 数据完整性
|
|
364
|
+
|
|
365
|
+
响应在进入缓存前会先经过校验,因此不完整的标注、切图清单或分享详情不会被缓存,也不会作为成功结果返回。`list_artboards`、`get_artboard_spec` 和 `download_slice` 会返回 `integrity` 字段,包含 `ok`、`warnings` 和 `stats`。结构性损坏(图层 object_id 重复、rect 非法、图层树为空、缺少 `screenshot.url`)会直接让工具失败;语义存疑的情况(例如 `parent_id` 悬空)默认只告警,设置 `CODESIGN_INTEGRITY_STRICT=1` 可让告警也升级为错误。
|
|
366
|
+
|
|
367
|
+
基于真实分享数据的实测,CoDesign 有两个字段**不能**用于完整性判断:`slices_count` 不等于切图清单条目数,`exportables[].size` 是导出倍率(例如 `3`)而不是字节数。`download_slice` 只有在 `screenshot.length` / `screenshot.size` 存在且为正数时才把它们当作字节数;否则通过 HTTP `Content-Length`(响应未压缩时)、MIME 类型和文件魔数校验每个文件。每个下载项都带 `verified` 字段,记录字节数、识别出的格式、SHA-256 和编码方式。没有 URL 的导出项会进入 `skipped` 而不是被静默丢弃,同时返回 `requested` / `downloaded` / `reused` 计数,让部分成功可见。
|
|
368
|
+
|
|
369
|
+
## 安全说明
|
|
370
|
+
|
|
371
|
+
远程标注数据和资源下载仅允许访问 `https://codesign.qq.com` 与 `https://cdn*.codesign.qq.com`。不支持的远程主机会明确返回 `REMOTE_URL_NOT_ALLOWED`。
|
|
372
|
+
|
|
373
|
+
`codesign_logout` 只会清理位于运行目录内的 profile 目录。不安全的 profile 路径会明确返回 `PROFILE_DIR_UNSAFE`。
|
|
374
|
+
|
|
375
|
+
## 提示词
|
|
376
|
+
|
|
377
|
+
- `implement_codesign_page`:为完整页面或复制的 CoDesign 选区生成结构化设计还原提示词,引导 Agent 按预期顺序调用 `list_artboards`、`get_artboard_spec` 和 `download_slice`。
|
|
378
|
+
|
|
379
|
+
## 资源
|
|
380
|
+
|
|
381
|
+
- `codesign://workflow/design-to-code`:只读流程说明,用于指导 MCP 工具的正确组合方式,避免裁剪预览图或伪造不可用的 CoDesign 数据。
|
|
382
|
+
|
|
383
|
+
设计还原建议优先使用:
|
|
384
|
+
|
|
385
|
+
```text
|
|
386
|
+
list_artboards -> get_artboard_spec -> download_slice
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
预览截图只适合做视觉对比,不应作为生产切图来源。
|
|
390
|
+
|
|
391
|
+
## CoDesign AI 选区油猴脚本
|
|
392
|
+
|
|
393
|
+
可选油猴脚本会在当前选中图层的右侧标注面板中增加“复制给 AI”按钮。它读取 CoDesign 页面中已有的当前画板 ID 和图层对象 ID,生成结构化 Agent 提示词;脚本不会请求额外接口,也不会复制分享访问码。
|
|
394
|
+
|
|
395
|
+
1. 安装 [Tampermonkey](https://www.tampermonkey.net/) 或其他兼容的用户脚本管理器。
|
|
396
|
+
2. 打开 [codesign-ai-selection.user.js](https://raw.githubusercontent.com/DOIT008/codesign-mcp/main/userscripts/codesign-ai-selection.user.js) 并确认安装。
|
|
397
|
+
3. 在 CoDesign 分享页进入标注模式,从左侧图层树选中一个图层或分组。
|
|
398
|
+
4. 点击右侧检查器中的“复制给 AI”,把提示词粘贴到已经连接 `codesign-mcp-next` 的 Agent。
|
|
399
|
+
5. 分享链接需要访问码时,单独向 Agent 提供访问码。
|
|
400
|
+
|
|
401
|
+
复制出的引用格式如下:
|
|
402
|
+
|
|
403
|
+
```json
|
|
404
|
+
{
|
|
405
|
+
"type": "codesign-selection",
|
|
406
|
+
"sharingUrl": "https://codesign.qq.com/s/<PROJECT_ID>",
|
|
407
|
+
"screenId": "<SCREEN_ID>",
|
|
408
|
+
"screenName": "<SCREEN_NAME>",
|
|
409
|
+
"layerObjectId": "<LAYER_OBJECT_ID>",
|
|
410
|
+
"layerName": "<LAYER_NAME>",
|
|
411
|
+
"selectionScope": "region"
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
`selectionScope=region` 会返回选中边界内完整包含的非祖先图层和分组,适合视觉上属于同一区域、但在设计文件中互为兄弟节点的情况。只需要选中节点的严格子层级时,可改用 `subtree`。如果 CoDesign 更新 DOM 结构导致无法读取当前选区,脚本会明确报错,不会复制不完整引用。
|
|
416
|
+
|
|
417
|
+
## 设计还原流程提示词
|
|
418
|
+
|
|
419
|
+
让 Agent 基于 CoDesign 实现页面前,请先确认 MCP 服务器已经连接。如果设计稿需要登录,先调用 `codesign_status`。当 profile 不存在或者 CoDesign 尚未登录时,调用 `codesign_login`,在打开的浏览器窗口中扫码登录,然后再次调用 `codesign_status` 确认登录状态。
|
|
420
|
+
|
|
421
|
+
可以把下面的模板发给 Agent。将 `<PROJECT_ID>` 替换为 CoDesign 分享链接中 `/s/` 后面的项目 ID。如果分享链接不需要密码,删除密码这一行。
|
|
422
|
+
|
|
423
|
+
```text
|
|
424
|
+
请基于这个 CoDesign 设计稿实现页面:
|
|
425
|
+
|
|
426
|
+
链接:https://codesign.qq.com/s/<PROJECT_ID>
|
|
427
|
+
密码:<PASSWORD_IF_REQUIRED>
|
|
428
|
+
|
|
429
|
+
要求:
|
|
430
|
+
1. 先调用 codesign-mcp-next 的 list_artboards 获取画板列表。
|
|
431
|
+
2. 再调用 get_artboard_spec 获取官方标注信息。如果已知目标开发平台,把它作为 targetPlatform 传入,例如 `Android`、`iOS` 或 `微信小程序`。如果用户指定了自定义平台设置,同时传入 targetUnit、customScale、customWidth 和 remBasePx。
|
|
432
|
+
3. 除非用户明确要求 absolute/canvas 式实现,否则先把坐标信息转译为语义化页面结构和正常文档流,再开始编码。页面布局优先使用 Flexbox/Grid,不要把整页还原成全局绝对定位图层;用户明确提出的布局要求优先于该默认策略。
|
|
433
|
+
4. 如果设计稿里存在设计师导出的切图资源,优先调用 download_slice 获取,不要从整页预览图里自行裁图。
|
|
434
|
+
5. 预览图只用于视觉对比,不作为生产切图来源。
|
|
435
|
+
6. 在用户指定的目标目录中实现页面;若用户未指定,先询问再写文件。
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## 开发
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
npm install
|
|
442
|
+
npm test
|
|
443
|
+
node scripts/stdio-smoke.mjs
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## 发布
|
|
447
|
+
|
|
448
|
+
建议通过 GitHub Actions 的 npm Trusted Publishing 发布。不要在仓库里保存长期有效的 npm token。
|
|
449
|
+
|
|
450
|
+
首次发布前:
|
|
451
|
+
|
|
452
|
+
1. 在 npm 上为这个 GitHub 仓库和 `.github/workflows/publish.yml` 配置 Trusted Publishing。
|
|
453
|
+
2. 为 npm 账号开启 2FA。
|
|
454
|
+
3. 创建并推送与 `package.json` 一致的版本标签,例如 `v0.3.2`,触发发布。
|
|
455
|
+
|
|
456
|
+
## 许可证
|
|
457
|
+
|
|
458
|
+
MIT
|