@weapp-vite/mcp 1.5.8 → 2.1.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 CHANGED
@@ -19,6 +19,8 @@
19
19
 
20
20
  ## 启动
21
21
 
22
+ 直接使用 `@weapp-vite/mcp` 或 `@weapp-vite/acceptance` 需要 **Node.js >=22.12.0**。这两个包不再支持 Node 20;通过 `weapp-vite` 命令使用时,还须满足 `weapp-vite` 自身的 Node 范围 `^22.18.0 || ^24.11.0 || >=26.0.0`。
23
+
22
24
  ```bash
23
25
  pnpm --filter @weapp-vite/mcp start
24
26
  ```
package/dist/index.d.ts CHANGED
@@ -1,222 +1,254 @@
1
- import { DevtoolsRuntimeHooks } from '@weapp-vite/devtools-runtime';
2
- import { McpServer } from '@modelcontextprotocol/server';
3
-
4
- declare const MCP_SERVER_NAME = "@weapp-vite/mcp";
5
- declare const MCP_SERVER_VERSION = "2.0.0";
6
- declare const EXPOSED_PACKAGES: {
7
- readonly 'weapp-vite': {
8
- readonly id: "weapp-vite";
9
- readonly label: "weapp-vite";
10
- readonly packageName: "weapp-vite";
11
- readonly relativePath: string;
12
- };
13
- readonly wevu: {
14
- readonly id: "wevu";
15
- readonly label: "wevu";
16
- readonly packageName: "wevu";
17
- readonly relativePath: string;
18
- };
19
- readonly 'wevu-compiler': {
20
- readonly id: "wevu-compiler";
21
- readonly label: "wevu-compiler";
22
- readonly packageName: "@wevu/compiler";
23
- readonly relativePath: string;
24
- };
25
- };
26
- type ExposedPackageId = keyof typeof EXPOSED_PACKAGES;
27
- declare const DEFAULT_TIMEOUT_MS = 120000;
28
- declare const DEFAULT_MAX_OUTPUT_CHARS = 120000;
29
- declare const DEFAULT_MAX_FILE_CHARS = 80000;
30
- declare const DEFAULT_MAX_RESULTS = 200;
31
- declare const SKIPPED_DIR_NAMES: Set<string>;
32
-
33
- interface ResolvedExposedPackage {
34
- id: ExposedPackageId;
35
- label: string;
36
- packageName: string;
37
- version: string;
38
- absolutePath: string;
39
- relativePath: string;
40
- scripts: string[];
41
- docs: {
42
- readme?: string;
43
- changelog?: string;
44
- };
45
- sourceRoot?: string;
46
- cliPath?: string;
47
- }
48
-
49
- interface ExposedPackageSummary extends ResolvedExposedPackage {
50
- }
51
- declare function loadPackageSummary(workspaceRoot: string, id: ExposedPackageId): Promise<ExposedPackageSummary>;
52
- declare function loadExposedCatalog(workspaceRoot: string): Promise<ResolvedExposedPackage[]>;
53
-
54
- interface CommandResult {
55
- command: string;
56
- args: string[];
57
- cwd: string;
58
- exitCode: number;
59
- stdout: string;
60
- stderr: string;
61
- timedOut: boolean;
62
- }
63
- declare function runCommand(workspaceRoot: string, command: string, args: string[], options?: {
64
- cwdRelative?: string;
65
- timeoutMs?: number;
66
- maxOutputChars?: number;
67
- }): Promise<CommandResult>;
68
-
69
- interface SearchMatch {
70
- filePath: string;
71
- line: number;
72
- column: number;
73
- text: string;
74
- }
75
- declare function listFilesInDirectory(root: string, relativeDirectory?: string, maxResults?: number): Promise<string[]>;
76
- declare function readFileContent(root: string, relativeFilePath: string, options?: {
77
- startLine?: number;
78
- endLine?: number;
79
- maxChars?: number;
80
- }): Promise<{
81
- filePath: string;
82
- content: string;
83
- }>;
84
- declare function searchTextInDirectory(root: string, query: string, options?: {
85
- relativeDirectory?: string;
86
- maxResults?: number;
87
- }): Promise<SearchMatch[]>;
88
-
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
+ import { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT } from "@weapp-core/constants";
3
+ import { AcceptanceOptions, AcceptanceService, RuntimeConnector } from "@weapp-vite/acceptance";
4
+ import { z } from "zod";
5
+ import { DevtoolsRuntimeHooks } from "@weapp-vite/devtools-runtime";
6
+ import { Buffer } from "node:buffer";
7
+ import { WechatDevtoolsSelectionOptions } from "weapp-ide-cli";
8
+ //#region src/server/runtime/shared.d.ts
89
9
  interface MiniProgramElement {
90
- tagName?: string;
91
- $?: (selector: string) => Promise<MiniProgramElement | null>;
92
- $$?: (selector: string) => Promise<MiniProgramElement[]>;
93
- tap: () => Promise<void>;
10
+ tagName?: string;
11
+ $?: (selector: string) => Promise<MiniProgramElement | null>;
12
+ $$?: (selector: string) => Promise<MiniProgramElement[]>;
13
+ tap: () => Promise<void>;
94
14
  }
