@weapp-vite/mcp 1.1.2 → 1.2.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/README.md +2 -0
- package/dist/index.mjs +111 -13
- package/package.json +1 -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
|
@@ -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);
|
|
561
603
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
finalArgs.push(resolveSubPath(workspaceRoot, projectPath));
|
|
604
|
+
if (outputPath) {
|
|
605
|
+
args.push("--output", outputPath);
|
|
565
606
|
}
|
|
566
|
-
|
|
567
|
-
|
|
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);
|
|
568
643
|
}
|
|
569
|
-
if (
|
|
570
|
-
|
|
644
|
+
if (currentOutputPath) {
|
|
645
|
+
args.push("--current-output", currentOutputPath);
|
|
571
646
|
}
|
|
572
|
-
|
|
573
|
-
|
|
647
|
+
if (diffOutputPath) {
|
|
648
|
+
args.push("--diff-output", diffOutputPath);
|
|
649
|
+
}
|
|
650
|
+
if (threshold != null) {
|
|
651
|
+
args.push("--threshold", String(threshold));
|
|
652
|
+
}
|
|
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
|
}
|