@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 +2 -0
- package/dist/index.d.ts +234 -202
- package/dist/index.mjs +2502 -2436
- package/package.json +21 -11
- package/dist/index.d.mts +0 -222
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,222 +1,254 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
26
|
+
fallback?: boolean;
|
|
107
27
|
}
|
|
108
28
|
interface MiniProgramLike {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
193
|
-
|
|
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
|
-
|
|
199
|
-
declare function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
241
|
+
export declare function toToolError(error: unknown): {
|
|
242
|
+
isError: boolean;
|
|
243
|
+
content: {
|
|
244
|
+
type: "text";
|
|
245
|
+
text: string;
|
|
246
|
+
}[];
|
|
215
247
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
declare function
|
|
219
|
-
declare function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
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 };
|