@douyinfe/semi-mcp 1.0.0-alpha.0 → 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 +70 -29
- package/dist/utils/get-component-list.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -59,6 +59,25 @@ async function fetchDirectoryList(packageName, version, path) {
|
|
|
59
59
|
for (const result of results)if ('rejected' === result.status) errors.push(result.reason instanceof Error ? result.reason : new Error(String(result.reason)));
|
|
60
60
|
throw new Error(`所有数据源都失败了: ${errors.map((e)=>e.message).join('; ')}`);
|
|
61
61
|
}
|
|
62
|
+
async function getComponentList(version) {
|
|
63
|
+
const packageName = '@douyinfe/semi-ui';
|
|
64
|
+
const files = await fetchDirectoryList(packageName, version, 'lib');
|
|
65
|
+
if (!files || 0 === files.length) return [];
|
|
66
|
+
const componentSet = new Set();
|
|
67
|
+
for (const file of files){
|
|
68
|
+
const path = file.path;
|
|
69
|
+
const pathWithoutLib = path.replace(/^\/lib\//, '').replace(/^lib\//, '');
|
|
70
|
+
const parts = pathWithoutLib.split('/');
|
|
71
|
+
if (parts.length >= 2 && ('cjs' === parts[0] || 'es' === parts[0])) {
|
|
72
|
+
const componentName = parts[1];
|
|
73
|
+
if (componentName && 'lib' !== componentName) componentSet.add(componentName.toLowerCase());
|
|
74
|
+
} else if (parts.length >= 1) {
|
|
75
|
+
const componentName = parts[0];
|
|
76
|
+
if (componentName && 'lib' !== componentName && 'cjs' !== componentName && 'es' !== componentName) componentSet.add(componentName.toLowerCase());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(componentSet).sort();
|
|
80
|
+
}
|
|
62
81
|
const getSemiDocumentTool = {
|
|
63
82
|
name: 'get_semi_document',
|
|
64
83
|
description: '获取 Semi Design 组件文档或组件列表',
|
|
@@ -77,17 +96,6 @@ const getSemiDocumentTool = {
|
|
|
77
96
|
required: []
|
|
78
97
|
}
|
|
79
98
|
};
|
|
80
|
-
async function getComponentList(version) {
|
|
81
|
-
const packageName = '@douyinfe/semi-ui';
|
|
82
|
-
const files = await fetchDirectoryList(packageName, version, 'lib');
|
|
83
|
-
if (!files || 0 === files.length) return [];
|
|
84
|
-
const components = files.filter((file)=>'directory' === file.type).map((file)=>{
|
|
85
|
-
const parts = file.path.split('/');
|
|
86
|
-
const componentName = parts[parts.length - 1] || parts[0];
|
|
87
|
-
return componentName.toLowerCase();
|
|
88
|
-
}).filter((name)=>name && 'lib' !== name);
|
|
89
|
-
return Array.from(new Set(components)).sort();
|
|
90
|
-
}
|
|
91
99
|
async function getComponentDocuments(componentName, version) {
|
|
92
100
|
const packageName = '@douyinfe/semi-ui';
|
|
93
101
|
const componentNameLower = componentName.toLowerCase();
|
|
@@ -160,6 +168,20 @@ async function handleGetSemiDocument(args) {
|
|
|
160
168
|
}
|
|
161
169
|
{
|
|
162
170
|
const components = await getComponentList(version);
|
|
171
|
+
if (0 === components.length) return {
|
|
172
|
+
content: [
|
|
173
|
+
{
|
|
174
|
+
type: 'text',
|
|
175
|
+
text: JSON.stringify({
|
|
176
|
+
version,
|
|
177
|
+
error: `未找到组件列表,请检查版本号 ${version} 是否正确`,
|
|
178
|
+
components: [],
|
|
179
|
+
count: 0
|
|
180
|
+
}, null, 2)
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
isError: true
|
|
184
|
+
};
|
|
163
185
|
return {
|
|
164
186
|
content: [
|
|
165
187
|
{
|
|
@@ -227,24 +249,43 @@ async function main() {
|
|
|
227
249
|
}));
|
|
228
250
|
server.setRequestHandler(ReadResourceRequestSchema, async (request)=>{
|
|
229
251
|
const { uri } = request.params;
|
|
230
|
-
if ('semi://components' === uri)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
'
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
if ('semi://components' === uri || uri.startsWith('semi://components')) {
|
|
253
|
+
const version = 'latest';
|
|
254
|
+
try {
|
|
255
|
+
const components = await getComponentList(version);
|
|
256
|
+
return {
|
|
257
|
+
contents: [
|
|
258
|
+
{
|
|
259
|
+
uri,
|
|
260
|
+
mimeType: 'application/json',
|
|
261
|
+
text: JSON.stringify({
|
|
262
|
+
version,
|
|
263
|
+
components,
|
|
264
|
+
count: components.length,
|
|
265
|
+
description: 'Semi Design 组件列表',
|
|
266
|
+
note: '如需指定版本,请使用 get_semi_document 工具'
|
|
267
|
+
}, null, 2)
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
} catch (error) {
|
|
272
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
273
|
+
return {
|
|
274
|
+
contents: [
|
|
275
|
+
{
|
|
276
|
+
uri,
|
|
277
|
+
mimeType: 'application/json',
|
|
278
|
+
text: JSON.stringify({
|
|
279
|
+
version,
|
|
280
|
+
error: errorMessage,
|
|
281
|
+
components: [],
|
|
282
|
+
count: 0
|
|
283
|
+
}, null, 2)
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
248
289
|
throw new Error(`未知的资源 URI: ${uri}`);
|
|
249
290
|
});
|
|
250
291
|
const transport = new StdioServerTransport();
|
package/package.json
CHANGED