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