95
15
  interface MiniProgramPage {
96
- path: string;
97
- query?: unknown;
98
- $: (selector: string, options?: MiniProgramPageQueryOptions) => Promise<MiniProgramElement | null>;
99
- $$?: (selector: string, options?: MiniProgramPageQueryOptions) => Promise<MiniProgramElement[]>;
100
- data: (path?: string) => Promise<unknown>;
101
- size: () => Promise<unknown>;
102
- scrollTop: () => Promise<unknown>;
103
- waitFor: (milliseconds: number) => Promise<void>;
16
+ path: string;
17
+ query?: unknown;
18
+ $: (selector: string, options?: MiniProgramPageQueryOptions) => Promise<MiniProgramElement | null>;
19
+ $$?: (selector: string, options?: MiniProgramPageQueryOptions) => Promise<MiniProgramElement[]>;
20
+ data: (path?: string) => Promise<unknown>;
21
+ size: () => Promise<unknown>;
22
+ scrollTop: () => Promise<unknown>;
23
+ waitFor: (milliseconds: number) => Promise<void>;
104
24
  }
105
25
  interface MiniProgramPageQueryOptions {
106
- fallback?: boolean;
26
+ fallback?: boolean;
107
27
  }
108
28
  interface MiniProgramLike {
109
- on: (name: 'console' | 'exception', handler: (payload: unknown) => void) => void;
110
- off?: (name: 'console' | 'exception', handler: (payload: unknown) => void) => void;
111
- currentPage: () => Promise<MiniProgramPage>;
112
- systemInfo: () => Promise<unknown>;
113
- pageStack: () => Promise<MiniProgramPage[]>;
114
- navigateTo: (url: string) => Promise<MiniProgramPage>;
115
- redirectTo: (url: string) => Promise<MiniProgramPage>;
116
- reLaunch: (url: string) => Promise<MiniProgramPage>;
117
- switchTab: (url: string) => Promise<MiniProgramPage>;
118
- navigateBack: () => Promise<MiniProgramPage>;
119
- screenshot: (options?: {
120
- timeout?: number;
121
- }) => Promise<string | Uint8Array | undefined>;
122
- callWxMethod: (method: string, ...args: unknown[]) => Promise<unknown>;
123
- }
124
- interface RuntimeConnectionInput {
125
- projectPath: string;
29
+ on: (name: 'console' | 'exception', handler: (payload: unknown) => void) => void;
30
+ off?: (name: 'console' | 'exception', handler: (payload: unknown) => void) => void;
31
+ currentPage: () => Promise<MiniProgramPage>;
32
+ systemInfo: () => Promise<unknown>;
33
+ pageStack: () => Promise<MiniProgramPage[]>;
34
+ navigateTo: (url: string) => Promise<MiniProgramPage>;
35
+ redirectTo: (url: string) => Promise<MiniProgramPage>;
36
+ reLaunch: (url: string) => Promise<MiniProgramPage>;
37
+ switchTab: (url: string) => Promise<MiniProgramPage>;
38
+ navigateBack: () => Promise<MiniProgramPage>;
39
+ screenshot: (options?: {
126
40
  timeout?: number;
127
- port?: number;
128
- preferOpenedSession?: boolean;
129
- preserveProjectRoot?: boolean;
130
- sessionId?: string;
41
+ }) => Promise<string | Uint8Array | undefined>;
42
+ callWxMethod: (method: string, ...args: unknown[]) => Promise<unknown>;
43
+ }
44
+ interface RuntimeConnectionInput extends WechatDevtoolsSelectionOptions {
45
+ cliPath?: string;
46
+ installationId?: string;
47
+ runtimeProvider?: 'devtools' | 'headless';
48
+ projectPath: string;
49
+ timeout?: number;
50
+ port?: number;
51
+ preferOpenedSession?: boolean;
52
+ preserveProjectRoot?: boolean;
53
+ sessionId?: string;
131
54
  }
