@weapp-vite/mcp 1.4.16 → 1.5.1
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 +6 -1
- package/dist/index.d.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.mjs +307 -250
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
|
|
14
14
|
默认通过 `stdio` 运行,适合接入任意 MCP Client,也支持 `streamable-http`。
|
|
15
15
|
|
|
16
|
+
当前实现基于 MCP TypeScript SDK v2,`stdio` 与 `streamable-http` 都显式支持
|
|
17
|
+
`2026-07-28` 协议版本;旧版 2025-era 客户端仍可通过兼容路径接入。HTTP 模式默认校验
|
|
18
|
+
`Host` 与 `Origin`,建议保持监听在 `127.0.0.1`。
|
|
19
|
+
|
|
16
20
|
## 启动
|
|
17
21
|
|
|
18
22
|
```bash
|
|
@@ -68,6 +72,7 @@ const handle = await startWeappViteMcpServer({
|
|
|
68
72
|
- `weapp_devtools_host_api`: 调用 `wx.*` API
|
|
69
73
|
- `weapp_devtools_console`: 读取 MCP 会话期间捕获的 console/exception 日志
|
|
70
74
|
- `weapp_runtime_find_node` / `weapp_runtime_find_nodes` / `weapp_runtime_wait_node`: 查询和等待页面元素
|
|
75
|
+
- `weapp_runtime_find_node_by_xpath` / `weapp_runtime_find_nodes_by_xpath`: 通过 XPath 查询页面元素
|
|
71
76
|
- `weapp_runtime_page_state` / `weapp_runtime_update_page_state` / `weapp_runtime_invoke_page`: 操作页面实例
|
|
72
77
|
- `weapp_runtime_tap_node` / `weapp_runtime_input_node`: 操作页面元素
|
|
73
78
|
- `weapp_runtime_component_state` / `weapp_runtime_update_component_state` / `weapp_runtime_invoke_component`: 操作组件实例
|
|
@@ -130,5 +135,5 @@ pnpm --filter @weapp-vite/mcp build
|
|
|
130
135
|
|
|
131
136
|
## 相关链接
|
|
132
137
|
|
|
133
|
-
- MCP SDK: https://github.com/modelcontextprotocol/sdk
|
|
138
|
+
- MCP TypeScript SDK v2: https://github.com/modelcontextprotocol/typescript-sdk
|
|
134
139
|
- 仓库: https://github.com/weapp-vite/weapp-vite
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevtoolsRuntimeHooks } from '@weapp-vite/devtools-runtime';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
3
3
|
|
|
4
4
|
declare const MCP_SERVER_NAME = "@weapp-vite/mcp";
|
|
5
5
|
declare const MCP_SERVER_VERSION = "2.0.0";
|
|
@@ -161,6 +161,12 @@ interface CreateServerOptions {
|
|
|
161
161
|
runtimeHooks?: DevtoolsRuntimeHooks;
|
|
162
162
|
workspaceRoot?: string;
|
|
163
163
|
}
|
|
164
|
+
interface WeappViteMcpServerFactory {
|
|
165
|
+
createServer: () => McpServer;
|
|
166
|
+
runtimeManager: RuntimeSessionManager;
|
|
167
|
+
workspaceRoot: string;
|
|
168
|
+
}
|
|
169
|
+
declare function createWeappViteMcpServerFactory(options?: CreateServerOptions): Promise<WeappViteMcpServerFactory>;
|
|
164
170
|
declare function createWeappViteMcpServer(options?: CreateServerOptions): Promise<{
|
|
165
171
|
runtimeManager: RuntimeSessionManager;
|
|
166
172
|
server: McpServer;
|
|
@@ -186,7 +192,7 @@ interface McpServerHandle {
|
|
|
186
192
|
transport: 'stdio' | 'streamable-http';
|
|
187
193
|
close?: () => Promise<void>;
|
|
188
194
|
}
|
|
189
|
-
declare function startStdioServer(options?: CreateServerOptions): Promise<
|
|
195
|
+
declare function startStdioServer(options?: CreateServerOptions): Promise<McpServerHandle>;
|
|
190
196
|
declare function startWeappViteMcpServer(options?: StartMcpServerOptions): Promise<McpServerHandle>;
|
|
191
197
|
|
|
192
198
|
declare function formatJson(value: unknown): string;
|
|
@@ -212,5 +218,5 @@ declare function resolveWorkspaceRoot(start?: string): string;
|
|
|
212
218
|
declare function assertInsideRoot(root: string, targetPath: string): string;
|
|
213
219
|
declare function resolveSubPath(root: string, relativePath: string): string;
|
|
214
220
|
|
|
215
|
-
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
|
216
|
-
export type { CommandResult, CreateServerOptions, ExposedPackageId, ExposedPackageSummary, McpServerHandle, SearchMatch, StartMcpServerOptions };
|
|
221
|
+
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, createWeappViteMcpServerFactory, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
|
222
|
+
export type { CommandResult, CreateServerOptions, ExposedPackageId, ExposedPackageSummary, McpServerHandle, SearchMatch, StartMcpServerOptions, WeappViteMcpServerFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevtoolsRuntimeHooks } from '@weapp-vite/devtools-runtime';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
3
3
|
|
|
4
4
|
declare const MCP_SERVER_NAME = "@weapp-vite/mcp";
|
|
5
5
|
declare const MCP_SERVER_VERSION = "2.0.0";
|
|
@@ -161,6 +161,12 @@ interface CreateServerOptions {
|
|
|
161
161
|
runtimeHooks?: DevtoolsRuntimeHooks;
|
|
162
162
|
workspaceRoot?: string;
|
|
163
163
|
}
|
|
164
|
+
interface WeappViteMcpServerFactory {
|
|
165
|
+
createServer: () => McpServer;
|
|
166
|
+
runtimeManager: RuntimeSessionManager;
|
|
167
|
+
workspaceRoot: string;
|
|
168
|
+
}
|
|
169
|
+
declare function createWeappViteMcpServerFactory(options?: CreateServerOptions): Promise<WeappViteMcpServerFactory>;
|
|
164
170
|
declare function createWeappViteMcpServer(options?: CreateServerOptions): Promise<{
|
|
165
171
|
runtimeManager: RuntimeSessionManager;
|
|
166
172
|
server: McpServer;
|
|
@@ -186,7 +192,7 @@ interface McpServerHandle {
|
|
|
186
192
|
transport: 'stdio' | 'streamable-http';
|
|
187
193
|
close?: () => Promise<void>;
|
|
188
194
|
}
|
|
189
|
-
declare function startStdioServer(options?: CreateServerOptions): Promise<
|
|
195
|
+
declare function startStdioServer(options?: CreateServerOptions): Promise<McpServerHandle>;
|
|
190
196
|
declare function startWeappViteMcpServer(options?: StartMcpServerOptions): Promise<McpServerHandle>;
|
|
191
197
|
|
|
192
198
|
declare function formatJson(value: unknown): string;
|
|
@@ -212,5 +218,5 @@ declare function resolveWorkspaceRoot(start?: string): string;
|
|
|
212
218
|
declare function assertInsideRoot(root: string, targetPath: string): string;
|
|
213
219
|
declare function resolveSubPath(root: string, relativePath: string): string;
|
|
214
220
|
|
|
215
|
-
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
|
216
|
-
export type { CommandResult, CreateServerOptions, ExposedPackageId, ExposedPackageSummary, McpServerHandle, SearchMatch, StartMcpServerOptions };
|
|
221
|
+
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, createWeappViteMcpServerFactory, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
|
222
|
+
export type { CommandResult, CreateServerOptions, ExposedPackageId, ExposedPackageSummary, McpServerHandle, SearchMatch, StartMcpServerOptions, WeappViteMcpServerFactory };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { Buffer } from 'node:buffer';
|
|
4
|
-
import { randomUUID } from 'node:crypto';
|
|
5
3
|
import http from 'node:http';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { toNodeHandler, localhostHostValidation, hostHeaderValidation, localhostOriginValidation, originValidation } from '@modelcontextprotocol/node';
|
|
5
|
+
import { ResourceTemplate, McpServer, createMcpHandler } from '@modelcontextprotocol/server';
|
|
6
|
+
import { serveStdio } from '@modelcontextprotocol/server/stdio';
|
|
7
|
+
import { Buffer } from 'node:buffer';
|
|
8
8
|
import fs$1 from 'node:fs/promises';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import { closeSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, acquireSharedMiniProgram, releaseSharedMiniProgram, resolveSharedMiniProgramSessionKey, toDevtoolsSerializableValue } from '@weapp-vite/devtools-runtime';
|
|
12
|
-
import { ResourceTemplate, McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
13
|
-
import fs from 'node:fs';
|
|
14
12
|
import { createRequire } from 'node:module';
|
|
13
|
+
import fs from 'node:fs';
|
|
15
14
|
import { spawn } from 'node:child_process';
|
|
16
15
|
|
|
17
16
|
const MCP_SERVER_NAME = "@weapp-vite/mcp";
|
|
@@ -86,118 +85,6 @@ function resolveSubPath(root, relativePath) {
|
|
|
86
85
|
return assertInsideRoot(root, path.resolve(root, relativePath));
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
function registerServerPrompts(server, options) {
|
|
90
|
-
const { packageIds, packageIdSchema } = options;
|
|
91
|
-
server.registerPrompt("plan-weapp-vite-change", {
|
|
92
|
-
title: "Plan weapp-vite Change",
|
|
93
|
-
description: "\u6839\u636E\u53D8\u66F4\u76EE\u6807\u751F\u6210 weapp-vite / wevu \u4FEE\u6539\u8BA1\u5212\u63D0\u793A\u8BCD",
|
|
94
|
-
argsSchema: {
|
|
95
|
-
objective: z.string().min(1),
|
|
96
|
-
focusPackage: packageIdSchema.optional()
|
|
97
|
-
}
|
|
98
|
-
}, async ({ objective, focusPackage }) => {
|
|
99
|
-
const targets = focusPackage ? [focusPackage] : packageIds;
|
|
100
|
-
return {
|
|
101
|
-
messages: [
|
|
102
|
-
{
|
|
103
|
-
role: "user",
|
|
104
|
-
content: {
|
|
105
|
-
type: "text",
|
|
106
|
-
text: [
|
|
107
|
-
"\u4F60\u662F weapp-vite monorepo \u7EF4\u62A4\u8005\uFF0C\u8BF7\u7ED9\u51FA\u53EF\u6267\u884C\u7684\u6539\u9020\u8BA1\u5212\u3002",
|
|
108
|
-
`\u76EE\u6807\uFF1A${objective}`,
|
|
109
|
-
`\u805A\u7126\u5305\uFF1A${targets.join(", ")}`,
|
|
110
|
-
"\u8BF7\u5305\u542B\uFF1A\u5F71\u54CD\u9762\u3001\u98CE\u9669\u70B9\u3001\u6D4B\u8BD5\u7B56\u7565\u3001\u56DE\u6EDA\u7B56\u7565\u3002"
|
|
111
|
-
].join("\n")
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
server.registerPrompt("debug-wevu-runtime", {
|
|
118
|
-
title: "Debug wevu Runtime",
|
|
119
|
-
description: "\u7528\u4E8E\u5B9A\u4F4D wevu runtime \u751F\u547D\u5468\u671F/\u54CD\u5E94\u5F0F\u95EE\u9898\u7684\u6807\u51C6\u63D0\u793A\u8BCD",
|
|
120
|
-
argsSchema: {
|
|
121
|
-
symptom: z.string().min(1)
|
|
122
|
-
}
|
|
123
|
-
}, async ({ symptom }) => {
|
|
124
|
-
return {
|
|
125
|
-
messages: [
|
|
126
|
-
{
|
|
127
|
-
role: "user",
|
|
128
|
-
content: {
|
|
129
|
-
type: "text",
|
|
130
|
-
text: [
|
|
131
|
-
"\u8BF7\u57FA\u4E8E wevu runtime \u4EE3\u7801\u8DEF\u5F84\u8FDB\u884C\u5206\u5C42\u6392\u67E5\uFF1A",
|
|
132
|
-
"1. \u590D\u73B0\u573A\u666F\u4E0E\u6700\u5C0F\u6837\u4F8B",
|
|
133
|
-
"2. \u751F\u547D\u5468\u671F\u94A9\u5B50\u89E6\u53D1\u94FE",
|
|
134
|
-
"3. \u54CD\u5E94\u5F0F\u4E0E setData \u5DEE\u91CF\u540C\u6B65\u94FE",
|
|
135
|
-
"4. \u5355\u6D4B\u4E0E e2e \u56DE\u5F52\u8865\u4E01",
|
|
136
|
-
`\u73B0\u8C61\uFF1A${symptom}`
|
|
137
|
-
].join("\n")
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
server.registerPrompt("inspect-mini-program-page", {
|
|
144
|
-
title: "Inspect Mini Program Page",
|
|
145
|
-
description: "\u8FDE\u63A5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u5E76\u68C0\u67E5\u5F53\u524D\u5C0F\u7A0B\u5E8F\u9875\u9762\u7684\u6807\u51C6\u6D41\u7A0B",
|
|
146
|
-
argsSchema: {
|
|
147
|
-
projectPath: z.string().min(1),
|
|
148
|
-
pagePath: z.string().optional(),
|
|
149
|
-
focus: z.string().optional()
|
|
150
|
-
}
|
|
151
|
-
}, async ({ projectPath, pagePath, focus }) => {
|
|
152
|
-
return {
|
|
153
|
-
messages: [
|
|
154
|
-
{
|
|
155
|
-
role: "user",
|
|
156
|
-
content: {
|
|
157
|
-
type: "text",
|
|
158
|
-
text: [
|
|
159
|
-
"\u8BF7\u6309\u987A\u5E8F\u4F7F\u7528 weapp-vite MCP runtime tools \u68C0\u67E5\u5C0F\u7A0B\u5E8F\u9875\u9762\uFF1A",
|
|
160
|
-
`1. \u8C03\u7528 weapp_devtools_connect\uFF0CprojectPath=${projectPath}`,
|
|
161
|
-
pagePath ? `2. \u8C03\u7528 weapp_devtools_route \u8DF3\u8F6C\u5230 ${pagePath}` : "2. \u8C03\u7528 weapp_devtools_active_page \u786E\u8BA4\u5F53\u524D\u9875\u9762",
|
|
162
|
-
"3. \u8C03\u7528 weapp_devtools_capture \u83B7\u53D6\u622A\u56FE",
|
|
163
|
-
"4. \u5982\u9700\u68C0\u67E5\u7ED3\u6784\uFF0C\u4F18\u5148\u8C03\u7528 weapp_runtime_find_node/weapp_runtime_find_nodes\uFF0C\u5FC5\u8981\u65F6\u8BBE\u7F6E withWxml=true",
|
|
164
|
-
"5. \u8C03\u7528 weapp_devtools_console \u68C0\u67E5 console/exception \u65E5\u5FD7",
|
|
165
|
-
focus ? `\u5173\u6CE8\u70B9\uFF1A${focus}` : "\u5173\u6CE8\u70B9\uFF1A\u9875\u9762\u662F\u5426\u6B63\u786E\u6E32\u67D3\u3001\u662F\u5426\u5B58\u5728\u8FD0\u884C\u65F6\u9519\u8BEF\u3002"
|
|
166
|
-
].join("\n")
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
};
|
|
171
|
-
});
|
|
172
|
-
server.registerPrompt("recover-mini-program-connection", {
|
|
173
|
-
title: "Recover Mini Program Connection",
|
|
174
|
-
description: "\u6062\u590D\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177 automator \u8FDE\u63A5\u7684\u6807\u51C6\u6D41\u7A0B",
|
|
175
|
-
argsSchema: {
|
|
176
|
-
projectPath: z.string().min(1),
|
|
177
|
-
lastError: z.string().optional()
|
|
178
|
-
}
|
|
179
|
-
}, async ({ projectPath, lastError }) => {
|
|
180
|
-
return {
|
|
181
|
-
messages: [
|
|
182
|
-
{
|
|
183
|
-
role: "user",
|
|
184
|
-
content: {
|
|
185
|
-
type: "text",
|
|
186
|
-
text: [
|
|
187
|
-
"\u8BF7\u6309\u987A\u5E8F\u6062\u590D weapp-vite MCP runtime \u8FDE\u63A5\uFF1A",
|
|
188
|
-
`1. \u8C03\u7528 weapp_devtools_connect\uFF0CprojectPath=${projectPath}\uFF0Creconnect=true`,
|
|
189
|
-
"2. \u5982\u679C\u4ECD\u5931\u8D25\uFF0C\u68C0\u67E5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u662F\u5426\u5DF2\u5F00\u542F\u670D\u52A1\u7AEF\u53E3\u4E0E\u81EA\u52A8\u5316\u6D4B\u8BD5\u80FD\u529B",
|
|
190
|
-
"3. \u5982\u679C\u662F\u534F\u8BAE\u8D85\u65F6\uFF0C\u5173\u95ED\u591A\u4F59 DevTools \u7A97\u53E3\u540E\u53EA\u91CD\u8BD5\u4E00\u6B21",
|
|
191
|
-
"4. \u6062\u590D\u540E\u8C03\u7528 weapp_devtools_active_page \u548C weapp_devtools_console \u786E\u8BA4\u72B6\u6001",
|
|
192
|
-
lastError ? `\u4E0A\u4E00\u6B21\u9519\u8BEF\uFF1A${lastError}` : "\u4E0A\u4E00\u6B21\u9519\u8BEF\uFF1A\u672A\u63D0\u4F9B\u3002"
|
|
193
|
-
].join("\n")
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
};
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
88
|
async function pathExists(filePath) {
|
|
202
89
|
try {
|
|
203
90
|
await fs$1.access(filePath);
|
|
@@ -309,6 +196,118 @@ async function resolveExposedPackages(workspaceRoot) {
|
|
|
309
196
|
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
310
197
|
}
|
|
311
198
|
|
|
199
|
+
function registerServerPrompts(server, options) {
|
|
200
|
+
const { packageIds, packageIdSchema } = options;
|
|
201
|
+
server.registerPrompt("plan-weapp-vite-change", {
|
|
202
|
+
title: "Plan weapp-vite Change",
|
|
203
|
+
description: "\u6839\u636E\u53D8\u66F4\u76EE\u6807\u751F\u6210 weapp-vite / wevu \u4FEE\u6539\u8BA1\u5212\u63D0\u793A\u8BCD",
|
|
204
|
+
argsSchema: z.object({
|
|
205
|
+
objective: z.string().min(1),
|
|
206
|
+
focusPackage: packageIdSchema.optional()
|
|
207
|
+
})
|
|
208
|
+
}, async ({ objective, focusPackage }) => {
|
|
209
|
+
const targets = focusPackage ? [focusPackage] : packageIds;
|
|
210
|
+
return {
|
|
211
|
+
messages: [
|
|
212
|
+
{
|
|
213
|
+
role: "user",
|
|
214
|
+
content: {
|
|
215
|
+
type: "text",
|
|
216
|
+
text: [
|
|
217
|
+
"\u4F60\u662F weapp-vite monorepo \u7EF4\u62A4\u8005\uFF0C\u8BF7\u7ED9\u51FA\u53EF\u6267\u884C\u7684\u6539\u9020\u8BA1\u5212\u3002",
|
|
218
|
+
`\u76EE\u6807\uFF1A${objective}`,
|
|
219
|
+
`\u805A\u7126\u5305\uFF1A${targets.join(", ")}`,
|
|
220
|
+
"\u8BF7\u5305\u542B\uFF1A\u5F71\u54CD\u9762\u3001\u98CE\u9669\u70B9\u3001\u6D4B\u8BD5\u7B56\u7565\u3001\u56DE\u6EDA\u7B56\u7565\u3002"
|
|
221
|
+
].join("\n")
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
server.registerPrompt("debug-wevu-runtime", {
|
|
228
|
+
title: "Debug wevu Runtime",
|
|
229
|
+
description: "\u7528\u4E8E\u5B9A\u4F4D wevu runtime \u751F\u547D\u5468\u671F/\u54CD\u5E94\u5F0F\u95EE\u9898\u7684\u6807\u51C6\u63D0\u793A\u8BCD",
|
|
230
|
+
argsSchema: z.object({
|
|
231
|
+
symptom: z.string().min(1)
|
|
232
|
+
})
|
|
233
|
+
}, async ({ symptom }) => {
|
|
234
|
+
return {
|
|
235
|
+
messages: [
|
|
236
|
+
{
|
|
237
|
+
role: "user",
|
|
238
|
+
content: {
|
|
239
|
+
type: "text",
|
|
240
|
+
text: [
|
|
241
|
+
"\u8BF7\u57FA\u4E8E wevu runtime \u4EE3\u7801\u8DEF\u5F84\u8FDB\u884C\u5206\u5C42\u6392\u67E5\uFF1A",
|
|
242
|
+
"1. \u590D\u73B0\u573A\u666F\u4E0E\u6700\u5C0F\u6837\u4F8B",
|
|
243
|
+
"2. \u751F\u547D\u5468\u671F\u94A9\u5B50\u89E6\u53D1\u94FE",
|
|
244
|
+
"3. \u54CD\u5E94\u5F0F\u4E0E setData \u5DEE\u91CF\u540C\u6B65\u94FE",
|
|
245
|
+
"4. \u5355\u6D4B\u4E0E e2e \u56DE\u5F52\u8865\u4E01",
|
|
246
|
+
`\u73B0\u8C61\uFF1A${symptom}`
|
|
247
|
+
].join("\n")
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
server.registerPrompt("inspect-mini-program-page", {
|
|
254
|
+
title: "Inspect Mini Program Page",
|
|
255
|
+
description: "\u8FDE\u63A5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u5E76\u68C0\u67E5\u5F53\u524D\u5C0F\u7A0B\u5E8F\u9875\u9762\u7684\u6807\u51C6\u6D41\u7A0B",
|
|
256
|
+
argsSchema: z.object({
|
|
257
|
+
projectPath: z.string().min(1),
|
|
258
|
+
pagePath: z.string().optional(),
|
|
259
|
+
focus: z.string().optional()
|
|
260
|
+
})
|
|
261
|
+
}, async ({ projectPath, pagePath, focus }) => {
|
|
262
|
+
return {
|
|
263
|
+
messages: [
|
|
264
|
+
{
|
|
265
|
+
role: "user",
|
|
266
|
+
content: {
|
|
267
|
+
type: "text",
|
|
268
|
+
text: [
|
|
269
|
+
"\u8BF7\u6309\u987A\u5E8F\u4F7F\u7528 weapp-vite MCP runtime tools \u68C0\u67E5\u5C0F\u7A0B\u5E8F\u9875\u9762\uFF1A",
|
|
270
|
+
`1. \u8C03\u7528 weapp_devtools_connect\uFF0CprojectPath=${projectPath}`,
|
|
271
|
+
pagePath ? `2. \u8C03\u7528 weapp_devtools_route \u8DF3\u8F6C\u5230 ${pagePath}` : "2. \u8C03\u7528 weapp_devtools_active_page \u786E\u8BA4\u5F53\u524D\u9875\u9762",
|
|
272
|
+
"3. \u8C03\u7528 weapp_devtools_capture \u83B7\u53D6\u622A\u56FE",
|
|
273
|
+
"4. \u5982\u9700\u68C0\u67E5\u7ED3\u6784\uFF0C\u4F18\u5148\u8C03\u7528 weapp_runtime_find_node/weapp_runtime_find_nodes\uFF0C\u5FC5\u8981\u65F6\u8BBE\u7F6E withWxml=true",
|
|
274
|
+
"5. \u8C03\u7528 weapp_devtools_console \u68C0\u67E5 console/exception \u65E5\u5FD7",
|
|
275
|
+
focus ? `\u5173\u6CE8\u70B9\uFF1A${focus}` : "\u5173\u6CE8\u70B9\uFF1A\u9875\u9762\u662F\u5426\u6B63\u786E\u6E32\u67D3\u3001\u662F\u5426\u5B58\u5728\u8FD0\u884C\u65F6\u9519\u8BEF\u3002"
|
|
276
|
+
].join("\n")
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
server.registerPrompt("recover-mini-program-connection", {
|
|
283
|
+
title: "Recover Mini Program Connection",
|
|
284
|
+
description: "\u6062\u590D\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177 automator \u8FDE\u63A5\u7684\u6807\u51C6\u6D41\u7A0B",
|
|
285
|
+
argsSchema: z.object({
|
|
286
|
+
projectPath: z.string().min(1),
|
|
287
|
+
lastError: z.string().optional()
|
|
288
|
+
})
|
|
289
|
+
}, async ({ projectPath, lastError }) => {
|
|
290
|
+
return {
|
|
291
|
+
messages: [
|
|
292
|
+
{
|
|
293
|
+
role: "user",
|
|
294
|
+
content: {
|
|
295
|
+
type: "text",
|
|
296
|
+
text: [
|
|
297
|
+
"\u8BF7\u6309\u987A\u5E8F\u6062\u590D weapp-vite MCP runtime \u8FDE\u63A5\uFF1A",
|
|
298
|
+
`1. \u8C03\u7528 weapp_devtools_connect\uFF0CprojectPath=${projectPath}\uFF0Creconnect=true`,
|
|
299
|
+
"2. \u5982\u679C\u4ECD\u5931\u8D25\uFF0C\u68C0\u67E5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u662F\u5426\u5DF2\u5F00\u542F\u670D\u52A1\u7AEF\u53E3\u4E0E\u81EA\u52A8\u5316\u6D4B\u8BD5\u80FD\u529B",
|
|
300
|
+
"3. \u5982\u679C\u662F\u534F\u8BAE\u8D85\u65F6\uFF0C\u5173\u95ED\u591A\u4F59 DevTools \u7A97\u53E3\u540E\u53EA\u91CD\u8BD5\u4E00\u6B21",
|
|
301
|
+
"4. \u6062\u590D\u540E\u8C03\u7528 weapp_devtools_active_page \u548C weapp_devtools_console \u786E\u8BA4\u72B6\u6001",
|
|
302
|
+
lastError ? `\u4E0A\u4E00\u6B21\u9519\u8BEF\uFF1A${lastError}` : "\u4E0A\u4E00\u6B21\u9519\u8BEF\uFF1A\u672A\u63D0\u4F9B\u3002"
|
|
303
|
+
].join("\n")
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
312
311
|
async function walkFilesRecursive(root, current, output, maxResults) {
|
|
313
312
|
if (output.length >= maxResults) {
|
|
314
313
|
return;
|
|
@@ -538,15 +537,15 @@ async function runWeappViteCliTool(workspaceRoot, input) {
|
|
|
538
537
|
});
|
|
539
538
|
}
|
|
540
539
|
|
|
541
|
-
|
|
542
|
-
const { workspaceRoot, packageIds } = options;
|
|
540
|
+
function registerServerResources(server, options) {
|
|
541
|
+
const { workspaceRoot, packageIds, exposedPackages } = options;
|
|
543
542
|
server.registerResource("workspace-catalog", "weapp-vite://workspace/catalog", {
|
|
544
543
|
title: "Workspace Catalog",
|
|
545
544
|
description: "weapp-vite / wevu \u5305\u76EE\u5F55\u3001\u7248\u672C\u548C\u811A\u672C\u5217\u8868",
|
|
546
545
|
mimeType: "application/json"
|
|
547
546
|
}, async () => {
|
|
548
|
-
const
|
|
549
|
-
const text = JSON.stringify({ workspaceRoot, packages:
|
|
547
|
+
const catalog = await resolveExposedPackages(workspaceRoot);
|
|
548
|
+
const text = JSON.stringify({ workspaceRoot, packages: catalog }, null, 2);
|
|
550
549
|
return {
|
|
551
550
|
contents: [{
|
|
552
551
|
uri: "weapp-vite://workspace/catalog",
|
|
@@ -555,8 +554,7 @@ async function registerServerResources(server, options) {
|
|
|
555
554
|
}]
|
|
556
555
|
};
|
|
557
556
|
});
|
|
558
|
-
const
|
|
559
|
-
for (const summary of catalog) {
|
|
557
|
+
for (const summary of exposedPackages) {
|
|
560
558
|
if (summary.docs.readme) {
|
|
561
559
|
const uri = toDocsUri(summary.id, "README.md");
|
|
562
560
|
server.registerResource(`docs-${summary.id}-readme`, uri, {
|
|
@@ -624,7 +622,7 @@ async function registerServerResources(server, options) {
|
|
|
624
622
|
|
|
625
623
|
const DEFAULT_SCREENSHOT_TIMEOUT = 6e4;
|
|
626
624
|
const SCREENSHOT_RETRY_DELAY = 500;
|
|
627
|
-
z.object({
|
|
625
|
+
const connectionSchema$1 = z.object({
|
|
628
626
|
projectPath: z.string().trim().min(1).describe("\u5C0F\u7A0B\u5E8F\u9879\u76EE\u8DEF\u5F84\uFF1B\u652F\u6301 workspaceRoot \u76F8\u5BF9\u8DEF\u5F84"),
|
|
629
627
|
timeout: z.number().int().positive().optional(),
|
|
630
628
|
port: z.number().int().positive().optional(),
|
|
@@ -1022,10 +1020,10 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1022
1020
|
server.registerTool("weapp_devtools_connect", {
|
|
1023
1021
|
title: "Ensure Mini Program Connection",
|
|
1024
1022
|
description: "\u786E\u4FDD\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177 automator \u4F1A\u8BDD\u53EF\u7528\uFF0C\u5E76\u8FD4\u56DE\u5F53\u524D\u9875\u9762\u4E0E\u7CFB\u7EDF\u4FE1\u606F\u3002",
|
|
1025
|
-
inputSchema: {
|
|
1023
|
+
inputSchema: z.object({
|
|
1026
1024
|
...connectionInputSchema,
|
|
1027
1025
|
reconnect: z.boolean().optional()
|
|
1028
|
-
}
|
|
1026
|
+
})
|
|
1029
1027
|
}, async ({ reconnect, ...connection }) => {
|
|
1030
1028
|
try {
|
|
1031
1029
|
if (reconnect) {
|
|
@@ -1051,7 +1049,7 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1051
1049
|
server.registerTool("weapp_devtools_route", {
|
|
1052
1050
|
title: "Navigate Mini Program",
|
|
1053
1051
|
description: "\u5728\u5C0F\u7A0B\u5E8F\u5185\u6267\u884C navigateTo\u3001redirectTo\u3001reLaunch\u3001switchTab \u6216 navigateBack\u3002",
|
|
1054
|
-
inputSchema: navigateSchema
|
|
1052
|
+
inputSchema: z.object(navigateSchema)
|
|
1055
1053
|
}, async ({ path: pagePath, query, transition = "navigateTo", waitMs, ...connection }) => {
|
|
1056
1054
|
try {
|
|
1057
1055
|
const result = await manager.withMiniProgram(connection, async (miniProgram) => {
|
|
@@ -1093,10 +1091,10 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1093
1091
|
server.registerTool("weapp_devtools_active_page", {
|
|
1094
1092
|
title: "Current Mini Program Page",
|
|
1095
1093
|
description: "\u83B7\u53D6\u5F53\u524D\u9875\u9762\u8DEF\u5F84\u3001\u67E5\u8BE2\u53C2\u6570\u3001\u5C3A\u5BF8\u3001\u6EDA\u52A8\u4F4D\u7F6E\uFF1B\u53EF\u9009\u8FD4\u56DE\u9875\u9762 data\u3002",
|
|
1096
|
-
inputSchema: {
|
|
1094
|
+
inputSchema: z.object({
|
|
1097
1095
|
...connectionInputSchema,
|
|
1098
1096
|
withData: z.boolean().optional()
|
|
1099
|
-
}
|
|
1097
|
+
})
|
|
1100
1098
|
}, async ({ withData, ...connection }) => {
|
|
1101
1099
|
try {
|
|
1102
1100
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1121,7 +1119,7 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1121
1119
|
server.registerTool("weapp_devtools_page_stack", {
|
|
1122
1120
|
title: "Mini Program Page Stack",
|
|
1123
1121
|
description: "\u83B7\u53D6\u5F53\u524D\u5C0F\u7A0B\u5E8F\u9875\u9762\u6808\u3002",
|
|
1124
|
-
inputSchema:
|
|
1122
|
+
inputSchema: connectionSchema$1
|
|
1125
1123
|
}, async (connection) => {
|
|
1126
1124
|
try {
|
|
1127
1125
|
const result = await manager.withMiniProgram(connection, async (miniProgram) => {
|
|
@@ -1139,7 +1137,7 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1139
1137
|
server.registerTool("weapp_devtools_capture", {
|
|
1140
1138
|
title: "Mini Program Screenshot",
|
|
1141
1139
|
description: "\u622A\u53D6\u5F53\u524D\u5C0F\u7A0B\u5E8F\u89C6\u53E3\uFF0C\u8FD4\u56DE base64\uFF0C\u6216\u4FDD\u5B58\u5230 workspaceRoot \u76F8\u5BF9 outputPath\u3002",
|
|
1142
|
-
inputSchema: screenshotSchema
|
|
1140
|
+
inputSchema: z.object(screenshotSchema)
|
|
1143
1141
|
}, async ({ outputPath, ...connection }) => {
|
|
1144
1142
|
try {
|
|
1145
1143
|
const result = await manager.withMiniProgram(connection, async (miniProgram) => {
|
|
@@ -1169,7 +1167,7 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1169
1167
|
server.registerTool("weapp_devtools_host_api", {
|
|
1170
1168
|
title: "Call wx Method",
|
|
1171
1169
|
description: "\u8C03\u7528\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F wx API\uFF0C\u4F8B\u5982 wx.pageScrollTo\u3002",
|
|
1172
|
-
inputSchema: hostApiSchema
|
|
1170
|
+
inputSchema: z.object(hostApiSchema)
|
|
1173
1171
|
}, async ({ method, args, ...connection }) => {
|
|
1174
1172
|
try {
|
|
1175
1173
|
const result = await manager.withMiniProgram(connection, async (miniProgram) => {
|
|
@@ -1189,9 +1187,9 @@ function registerDevtoolsRuntimeTools(server, manager) {
|
|
|
1189
1187
|
server.registerTool("weapp_devtools_console", {
|
|
1190
1188
|
title: "Get Mini Program Logs",
|
|
1191
1189
|
description: "\u8BFB\u53D6 MCP \u4F1A\u8BDD\u6355\u83B7\u5230\u7684\u5C0F\u7A0B\u5E8F console/exception \u65E5\u5FD7\uFF1B\u53EF\u9009\u8BFB\u53D6\u540E\u6E05\u7A7A\u3002",
|
|
1192
|
-
inputSchema: {
|
|
1190
|
+
inputSchema: z.object({
|
|
1193
1191
|
clear: z.boolean().optional()
|
|
1194
|
-
}
|
|
1192
|
+
})
|
|
1195
1193
|
}, async ({ clear }) => {
|
|
1196
1194
|
try {
|
|
1197
1195
|
const logs = manager.getLogs();
|
|
@@ -1218,10 +1216,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1218
1216
|
server.registerTool("weapp_runtime_tap_node", {
|
|
1219
1217
|
title: "Tap Element",
|
|
1220
1218
|
description: "\u70B9\u51FB\u9875\u9762\u5143\u7D20\uFF0C\u652F\u6301 selector[index=N]\u3001innerSelector \u548C\u70B9\u51FB\u540E\u7B49\u5F85\u3002",
|
|
1221
|
-
inputSchema: {
|
|
1219
|
+
inputSchema: z.object({
|
|
1222
1220
|
...elementSelectorSchema,
|
|
1223
1221
|
waitMs: z.number().int().nonnegative().optional()
|
|
1224
|
-
}
|
|
1222
|
+
})
|
|
1225
1223
|
}, async ({ selector, innerSelector, waitMs, ...connection }) => {
|
|
1226
1224
|
try {
|
|
1227
1225
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1244,10 +1242,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1244
1242
|
server.registerTool("weapp_runtime_input_node", {
|
|
1245
1243
|
title: "Input Element Text",
|
|
1246
1244
|
description: "\u5411 input \u6216 textarea \u5143\u7D20\u8F93\u5165\u6587\u672C\u3002",
|
|
1247
|
-
inputSchema: {
|
|
1245
|
+
inputSchema: z.object({
|
|
1248
1246
|
...elementSelectorSchema,
|
|
1249
1247
|
value: z.union([z.string(), z.number()])
|
|
1250
|
-
}
|
|
1248
|
+
})
|
|
1251
1249
|
}, async ({ selector, innerSelector, value, ...connection }) => {
|
|
1252
1250
|
try {
|
|
1253
1251
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1267,11 +1265,11 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1267
1265
|
server.registerTool("weapp_runtime_invoke_component", {
|
|
1268
1266
|
title: "Call Element Method",
|
|
1269
1267
|
description: "\u8C03\u7528\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5143\u7D20\u5B9E\u4F8B\u65B9\u6CD5\u3002",
|
|
1270
|
-
inputSchema: {
|
|
1268
|
+
inputSchema: z.object({
|
|
1271
1269
|
...elementSelectorSchema,
|
|
1272
1270
|
method: z.string().trim().min(1),
|
|
1273
1271
|
args: z.array(z.unknown()).optional()
|
|
1274
|
-
}
|
|
1272
|
+
})
|
|
1275
1273
|
}, async ({ selector, innerSelector, method, args, ...connection }) => {
|
|
1276
1274
|
try {
|
|
1277
1275
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1293,10 +1291,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1293
1291
|
server.registerTool("weapp_runtime_component_state", {
|
|
1294
1292
|
title: "Get Element Data",
|
|
1295
1293
|
description: "\u8BFB\u53D6\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5143\u7D20 data\uFF0C\u53EF\u901A\u8FC7 path \u8BFB\u53D6\u5D4C\u5957\u5B57\u6BB5\u3002",
|
|
1296
|
-
inputSchema: {
|
|
1294
|
+
inputSchema: z.object({
|
|
1297
1295
|
...elementSelectorSchema,
|
|
1298
1296
|
path: z.string().trim().min(1).optional()
|
|
1299
|
-
}
|
|
1297
|
+
})
|
|
1300
1298
|
}, async ({ selector, innerSelector, path, ...connection }) => {
|
|
1301
1299
|
try {
|
|
1302
1300
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1316,10 +1314,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1316
1314
|
server.registerTool("weapp_runtime_update_component_state", {
|
|
1317
1315
|
title: "Set Element Data",
|
|
1318
1316
|
description: "\u8C03\u7528\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5143\u7D20 setData \u66F4\u65B0 data\u3002",
|
|
1319
|
-
inputSchema: {
|
|
1317
|
+
inputSchema: z.object({
|
|
1320
1318
|
...elementSelectorSchema,
|
|
1321
1319
|
data: z.record(z.string(), z.unknown())
|
|
1322
|
-
}
|
|
1320
|
+
})
|
|
1323
1321
|
}, async ({ selector, innerSelector, data, ...connection }) => {
|
|
1324
1322
|
try {
|
|
1325
1323
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1339,11 +1337,11 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1339
1337
|
server.registerTool("weapp_runtime_find_child", {
|
|
1340
1338
|
title: "Get Inner Element",
|
|
1341
1339
|
description: "\u5728\u5143\u7D20\u8303\u56F4\u5185\u67E5\u8BE2\u5355\u4E2A\u5185\u90E8\u5143\u7D20\u3002",
|
|
1342
|
-
inputSchema: {
|
|
1340
|
+
inputSchema: z.object({
|
|
1343
1341
|
...elementSelectorSchema,
|
|
1344
1342
|
targetSelector: z.string().trim().min(1),
|
|
1345
1343
|
withWxml: z.boolean().optional()
|
|
1346
|
-
}
|
|
1344
|
+
})
|
|
1347
1345
|
}, async ({ selector, innerSelector, targetSelector, withWxml, ...connection }) => {
|
|
1348
1346
|
try {
|
|
1349
1347
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1367,11 +1365,11 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1367
1365
|
server.registerTool("weapp_runtime_find_children", {
|
|
1368
1366
|
title: "Get Inner Elements",
|
|
1369
1367
|
description: "\u5728\u5143\u7D20\u8303\u56F4\u5185\u67E5\u8BE2\u5185\u90E8\u5143\u7D20\u6570\u7EC4\u3002",
|
|
1370
|
-
inputSchema: {
|
|
1368
|
+
inputSchema: z.object({
|
|
1371
1369
|
...elementSelectorSchema,
|
|
1372
1370
|
targetSelector: z.string().trim().min(1),
|
|
1373
1371
|
withWxml: z.boolean().optional()
|
|
1374
|
-
}
|
|
1372
|
+
})
|
|
1375
1373
|
}, async ({ selector, innerSelector, targetSelector, withWxml, ...connection }) => {
|
|
1376
1374
|
try {
|
|
1377
1375
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1399,10 +1397,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1399
1397
|
server.registerTool("weapp_runtime_node_markup", {
|
|
1400
1398
|
title: "Get Element WXML",
|
|
1401
1399
|
description: "\u8BFB\u53D6\u5143\u7D20 inner WXML \u6216 outer WXML\u3002",
|
|
1402
|
-
inputSchema: {
|
|
1400
|
+
inputSchema: z.object({
|
|
1403
1401
|
...elementSelectorSchema,
|
|
1404
1402
|
outer: z.boolean().optional()
|
|
1405
|
-
}
|
|
1403
|
+
})
|
|
1406
1404
|
}, async ({ selector, innerSelector, outer, ...connection }) => {
|
|
1407
1405
|
try {
|
|
1408
1406
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1423,10 +1421,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1423
1421
|
server.registerTool("weapp_runtime_node_styles", {
|
|
1424
1422
|
title: "Get Element Styles",
|
|
1425
1423
|
description: "\u8BFB\u53D6\u5143\u7D20\u6837\u5F0F\u503C\u3002",
|
|
1426
|
-
inputSchema: {
|
|
1424
|
+
inputSchema: z.object({
|
|
1427
1425
|
...elementSelectorSchema,
|
|
1428
1426
|
names: z.array(z.string().trim().min(1)).min(1)
|
|
1429
|
-
}
|
|
1427
|
+
})
|
|
1430
1428
|
}, async ({ selector, innerSelector, names, ...connection }) => {
|
|
1431
1429
|
try {
|
|
1432
1430
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1448,10 +1446,10 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1448
1446
|
server.registerTool("weapp_runtime_node_attrs", {
|
|
1449
1447
|
title: "Get Element Attributes",
|
|
1450
1448
|
description: "\u8BFB\u53D6\u5143\u7D20 attribute \u503C\u3002",
|
|
1451
|
-
inputSchema: {
|
|
1449
|
+
inputSchema: z.object({
|
|
1452
1450
|
...elementSelectorSchema,
|
|
1453
1451
|
names: z.array(z.string().trim().min(1)).min(1)
|
|
1454
|
-
}
|
|
1452
|
+
})
|
|
1455
1453
|
}, async ({ selector, innerSelector, names, ...connection }) => {
|
|
1456
1454
|
try {
|
|
1457
1455
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1473,11 +1471,11 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1473
1471
|
server.registerTool("weapp_runtime_scroll_node", {
|
|
1474
1472
|
title: "Scroll Element",
|
|
1475
1473
|
description: "\u6EDA\u52A8 scroll-view \u5143\u7D20\u5230\u6307\u5B9A\u4F4D\u7F6E\u3002",
|
|
1476
|
-
inputSchema: {
|
|
1474
|
+
inputSchema: z.object({
|
|
1477
1475
|
...elementSelectorSchema,
|
|
1478
1476
|
x: z.number(),
|
|
1479
1477
|
y: z.number()
|
|
1480
|
-
}
|
|
1478
|
+
})
|
|
1481
1479
|
}, async ({ selector, innerSelector, x, y, ...connection }) => {
|
|
1482
1480
|
try {
|
|
1483
1481
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1498,7 +1496,7 @@ function registerRuntimeNodeTools(server, manager) {
|
|
|
1498
1496
|
server.registerTool("weapp_runtime_measure_node", {
|
|
1499
1497
|
title: "Get Element Bounding Rect",
|
|
1500
1498
|
description: "\u8BFB\u53D6\u5143\u7D20\u89C6\u53E3\u77E9\u5F62\uFF1B\u4F18\u5148\u4F7F\u7528\u5143\u7D20 offset/size\uFF0C\u7F3A\u5931\u65F6\u8FD4\u56DE\u53EF\u7528\u5B57\u6BB5\u3002",
|
|
1501
|
-
inputSchema: elementSelectorSchema
|
|
1499
|
+
inputSchema: z.object(elementSelectorSchema)
|
|
1502
1500
|
}, async ({ selector, innerSelector, ...connection }) => {
|
|
1503
1501
|
try {
|
|
1504
1502
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1544,11 +1542,16 @@ const selectorSchema = {
|
|
|
1544
1542
|
innerSelector: z.string().trim().min(1).optional(),
|
|
1545
1543
|
withWxml: z.boolean().optional()
|
|
1546
1544
|
};
|
|
1545
|
+
const xpathSchema = {
|
|
1546
|
+
...connectionInputSchema,
|
|
1547
|
+
xpath: z.string().trim().min(1),
|
|
1548
|
+
withWxml: z.boolean().optional()
|
|
1549
|
+
};
|
|
1547
1550
|
function registerRuntimePageTools(server, manager) {
|
|
1548
1551
|
server.registerTool("weapp_runtime_find_node", {
|
|
1549
1552
|
title: "Get Page Element",
|
|
1550
1553
|
description: "\u901A\u8FC7\u9009\u62E9\u5668\u83B7\u53D6\u5F53\u524D\u9875\u9762\u5143\u7D20\u6458\u8981\uFF0C\u652F\u6301 selector[index=N]\u3001innerSelector \u4E0E withWxml\u3002",
|
|
1551
|
-
inputSchema: selectorSchema
|
|
1554
|
+
inputSchema: z.object(selectorSchema)
|
|
1552
1555
|
}, async ({ selector, innerSelector, withWxml, ...connection }) => {
|
|
1553
1556
|
try {
|
|
1554
1557
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1567,11 +1570,11 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1567
1570
|
server.registerTool("weapp_runtime_find_nodes", {
|
|
1568
1571
|
title: "Get Page Elements",
|
|
1569
1572
|
description: "\u901A\u8FC7\u9009\u62E9\u5668\u83B7\u53D6\u5F53\u524D\u9875\u9762\u5143\u7D20\u6570\u7EC4\u6458\u8981\uFF0C\u652F\u6301 selector[index=N] \u4E0E withWxml\u3002",
|
|
1570
|
-
inputSchema: {
|
|
1573
|
+
inputSchema: z.object({
|
|
1571
1574
|
...connectionInputSchema,
|
|
1572
1575
|
selector: z.string().trim().min(1),
|
|
1573
1576
|
withWxml: z.boolean().optional()
|
|
1574
|
-
}
|
|
1577
|
+
})
|
|
1575
1578
|
}, async ({ selector, withWxml, ...connection }) => {
|
|
1576
1579
|
try {
|
|
1577
1580
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1590,15 +1593,58 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1590
1593
|
return toToolError(error);
|
|
1591
1594
|
}
|
|
1592
1595
|
});
|
|
1596
|
+
server.registerTool("weapp_runtime_find_node_by_xpath", {
|
|
1597
|
+
title: "Get Page Element by XPath",
|
|
1598
|
+
description: "\u901A\u8FC7 XPath \u83B7\u53D6\u5F53\u524D\u9875\u9762\u7B2C\u4E00\u4E2A\u5339\u914D\u5143\u7D20\uFF0C\u9002\u5408\u6309\u6587\u672C\u3001\u5C5E\u6027\u6216\u5C42\u7EA7\u5173\u7CFB\u5B9A\u4F4D\u3002",
|
|
1599
|
+
inputSchema: z.object(xpathSchema)
|
|
1600
|
+
}, async ({ xpath, withWxml, ...connection }) => {
|
|
1601
|
+
try {
|
|
1602
|
+
const result = await manager.withPage(connection, async (page) => {
|
|
1603
|
+
const element = await callRequiredMethod(page, "getElementByXpath", xpath);
|
|
1604
|
+
if (!element) {
|
|
1605
|
+
throw new Error(`XPath \u672A\u627E\u5230\u5143\u7D20: "${xpath}"`);
|
|
1606
|
+
}
|
|
1607
|
+
return {
|
|
1608
|
+
xpath,
|
|
1609
|
+
...await summarizeElement(element, withWxml)
|
|
1610
|
+
};
|
|
1611
|
+
});
|
|
1612
|
+
return toToolResult(result);
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
return toToolError(error);
|
|
1615
|
+
}
|
|
1616
|
+
});
|
|
1617
|
+
server.registerTool("weapp_runtime_find_nodes_by_xpath", {
|
|
1618
|
+
title: "Get Page Elements by XPath",
|
|
1619
|
+
description: "\u901A\u8FC7 XPath \u83B7\u53D6\u5F53\u524D\u9875\u9762\u5168\u90E8\u5339\u914D\u5143\u7D20\uFF0C\u9002\u5408\u6279\u91CF\u68C0\u67E5\u7ED3\u6784\u4E0E\u5185\u5BB9\u3002",
|
|
1620
|
+
inputSchema: z.object(xpathSchema)
|
|
1621
|
+
}, async ({ xpath, withWxml, ...connection }) => {
|
|
1622
|
+
try {
|
|
1623
|
+
const result = await manager.withPage(connection, async (page) => {
|
|
1624
|
+
const elements = await callRequiredMethod(page, "getElementsByXpath", xpath);
|
|
1625
|
+
return {
|
|
1626
|
+
xpath,
|
|
1627
|
+
count: elements.length,
|
|
1628
|
+
elements: await Promise.all(elements.map(async (element, index) => ({
|
|
1629
|
+
index,
|
|
1630
|
+
...await summarizeElement(element, withWxml)
|
|
1631
|
+
})))
|
|
1632
|
+
};
|
|
1633
|
+
});
|
|
1634
|
+
return toToolResult(result);
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
return toToolError(error);
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1593
1639
|
server.registerTool("weapp_runtime_wait_node", {
|
|
1594
1640
|
title: "Wait Page Element",
|
|
1595
1641
|
description: "\u8F6E\u8BE2\u7B49\u5F85\u5143\u7D20\u51FA\u73B0\uFF0C\u652F\u6301 selector[index=N]\u3002",
|
|
1596
|
-
inputSchema: {
|
|
1642
|
+
inputSchema: z.object({
|
|
1597
1643
|
...connectionInputSchema,
|
|
1598
1644
|
selector: z.string().trim().min(1),
|
|
1599
1645
|
timeoutMs: z.number().int().positive().optional(),
|
|
1600
1646
|
intervalMs: z.number().int().positive().optional()
|
|
1601
|
-
}
|
|
1647
|
+
})
|
|
1602
1648
|
}, async ({ selector, timeoutMs = 5e3, intervalMs = 200, ...connection }) => {
|
|
1603
1649
|
try {
|
|
1604
1650
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1625,10 +1671,10 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1625
1671
|
server.registerTool("weapp_runtime_wait", {
|
|
1626
1672
|
title: "Wait Page Timeout",
|
|
1627
1673
|
description: "\u5728\u5F53\u524D\u9875\u9762\u7B49\u5F85\u6307\u5B9A\u6BEB\u79D2\u6570\u3002",
|
|
1628
|
-
inputSchema: {
|
|
1674
|
+
inputSchema: z.object({
|
|
1629
1675
|
...connectionInputSchema,
|
|
1630
1676
|
milliseconds: z.number().int().nonnegative()
|
|
1631
|
-
}
|
|
1677
|
+
})
|
|
1632
1678
|
}, async ({ milliseconds, ...connection }) => {
|
|
1633
1679
|
try {
|
|
1634
1680
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1643,10 +1689,10 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1643
1689
|
server.registerTool("weapp_runtime_page_state", {
|
|
1644
1690
|
title: "Get Page Data",
|
|
1645
1691
|
description: "\u8BFB\u53D6\u5F53\u524D\u9875\u9762 data\uFF0C\u53EF\u901A\u8FC7 path \u8BFB\u53D6\u5D4C\u5957\u5B57\u6BB5\u3002",
|
|
1646
|
-
inputSchema: {
|
|
1692
|
+
inputSchema: z.object({
|
|
1647
1693
|
...connectionInputSchema,
|
|
1648
1694
|
path: z.string().trim().min(1).optional()
|
|
1649
|
-
}
|
|
1695
|
+
})
|
|
1650
1696
|
}, async ({ path, ...connection }) => {
|
|
1651
1697
|
try {
|
|
1652
1698
|
const result = await manager.withPage(connection, async (page) => ({
|
|
@@ -1661,11 +1707,11 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1661
1707
|
server.registerTool("weapp_runtime_update_page_state", {
|
|
1662
1708
|
title: "Set Page Data",
|
|
1663
1709
|
description: "\u8C03\u7528\u5F53\u524D\u9875\u9762 setData \u66F4\u65B0 data\u3002",
|
|
1664
|
-
inputSchema: {
|
|
1710
|
+
inputSchema: z.object({
|
|
1665
1711
|
...connectionInputSchema,
|
|
1666
1712
|
data: z.record(z.string(), z.unknown()),
|
|
1667
1713
|
verify: z.boolean().optional()
|
|
1668
|
-
}
|
|
1714
|
+
})
|
|
1669
1715
|
}, async ({ data, verify, ...connection }) => {
|
|
1670
1716
|
try {
|
|
1671
1717
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1683,11 +1729,11 @@ function registerRuntimePageTools(server, manager) {
|
|
|
1683
1729
|
server.registerTool("weapp_runtime_invoke_page", {
|
|
1684
1730
|
title: "Call Page Method",
|
|
1685
1731
|
description: "\u8C03\u7528\u5F53\u524D\u9875\u9762\u5B9E\u4F8B\u65B9\u6CD5\u3002",
|
|
1686
|
-
inputSchema: {
|
|
1732
|
+
inputSchema: z.object({
|
|
1687
1733
|
...connectionInputSchema,
|
|
1688
1734
|
method: z.string().trim().min(1),
|
|
1689
1735
|
args: z.array(z.unknown()).optional()
|
|
1690
|
-
}
|
|
1736
|
+
})
|
|
1691
1737
|
}, async ({ method, args, ...connection }) => {
|
|
1692
1738
|
try {
|
|
1693
1739
|
const result = await manager.withPage(connection, async (page) => {
|
|
@@ -1739,11 +1785,11 @@ function registerServerTools(server, options) {
|
|
|
1739
1785
|
server.registerTool("list_source_files", {
|
|
1740
1786
|
title: "List Source Files",
|
|
1741
1787
|
description: "\u5217\u51FA weapp-vite / wevu \u5305\u4E0B\u6307\u5B9A\u76EE\u5F55\u6587\u4EF6\u5217\u8868",
|
|
1742
|
-
inputSchema: {
|
|
1788
|
+
inputSchema: z.object({
|
|
1743
1789
|
packageId: packageIdSchema,
|
|
1744
1790
|
directory: z.string().optional().describe("\u5305\u5185\u76F8\u5BF9\u76EE\u5F55\uFF0C\u9ED8\u8BA4 src"),
|
|
1745
1791
|
maxResults: z.number().int().positive().max(2e3).optional()
|
|
1746
|
-
}
|
|
1792
|
+
})
|
|
1747
1793
|
}, async ({ packageId, directory, maxResults }) => {
|
|
1748
1794
|
try {
|
|
1749
1795
|
const packageRoot = await resolvePackageRoot(workspaceRoot, packageId);
|
|
@@ -1761,13 +1807,13 @@ function registerServerTools(server, options) {
|
|
|
1761
1807
|
server.registerTool("read_source_file", {
|
|
1762
1808
|
title: "Read Source File",
|
|
1763
1809
|
description: "\u8BFB\u53D6 weapp-vite / wevu \u5305\u5185\u6E90\u7801\u6587\u4EF6\uFF0C\u652F\u6301\u884C\u533A\u95F4\u88C1\u526A",
|
|
1764
|
-
inputSchema: {
|
|
1810
|
+
inputSchema: z.object({
|
|
1765
1811
|
packageId: packageIdSchema,
|
|
1766
1812
|
filePath: z.string().describe("\u5305\u5185\u76F8\u5BF9\u6587\u4EF6\u8DEF\u5F84"),
|
|
1767
1813
|
startLine: z.number().int().positive().optional(),
|
|
1768
1814
|
endLine: z.number().int().positive().optional(),
|
|
1769
1815
|
maxChars: z.number().int().positive().max(2e5).optional()
|
|
1770
|
-
}
|
|
1816
|
+
})
|
|
1771
1817
|
}, async ({ packageId, filePath, startLine, endLine, maxChars }) => {
|
|
1772
1818
|
try {
|
|
1773
1819
|
const packageRoot = await resolvePackageRoot(workspaceRoot, packageId);
|
|
@@ -1791,12 +1837,12 @@ function registerServerTools(server, options) {
|
|
|
1791
1837
|
server.registerTool("search_source_code", {
|
|
1792
1838
|
title: "Search Source Code",
|
|
1793
1839
|
description: "\u5728 weapp-vite / wevu \u4EE3\u7801\u4E2D\u641C\u7D22\u5173\u952E\u8BCD",
|
|
1794
|
-
inputSchema: {
|
|
1840
|
+
inputSchema: z.object({
|
|
1795
1841
|
query: z.string().min(1),
|
|
1796
1842
|
packageId: packageIdSchema.optional(),
|
|
1797
1843
|
directory: z.string().optional(),
|
|
1798
1844
|
maxResults: z.number().int().positive().max(2e3).optional()
|
|
1799
|
-
}
|
|
1845
|
+
})
|
|
1800
1846
|
}, async ({ query, packageId, directory, maxResults }) => {
|
|
1801
1847
|
try {
|
|
1802
1848
|
const targetPackageIds = packageId ? [packageId] : packageIds;
|
|
@@ -1828,12 +1874,12 @@ function registerServerTools(server, options) {
|
|
|
1828
1874
|
server.registerTool("run_package_script", {
|
|
1829
1875
|
title: "Run Package Script",
|
|
1830
1876
|
description: "\u5728 weapp-vite / wevu \u5305\u76EE\u5F55\u6267\u884C pnpm script",
|
|
1831
|
-
inputSchema: {
|
|
1877
|
+
inputSchema: z.object({
|
|
1832
1878
|
packageId: packageIdSchema,
|
|
1833
1879
|
script: z.string().min(1),
|
|
1834
1880
|
args: z.array(z.string()).optional(),
|
|
1835
1881
|
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
1836
|
-
}
|
|
1882
|
+
})
|
|
1837
1883
|
}, async ({ packageId, script, args, timeoutMs }) => {
|
|
1838
1884
|
try {
|
|
1839
1885
|
const resolvedPackage = await resolveExposedPackage(workspaceRoot, packageId);
|
|
@@ -1849,13 +1895,13 @@ function registerServerTools(server, options) {
|
|
|
1849
1895
|
server.registerTool("run_weapp_vite_cli", {
|
|
1850
1896
|
title: "Run weapp-vite CLI",
|
|
1851
1897
|
description: "\u6267\u884C weapp-vite CLI\uFF08build/dev/open/analyze \u7B49\uFF09",
|
|
1852
|
-
inputSchema: {
|
|
1898
|
+
inputSchema: z.object({
|
|
1853
1899
|
subCommand: z.string().min(1),
|
|
1854
1900
|
projectPath: z.string().optional().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\uFF0C\u5982 e2e-apps/auto-routes-define-app-json"),
|
|
1855
1901
|
platform: z.string().optional(),
|
|
1856
1902
|
args: z.array(z.string()).optional(),
|
|
1857
1903
|
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
1858
|
-
}
|
|
1904
|
+
})
|
|
1859
1905
|
}, async ({ subCommand, projectPath, platform, args, timeoutMs }) => {
|
|
1860
1906
|
try {
|
|
1861
1907
|
const result = await runWeappViteCliTool(workspaceRoot, {
|
|
@@ -1873,12 +1919,12 @@ function registerServerTools(server, options) {
|
|
|
1873
1919
|
server.registerTool("take_weapp_screenshot", {
|
|
1874
1920
|
title: "Take Weapp Screenshot",
|
|
1875
1921
|
description: "\u5F53\u7528\u6237\u63D0\u5230\u622A\u56FE\u3001\u9875\u9762\u5FEB\u7167\u3001\u8FD0\u884C\u65F6\u622A\u56FE\u65F6\uFF0C\u4F18\u5148\u8C03\u7528\u6B64\u5DE5\u5177\u6267\u884C weapp-vite screenshot",
|
|
1876
|
-
inputSchema: {
|
|
1922
|
+
inputSchema: z.object({
|
|
1877
1923
|
projectPath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\uFF0C\u901A\u5E38\u662F dist/build/mp-weixin \u6216\u5177\u4F53\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55"),
|
|
1878
1924
|
page: z.string().optional().describe("\u622A\u56FE\u524D\u5148\u8DF3\u8F6C\u7684\u5C0F\u7A0B\u5E8F\u9875\u9762\u8DEF\u5F84"),
|
|
1879
1925
|
outputPath: z.string().optional().describe("\u622A\u56FE\u8F93\u51FA\u8DEF\u5F84\uFF0C\u5EFA\u8BAE\u5199\u5165 .tmp/ \u6216\u5DE5\u4F5C\u533A\u76F8\u5BF9\u8DEF\u5F84"),
|
|
1880
1926
|
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
1881
|
-
}
|
|
1927
|
+
})
|
|
1882
1928
|
}, async ({ projectPath, page, outputPath, timeoutMs }) => {
|
|
1883
1929
|
try {
|
|
1884
1930
|
const args = ["--json"];
|
|
@@ -1908,18 +1954,28 @@ function registerServerTools(server, options) {
|
|
|
1908
1954
|
server.registerTool("compare_weapp_screenshot", {
|
|
1909
1955
|
title: "Compare Weapp Screenshot",
|
|
1910
1956
|
description: "\u5F53\u7528\u6237\u63D0\u5230\u622A\u56FE\u5BF9\u6BD4\u3001diff\u3001baseline\u3001\u89C6\u89C9\u56DE\u5F52\u3001\u50CF\u7D20\u5BF9\u6BD4\u65F6\uFF0C\u4F18\u5148\u8C03\u7528\u6B64\u5DE5\u5177\u6267\u884C weapp-vite compare",
|
|
1911
|
-
inputSchema: {
|
|
1957
|
+
inputSchema: z.object({
|
|
1912
1958
|
projectPath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\uFF0C\u901A\u5E38\u662F dist/build/mp-weixin \u6216\u5177\u4F53\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55"),
|
|
1913
1959
|
baselinePath: z.string().describe("\u76F8\u5BF9 workspace \u6839\u8DEF\u5F84\u7684 baseline \u56FE\u7247\u8DEF\u5F84"),
|
|
1914
|
-
page: z.string().optional().describe("\u622A\u56FE\u5BF9\u6BD4\u524D\u5148\u8DF3\u8F6C\
|
|
1960
|
+
page: z.string().optional().describe("\u622A\u56FE\u5BF9\u6BD4\u524D\u5148\u8DF3\u8F6C\u9875\u9762\u8DEF\u5F84"),
|
|
1915
1961
|
currentOutputPath: z.string().optional().describe("\u5F53\u524D\u622A\u56FE\u8F93\u51FA\u8DEF\u5F84"),
|
|
1916
1962
|
diffOutputPath: z.string().optional().describe("diff \u56FE\u7247\u8F93\u51FA\u8DEF\u5F84"),
|
|
1917
1963
|
threshold: z.number().min(0).max(1).optional(),
|
|
1918
1964
|
maxDiffPixels: z.number().int().min(0).optional(),
|
|
1919
1965
|
maxDiffRatio: z.number().min(0).max(1).optional(),
|
|
1920
1966
|
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
1921
|
-
}
|
|
1922
|
-
}, async ({
|
|
1967
|
+
})
|
|
1968
|
+
}, async ({
|
|
1969
|
+
projectPath,
|
|
1970
|
+
baselinePath,
|
|
1971
|
+
page,
|
|
1972
|
+
currentOutputPath,
|
|
1973
|
+
diffOutputPath,
|
|
1974
|
+
threshold,
|
|
1975
|
+
maxDiffPixels,
|
|
1976
|
+
maxDiffRatio,
|
|
1977
|
+
timeoutMs
|
|
1978
|
+
}) => {
|
|
1923
1979
|
try {
|
|
1924
1980
|
const args = ["--json", "--baseline", baselinePath];
|
|
1925
1981
|
if (page) {
|
|
@@ -1962,12 +2018,12 @@ function registerServerTools(server, options) {
|
|
|
1962
2018
|
server.registerTool("run_repo_command", {
|
|
1963
2019
|
title: "Run Repo Command",
|
|
1964
2020
|
description: "\u6267\u884C\u4ED3\u5E93\u7EA7\u547D\u4EE4\uFF08\u652F\u6301 pnpm/node/git/rg\uFF09",
|
|
1965
|
-
inputSchema: {
|
|
2021
|
+
inputSchema: z.object({
|
|
1966
2022
|
command: z.enum(["pnpm", "node", "git", "rg"]),
|
|
1967
2023
|
args: z.array(z.string()).optional(),
|
|
1968
2024
|
cwdRelative: z.string().optional(),
|
|
1969
2025
|
timeoutMs: z.number().int().positive().max(9e5).optional()
|
|
1970
|
-
}
|
|
2026
|
+
})
|
|
1971
2027
|
}, async ({ command, args, cwdRelative, timeoutMs }) => {
|
|
1972
2028
|
try {
|
|
1973
2029
|
const result = await runCommand(workspaceRoot, command, args ?? [], {
|
|
@@ -1983,35 +2039,47 @@ function registerServerTools(server, options) {
|
|
|
1983
2039
|
|
|
1984
2040
|
const packageIds = Object.keys(EXPOSED_PACKAGES);
|
|
1985
2041
|
const packageIdSchema = z.enum(packageIds);
|
|
1986
|
-
async function
|
|
2042
|
+
async function createWeappViteMcpServerFactory(options) {
|
|
1987
2043
|
const workspaceRoot = resolveWorkspaceRoot(options?.workspaceRoot);
|
|
1988
|
-
const
|
|
1989
|
-
name: MCP_SERVER_NAME,
|
|
1990
|
-
version: MCP_SERVER_VERSION
|
|
1991
|
-
});
|
|
2044
|
+
const exposedPackages = await resolveExposedPackages(workspaceRoot);
|
|
1992
2045
|
const runtimeManager = new RuntimeSessionManager(workspaceRoot, options?.runtimeHooks);
|
|
1993
|
-
registerServerTools(server, {
|
|
1994
|
-
workspaceRoot,
|
|
1995
|
-
packageIds,
|
|
1996
|
-
packageIdSchema
|
|
1997
|
-
});
|
|
1998
|
-
registerRuntimeTools(server, {
|
|
1999
|
-
manager: runtimeManager,
|
|
2000
|
-
runtimeHooks: options?.runtimeHooks,
|
|
2001
|
-
workspaceRoot
|
|
2002
|
-
});
|
|
2003
|
-
registerServerPrompts(server, {
|
|
2004
|
-
packageIds,
|
|
2005
|
-
packageIdSchema
|
|
2006
|
-
});
|
|
2007
|
-
await registerServerResources(server, {
|
|
2008
|
-
workspaceRoot,
|
|
2009
|
-
packageIds
|
|
2010
|
-
});
|
|
2011
2046
|
return {
|
|
2012
2047
|
runtimeManager,
|
|
2013
|
-
|
|
2014
|
-
|
|
2048
|
+
workspaceRoot,
|
|
2049
|
+
createServer: () => {
|
|
2050
|
+
const server = new McpServer({
|
|
2051
|
+
name: MCP_SERVER_NAME,
|
|
2052
|
+
version: MCP_SERVER_VERSION
|
|
2053
|
+
});
|
|
2054
|
+
registerServerTools(server, {
|
|
2055
|
+
workspaceRoot,
|
|
2056
|
+
packageIds,
|
|
2057
|
+
packageIdSchema
|
|
2058
|
+
});
|
|
2059
|
+
registerRuntimeTools(server, {
|
|
2060
|
+
manager: runtimeManager,
|
|
2061
|
+
runtimeHooks: options?.runtimeHooks,
|
|
2062
|
+
workspaceRoot
|
|
2063
|
+
});
|
|
2064
|
+
registerServerPrompts(server, {
|
|
2065
|
+
packageIds,
|
|
2066
|
+
packageIdSchema
|
|
2067
|
+
});
|
|
2068
|
+
registerServerResources(server, {
|
|
2069
|
+
exposedPackages,
|
|
2070
|
+
workspaceRoot,
|
|
2071
|
+
packageIds
|
|
2072
|
+
});
|
|
2073
|
+
return server;
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
async function createWeappViteMcpServer(options) {
|
|
2078
|
+
const factory = await createWeappViteMcpServerFactory(options);
|
|
2079
|
+
return {
|
|
2080
|
+
runtimeManager: factory.runtimeManager,
|
|
2081
|
+
server: factory.createServer(),
|
|
2082
|
+
workspaceRoot: factory.workspaceRoot
|
|
2015
2083
|
};
|
|
2016
2084
|
}
|
|
2017
2085
|
|
|
@@ -2365,23 +2433,6 @@ function normalizePort(input) {
|
|
|
2365
2433
|
}
|
|
2366
2434
|
return DEFAULT_MCP_PORT;
|
|
2367
2435
|
}
|
|
2368
|
-
async function parseJsonBody(req) {
|
|
2369
|
-
if (req.method !== "POST") {
|
|
2370
|
-
return void 0;
|
|
2371
|
-
}
|
|
2372
|
-
const chunks = [];
|
|
2373
|
-
for await (const chunk of req) {
|
|
2374
|
-
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
2375
|
-
}
|
|
2376
|
-
if (chunks.length === 0) {
|
|
2377
|
-
return void 0;
|
|
2378
|
-
}
|
|
2379
|
-
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
2380
|
-
if (!raw) {
|
|
2381
|
-
return void 0;
|
|
2382
|
-
}
|
|
2383
|
-
return JSON.parse(raw);
|
|
2384
|
-
}
|
|
2385
2436
|
function writeJson(res, statusCode, payload) {
|
|
2386
2437
|
if (res.headersSent) {
|
|
2387
2438
|
return;
|
|
@@ -2396,9 +2447,14 @@ async function startStdioServer(options) {
|
|
|
2396
2447
|
process.chdir(options.workspaceRoot);
|
|
2397
2448
|
}
|
|
2398
2449
|
try {
|
|
2399
|
-
const
|
|
2400
|
-
const
|
|
2401
|
-
|
|
2450
|
+
const factory = await createWeappViteMcpServerFactory(options);
|
|
2451
|
+
const handle = serveStdio(() => factory.createServer());
|
|
2452
|
+
return {
|
|
2453
|
+
transport: "stdio",
|
|
2454
|
+
close: async () => {
|
|
2455
|
+
await handle.close();
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2402
2458
|
} finally {
|
|
2403
2459
|
if (options?.workspaceRoot) {
|
|
2404
2460
|
process.chdir(previousCwd);
|
|
@@ -2420,18 +2476,23 @@ async function startStreamableHttpServer(options) {
|
|
|
2420
2476
|
const normalizedEndpoint = normalizeEndpoint(endpoint);
|
|
2421
2477
|
const normalizedPort = normalizePort(port);
|
|
2422
2478
|
const normalizedRestEndpoint = normalizeRuntimeRestEndpoint(restEndpoint);
|
|
2423
|
-
const
|
|
2424
|
-
const
|
|
2425
|
-
|
|
2426
|
-
});
|
|
2427
|
-
|
|
2479
|
+
const factory = await createWeappViteMcpServerFactory({ runtimeHooks, workspaceRoot });
|
|
2480
|
+
const mcpHandler = createMcpHandler(() => factory.createServer(), {
|
|
2481
|
+
legacy: "stateless"
|
|
2482
|
+
});
|
|
2483
|
+
const nodeHandler = toNodeHandler(mcpHandler);
|
|
2484
|
+
const isLoopback = ["127.0.0.1", "localhost", "::1", "[::1]"].includes(host);
|
|
2485
|
+
const validateHost = isLoopback ? localhostHostValidation() : hostHeaderValidation([host]);
|
|
2486
|
+
const validateOrigin = isLoopback ? localhostOriginValidation() : originValidation([host]);
|
|
2428
2487
|
const httpServer = http.createServer(async (req, res) => {
|
|
2429
2488
|
try {
|
|
2430
|
-
|
|
2431
|
-
|
|
2489
|
+
if (!validateHost(req, res) || !validateOrigin(req, res)) {
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
2432
2493
|
const handledByRest = await handleRuntimeRestRequest(req, res, {
|
|
2433
2494
|
endpoint: normalizedRestEndpoint,
|
|
2434
|
-
manager: runtimeManager
|
|
2495
|
+
manager: factory.runtimeManager
|
|
2435
2496
|
});
|
|
2436
2497
|
if (handledByRest) {
|
|
2437
2498
|
return;
|
|
@@ -2459,8 +2520,7 @@ async function startStreamableHttpServer(options) {
|
|
|
2459
2520
|
});
|
|
2460
2521
|
return;
|
|
2461
2522
|
}
|
|
2462
|
-
|
|
2463
|
-
await transport.handleRequest(req, res, body);
|
|
2523
|
+
await nodeHandler(req, res);
|
|
2464
2524
|
} catch (error) {
|
|
2465
2525
|
writeJson(res, 500, {
|
|
2466
2526
|
jsonrpc: "2.0",
|
|
@@ -2490,7 +2550,7 @@ async function startStreamableHttpServer(options) {
|
|
|
2490
2550
|
return {
|
|
2491
2551
|
transport: "streamable-http",
|
|
2492
2552
|
close: async () => {
|
|
2493
|
-
await
|
|
2553
|
+
await mcpHandler.close();
|
|
2494
2554
|
await new Promise((resolve, reject) => {
|
|
2495
2555
|
httpServer.close((error) => {
|
|
2496
2556
|
if (error) {
|
|
@@ -2508,10 +2568,7 @@ async function startWeappViteMcpServer(options) {
|
|
|
2508
2568
|
if (transport === "streamable-http") {
|
|
2509
2569
|
return startStreamableHttpServer(options ?? {});
|
|
2510
2570
|
}
|
|
2511
|
-
await startStdioServer(options);
|
|
2512
|
-
return {
|
|
2513
|
-
transport: "stdio"
|
|
2514
|
-
};
|
|
2571
|
+
return await startStdioServer(options);
|
|
2515
2572
|
}
|
|
2516
2573
|
|
|
2517
2574
|
function isDirectExecution() {
|
|
@@ -2531,4 +2588,4 @@ ${message}
|
|
|
2531
2588
|
});
|
|
2532
2589
|
}
|
|
2533
2590
|
|
|
2534
|
-
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
|
2591
|
+
export { DEFAULT_MAX_FILE_CHARS, DEFAULT_MAX_OUTPUT_CHARS, DEFAULT_MAX_RESULTS, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, DEFAULT_TIMEOUT_MS, EXPOSED_PACKAGES, MCP_SERVER_NAME, MCP_SERVER_VERSION, SKIPPED_DIR_NAMES, assertInsideRoot, createWeappViteMcpServer, createWeappViteMcpServerFactory, formatJson, listFilesInDirectory, loadExposedCatalog, loadPackageSummary, normalizeErrorMessage, readFileContent, resolveSubPath, resolveWorkspaceRoot, runCommand, searchTextInDirectory, startStdioServer, startWeappViteMcpServer, toToolError, toToolResult };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"description": "mcp",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -31,9 +31,13 @@
|
|
|
31
31
|
"node": "^20.19.0 || >=22.12.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@modelcontextprotocol/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"@modelcontextprotocol/node": "^2.0.0",
|
|
35
|
+
"@modelcontextprotocol/server": "^2.0.0",
|
|
36
|
+
"zod": "^4.5.4",
|
|
37
|
+
"@weapp-vite/devtools-runtime": "0.4.17"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@modelcontextprotocol/client": "^2.0.0"
|
|
37
41
|
},
|
|
38
42
|
"scripts": {
|
|
39
43
|
"dev": "unbuild --stub",
|