ms-vite-plugin 1.1.3 → 1.1.5
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/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.js +121 -18
- package/dist/mcp-server.js +2 -2
- package/dist/project.d.ts +1 -0
- package/dist/project.js +6 -2
- package/package.json +1 -1
package/dist/mcp/tools.d.ts
CHANGED
package/dist/mcp/tools.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.DEFAULT_DEVICE_PORT = void 0;
|
|
37
37
|
exports.createMcpServer = createMcpServer;
|
|
38
|
-
const
|
|
38
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
39
39
|
const z = __importStar(require("zod/v4"));
|
|
40
40
|
const fsExtra = __importStar(require("fs-extra"));
|
|
41
41
|
const os = __importStar(require("os"));
|
|
@@ -76,7 +76,7 @@ function registerDocResources(server) {
|
|
|
76
76
|
],
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
|
-
server.registerResource("api-doc", new
|
|
79
|
+
server.registerResource("api-doc", new mcp_js_1.ResourceTemplate("kuaijs://docs/current/{slug}", {
|
|
80
80
|
list: async () => {
|
|
81
81
|
const language = (0, docs_service_1.getCurrentDocsLanguage)();
|
|
82
82
|
const docs = await (0, docs_service_1.getApiDocsByLanguage)(language);
|
|
@@ -269,6 +269,39 @@ function registerDocTools(server) {
|
|
|
269
269
|
* registerRuntimeTools(server)
|
|
270
270
|
*/
|
|
271
271
|
function registerRuntimeTools(server) {
|
|
272
|
+
/**
|
|
273
|
+
* MCP 进程内当前工作目录(可通过 set_workspace 修改)
|
|
274
|
+
*/
|
|
275
|
+
let currentWorkspacePath;
|
|
276
|
+
/**
|
|
277
|
+
* 解析并记忆工作目录
|
|
278
|
+
* @param workspacePath 可选的工作目录
|
|
279
|
+
* @returns 返回本次生效的绝对路径
|
|
280
|
+
* @example
|
|
281
|
+
* const workspace = resolveWorkspacePath("/Users/demo/project")
|
|
282
|
+
*/
|
|
283
|
+
function resolveWorkspacePath(workspacePath) {
|
|
284
|
+
if (workspacePath && workspacePath.trim()) {
|
|
285
|
+
currentWorkspacePath = path.resolve(workspacePath.trim());
|
|
286
|
+
return currentWorkspacePath;
|
|
287
|
+
}
|
|
288
|
+
if (currentWorkspacePath) {
|
|
289
|
+
return currentWorkspacePath;
|
|
290
|
+
}
|
|
291
|
+
return process.cwd();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 校验并返回有效工作目录
|
|
295
|
+
* @param workspacePath 可选工作目录
|
|
296
|
+
* @returns 返回校验通过的绝对路径
|
|
297
|
+
* @example
|
|
298
|
+
* const workspace = await ensureWorkspacePath("/Users/demo/project")
|
|
299
|
+
*/
|
|
300
|
+
async function ensureWorkspacePath(workspacePath) {
|
|
301
|
+
const workspace = resolveWorkspacePath(workspacePath);
|
|
302
|
+
await (0, project_2.ensureValidKuaiJSProject)(workspace);
|
|
303
|
+
return workspace;
|
|
304
|
+
}
|
|
272
305
|
/**
|
|
273
306
|
* 解析运行目标:
|
|
274
307
|
* - 显式 transport=ws: 强制走 ws
|
|
@@ -306,6 +339,41 @@ function registerRuntimeTools(server) {
|
|
|
306
339
|
label: `${device.ip}:${device.port}`,
|
|
307
340
|
};
|
|
308
341
|
}
|
|
342
|
+
server.registerTool("set_workspace", {
|
|
343
|
+
title: "Set Workspace",
|
|
344
|
+
description: "设置默认工作目录。后续 build/run/package/watch 等工具会优先使用该目录。",
|
|
345
|
+
inputSchema: {
|
|
346
|
+
workspacePath: z
|
|
347
|
+
.string()
|
|
348
|
+
.min(1)
|
|
349
|
+
.describe("快点JS 项目目录绝对路径(需包含 package.json 与 scripts)"),
|
|
350
|
+
},
|
|
351
|
+
}, async ({ workspacePath }) => {
|
|
352
|
+
const workspace = await ensureWorkspacePath(workspacePath);
|
|
353
|
+
return {
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
type: "text",
|
|
357
|
+
text: `默认工作目录已设置为: ${workspace}`,
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
server.registerTool("get_workspace", {
|
|
363
|
+
title: "Get Workspace",
|
|
364
|
+
description: "查看当前 MCP 生效的工作目录。",
|
|
365
|
+
inputSchema: {},
|
|
366
|
+
}, async () => {
|
|
367
|
+
const workspace = resolveWorkspacePath();
|
|
368
|
+
return {
|
|
369
|
+
content: [
|
|
370
|
+
{
|
|
371
|
+
type: "text",
|
|
372
|
+
text: `当前工作目录: ${workspace}`,
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
};
|
|
376
|
+
});
|
|
309
377
|
server.registerTool("set_device", {
|
|
310
378
|
title: "Set Device",
|
|
311
379
|
description: "设置默认设备连接信息。首次配置后,后续 run/stop 可不再传 ip。",
|
|
@@ -525,6 +593,11 @@ function registerRuntimeTools(server) {
|
|
|
525
593
|
title: "Watch Logs",
|
|
526
594
|
description: "通过 SSE 监听设备日志并自动判定异常。首次可传 ip,也可复用 set_device 保存的默认设备。",
|
|
527
595
|
inputSchema: {
|
|
596
|
+
workspacePath: z
|
|
597
|
+
.string()
|
|
598
|
+
.min(1)
|
|
599
|
+
.optional()
|
|
600
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
528
601
|
ip: z
|
|
529
602
|
.string()
|
|
530
603
|
.min(1)
|
|
@@ -554,8 +627,8 @@ function registerRuntimeTools(server) {
|
|
|
554
627
|
.default(200)
|
|
555
628
|
.describe("最多收集日志条数,默认 200"),
|
|
556
629
|
},
|
|
557
|
-
}, async ({ ip, port, durationSeconds, maxLogs }) => {
|
|
558
|
-
await (
|
|
630
|
+
}, async ({ workspacePath, ip, port, durationSeconds, maxLogs }) => {
|
|
631
|
+
await ensureWorkspacePath(workspacePath);
|
|
559
632
|
const device = await (0, device_config_1.resolveDeviceConfig)(ip, port);
|
|
560
633
|
const result = await (0, project_1.watchDeviceLogsBySse)(device.ip, device.port, durationSeconds * 1000, maxLogs);
|
|
561
634
|
const findingsPreview = result.findings
|
|
@@ -589,14 +662,19 @@ function registerRuntimeTools(server) {
|
|
|
589
662
|
title: "Build Project",
|
|
590
663
|
description: "构建 KuaiJS 项目,支持开发模式与生产模式。",
|
|
591
664
|
inputSchema: {
|
|
665
|
+
workspacePath: z
|
|
666
|
+
.string()
|
|
667
|
+
.min(1)
|
|
668
|
+
.optional()
|
|
669
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
592
670
|
dev: z
|
|
593
671
|
.boolean()
|
|
594
672
|
.optional()
|
|
595
673
|
.describe("是否开发模式构建,true=开发模式,false=生产模式"),
|
|
596
674
|
},
|
|
597
|
-
}, async ({ dev }) => {
|
|
598
|
-
await (
|
|
599
|
-
await (0, build_1.buildAll)(Boolean(dev),
|
|
675
|
+
}, async ({ workspacePath, dev }) => {
|
|
676
|
+
const workspace = await ensureWorkspacePath(workspacePath);
|
|
677
|
+
await (0, build_1.buildAll)(Boolean(dev), workspace);
|
|
600
678
|
return {
|
|
601
679
|
content: [
|
|
602
680
|
{ type: "text", text: `构建完成,模式: ${dev ? "dev" : "prod"}` },
|
|
@@ -606,10 +684,16 @@ function registerRuntimeTools(server) {
|
|
|
606
684
|
server.registerTool("package_project", {
|
|
607
685
|
title: "Package Project",
|
|
608
686
|
description: "执行生产构建并加密,返回 enc.msbundle 路径。",
|
|
609
|
-
inputSchema: {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
687
|
+
inputSchema: {
|
|
688
|
+
workspacePath: z
|
|
689
|
+
.string()
|
|
690
|
+
.min(1)
|
|
691
|
+
.optional()
|
|
692
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
693
|
+
},
|
|
694
|
+
}, async ({ workspacePath }) => {
|
|
695
|
+
const workspace = await ensureWorkspacePath(workspacePath);
|
|
696
|
+
const encryptedPath = await (0, packager_1.packageProject)(workspace);
|
|
613
697
|
return {
|
|
614
698
|
content: [{ type: "text", text: `打包完成: ${encryptedPath}` }],
|
|
615
699
|
};
|
|
@@ -648,9 +732,14 @@ function registerRuntimeTools(server) {
|
|
|
648
732
|
.max(600000)
|
|
649
733
|
.optional()
|
|
650
734
|
.describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
|
|
735
|
+
workspacePath: z
|
|
736
|
+
.string()
|
|
737
|
+
.min(1)
|
|
738
|
+
.optional()
|
|
739
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
651
740
|
},
|
|
652
|
-
}, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
|
|
653
|
-
await (
|
|
741
|
+
}, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
|
|
742
|
+
const workspace = await ensureWorkspacePath(workspacePath);
|
|
654
743
|
const target = await resolvePreferredRuntimeTarget({
|
|
655
744
|
transport,
|
|
656
745
|
ip,
|
|
@@ -663,11 +752,13 @@ function registerRuntimeTools(server) {
|
|
|
663
752
|
transport: "ws",
|
|
664
753
|
wsPort: target.wsPort,
|
|
665
754
|
wsWaitMs: target.wsWaitMs,
|
|
755
|
+
workspacePath: workspace,
|
|
666
756
|
}
|
|
667
757
|
: {
|
|
668
758
|
ip: target.ip,
|
|
669
759
|
port: target.port,
|
|
670
760
|
transport: "http",
|
|
761
|
+
workspacePath: workspace,
|
|
671
762
|
});
|
|
672
763
|
return {
|
|
673
764
|
content: [
|
|
@@ -712,9 +803,14 @@ function registerRuntimeTools(server) {
|
|
|
712
803
|
.max(600000)
|
|
713
804
|
.optional()
|
|
714
805
|
.describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
|
|
806
|
+
workspacePath: z
|
|
807
|
+
.string()
|
|
808
|
+
.min(1)
|
|
809
|
+
.optional()
|
|
810
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
715
811
|
},
|
|
716
|
-
}, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
|
|
717
|
-
await (
|
|
812
|
+
}, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
|
|
813
|
+
const workspace = await ensureWorkspacePath(workspacePath);
|
|
718
814
|
const target = await resolvePreferredRuntimeTarget({
|
|
719
815
|
transport,
|
|
720
816
|
ip,
|
|
@@ -727,11 +823,13 @@ function registerRuntimeTools(server) {
|
|
|
727
823
|
transport: "ws",
|
|
728
824
|
wsPort: target.wsPort,
|
|
729
825
|
wsWaitMs: target.wsWaitMs,
|
|
826
|
+
workspacePath: workspace,
|
|
730
827
|
}
|
|
731
828
|
: {
|
|
732
829
|
ip: target.ip,
|
|
733
830
|
port: target.port,
|
|
734
831
|
transport: "http",
|
|
832
|
+
workspacePath: workspace,
|
|
735
833
|
});
|
|
736
834
|
return {
|
|
737
835
|
content: [
|
|
@@ -776,9 +874,14 @@ function registerRuntimeTools(server) {
|
|
|
776
874
|
.max(600000)
|
|
777
875
|
.optional()
|
|
778
876
|
.describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
|
|
877
|
+
workspacePath: z
|
|
878
|
+
.string()
|
|
879
|
+
.min(1)
|
|
880
|
+
.optional()
|
|
881
|
+
.describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
|
|
779
882
|
},
|
|
780
|
-
}, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
|
|
781
|
-
|
|
883
|
+
}, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
|
|
884
|
+
resolveWorkspacePath(workspacePath);
|
|
782
885
|
const target = await resolvePreferredRuntimeTarget({
|
|
783
886
|
transport,
|
|
784
887
|
ip,
|
|
@@ -814,7 +917,7 @@ function registerRuntimeTools(server) {
|
|
|
814
917
|
* const server = createMcpServer()
|
|
815
918
|
*/
|
|
816
919
|
function createMcpServer() {
|
|
817
|
-
const server = new
|
|
920
|
+
const server = new mcp_js_1.McpServer({
|
|
818
921
|
name: "ms-vite-plugin-mcp",
|
|
819
922
|
version: version_1.PACKAGE_VERSION,
|
|
820
923
|
});
|
package/dist/mcp-server.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
const fsExtra = __importStar(require("fs-extra"));
|
|
38
|
-
const
|
|
38
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
39
39
|
const tools_1 = require("./mcp/tools");
|
|
40
40
|
const device_config_1 = require("./mcp/device-config");
|
|
41
41
|
/**
|
|
@@ -46,7 +46,7 @@ const device_config_1 = require("./mcp/device-config");
|
|
|
46
46
|
*/
|
|
47
47
|
async function main() {
|
|
48
48
|
const server = (0, tools_1.createMcpServer)();
|
|
49
|
-
const transport = new
|
|
49
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
50
50
|
/**
|
|
51
51
|
* 进程退出时清理当前实例的临时配置文件,避免系统临时目录残留
|
|
52
52
|
* 注意:只清理“当前进程文件”,不会影响其他并发窗口实例
|
package/dist/project.d.ts
CHANGED
package/dist/project.js
CHANGED
|
@@ -709,7 +709,9 @@ async function ensureWsReady(options) {
|
|
|
709
709
|
* await runOnDevice({ ip: "192.168.1.10", port: "9800", path: "./demo" })
|
|
710
710
|
*/
|
|
711
711
|
async function runOnDevice(options) {
|
|
712
|
-
const workspacePath =
|
|
712
|
+
const workspacePath = options.workspacePath
|
|
713
|
+
? path.resolve(options.workspacePath)
|
|
714
|
+
: process.cwd();
|
|
713
715
|
const transport = parseTransport(options);
|
|
714
716
|
console.log(`🔧 开始构建项目: ${workspacePath}`);
|
|
715
717
|
await runDevBuild(workspacePath);
|
|
@@ -737,7 +739,9 @@ async function runOnDevice(options) {
|
|
|
737
739
|
* await runUIOnDevice({ ip: "192.168.1.10", port: "9800", path: "./demo" })
|
|
738
740
|
*/
|
|
739
741
|
async function runUIOnDevice(options) {
|
|
740
|
-
const workspacePath =
|
|
742
|
+
const workspacePath = options.workspacePath
|
|
743
|
+
? path.resolve(options.workspacePath)
|
|
744
|
+
: process.cwd();
|
|
741
745
|
const transport = parseTransport(options);
|
|
742
746
|
console.log(`🔧 开始构建项目: ${workspacePath}`);
|
|
743
747
|
await runDevBuild(workspacePath);
|