canpoint-ui-mcp 0.1.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 +70 -0
- package/bin/_run.js +92 -0
- package/bin/canpoint-ui-mcp.js +7 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# canpoint-ui-mcp
|
|
2
|
+
|
|
3
|
+
UI 规范查询 MCP(npm 包装器)。真正的实现在 PyPI 的同名
|
|
4
|
+
[Python 包](https://pypi.org/project/canpoint-ui-mcp/)中,本包通过
|
|
5
|
+
[`uvx`](https://docs.astral.sh/uv/) 拉起它,方便在 Claude Code / Cursor 等
|
|
6
|
+
支持 MCP 的工具里用 `npx` 直接配置。
|
|
7
|
+
|
|
8
|
+
「成果不出门、能力出门」:设计数据源(研学小程序 / 研学后台两套 Design DNA)
|
|
9
|
+
由远程服务做 allowlist 投影,客户端只拿到 token、组件规格、生成纪律与截图
|
|
10
|
+
色彩校验结论。
|
|
11
|
+
|
|
12
|
+
## 能做什么
|
|
13
|
+
|
|
14
|
+
- `list_platforms`:列出可用平台(mini=研学小程序,admin=研学后台)与数据状态
|
|
15
|
+
- `get_tokens(platform, category)`:按类别查设计 token(color/typography/spacing/shape/elevation/layout)
|
|
16
|
+
- `list_components(platform)`:列出组件规范条目
|
|
17
|
+
- `get_component_spec(platform, component)`:查单个组件完整规格(支持中文别名与模糊匹配)
|
|
18
|
+
- `get_generation_rules(platform)`:生成 UI 前必须遵守的纪律包
|
|
19
|
+
- `verify_ui(platform, image_base64)`:对生成页面截图做确定性色彩校验(CIEDE2000)
|
|
20
|
+
|
|
21
|
+
## 前置条件
|
|
22
|
+
|
|
23
|
+
- 已安装 [uv](https://docs.astral.sh/uv/getting-started/installation/)(提供 `uvx` 命令)
|
|
24
|
+
- 远程 UI 规范服务地址与服务管理员发放的 API key(`usk_` 前缀;本包不含服务端)
|
|
25
|
+
|
|
26
|
+
## 配置
|
|
27
|
+
|
|
28
|
+
两个环境变量**必填**:
|
|
29
|
+
|
|
30
|
+
| 变量 | 说明 |
|
|
31
|
+
|------|------|
|
|
32
|
+
| `UI_SPEC_SERVER_URL` | 远程服务地址,如 `http://175.27.156.19:47393`(不带 `/mcp`) |
|
|
33
|
+
| `UI_SPEC_API_KEY` | 服务管理员发放的 Bearer key(`usk_` 前缀) |
|
|
34
|
+
|
|
35
|
+
可选:`UI_SPEC_TIMEOUT`(HTTP 超时秒数,默认 30)、`UI_SPEC_LOG_LEVEL`(默认 INFO)。
|
|
36
|
+
|
|
37
|
+
Claude Code 配置示例(`.mcp.json`):
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"canpoint-ui": {
|
|
43
|
+
"command": "npx",
|
|
44
|
+
"args": ["-y", "canpoint-ui-mcp"],
|
|
45
|
+
"env": {
|
|
46
|
+
"UI_SPEC_SERVER_URL": "http://175.27.156.19:47393",
|
|
47
|
+
"UI_SPEC_API_KEY": "usk_<你的key>"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Cursor(`mcp.json`)同款。Windows 下若 `npx` 启动失败,可把 `command` 改为
|
|
55
|
+
`cmd`、`args` 改为 `["/c", "npx", "-y", "canpoint-ui-mcp"]`(env 表不变)。
|
|
56
|
+
|
|
57
|
+
不想走 npm 时也可直接用 PyPI 包:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
UI_SPEC_SERVER_URL=http://175.27.156.19:47393 UI_SPEC_API_KEY=usk_xxx uvx canpoint-ui-mcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
或跳过本客户端,直连远程 streamable-http 端点(`http://<host>/mcp`,
|
|
64
|
+
`Authorization: Bearer usk_xxx`)。
|
|
65
|
+
|
|
66
|
+
完整文档见仓库 [README](https://github.com/mjwyr/ui-knowledge/tree/main/mcp-server)。
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache-2.0 © 若清风
|
package/bin/_run.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 共享启动器:通过 `uvx` 拉起 PyPI 包 `canpoint-ui-mcp` 的 console script,
|
|
5
|
+
* 透传 stdio 并转发退出码。
|
|
6
|
+
*
|
|
7
|
+
* 真正的 MCP 服务器在 Python 包里;本包装器只是为了让
|
|
8
|
+
* `npx canpoint-ui-mcp` 像其他 npm MCP 服务器一样可用。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { spawn } = require("node:child_process");
|
|
12
|
+
const fs = require("node:fs");
|
|
13
|
+
const path = require("node:path");
|
|
14
|
+
|
|
15
|
+
const PYPI_PACKAGE = "canpoint-ui-mcp";
|
|
16
|
+
|
|
17
|
+
function packageVersion() {
|
|
18
|
+
try {
|
|
19
|
+
// eslint-disable-next-line global-require
|
|
20
|
+
return require(path.join(__dirname, "..", "package.json")).version;
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Windows 下不带 shell 的 spawn("uvx") 不会按 PATHEXT 解析 uvx.exe,
|
|
28
|
+
* 而 shell:true 又会触发 DEP0190 告警;这里自行在 PATH 中解析可执行文件。
|
|
29
|
+
*/
|
|
30
|
+
function resolveUvx() {
|
|
31
|
+
if (process.platform !== "win32") {
|
|
32
|
+
return "uvx";
|
|
33
|
+
}
|
|
34
|
+
const extensions = (process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM")
|
|
35
|
+
.split(";")
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
const dirs = (process.env.PATH || process.env.Path || "")
|
|
38
|
+
.split(";")
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
for (const dir of dirs) {
|
|
41
|
+
for (const ext of extensions) {
|
|
42
|
+
const candidate = path.join(dir, `uvx${ext.toLowerCase()}`);
|
|
43
|
+
try {
|
|
44
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
45
|
+
return candidate;
|
|
46
|
+
} catch {
|
|
47
|
+
// 继续找下一个候选
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return "uvx";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function run(entrypoint) {
|
|
55
|
+
const version = packageVersion();
|
|
56
|
+
// 按 npm 包自身版本钉死 PyPI 包版本,两平台必须同版本发布
|
|
57
|
+
const spec = version ? `${PYPI_PACKAGE}==${version}` : PYPI_PACKAGE;
|
|
58
|
+
const args = ["--from", spec, entrypoint, ...process.argv.slice(2)];
|
|
59
|
+
|
|
60
|
+
const child = spawn(resolveUvx(), args, {
|
|
61
|
+
stdio: "inherit",
|
|
62
|
+
env: process.env,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
child.on("error", (err) => {
|
|
66
|
+
if (err.code === "ENOENT") {
|
|
67
|
+
console.error(
|
|
68
|
+
[
|
|
69
|
+
"[canpoint-ui-mcp] 未找到 `uvx` 命令。",
|
|
70
|
+
"此 npm 包是 Python MCP 的包装器,需要先安装 uv:",
|
|
71
|
+
" Windows: powershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"",
|
|
72
|
+
" macOS/Linux: curl -LsSf https://astral.sh/uv/install.sh | sh",
|
|
73
|
+
" 或 pip install uv",
|
|
74
|
+
`原始错误: ${err.message}`,
|
|
75
|
+
].join("\n")
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`[canpoint-ui-mcp] 启动失败: ${err.message}`);
|
|
79
|
+
}
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
child.on("exit", (code, signal) => {
|
|
84
|
+
if (signal) {
|
|
85
|
+
process.kill(process.pid, signal);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
process.exit(code ?? 1);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { run };
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "canpoint-ui-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "UI spec query MCP for design-DNA-driven generation: fetch design tokens, component specs and generation rules, and verify generated-page screenshots against the palette. Wrapper that runs the PyPI package via uvx.",
|
|
5
|
+
"author": "若清风",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://github.com/mjwyr/ui-knowledge",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/mjwyr/ui-knowledge.git",
|
|
11
|
+
"directory": "mcp-server/npm"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mjwyr/ui-knowledge/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"ui",
|
|
20
|
+
"design-tokens",
|
|
21
|
+
"design-system"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"canpoint-ui-mcp": "bin/canpoint-ui-mcp.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
}
|
|
33
|
+
}
|