@weapp-vite/mcp 1.3.5 → 1.4.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/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +34 -15
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -119,7 +119,9 @@ interface MiniProgramLike {
|
|
|
119
119
|
interface RuntimeConnectionInput {
|
|
120
120
|
projectPath: string;
|
|
121
121
|
timeout?: number;
|
|
122
|
+
port?: number;
|
|
122
123
|
preferOpenedSession?: boolean;
|
|
124
|
+
sessionId?: string;
|
|
123
125
|
}
|
|
124
126
|
interface RuntimeConsoleLogEntry {
|
|
125
127
|
level: string;
|
|
@@ -141,6 +143,7 @@ declare class RuntimeSessionManager {
|
|
|
141
143
|
resolveWorkspacePath(filePath: string): string;
|
|
142
144
|
withMiniProgram<T>(input: RuntimeConnectionInput, runner: (miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
|
|
143
145
|
withPage<T>(input: RuntimeConnectionInput, runner: (page: MiniProgramPage, miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
|
|
146
|
+
private resolveSessionKey;
|
|
144
147
|
private attach;
|
|
145
148
|
private detach;
|
|
146
149
|
private pushLog;
|
package/dist/index.d.ts
CHANGED
|
@@ -119,7 +119,9 @@ interface MiniProgramLike {
|
|
|
119
119
|
interface RuntimeConnectionInput {
|
|
120
120
|
projectPath: string;
|
|
121
121
|
timeout?: number;
|
|
122
|
+
port?: number;
|
|
122
123
|
preferOpenedSession?: boolean;
|
|
124
|
+
sessionId?: string;
|
|
123
125
|
}
|
|
124
126
|
interface RuntimeConsoleLogEntry {
|
|
125
127
|
level: string;
|
|
@@ -141,6 +143,7 @@ declare class RuntimeSessionManager {
|
|
|
141
143
|
resolveWorkspacePath(filePath: string): string;
|
|
142
144
|
withMiniProgram<T>(input: RuntimeConnectionInput, runner: (miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
|
|
143
145
|
withPage<T>(input: RuntimeConnectionInput, runner: (page: MiniProgramPage, miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
|
|
146
|
+
private resolveSessionKey;
|
|
144
147
|
private attach;
|
|
145
148
|
private detach;
|
|
146
149
|
private pushLog;
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
|
|
|
8
8
|
import fs$1 from 'node:fs/promises';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
-
import { closeSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, acquireSharedMiniProgram, releaseSharedMiniProgram, toDevtoolsSerializableValue } from '@weapp-vite/devtools-runtime';
|
|
11
|
+
import { closeSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, acquireSharedMiniProgram, releaseSharedMiniProgram, resolveSharedMiniProgramSessionKey, toDevtoolsSerializableValue } from '@weapp-vite/devtools-runtime';
|
|
12
12
|
import { ResourceTemplate, McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import { createRequire } from 'node:module';
|
|
@@ -625,12 +625,16 @@ async function registerServerResources(server, options) {
|
|
|
625
625
|
z.object({
|
|
626
626
|
projectPath: z.string().trim().min(1).describe("\u5C0F\u7A0B\u5E8F\u9879\u76EE\u8DEF\u5F84\uFF1B\u652F\u6301 workspaceRoot \u76F8\u5BF9\u8DEF\u5F84"),
|
|
627
627
|
timeout: z.number().int().positive().optional(),
|
|
628
|
-
|
|
628
|
+
port: z.number().int().positive().optional(),
|
|
629
|
+
preferOpenedSession: z.boolean().optional(),
|
|
630
|
+
sessionId: z.string().trim().min(1).optional()
|
|
629
631
|
});
|
|
630
632
|
const connectionInputSchema = {
|
|
631
633
|
projectPath: z.string().trim().min(1).describe("\u5C0F\u7A0B\u5E8F\u9879\u76EE\u8DEF\u5F84\uFF1B\u652F\u6301 workspaceRoot \u76F8\u5BF9\u8DEF\u5F84"),
|
|
632
634
|
timeout: z.number().int().positive().optional(),
|
|
633
|
-
|
|
635
|
+
port: z.number().int().positive().optional(),
|
|
636
|
+
preferOpenedSession: z.boolean().optional(),
|
|
637
|
+
sessionId: z.string().trim().min(1).optional()
|
|
634
638
|
};
|
|
635
639
|
class RuntimeSessionManager {
|
|
636
640
|
constructor(workspaceRoot, runtimeHooks = createUnavailableRuntimeHooks()) {
|
|
@@ -642,8 +646,9 @@ class RuntimeSessionManager {
|
|
|
642
646
|
maxLogs = 1e3;
|
|
643
647
|
async close(input) {
|
|
644
648
|
const projectPath = this.resolveProjectPath(input.projectPath);
|
|
645
|
-
this.
|
|
646
|
-
|
|
649
|
+
const sessionKey = this.resolveSessionKey(projectPath, input);
|
|
650
|
+
this.detach(sessionKey);
|
|
651
|
+
await closeSharedMiniProgram(projectPath, input.sessionId || input.port);
|
|
647
652
|
}
|
|
648
653
|
clearLogs() {
|
|
649
654
|
this.logs.length = 0;
|
|
@@ -660,20 +665,23 @@ class RuntimeSessionManager {
|
|
|
660
665
|
async withMiniProgram(input, runner) {
|
|
661
666
|
const projectPath = this.resolveProjectPath(input.projectPath);
|
|
662
667
|
const miniProgram = await acquireSharedMiniProgram(this.runtimeHooks, {
|
|
668
|
+
port: input.port,
|
|
663
669
|
projectPath,
|
|
670
|
+
sessionId: input.sessionId,
|
|
664
671
|
timeout: input.timeout,
|
|
665
672
|
preferOpenedSession: input.preferOpenedSession,
|
|
666
673
|
sharedSession: true
|
|
667
674
|
});
|
|
668
|
-
this.
|
|
675
|
+
const sessionKey = this.resolveSessionKey(projectPath, input);
|
|
676
|
+
this.attach(sessionKey, miniProgram);
|
|
669
677
|
try {
|
|
670
678
|
return await runner(miniProgram);
|
|
671
679
|
} catch (error) {
|
|
672
|
-
this.detach(
|
|
673
|
-
await closeSharedMiniProgram(projectPath);
|
|
680
|
+
this.detach(sessionKey);
|
|
681
|
+
await closeSharedMiniProgram(projectPath, input.sessionId || input.port);
|
|
674
682
|
throw error;
|
|
675
683
|
} finally {
|
|
676
|
-
releaseSharedMiniProgram(projectPath);
|
|
684
|
+
releaseSharedMiniProgram(projectPath, input.sessionId || input.port);
|
|
677
685
|
}
|
|
678
686
|
}
|
|
679
687
|
async withPage(input, runner) {
|
|
@@ -685,12 +693,19 @@ class RuntimeSessionManager {
|
|
|
685
693
|
return await runner(page, miniProgram);
|
|
686
694
|
});
|
|
687
695
|
}
|
|
688
|
-
|
|
689
|
-
|
|
696
|
+
resolveSessionKey(projectPath, input) {
|
|
697
|
+
return resolveSharedMiniProgramSessionKey({
|
|
698
|
+
port: input.port,
|
|
699
|
+
projectPath,
|
|
700
|
+
sessionId: input.sessionId
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
attach(sessionKey, miniProgram) {
|
|
704
|
+
const existing = this.attachedSessions.get(sessionKey);
|
|
690
705
|
if (existing?.miniProgram === miniProgram) {
|
|
691
706
|
return;
|
|
692
707
|
}
|
|
693
|
-
this.detach(
|
|
708
|
+
this.detach(sessionKey);
|
|
694
709
|
const onConsole = (payload) => {
|
|
695
710
|
this.pushLog(normalizeConsoleEvent(payload));
|
|
696
711
|
};
|
|
@@ -699,7 +714,7 @@ class RuntimeSessionManager {
|
|
|
699
714
|
};
|
|
700
715
|
miniProgram.on("console", onConsole);
|
|
701
716
|
miniProgram.on("exception", onException);
|
|
702
|
-
this.attachedSessions.set(
|
|
717
|
+
this.attachedSessions.set(sessionKey, {
|
|
703
718
|
miniProgram,
|
|
704
719
|
onConsole,
|
|
705
720
|
onException
|
|
@@ -1921,7 +1936,9 @@ const DEFAULT_RUNTIME_REST_ENDPOINT = "/api/weapp/devtools";
|
|
|
1921
1936
|
const connectionSchema = z.object({
|
|
1922
1937
|
projectPath: z.string().trim().min(1),
|
|
1923
1938
|
timeout: z.number().int().positive().optional(),
|
|
1924
|
-
|
|
1939
|
+
port: z.number().int().positive().optional(),
|
|
1940
|
+
preferOpenedSession: z.boolean().optional(),
|
|
1941
|
+
sessionId: z.string().trim().min(1).optional()
|
|
1925
1942
|
});
|
|
1926
1943
|
const routeBodySchema = connectionSchema.extend({
|
|
1927
1944
|
path: z.string().trim().min(1).optional(),
|
|
@@ -2000,7 +2017,9 @@ function readConnectionFromQuery(url) {
|
|
|
2000
2017
|
return connectionSchema.parse(compactObject({
|
|
2001
2018
|
projectPath: url.searchParams.get("projectPath") ?? void 0,
|
|
2002
2019
|
timeout: readNumberParam(url.searchParams.get("timeout")),
|
|
2003
|
-
|
|
2020
|
+
port: readNumberParam(url.searchParams.get("port")),
|
|
2021
|
+
preferOpenedSession: readBooleanParam(url.searchParams.get("preferOpenedSession")),
|
|
2022
|
+
sessionId: url.searchParams.get("sessionId") ?? void 0
|
|
2004
2023
|
}));
|
|
2005
2024
|
}
|
|
2006
2025
|
function getRouteContext(req, endpoint) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "mcp",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
35
35
|
"zod": "^4.4.3",
|
|
36
|
-
"@weapp-vite/devtools-runtime": "0.
|
|
36
|
+
"@weapp-vite/devtools-runtime": "0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"dev": "unbuild --stub",
|