@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 +1 -1
- package/dist/index.d.ts +201 -212
- package/dist/index.mjs +2419 -2589
- package/package.json +19 -12
- package/dist/index.d.mts +0 -241
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
## 启动
|
|
21
21
|
|
|
22
|
-
直接使用 `@weapp-vite/mcp
|
|
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 {
|
|
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";
|
|
6
8
|
interface MiniProgramElement {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
+
fallback?: boolean;
|
|
24
26
|
}
|
|
25
27
|
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;
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
93
|
-
declare
|
|
94
|
-
|
|
95
|
-
declare const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
readonly
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
readonly
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
readonly
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
declare function
|
|
144
|
-
|
|
145
|
-
interface CommandResult {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
168
|
+
filePath: string;
|
|
169
|
+
content: string;
|
|
174
170
|
}>;
|
|
175
|
-
declare function searchTextInDirectory(root: string, query: string, options?: {
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
export declare function searchTextInDirectory(root: string, query: string, options?: {
|
|
172
|
+
relativeDirectory?: string;
|
|
173
|
+
maxResults?: number;
|
|
178
174
|
}): Promise<SearchMatch[]>;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
workspaceRoot?: string;
|
|
175
|
+
export interface CreateServerOptions {
|
|
176
|
+
runtimeHooks?: DevtoolsRuntimeHooks;
|
|
177
|
+
workspaceRoot?: string;
|
|
183
178
|
}
|
|
184
|
-
interface WeappViteMcpServerFactory {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
210
|
-
|
|
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
|
|
216
|
-
|
|
217
|
-
declare function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
|
237
|
-
declare function
|
|
238
|
-
|
|
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 };
|