customs-ui-kit-mcp 1.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/dist/index.js +198 -0
- package/package.json +37 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
38
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
39
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
// 动态解析 UI package 路径
|
|
43
|
+
// 当作为 npm 包全局安装时,尝试在 node_modules 中寻找 customs-ui-kit
|
|
44
|
+
function getUiPackagePath() {
|
|
45
|
+
// 1. 本地开发环境路径 (Monorepo)
|
|
46
|
+
const localPath = path.resolve(__dirname, "../../ui/src/components");
|
|
47
|
+
if (fs.existsSync(localPath)) {
|
|
48
|
+
return localPath;
|
|
49
|
+
}
|
|
50
|
+
// 2. 作为 npm 包安装后的路径 (寻找兄弟依赖 customs-ui-kit)
|
|
51
|
+
try {
|
|
52
|
+
const uiPkgPath = require.resolve("customs-ui-kit/package.json");
|
|
53
|
+
// 假设发布时将 src 也打包进去了,或者直接读取 dist/types
|
|
54
|
+
// 为了简单起见,我们假设团队成员也会安装 customs-ui-kit 到他们的项目中
|
|
55
|
+
// 我们需要读取的是组件的元数据。
|
|
56
|
+
// 这里我们先尝试找项目根目录下的 node_modules/customs-ui-kit/src/components
|
|
57
|
+
const resolvedPath = path.join(path.dirname(uiPkgPath), "src/components");
|
|
58
|
+
if (fs.existsSync(resolvedPath)) {
|
|
59
|
+
return resolvedPath;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// 忽略错误
|
|
64
|
+
}
|
|
65
|
+
// 3. 如果找不到,返回一个默认路径防止报错崩溃
|
|
66
|
+
return localPath;
|
|
67
|
+
}
|
|
68
|
+
const UI_PACKAGE_PATH = getUiPackagePath();
|
|
69
|
+
const server = new index_js_1.Server({
|
|
70
|
+
name: "customs-ui-kit-mcp",
|
|
71
|
+
version: "1.0.0",
|
|
72
|
+
}, {
|
|
73
|
+
capabilities: {
|
|
74
|
+
tools: {},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
// 获取组件列表
|
|
78
|
+
function getComponents() {
|
|
79
|
+
if (!fs.existsSync(UI_PACKAGE_PATH))
|
|
80
|
+
return [];
|
|
81
|
+
return fs.readdirSync(UI_PACKAGE_PATH).filter((file) => {
|
|
82
|
+
return fs.statSync(path.join(UI_PACKAGE_PATH, file)).isDirectory();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// 获取组件 API (读取 Vue 文件或 ts 文件的 Props 定义)
|
|
86
|
+
function getComponentApi(componentName) {
|
|
87
|
+
const compPath = path.join(UI_PACKAGE_PATH, componentName, `${componentName}.vue`);
|
|
88
|
+
if (!fs.existsSync(compPath)) {
|
|
89
|
+
return `Component ${componentName} not found.`;
|
|
90
|
+
}
|
|
91
|
+
const content = fs.readFileSync(compPath, "utf-8");
|
|
92
|
+
// 简单提取 script setup 里的类型定义部分
|
|
93
|
+
const scriptMatch = content.match(/<script setup lang="ts">([\s\S]*?)<\/script>/);
|
|
94
|
+
if (scriptMatch && scriptMatch[1]) {
|
|
95
|
+
return scriptMatch[1].trim();
|
|
96
|
+
}
|
|
97
|
+
return "No TypeScript API definition found.";
|
|
98
|
+
}
|
|
99
|
+
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
100
|
+
return {
|
|
101
|
+
tools: [
|
|
102
|
+
{
|
|
103
|
+
name: "list_components",
|
|
104
|
+
description: "List all available components in the Customs UI Kit",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "get_component_api",
|
|
112
|
+
description: "Get the TypeScript Props API and JSDoc for a specific component",
|
|
113
|
+
inputSchema: {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
componentName: {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: "The name of the component (e.g., Button, Table)",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
required: ["componentName"],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "get_component_examples",
|
|
126
|
+
description: "Get usage examples for a specific component from Storybook",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
componentName: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "The name of the component (e.g., Button, Table)",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
required: ["componentName"],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
// 获取组件示例 (读取 Storybook 文件)
|
|
142
|
+
function getComponentExamples(componentName) {
|
|
143
|
+
const storyPath = path.join(UI_PACKAGE_PATH, componentName, `${componentName}.stories.ts`);
|
|
144
|
+
if (!fs.existsSync(storyPath)) {
|
|
145
|
+
return `No examples found for component ${componentName}.`;
|
|
146
|
+
}
|
|
147
|
+
return fs.readFileSync(storyPath, "utf-8");
|
|
148
|
+
}
|
|
149
|
+
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
150
|
+
if (request.params.name === "list_components") {
|
|
151
|
+
const components = getComponents();
|
|
152
|
+
return {
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
type: "text",
|
|
156
|
+
text: JSON.stringify(components, null, 2),
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (request.params.name === "get_component_api") {
|
|
162
|
+
const componentName = request.params.arguments?.componentName;
|
|
163
|
+
if (!componentName) {
|
|
164
|
+
throw new Error("componentName is required");
|
|
165
|
+
}
|
|
166
|
+
const api = getComponentApi(componentName);
|
|
167
|
+
return {
|
|
168
|
+
content: [
|
|
169
|
+
{
|
|
170
|
+
type: "text",
|
|
171
|
+
text: api,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (request.params.name === "get_component_examples") {
|
|
177
|
+
const componentName = request.params.arguments?.componentName;
|
|
178
|
+
if (!componentName) {
|
|
179
|
+
throw new Error("componentName is required");
|
|
180
|
+
}
|
|
181
|
+
const examples = getComponentExamples(componentName);
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "text",
|
|
186
|
+
text: examples,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
192
|
+
});
|
|
193
|
+
async function main() {
|
|
194
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
195
|
+
await server.connect(transport);
|
|
196
|
+
console.error("Customs UI Kit MCP Server running on stdio");
|
|
197
|
+
}
|
|
198
|
+
main().catch(console.error);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "customs-ui-kit-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"bin": {
|
|
6
|
+
"customs-ui-kit-mcp": "dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"start": "node dist/index.js",
|
|
14
|
+
"dev": "ts-node src/index.ts"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
22
|
+
"express": "^5.2.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@storybook/addon-essentials": "^8.6.14",
|
|
26
|
+
"@storybook/addon-interactions": "^8.6.14",
|
|
27
|
+
"@storybook/addon-links": "^10.2.17",
|
|
28
|
+
"@storybook/blocks": "^8.6.14",
|
|
29
|
+
"@storybook/vue3": "^10.2.17",
|
|
30
|
+
"@storybook/vue3-vite": "^10.2.17",
|
|
31
|
+
"@types/express": "^5.0.6",
|
|
32
|
+
"@types/node": "^25.4.0",
|
|
33
|
+
"storybook": "^10.2.17",
|
|
34
|
+
"ts-node": "^10.9.2",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
37
|
+
}
|