@douyinfe/semi-mcp 1.0.0 → 1.0.1
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 +30 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
const UNPKG_BASE_URL = 'https://unpkg.com';
|
|
6
|
-
const NPMMIRROR_BASE_URL = 'https://npmmirror.com';
|
|
7
|
-
async function fetchFromSource(baseUrl, packageName, version, path) {
|
|
8
|
-
const url = `${baseUrl}/${packageName}@${version}/${path}/?meta`;
|
|
6
|
+
const NPMMIRROR_BASE_URL = 'https://registry.npmmirror.com';
|
|
7
|
+
async function fetchFromSource(baseUrl, packageName, version, path, isNpmMirror = false) {
|
|
8
|
+
const url = isNpmMirror ? `${baseUrl}/${packageName}/${version}/files/${path}/?meta` : `${baseUrl}/${packageName}@${version}/${path}/?meta`;
|
|
9
9
|
const response = await fetch(url, {
|
|
10
10
|
headers: {
|
|
11
11
|
Accept: 'application/json'
|
|
@@ -42,8 +42,8 @@ async function fetchFromSource(baseUrl, packageName, version, path) {
|
|
|
42
42
|
throw new Error('无法解析目录列表数据格式');
|
|
43
43
|
}
|
|
44
44
|
async function fetchDirectoryList(packageName, version, path) {
|
|
45
|
-
const unpkgPromise = fetchFromSource(UNPKG_BASE_URL, packageName, version, path);
|
|
46
|
-
const npmmirrorPromise = fetchFromSource(NPMMIRROR_BASE_URL, packageName, version, path);
|
|
45
|
+
const unpkgPromise = fetchFromSource(UNPKG_BASE_URL, packageName, version, path, false);
|
|
46
|
+
const npmmirrorPromise = fetchFromSource(NPMMIRROR_BASE_URL, packageName, version, path, true);
|
|
47
47
|
const unpkgWithFallback = unpkgPromise.catch(()=>new Promise(()=>{}));
|
|
48
48
|
const npmmirrorWithFallback = npmmirrorPromise.catch(()=>new Promise(()=>{}));
|
|
49
49
|
const raceResult = await Promise.race([
|
|
@@ -99,32 +99,32 @@ const getSemiDocumentTool = {
|
|
|
99
99
|
async function getComponentDocuments(componentName, version) {
|
|
100
100
|
const packageName = '@douyinfe/semi-ui';
|
|
101
101
|
const componentNameLower = componentName.toLowerCase();
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}).filter((name)=>name);
|
|
118
|
-
return {
|
|
119
|
-
category,
|
|
120
|
-
documents: Array.from(new Set(documents)).sort()
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
continue;
|
|
102
|
+
const contentFiles = await fetchDirectoryList(packageName, version, 'content');
|
|
103
|
+
if (!contentFiles || 0 === contentFiles.length) return null;
|
|
104
|
+
const componentFiles = contentFiles.filter((file)=>{
|
|
105
|
+
if ('file' !== file.type) return false;
|
|
106
|
+
const path = file.path.toLowerCase();
|
|
107
|
+
const pathPattern = new RegExp(`/content/[^/]+/${componentNameLower}/[^/]+$`);
|
|
108
|
+
return pathPattern.test(path);
|
|
109
|
+
});
|
|
110
|
+
if (0 === componentFiles.length) return null;
|
|
111
|
+
const firstPath = componentFiles[0].path;
|
|
112
|
+
const pathParts = firstPath.split('/');
|
|
113
|
+
let categoryIndex = -1;
|
|
114
|
+
for(let i = 0; i < pathParts.length; i++)if ('content' === pathParts[i].toLowerCase()) {
|
|
115
|
+
categoryIndex = i + 1;
|
|
116
|
+
break;
|
|
126
117
|
}
|
|
127
|
-
return null;
|
|
118
|
+
if (-1 === categoryIndex || categoryIndex >= pathParts.length) return null;
|
|
119
|
+
const category = pathParts[categoryIndex];
|
|
120
|
+
const documents = componentFiles.map((file)=>{
|
|
121
|
+
const parts = file.path.split('/');
|
|
122
|
+
return parts[parts.length - 1].toLowerCase();
|
|
123
|
+
}).filter((name)=>name);
|
|
124
|
+
return {
|
|
125
|
+
category,
|
|
126
|
+
documents: Array.from(new Set(documents)).sort()
|
|
127
|
+
};
|
|
128
128
|
}
|
|
129
129
|
async function handleGetSemiDocument(args) {
|
|
130
130
|
const componentName = args?.componentName;
|
package/package.json
CHANGED