@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 +225 -212
- package/dist/index.mjs +2443 -2590
- package/package.json +15 -8
- package/dist/index.d.mts +0 -241
package/dist/index.d.ts
CHANGED
|
@@ -1,241 +1,254 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
26
|
+
fallback?: boolean;
|
|
24
27
|
}
|
|
25
28
|
interface MiniProgramLike {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
declare function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
declare const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
readonly
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
readonly
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
181
|
+
filePath: string;
|
|
182
|
+
content: string;
|
|
174
183
|
}>;
|
|
175
|
-
declare function searchTextInDirectory(root: string, query: string, options?: {
|
|
176
|
-
|
|
177
|
-
|
|
184
|
+
export declare function searchTextInDirectory(root: string, query: string, options?: {
|
|
185
|
+
relativeDirectory?: string;
|
|
186
|
+
maxResults?: number;
|
|
178
187
|
}): Promise<SearchMatch[]>;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
210
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
declare function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
241
|
+
export declare function toToolError(error: unknown): {
|
|
242
|
+
isError: boolean;
|
|
243
|
+
content: {
|
|
244
|
+
type: "text";
|
|
245
|
+
text: string;
|
|
246
|
+
}[];
|
|
234
247
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
declare function
|
|
238
|
-
declare function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
export
|
|
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 };
|