@weapp-vite/mcp 2.0.0 → 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/dist/index.d.ts CHANGED
@@ -1,241 +1,254 @@
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";
8
+ //#region src/server/runtime/shared.d.ts
6
9
  interface MiniProgramElement {
7
- tagName?: string;
8
- $?: (selector: string) => Promise<MiniProgramElement | null>;
9
- $$?: (selector: string) => Promise<MiniProgramElement[]>;
10
- tap: () => Promise<void>;
10
+ tagName?: string;
11
+ $?: (selector: string) => Promise<MiniProgramElement | null>;
12
+ $$?: (selector: string) => Promise<MiniProgramElement[]>;
13
+ tap: () => Promise<void>;
11
14
  }
12
15
  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>;
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>;
21
24
  }
22
25
  interface MiniProgramPageQueryOptions {
23
- fallback?: boolean;
26
+ fallback?: boolean;
24
27
  }
25
28
  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;
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?: {
46
40
  timeout?: number;
47
- port?: number;
48
- preferOpenedSession?: boolean;
49
- preserveProjectRoot?: boolean;
50
- 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;
51
54
  }
52
55
  interface RuntimeConsoleLogEntry {
53
- level: string;
54
- message: string;
55
- timestamp: number;
56
- raw: unknown;
57
- projectPath?: string;
58
- sessionKey?: string;
59
- sequence?: number;
56
+ level: string;
57
+ message: string;
58
+ timestamp: number;
59
+ raw: unknown;
60
+ projectPath?: string;
61
+ sessionKey?: string;
62
+ sequence?: number;
60
63
  }
61
64
  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;
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;
90
94
  }
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
- };
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
+ };
116
122
  };
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
-
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
124
131
  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 {
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;
141
145
  }
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;
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;
153
161
  }
154
- declare function runCommand(workspaceRoot: string, command: string, args: string[], options?: {
155
- cwdRelative?: string;
156
- timeoutMs?: number;
157
- maxOutputChars?: number;
162
+ export declare function runCommand(workspaceRoot: string, command: string, args: string[], options?: {
163
+ cwdRelative?: string;
164
+ timeoutMs?: number;
165
+ maxOutputChars?: number;
158
166
  }): Promise<CommandResult>;
159
-
160
- interface SearchMatch {
161
- filePath: string;
162
- line: number;
163
- column: number;
164
- text: string;
167
+ //#endregion
168
+ //#region src/fileOps.d.ts
169
+ export interface SearchMatch {
170
+ filePath: string;
171
+ line: number;
172
+ column: number;
173
+ text: string;
165
174
  }
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;
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;
171
180
  }): Promise<{
172
- filePath: string;
173
- content: string;
181
+ filePath: string;
182
+ content: string;
174
183
  }>;
175
- declare function searchTextInDirectory(root: string, query: string, options?: {
176
- relativeDirectory?: string;
177
- maxResults?: number;
184
+ export declare function searchTextInDirectory(root: string, query: string, options?: {
185
+ relativeDirectory?: string;
186
+ maxResults?: number;
178
187
  }): Promise<SearchMatch[]>;
179
-
180
- interface CreateServerOptions {
181
- runtimeHooks?: DevtoolsRuntimeHooks;
182
- workspaceRoot?: string;
188
+ //#endregion
189
+ //#region src/server/index.d.ts
190
+ export interface CreateServerOptions {
191
+ runtimeHooks?: DevtoolsRuntimeHooks;
192
+ workspaceRoot?: string;
183
193
  }
184
- interface WeappViteMcpServerFactory {
185
- createServer: () => McpServer;
186
- runtimeManager: RuntimeSessionManager;
187
- workspaceRoot: string;
188
- close: () => Promise<void>;
194
+ export interface WeappViteMcpServerFactory {
195
+ createServer: () => McpServer;
196
+ runtimeManager: RuntimeSessionManager;
197
+ workspaceRoot: string;
198
+ close: () => Promise<void>;
189
199
  }
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;
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;
196
206
  }>;
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;
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;
207
218
  }
208
- interface McpServerHandle {
209
- transport: 'stdio' | 'streamable-http';
210
- close?: () => Promise<void>;
219
+ export interface McpServerHandle {
220
+ transport: 'stdio' | 'streamable-http';
221
+ close?: () => Promise<void>;
211
222
  }
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
- };
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
+ };
227
240
  };
228
- declare function toToolError(error: unknown): {
229
- isError: boolean;
230
- content: {
231
- type: "text";
232
- text: string;
233
- }[];
241
+ export declare function toToolError(error: unknown): {
242
+ isError: boolean;
243
+ content: {
244
+ type: "text";
245
+ text: string;
246
+ }[];
234
247
  };
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 };
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 };