@weapp-vite/mcp 1.1.1 → 1.1.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/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +112 -23
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -6,16 +6,19 @@ declare const EXPOSED_PACKAGES: {
|
|
|
6
6
|
readonly 'weapp-vite': {
|
|
7
7
|
readonly id: "weapp-vite";
|
|
8
8
|
readonly label: "weapp-vite";
|
|
9
|
+
readonly packageName: "weapp-vite";
|
|
9
10
|
readonly relativePath: string;
|
|
10
11
|
};
|
|
11
12
|
readonly wevu: {
|
|
12
13
|
readonly id: "wevu";
|
|
13
14
|
readonly label: "wevu";
|
|
15
|
+
readonly packageName: "wevu";
|
|
14
16
|
readonly relativePath: string;
|
|
15
17
|
};
|
|
16
18
|
readonly 'wevu-compiler': {
|
|
17
19
|
readonly id: "wevu-compiler";
|
|
18
20
|
readonly label: "wevu-compiler";
|
|
21
|
+
readonly packageName: "@wevu/compiler";
|
|
19
22
|
readonly relativePath: string;
|
|
20
23
|
};
|
|
21
24
|
};
|
|
@@ -26,7 +29,7 @@ declare const DEFAULT_MAX_FILE_CHARS = 80000;
|
|
|
26
29
|
declare const DEFAULT_MAX_RESULTS = 200;
|
|
27
30
|
declare const SKIPPED_DIR_NAMES: Set<string>;
|
|
28
31
|
|
|
29
|
-
interface
|
|
32
|
+
interface ResolvedExposedPackage {
|
|
30
33
|
id: ExposedPackageId;
|
|
31
34
|
label: string;
|
|
32
35
|
packageName: string;
|
|
@@ -38,9 +41,14 @@ interface ExposedPackageSummary {
|
|
|
38
41
|
readme?: string;
|
|
39
42
|
changelog?: string;
|
|
40
43
|
};
|
|
44
|
+
sourceRoot?: string;
|
|
45
|
+
cliPath?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ExposedPackageSummary extends ResolvedExposedPackage {
|
|
41
49
|
}
|
|
42
50
|
declare function loadPackageSummary(workspaceRoot: string, id: ExposedPackageId): Promise<ExposedPackageSummary>;
|
|
43
|
-
declare function loadExposedCatalog(workspaceRoot: string): Promise<
|
|
51
|
+
declare function loadExposedCatalog(workspaceRoot: string): Promise<ResolvedExposedPackage[]>;
|
|
44
52
|
|
|
45
53
|
interface CommandResult {
|
|
46
54
|
command: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,16 +6,19 @@ declare const EXPOSED_PACKAGES: {
|
|
|
6
6
|
readonly 'weapp-vite': {
|
|
7
7
|
readonly id: "weapp-vite";
|
|
8
8
|
readonly label: "weapp-vite";
|
|
9
|
+
readonly packageName: "weapp-vite";
|
|
9
10
|
readonly relativePath: string;
|
|
10
11
|
};
|
|
11
12
|
readonly wevu: {
|
|
12
13
|
readonly id: "wevu";
|
|
13
14
|
readonly label: "wevu";
|
|
15
|
+
readonly packageName: "wevu";
|
|
14
16
|
readonly relativePath: string;
|
|
15
17
|
};
|
|
16
18
|
readonly 'wevu-compiler': {
|
|
17
19
|
readonly id: "wevu-compiler";
|
|
18
20
|
readonly label: "wevu-compiler";
|
|
21
|
+
readonly packageName: "@wevu/compiler";
|
|
19
22
|
readonly relativePath: string;
|
|
20
23
|
};
|
|
21
24
|
};
|
|
@@ -26,7 +29,7 @@ declare const DEFAULT_MAX_FILE_CHARS = 80000;
|
|
|
26
29
|
declare const DEFAULT_MAX_RESULTS = 200;
|
|
27
30
|
declare const SKIPPED_DIR_NAMES: Set<string>;
|
|
28
31
|
|
|
29
|
-
interface
|
|
32
|
+
interface ResolvedExposedPackage {
|
|
30
33
|
id: ExposedPackageId;
|
|
31
34
|
label: string;
|
|
32
35
|
packageName: string;
|
|
@@ -38,9 +41,14 @@ interface ExposedPackageSummary {
|
|
|
38
41
|
readme?: string;
|
|
39
42
|
changelog?: string;
|
|
40
43
|
};
|
|
44
|
+
sourceRoot?: string;
|
|
45
|
+
cliPath?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ExposedPackageSummary extends ResolvedExposedPackage {
|
|
41
49
|
}
|
|
42
50
|
declare function loadPackageSummary(workspaceRoot: string, id: ExposedPackageId): Promise<ExposedPackageSummary>;
|
|
43
|
-
declare function loadExposedCatalog(workspaceRoot: string): Promise<
|
|
51
|
+
declare function loadExposedCatalog(workspaceRoot: string): Promise<ResolvedExposedPackage[]>;
|
|
44
52
|
|
|
45
53
|
interface CommandResult {
|
|
46
54
|
command: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import fs$1 from 'node:fs/promises';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
4
5
|
import path from 'node:path';
|
|
5
6
|
import fs from 'node:fs';
|
|
6
7
|
import { spawn } from 'node:child_process';
|
|
@@ -17,17 +18,20 @@ const EXPOSED_PACKAGES = {
|
|
|
17
18
|
"weapp-vite": {
|
|
18
19
|
id: "weapp-vite",
|
|
19
20
|
label: "weapp-vite",
|
|
21
|
+
packageName: "weapp-vite",
|
|
20
22
|
relativePath: path.join("packages", "weapp-vite")
|
|
21
23
|
},
|
|
22
24
|
"wevu": {
|
|
23
25
|
id: "wevu",
|
|
24
26
|
label: "wevu",
|
|
25
|
-
|
|
27
|
+
packageName: "wevu",
|
|
28
|
+
relativePath: path.join("packages-runtime", "wevu")
|
|
26
29
|
},
|
|
27
30
|
"wevu-compiler": {
|
|
28
31
|
id: "wevu-compiler",
|
|
29
32
|
label: "wevu-compiler",
|
|
30
|
-
|
|
33
|
+
packageName: "@wevu/compiler",
|
|
34
|
+
relativePath: path.join("packages-runtime", "wevu-compiler")
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
37
|
const DEFAULT_TIMEOUT_MS = 12e4;
|
|
@@ -80,10 +84,6 @@ function resolveSubPath(root, relativePath) {
|
|
|
80
84
|
return assertInsideRoot(root, path.resolve(root, relativePath));
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
async function readJsonFile(filePath) {
|
|
84
|
-
const content = await fs$1.readFile(filePath, "utf8");
|
|
85
|
-
return JSON.parse(content);
|
|
86
|
-
}
|
|
87
87
|
async function pathExists(filePath) {
|
|
88
88
|
try {
|
|
89
89
|
await fs$1.access(filePath);
|
|
@@ -92,17 +92,40 @@ async function pathExists(filePath) {
|
|
|
92
92
|
return false;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
async function
|
|
95
|
+
async function toWorkspaceRelativePath(workspaceRoot, absolutePath) {
|
|
96
|
+
const [realWorkspaceRoot, realAbsolutePath] = await Promise.all([
|
|
97
|
+
fs$1.realpath(workspaceRoot),
|
|
98
|
+
fs$1.realpath(absolutePath)
|
|
99
|
+
]);
|
|
100
|
+
const relativePath = path.relative(realWorkspaceRoot, realAbsolutePath);
|
|
101
|
+
if (!relativePath || relativePath === ".") {
|
|
102
|
+
return ".";
|
|
103
|
+
}
|
|
104
|
+
return relativePath;
|
|
105
|
+
}
|
|
106
|
+
async function readPackageJson(filePath) {
|
|
107
|
+
const content = await fs$1.readFile(filePath, "utf8");
|
|
108
|
+
return JSON.parse(content);
|
|
109
|
+
}
|
|
110
|
+
function createWorkspaceRequire(workspaceRoot) {
|
|
111
|
+
return createRequire(path.join(workspaceRoot, "__weapp_vite_mcp__.cjs"));
|
|
112
|
+
}
|
|
113
|
+
async function resolveMonorepoPackage(workspaceRoot, id) {
|
|
96
114
|
const config = EXPOSED_PACKAGES[id];
|
|
97
115
|
const absolutePath = assertInsideRoot(workspaceRoot, path.join(workspaceRoot, config.relativePath));
|
|
98
116
|
const packageJsonPath = path.join(absolutePath, "package.json");
|
|
99
|
-
|
|
117
|
+
if (!await pathExists(packageJsonPath)) {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
120
|
+
const packageJson = await readPackageJson(packageJsonPath);
|
|
100
121
|
const readmePath = path.join(absolutePath, "README.md");
|
|
101
122
|
const changelogPath = path.join(absolutePath, "CHANGELOG.md");
|
|
123
|
+
const sourceRoot = await pathExists(path.join(absolutePath, "src")) ? absolutePath : void 0;
|
|
124
|
+
const cliPath = id === "weapp-vite" ? await pathExists(path.join(absolutePath, "bin", "weapp-vite.js")) ? path.join(absolutePath, "bin", "weapp-vite.js") : void 0 : void 0;
|
|
102
125
|
return {
|
|
103
126
|
id,
|
|
104
127
|
label: config.label,
|
|
105
|
-
packageName: packageJson.name ?? config.
|
|
128
|
+
packageName: packageJson.name ?? config.packageName,
|
|
106
129
|
version: packageJson.version ?? "0.0.0",
|
|
107
130
|
absolutePath,
|
|
108
131
|
relativePath: config.relativePath,
|
|
@@ -110,14 +133,73 @@ async function loadPackageSummary(workspaceRoot, id) {
|
|
|
110
133
|
docs: {
|
|
111
134
|
readme: await pathExists(readmePath) ? readmePath : void 0,
|
|
112
135
|
changelog: await pathExists(changelogPath) ? changelogPath : void 0
|
|
136
|
+
},
|
|
137
|
+
sourceRoot,
|
|
138
|
+
cliPath
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async function resolveInstalledPackage(workspaceRoot, id) {
|
|
142
|
+
const config = EXPOSED_PACKAGES[id];
|
|
143
|
+
const workspaceRequire = createWorkspaceRequire(workspaceRoot);
|
|
144
|
+
let packageJsonPath;
|
|
145
|
+
try {
|
|
146
|
+
packageJsonPath = workspaceRequire.resolve(`${config.packageName}/package.json`);
|
|
147
|
+
} catch {
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
const absolutePath = path.dirname(packageJsonPath);
|
|
151
|
+
const relativePath = await toWorkspaceRelativePath(workspaceRoot, absolutePath);
|
|
152
|
+
const packageJson = await readPackageJson(packageJsonPath);
|
|
153
|
+
const docsRoot = path.join(absolutePath, "dist", "docs");
|
|
154
|
+
const installedReadmePath = path.join(docsRoot, "README.md");
|
|
155
|
+
const installedChangelogPath = path.join(docsRoot, "CHANGELOG.md");
|
|
156
|
+
const sourceRoot = await pathExists(path.join(absolutePath, "src")) ? absolutePath : void 0;
|
|
157
|
+
let cliPath;
|
|
158
|
+
if (id === "weapp-vite") {
|
|
159
|
+
const binEntry = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.["weapp-vite"];
|
|
160
|
+
if (typeof binEntry === "string" && binEntry.trim()) {
|
|
161
|
+
const resolvedCliPath = path.resolve(absolutePath, binEntry);
|
|
162
|
+
if (await pathExists(resolvedCliPath)) {
|
|
163
|
+
cliPath = resolvedCliPath;
|
|
164
|
+
}
|
|
113
165
|
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
id,
|
|
169
|
+
label: config.label,
|
|
170
|
+
packageName: packageJson.name ?? config.packageName,
|
|
171
|
+
version: packageJson.version ?? "0.0.0",
|
|
172
|
+
absolutePath,
|
|
173
|
+
relativePath,
|
|
174
|
+
scripts: Object.keys(packageJson.scripts ?? {}),
|
|
175
|
+
docs: {
|
|
176
|
+
readme: await pathExists(installedReadmePath) ? installedReadmePath : void 0,
|
|
177
|
+
changelog: await pathExists(installedChangelogPath) ? installedChangelogPath : void 0
|
|
178
|
+
},
|
|
179
|
+
sourceRoot,
|
|
180
|
+
cliPath
|
|
114
181
|
};
|
|
115
182
|
}
|
|
116
|
-
async function
|
|
117
|
-
|
|
118
|
-
|
|
183
|
+
async function resolveExposedPackage(workspaceRoot, id) {
|
|
184
|
+
return await resolveMonorepoPackage(workspaceRoot, id) ?? await resolveInstalledPackage(workspaceRoot, id) ?? Promise.reject(new Error(`\u672A\u627E\u5230\u66B4\u9732\u5305\uFF1A${id}`));
|
|
185
|
+
}
|
|
186
|
+
async function resolveExposedPackages(workspaceRoot) {
|
|
187
|
+
const resolved = await Promise.allSettled(
|
|
188
|
+
Object.keys(EXPOSED_PACKAGES).map((id) => resolveExposedPackage(workspaceRoot, id))
|
|
119
189
|
);
|
|
120
|
-
return
|
|
190
|
+
return resolved.flatMap((result) => {
|
|
191
|
+
if (result.status === "fulfilled") {
|
|
192
|
+
return [result.value];
|
|
193
|
+
}
|
|
194
|
+
return [];
|
|
195
|
+
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function loadPackageSummary(workspaceRoot, id) {
|
|
199
|
+
return resolveExposedPackage(workspaceRoot, id);
|
|
200
|
+
}
|
|
201
|
+
async function loadExposedCatalog(workspaceRoot) {
|
|
202
|
+
return resolveExposedPackages(workspaceRoot);
|
|
121
203
|
}
|
|
122
204
|
|
|
123
205
|
const ALLOWED_COMMANDS = /* @__PURE__ */ new Set([
|
|
@@ -318,8 +400,12 @@ function toToolError(error) {
|
|
|
318
400
|
|
|
319
401
|
const packageIds = Object.keys(EXPOSED_PACKAGES);
|
|
320
402
|
const packageIdSchema = z.enum(packageIds);
|
|
321
|
-
function resolvePackageRoot(workspaceRoot, packageId) {
|
|
322
|
-
|
|
403
|
+
async function resolvePackageRoot(workspaceRoot, packageId) {
|
|
404
|
+
const resolved = await resolveExposedPackage(workspaceRoot, packageId);
|
|
405
|
+
if (!resolved.sourceRoot) {
|
|
406
|
+
throw new Error(`\u5F53\u524D\u5DE5\u4F5C\u533A\u4E2D\u7684 ${packageId} \u4E0D\u5305\u542B\u6E90\u7801\u76EE\u5F55\uFF0C\u8BF7\u6539\u4E3A\u4F18\u5148\u8BFB\u53D6\u672C\u5730\u968F\u5305\u6587\u6863\u3002`);
|
|
407
|
+
}
|
|
408
|
+
return assertInsideRoot(workspaceRoot, resolved.sourceRoot);
|
|
323
409
|
}
|
|
324
410
|
function toDocsUri(packageId, fileName) {
|
|
325
411
|
return `weapp-vite://docs/${packageId}/${fileName}`;
|
|
@@ -357,7 +443,7 @@ async function createWeappViteMcpServer(options) {
|
|
|
357
443
|
}
|
|
358
444
|
}, async ({ packageId, directory, maxResults }) => {
|
|
359
445
|
try {
|
|
360
|
-
const packageRoot = resolvePackageRoot(workspaceRoot, packageId);
|
|
446
|
+
const packageRoot = await resolvePackageRoot(workspaceRoot, packageId);
|
|
361
447
|
const files = await listFilesInDirectory(packageRoot, directory ?? "src", maxResults ?? DEFAULT_MAX_RESULTS);
|
|
362
448
|
return toToolResult({
|
|
363
449
|
packageId,
|
|
@@ -381,7 +467,7 @@ async function createWeappViteMcpServer(options) {
|
|
|
381
467
|
}
|
|
382
468
|
}, async ({ packageId, filePath, startLine, endLine, maxChars }) => {
|
|
383
469
|
try {
|
|
384
|
-
const packageRoot = resolvePackageRoot(workspaceRoot, packageId);
|
|
470
|
+
const packageRoot = await resolvePackageRoot(workspaceRoot, packageId);
|
|
385
471
|
const { filePath: absolutePath, content } = await readFileContent(packageRoot, filePath, {
|
|
386
472
|
startLine,
|
|
387
473
|
endLine,
|
|
@@ -417,7 +503,7 @@ async function createWeappViteMcpServer(options) {
|
|
|
417
503
|
if (allMatches.length >= safeMax) {
|
|
418
504
|
break;
|
|
419
505
|
}
|
|
420
|
-
const packageRoot = resolvePackageRoot(workspaceRoot, id);
|
|
506
|
+
const packageRoot = await resolvePackageRoot(workspaceRoot, id);
|
|
421
507
|
const matches = await searchTextInDirectory(packageRoot, query, {
|
|
422
508
|
relativeDirectory: directory ?? "src",
|
|
423
509
|
maxResults: safeMax - allMatches.length
|
|
@@ -447,9 +533,9 @@ async function createWeappViteMcpServer(options) {
|
|
|
447
533
|
}
|
|
448
534
|
}, async ({ packageId, script, args, timeoutMs }) => {
|
|
449
535
|
try {
|
|
450
|
-
const
|
|
536
|
+
const resolvedPackage = await resolveExposedPackage(workspaceRoot, packageId);
|
|
451
537
|
const result = await runCommand(workspaceRoot, "pnpm", ["run", script, ...args ?? []], {
|
|
452
|
-
cwdRelative,
|
|
538
|
+
cwdRelative: resolvedPackage.relativePath,
|
|
453
539
|
timeoutMs: timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
454
540
|
});
|
|
455
541
|
return toToolResult(result);
|
|
@@ -469,7 +555,10 @@ async function createWeappViteMcpServer(options) {
|
|
|
469
555
|
}
|
|
470
556
|
}, async ({ subCommand, projectPath, platform, args, timeoutMs }) => {
|
|
471
557
|
try {
|
|
472
|
-
const cliPath =
|
|
558
|
+
const cliPath = (await resolveExposedPackage(workspaceRoot, "weapp-vite")).cliPath;
|
|
559
|
+
if (!cliPath) {
|
|
560
|
+
throw new Error("\u5F53\u524D\u5DE5\u4F5C\u533A\u4E2D\u7684 weapp-vite \u672A\u66B4\u9732 CLI \u5165\u53E3");
|
|
561
|
+
}
|
|
473
562
|
const finalArgs = [cliPath, subCommand];
|
|
474
563
|
if (projectPath) {
|
|
475
564
|
finalArgs.push(resolveSubPath(workspaceRoot, projectPath));
|
|
@@ -575,7 +664,7 @@ async function createWeappViteMcpServer(options) {
|
|
|
575
664
|
}]
|
|
576
665
|
};
|
|
577
666
|
});
|
|
578
|
-
const catalog = await
|
|
667
|
+
const catalog = await resolveExposedPackages(workspaceRoot);
|
|
579
668
|
for (const summary of catalog) {
|
|
580
669
|
if (summary.docs.readme) {
|
|
581
670
|
const uri = toDocsUri(summary.id, "README.md");
|
|
@@ -619,7 +708,7 @@ async function createWeappViteMcpServer(options) {
|
|
|
619
708
|
throw new Error(`\u672A\u77E5 package\uFF1A${packageId}`);
|
|
620
709
|
}
|
|
621
710
|
const relativePath = decodeURIComponent(String(variables.path ?? ""));
|
|
622
|
-
const packageRoot = resolvePackageRoot(workspaceRoot, packageId);
|
|
711
|
+
const packageRoot = await resolvePackageRoot(workspaceRoot, packageId);
|
|
623
712
|
const { content } = await readFileContent(packageRoot, relativePath, {
|
|
624
713
|
maxChars: DEFAULT_MAX_FILE_CHARS
|
|
625
714
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "mcp",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"node": "^20.19.0 || >=22.12.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
35
35
|
"zod": "^4.3.6"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|