132
55
  interface RuntimeConsoleLogEntry {
133
- level: string;
134
- message: string;
135
- timestamp: number;
136
- raw: unknown;
56
+ level: string;
57
+ message: string;
58
+ timestamp: number;
59
+ raw: unknown;
60
+ projectPath?: string;
61
+ sessionKey?: string;
62
+ sequence?: number;
137
63
  }
138
64
  declare class RuntimeSessionManager {
139
- private readonly workspaceRoot;
140
- private readonly runtimeHooks;
141
- private readonly logs;
142
- private readonly attachedSessions;
143
- private readonly maxLogs;
144
- constructor(workspaceRoot: string, runtimeHooks?: DevtoolsRuntimeHooks);
145
- close(input: RuntimeConnectionInput): Promise<void>;
146
- clearLogs(): void;
147
- getLogs(): RuntimeConsoleLogEntry[];
148
- resolveProjectPath(projectPath: string): string;
149
- resolveWorkspacePath(filePath: string): string;
150
- withMiniProgram<T>(input: RuntimeConnectionInput, runner: (miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
151
- withPage<T>(input: RuntimeConnectionInput, runner: (page: MiniProgramPage, miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
152
- rememberPage(input: RuntimeConnectionInput, page: MiniProgramPage | null | undefined): void;
153
- private resolveSessionKey;
154
- private attach;
155
- private resolveCurrentPage;
156
- private detach;
157
- private pushLog;
65
+ private readonly workspaceRoot;
66
+ private readonly runtimeHooks;
67
+ private readonly resolvedInputs;
68
+ private readonly resolvedSessionKeys;
69
+ private readonly logs;
70
+ private readonly attachedSessions;
71
+ private readonly maxLogs;
72
+ private logSequence;
73
+ private readonly ownedSessions;
74
+ constructor(workspaceRoot: string, runtimeHooks?: DevtoolsRuntimeHooks);
75
+ close(input: RuntimeConnectionInput): Promise<void>;
76
+ clearLogs(): void;
77
+ getLogs(projectPath?: string, afterSequence?: number): RuntimeConsoleLogEntry[];
78
+ getLogCursor(): number;
79
+ prepareProject(projectPath: string, signal: AbortSignal): Promise<void>;
80
+ fork(workspaceRoot?: string): RuntimeSessionManager;
81
+ dispose(): Promise<void>;
82
+ resolveProjectPath(projectPath: string): string;
83
+ resolveWorkspacePath(filePath: string): string;
84
+ withMiniProgram<T>(input: RuntimeConnectionInput, runner: (miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
85
+ withPage<T>(input: RuntimeConnectionInput, runner: (page: MiniProgramPage, miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
86
+ rememberPage(input: RuntimeConnectionInput, page: MiniProgramPage | null | undefined): void;
87
+ private selectionKey;
88
+ private resolveInput;
89
+ private resolveSessionKey;
90
+ private attach;
91
+ private resolveCurrentPage;
92
+ private detach;
93
+ private pushLog;
94
+ }
95
+ //#endregion
96
+ //#region src/acceptance.d.ts
97
+ export declare function acceptanceRuntime(parent: RuntimeSessionManager): RuntimeConnector;
98
+ export declare function createRuntimeAcceptanceService(root: string, options?: AcceptanceOptions, hooks?: DevtoolsRuntimeHooks): Promise<AcceptanceService>;
99
+ //#endregion
100
+ //#region src/constants.d.ts
101
+ export declare const MCP_SERVER_NAME = "@weapp-vite/mcp";
102
+ export declare const MCP_SERVER_VERSION: string;
103
+ export declare const EXPOSED_PACKAGES: {
104
+ readonly 'weapp-vite': {
105
+ readonly id: "weapp-vite";
106
+ readonly label: "weapp-vite";
107
+ readonly packageName: "weapp-vite";
108
+ readonly relativePath: string;
109
+ };
110
+ readonly wevu: {
111
+ readonly id: "wevu";
112
+ readonly label: "wevu";
113
+ readonly packageName: "wevu";
114
+ readonly relativePath: string;
115
+ };
116
+ readonly 'wevu-compiler': {
117
+ readonly id: "wevu-compiler";
118
+ readonly label: "wevu-compiler";
119
+ readonly packageName: "@wevu/compiler";
120
+ readonly relativePath: string;
121
+ };
122
+ };
123
+ export type ExposedPackageId = keyof typeof EXPOSED_PACKAGES;
124
+ export declare const DEFAULT_TIMEOUT_MS = 120000;
125
+ export declare const DEFAULT_MAX_OUTPUT_CHARS = 120000;
126
+ export declare const DEFAULT_MAX_FILE_CHARS = 80000;
127
+ export declare const DEFAULT_MAX_RESULTS = 200;
128
+ export declare const SKIPPED_DIR_NAMES: Set<string>;
129
+ //#endregion
130
+ //#region src/exposedPackages.d.ts
131
+ interface ResolvedExposedPackage {
132
+ id: ExposedPackageId;
133
+ label: string;
134
+ packageName: string;
135
+ version: string;
136
+ absolutePath: string;
137
+ relativePath: string;
138
+ scripts: string[];
139
+ docs: {
140
+ readme?: string;
141
+ changelog?: string;
142
+ };
143
+ sourceRoot?: string;
144
+ cliPath?: string;
145
+ }
146
+ //#endregion
147
+ //#region src/catalog.d.ts
148
+ export interface ExposedPackageSummary extends ResolvedExposedPackage {}
149
+ export declare function loadPackageSummary(workspaceRoot: string, id: ExposedPackageId): Promise<ExposedPackageSummary>;
150
+ export declare function loadExposedCatalog(workspaceRoot: string): Promise<ResolvedExposedPackage[]>;
151
+ //#endregion
152
+ //#region src/commandOps.d.ts
153
+ export interface CommandResult {
154
+ command: string;
155
+ args: string[];
156
+ cwd: string;
157
+ exitCode: number;
158
+ stdout: string;
159
+ stderr: string;
160
+ timedOut: boolean;
161
+ }
162
+ export declare function runCommand(workspaceRoot: string, command: string, args: string[], options?: {
163
+ cwdRelative?: string;
164
+ timeoutMs?: number;
165
+ maxOutputChars?: number;
166
+ }): Promise<CommandResult>;
167
+ //#endregion
168
+ //#region src/fileOps.d.ts
169
+ export interface SearchMatch {
170
+ filePath: string;
171
+ line: number;
172
+ column: number;
173
+ text: string;
158
174
  }
159
-
160
- interface CreateServerOptions {
161
- runtimeHooks?: DevtoolsRuntimeHooks;
162
- workspaceRoot?: string;
175
+ export declare function listFilesInDirectory(root: string, relativeDirectory?: string, maxResults?: number): Promise<string[]>;
176
+ export declare function readFileContent(root: string, relativeFilePath: string, options?: {
177
+ startLine?: number;
178
+ endLine?: number;
179
+ maxChars?: number;
180
+ }): Promise<{
181
+ filePath: string;
182
+ content: string;
183
+ }>;
184
+ export declare function searchTextInDirectory(root: string, query: string, options?: {
185
+ relativeDirectory?: string;
186
+ maxResults?: number;
187
+ }): Promise<SearchMatch[]>;
188
+ //#endregion
189
+ //#region src/server/index.d.ts
190
+ export interface CreateServerOptions {
191
+ runtimeHooks?: DevtoolsRuntimeHooks;
192
+ workspaceRoot?: string;
163
193
  }
164
- interface WeappViteMcpServerFactory {
165
- createServer: () => McpServer;
166
- runtimeManager: RuntimeSessionManager;
167
- workspaceRoot: string;
194
+ export interface WeappViteMcpServerFactory {
195
+ createServer: () => McpServer;
196
+ runtimeManager: RuntimeSessionManager;
197
+ workspaceRoot: string;
198
+ close: () => Promise<void>;
168
199
  }
169
- declare function createWeappViteMcpServerFactory(options?: CreateServerOptions): Promise<WeappViteMcpServerFactory>;
170
- declare function createWeappViteMcpServer(options?: CreateServerOptions): Promise<{
171
- runtimeManager: RuntimeSessionManager;
172
- server: McpServer;
173
- workspaceRoot: string;
200
+ export declare function createWeappViteMcpServerFactory(options?: CreateServerOptions): Promise<WeappViteMcpServerFactory>;
201
+ export declare function createWeappViteMcpServer(options?: CreateServerOptions): Promise<{
202
+ close: () => Promise<void>;
203
+ runtimeManager: RuntimeSessionManager;
204
+ server: McpServer;
205
+ workspaceRoot: string;
174
206
  }>;
175
-
176
- declare const DEFAULT_RUNTIME_REST_ENDPOINT = "/api/weapp/devtools";
177
-
178
- declare const DEFAULT_MCP_HOST = "127.0.0.1";
179
- declare const DEFAULT_MCP_PORT = 3088;
180
- declare const DEFAULT_MCP_ENDPOINT = "/mcp";
181
- interface StartMcpServerOptions extends CreateServerOptions {
182
- transport?: 'stdio' | 'streamable-http';
183
- host?: string;
184
- port?: number;
185
- endpoint?: string;
186
- restEndpoint?: string | false;
187
- unref?: boolean;
188
- quiet?: boolean;
189
- onReady?: (message: string) => void;
207
+ //#endregion
208
+ //#region src/runtime.d.ts
209
+ export interface StartMcpServerOptions extends CreateServerOptions {
210
+ transport?: 'stdio' | 'streamable-http';
211
+ host?: string;
212
+ port?: number;
213
+ endpoint?: string;
214
+ restEndpoint?: string | false;
215
+ unref?: boolean;
216
+ quiet?: boolean;
217
+ onReady?: (message: string) => void;
190
218
  }
191
- interface McpServerHandle {
192
- transport: 'stdio' | 'streamable-http';
193
- close?: () => Promise<void>;
219
+ export interface McpServerHandle {
220
+ transport: 'stdio' | 'streamable-http';
221
+ close?: () => Promise<void>;
194
222
  }
195
- declare function startStdioServer(options?: CreateServerOptions): Promise<McpServerHandle>;
196
- declare function startWeappViteMcpServer(options?: StartMcpServerOptions): Promise<McpServerHandle>;
197
-
198
- declare function formatJson(value: unknown): string;
199
- declare function normalizeErrorMessage(error: unknown): string;
200
- declare function toToolResult(data: unknown, text?: string): {
201
- content: {
202
- type: "text";
203
- text: string;
204
- }[];
205
- structuredContent: {
206
- result: unknown;
207
- };
223
+ export declare function startStdioServer(options?: CreateServerOptions): Promise<McpServerHandle>;
224
+ export declare function startWeappViteMcpServer(options?: StartMcpServerOptions): Promise<McpServerHandle>;
225
+ //#endregion
226
+ //#region src/server/acceptance.d.ts
227
+ export declare function registerAcceptanceTools(server: McpServer, service: () => Promise<AcceptanceService>): McpServer;
228
+ //#endregion
229
+ //#region src/utils.d.ts
230
+ export declare function formatJson(value: unknown): string;
231
+ export declare function normalizeErrorMessage(error: unknown): string;
232
+ export declare function toToolResult(data: unknown, text?: string): {
233
+ content: {
234
+ type: "text";
235
+ text: string;
236
+ }[];
237
+ structuredContent: {
238
+ result: unknown;
239
+ };
208
240
  };
209
- declare function toToolError(error: unknown): {
210
- isError: boolean;
211
- content: {
212
- type: "text";
213
- text: string;
214
- }[];
241
+ export declare function toToolError(error: unknown): {
242
+ isError: boolean;
243
+ content: {
244
+ type: "text";
245
+ text: string;
246
+ }[];
215
247
  };
216
-
217
- declare function resolveWorkspaceRoot(start?: string): string;
218
- declare function assertInsideRoot(root: string, targetPath: string): string;
219
- declare function resolveSubPath(root: string, relativePath: string): string;
220
-
221
- export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, createWeappViteMcpServerFactory, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
222
- export type { CommandResult, CreateServerOptions, ExposedPackageId, ExposedPackageSummary, McpServerHandle, SearchMatch, StartMcpServerOptions, WeappViteMcpServerFactory };
248
+ //#endregion
249
+ //#region src/workspace.d.ts
250
+ export declare function resolveWorkspaceRoot(start?: string): string;
251
+ export declare function assertInsideRoot(root: string, targetPath: string): string;
252
+ export declare function resolveSubPath(root: string, relativePath: string): string;
253
+ //#endregion
254
+ export { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT };