@weapp-vite/mcp 1.1.2 → 1.2.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/README.md +2 -0
- package/dist/index.mjs +119 -21
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ await handle.close?.()
|
|
|
43
43
|
- `search_source_code`: 在包源码中检索关键词
|
|
44
44
|
- `run_package_script`: 在指定包目录执行 `pnpm run <script>`
|
|
45
45
|
- `run_weapp_vite_cli`: 执行 `node packages/weapp-vite/bin/weapp-vite.js ...`
|
|
46
|
+
- `take_weapp_screenshot`: 面向“小程序截图 / 页面快照”语义,执行 `weapp-vite screenshot --json`
|
|
47
|
+
- `compare_weapp_screenshot`: 面向“截图对比 / diff / baseline / 视觉回归”语义,执行 `weapp-vite compare --json`
|
|
46
48
|
- `run_repo_command`: 执行仓库级命令(`pnpm/node/git/rg`)
|
|
47
49
|
|
|
48
50
|
## 主要 Resources
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import fs$1 from 'node:fs/promises';
|
|
4
|
-
import { createRequire } from 'node:module';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import { spawn } from 'node:child_process';
|
|
8
3
|
import { Buffer } from 'node:buffer';
|
|
9
4
|
import http from 'node:http';
|
|
10
5
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
11
6
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
7
|
+
import fs$1 from 'node:fs/promises';
|
|
12
8
|
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
13
9
|
import { z } from 'zod';
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
14
|
|
|
15
15
|
const MCP_SERVER_NAME = "@weapp-vite/mcp";
|
|
16
16
|
const MCP_SERVER_VERSION = "2.0.0";
|
|
@@ -413,6 +413,25 @@ function toDocsUri(packageId, fileName) {
|
|
|
413
413
|
async function readTextFile(filePath) {
|
|
414
414
|
return fs$1.readFile(filePath, "utf8");
|
|
415
415
|
}
|
|
416
|
+
async function runWeappViteCliTool(workspaceRoot, input) {
|
|
417
|
+
const cliPath = (await resolveExposedPackage(workspaceRoot, "weapp-vite")).cliPath;
|
|
418
|
+
if (!cliPath) {
|
|
419
|
+
throw new Error("\u5F53\u524D\u5DE5\u4F5C\u533A\u4E2D\u7684 weapp-vite \u672A\u66B4\u9732 CLI \u5165\u53E3");
|
|
420
|
+
}
|
|
421
|
+
const finalArgs = [cliPath, input.subCommand];
|
|
422
|
+
if (input.projectPath) {
|
|
423
|
+
finalArgs.push(resolveSubPath(workspaceRoot, input.projectPath));
|
|
424
|
+
}
|
|
425
|
+
if (input.platform) {
|
|
426
|
+
finalArgs.push("--platform", input.platform);
|
|
427
|
+
}
|
|
428
|
+
if (Array.isArray(input.args) && input.args.length > 0) {
|
|
429
|
+
finalArgs.push(...input.args);
|
|
430
|
+
}
|
|
431
|
+
return runCommand(workspaceRoot, "node", finalArgs, {
|
|
432
|
+
timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
433
|
+
});
|
|
434
|
+
}
|
|
416
435
|
async function createWeappViteMcpServer(options) {
|
|
417
436
|
const workspaceRoot = resolveWorkspaceRoot(options?.workspaceRoot);
|
|
418
437
|
const server = new McpServer({
|
|
@@ -555,24 +574,103 @@ async function createWeappViteMcpServer(options) {
|
|
|
555
574
|
}
|
|
556
575
|
}, async ({ subCommand, projectPath, platform, args, timeoutMs }) => {
|
|
557
576
|
try {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
577
|
+
const result = await runWeappViteCliTool(workspaceRoot, {
|
|
578
|
+
subCommand,
|
|
579
|
+
projectPath,
|
|
580
|
+
platform,
|
|
581
|
+
args,
|
|
582
|
+
timeoutMs
|
|
583
|
+
});
|
|
584
|
+
return toToolResult(result);
|
|
585
|
+
} catch (error) {
|
|
586
|
+
return toToolError(error);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
server.registerTool("take_weapp_screenshot", {
|
|
590
|
+
title: "Take Weapp Screenshot",
|
|
591
|
+
description: "\u5F53\u7528\u6237\u63D0\u5230\u622A\u56FE\u3001\u9875\u9762\u5FEB\u7167\u3001\u8FD0\u884C\u65F6\u622A\u56FE\u65F6\uFF0C\u4F18\u5148\u8C03\u7528\u6B64\u5DE5\u5177\u6267\u884C weapp-vite screenshot",
|
|
592
|
+
inputSchema: {
|
|
593
|
+
projectPath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\uFF0C\u901A\u5E38\u662F dist/build/mp-weixin \u6216\u5177\u4F53\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55"),
|
|
594
|
+
page: z.string().optional().describe("\u622A\u56FE\u524D\u5148\u8DF3\u8F6C\u7684\u5C0F\u7A0B\u5E8F\u9875\u9762\u8DEF\u5F84"),
|
|
595
|
+
outputPath: z.string().optional().describe("\u622A\u56FE\u8F93\u51FA\u8DEF\u5F84\uFF0C\u5EFA\u8BAE\u5199\u5165 .tmp/ \u6216\u5DE5\u4F5C\u533A\u76F8\u5BF9\u8DEF\u5F84"),
|
|
596
|
+
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
597
|
+
}
|
|
598
|
+
}, async ({ projectPath, page, outputPath, timeoutMs }) => {
|
|
599
|
+
try {
|
|
600
|
+
const args = ["--json"];
|
|
601
|
+
if (page) {
|
|
602
|
+
args.push("--page", page);
|
|
603
|
+
}
|
|
604
|
+
if (outputPath) {
|
|
605
|
+
args.push("--output", outputPath);
|
|
606
|
+
}
|
|
607
|
+
const result = await runWeappViteCliTool(workspaceRoot, {
|
|
608
|
+
subCommand: "screenshot",
|
|
609
|
+
projectPath,
|
|
610
|
+
args,
|
|
611
|
+
timeoutMs
|
|
612
|
+
});
|
|
613
|
+
return toToolResult({
|
|
614
|
+
...result,
|
|
615
|
+
projectPath,
|
|
616
|
+
page: page ?? null,
|
|
617
|
+
outputPath: outputPath ?? null,
|
|
618
|
+
recommendedIntent: "screenshot"
|
|
619
|
+
});
|
|
620
|
+
} catch (error) {
|
|
621
|
+
return toToolError(error);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
server.registerTool("compare_weapp_screenshot", {
|
|
625
|
+
title: "Compare Weapp Screenshot",
|
|
626
|
+
description: "\u5F53\u7528\u6237\u63D0\u5230\u622A\u56FE\u5BF9\u6BD4\u3001diff\u3001baseline\u3001\u89C6\u89C9\u56DE\u5F52\u3001\u50CF\u7D20\u5BF9\u6BD4\u65F6\uFF0C\u4F18\u5148\u8C03\u7528\u6B64\u5DE5\u5177\u6267\u884C weapp-vite compare",
|
|
627
|
+
inputSchema: {
|
|
628
|
+
projectPath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\uFF0C\u901A\u5E38\u662F dist/build/mp-weixin \u6216\u5177\u4F53\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55"),
|
|
629
|
+
baselinePath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\u7684 baseline \u56FE\u7247\u8DEF\u5F84"),
|
|
630
|
+
page: z.string().optional().describe("\u622A\u56FE\u5BF9\u6BD4\u524D\u5148\u8DF3\u8F6C\u7684\u5C0F\u7A0B\u5E8F\u9875\u9762\u8DEF\u5F84"),
|
|
631
|
+
currentOutputPath: z.string().optional().describe("\u5F53\u524D\u622A\u56FE\u8F93\u51FA\u8DEF\u5F84"),
|
|
632
|
+
diffOutputPath: z.string().optional().describe("diff \u56FE\u7247\u8F93\u51FA\u8DEF\u5F84"),
|
|
633
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
634
|
+
maxDiffPixels: z.number().int().min(0).optional(),
|
|
635
|
+
maxDiffRatio: z.number().min(0).max(1).optional(),
|
|
636
|
+
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
637
|
+
}
|
|
638
|
+
}, async ({ projectPath, baselinePath, page, currentOutputPath, diffOutputPath, threshold, maxDiffPixels, maxDiffRatio, timeoutMs }) => {
|
|
639
|
+
try {
|
|
640
|
+
const args = ["--json", "--baseline", baselinePath];
|
|
641
|
+
if (page) {
|
|
642
|
+
args.push("--page", page);
|
|
561
643
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
finalArgs.push(resolveSubPath(workspaceRoot, projectPath));
|
|
644
|
+
if (currentOutputPath) {
|
|
645
|
+
args.push("--current-output", currentOutputPath);
|
|
565
646
|
}
|
|
566
|
-
if (
|
|
567
|
-
|
|
647
|
+
if (diffOutputPath) {
|
|
648
|
+
args.push("--diff-output", diffOutputPath);
|
|
568
649
|
}
|
|
569
|
-
if (
|
|
570
|
-
|
|
650
|
+
if (threshold != null) {
|
|
651
|
+
args.push("--threshold", String(threshold));
|
|
571
652
|
}
|
|
572
|
-
|
|
573
|
-
|
|
653
|
+
if (maxDiffPixels != null) {
|
|
654
|
+
args.push("--max-diff-pixels", String(maxDiffPixels));
|
|
655
|
+
}
|
|
656
|
+
if (maxDiffRatio != null) {
|
|
657
|
+
args.push("--max-diff-ratio", String(maxDiffRatio));
|
|
658
|
+
}
|
|
659
|
+
const result = await runWeappViteCliTool(workspaceRoot, {
|
|
660
|
+
subCommand: "compare",
|
|
661
|
+
projectPath,
|
|
662
|
+
args,
|
|
663
|
+
timeoutMs
|
|
664
|
+
});
|
|
665
|
+
return toToolResult({
|
|
666
|
+
...result,
|
|
667
|
+
projectPath,
|
|
668
|
+
baselinePath,
|
|
669
|
+
page: page ?? null,
|
|
670
|
+
currentOutputPath: currentOutputPath ?? null,
|
|
671
|
+
diffOutputPath: diffOutputPath ?? null,
|
|
672
|
+
recommendedIntent: "compare"
|
|
574
673
|
});
|
|
575
|
-
return toToolResult(result);
|
|
576
674
|
} catch (error) {
|
|
577
675
|
return toToolError(error);
|
|
578
676
|
}
|
|
@@ -776,7 +874,7 @@ function writeJson(res, statusCode, payload) {
|
|
|
776
874
|
res.setHeader("content-type", "application/json");
|
|
777
875
|
res.end(JSON.stringify(payload));
|
|
778
876
|
}
|
|
779
|
-
async function startStdioServer
|
|
877
|
+
async function startStdioServer(options) {
|
|
780
878
|
const previousCwd = process.cwd();
|
|
781
879
|
if (options?.workspaceRoot) {
|
|
782
880
|
process.chdir(options.workspaceRoot);
|
|
@@ -881,7 +979,7 @@ async function startWeappViteMcpServer(options) {
|
|
|
881
979
|
if (transport === "streamable-http") {
|
|
882
980
|
return startStreamableHttpServer(options ?? {});
|
|
883
981
|
}
|
|
884
|
-
await startStdioServer
|
|
982
|
+
await startStdioServer(options);
|
|
885
983
|
return {
|
|
886
984
|
transport: "stdio"
|
|
887
985
|
};
|
|
@@ -904,4 +1002,4 @@ ${message}
|
|
|
904
1002
|
});
|
|
905
1003
|
}
|
|
906
1004
|
|
|
907
|
-
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer
|
|
1005
|
+
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
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.2.1",
|
|
5
5
|
"description": "mcp",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
"build": "unbuild",
|
|
41
41
|
"test": "vitest run",
|
|
42
42
|
"test:dev": "vitest",
|
|
43
|
+
"pretest:types": "pnpm build",
|
|
44
|
+
"test:types": "tsd",
|
|
43
45
|
"typecheck": "tsc --noEmit",
|
|
44
46
|
"release": "pnpm publish",
|
|
45
47
|
"lint": "eslint .",
|