@creatoria/miniapp-mcp 0.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 +469 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +144 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/defaults.d.ts +73 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +118 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/loader.d.ts +50 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +189 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/core/element-ref.d.ts +44 -0
- package/dist/core/element-ref.d.ts.map +1 -0
- package/dist/core/element-ref.js +213 -0
- package/dist/core/element-ref.js.map +1 -0
- package/dist/core/logger.d.ts +55 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +378 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/output.d.ts +21 -0
- package/dist/core/output.d.ts.map +1 -0
- package/dist/core/output.js +56 -0
- package/dist/core/output.js.map +1 -0
- package/dist/core/report-generator.d.ts +24 -0
- package/dist/core/report-generator.d.ts.map +1 -0
- package/dist/core/report-generator.js +212 -0
- package/dist/core/report-generator.js.map +1 -0
- package/dist/core/session.d.ts +83 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +306 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/timeout.d.ts +49 -0
- package/dist/core/timeout.d.ts.map +1 -0
- package/dist/core/timeout.js +67 -0
- package/dist/core/timeout.js.map +1 -0
- package/dist/core/tool-logger.d.ts +83 -0
- package/dist/core/tool-logger.d.ts.map +1 -0
- package/dist/core/tool-logger.js +453 -0
- package/dist/core/tool-logger.js.map +1 -0
- package/dist/core/validation.d.ts +39 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +93 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +85 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/assert.d.ts +108 -0
- package/dist/tools/assert.d.ts.map +1 -0
- package/dist/tools/assert.js +291 -0
- package/dist/tools/assert.js.map +1 -0
- package/dist/tools/automator.d.ts +45 -0
- package/dist/tools/automator.d.ts.map +1 -0
- package/dist/tools/automator.js +186 -0
- package/dist/tools/automator.js.map +1 -0
- package/dist/tools/element.d.ts +253 -0
- package/dist/tools/element.d.ts.map +1 -0
- package/dist/tools/element.js +615 -0
- package/dist/tools/element.js.map +1 -0
- package/dist/tools/index.d.ts +97 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +1565 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/miniprogram.d.ts +79 -0
- package/dist/tools/miniprogram.d.ts.map +1 -0
- package/dist/tools/miniprogram.js +245 -0
- package/dist/tools/miniprogram.js.map +1 -0
- package/dist/tools/network.d.ts +65 -0
- package/dist/tools/network.d.ts.map +1 -0
- package/dist/tools/network.js +205 -0
- package/dist/tools/network.js.map +1 -0
- package/dist/tools/page.d.ts +108 -0
- package/dist/tools/page.d.ts.map +1 -0
- package/dist/tools/page.js +307 -0
- package/dist/tools/page.js.map +1 -0
- package/dist/tools/record.d.ts +86 -0
- package/dist/tools/record.d.ts.map +1 -0
- package/dist/tools/record.js +316 -0
- package/dist/tools/record.js.map +1 -0
- package/dist/tools/snapshot.d.ts +82 -0
- package/dist/tools/snapshot.d.ts.map +1 -0
- package/dist/tools/snapshot.js +258 -0
- package/dist/tools/snapshot.js.map +1 -0
- package/dist/types.d.ts +240 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/docs/SIMPLE_USAGE.md +210 -0
- package/docs/api/README.md +244 -0
- package/docs/api/assert.md +1015 -0
- package/docs/api/automator.md +345 -0
- package/docs/api/element.md +1454 -0
- package/docs/api/miniprogram.md +558 -0
- package/docs/api/network.md +883 -0
- package/docs/api/page.md +909 -0
- package/docs/api/record.md +963 -0
- package/docs/api/snapshot.md +792 -0
- package/docs/architecture.E-Docs.md +1359 -0
- package/docs/architecture.F1.md +720 -0
- package/docs/architecture.F2.md +871 -0
- package/docs/architecture.F3.md +905 -0
- package/docs/architecture.md +90 -0
- package/docs/charter.A1.align.yaml +170 -0
- package/docs/charter.A2.align.yaml +199 -0
- package/docs/charter.A3.align.yaml +242 -0
- package/docs/charter.A4.align.yaml +227 -0
- package/docs/charter.B1.align.yaml +179 -0
- package/docs/charter.B2.align.yaml +200 -0
- package/docs/charter.B3.align.yaml +200 -0
- package/docs/charter.B4.align.yaml +188 -0
- package/docs/charter.C1.align.yaml +190 -0
- package/docs/charter.C2.align.yaml +202 -0
- package/docs/charter.C3.align.yaml +211 -0
- package/docs/charter.C4.align.yaml +263 -0
- package/docs/charter.C5.align.yaml +220 -0
- package/docs/charter.D1.align.yaml +190 -0
- package/docs/charter.D2.align.yaml +234 -0
- package/docs/charter.D3.align.yaml +206 -0
- package/docs/charter.E-Docs.align.yaml +294 -0
- package/docs/charter.F1.align.yaml +193 -0
- package/docs/charter.F2.align.yaml +248 -0
- package/docs/charter.F3.align.yaml +287 -0
- package/docs/charter.G.align.yaml +174 -0
- package/docs/charter.align.yaml +111 -0
- package/docs/examples/session-report-usage.md +449 -0
- package/docs/maintenance.md +682 -0
- package/docs/playwright-mcp/350/260/203/347/240/224.md +53 -0
- package/docs/setup-guide.md +775 -0
- package/docs/tasks.A1.atomize.md +296 -0
- package/docs/tasks.A2.atomize.md +408 -0
- package/docs/tasks.A3.atomize.md +564 -0
- package/docs/tasks.A4.atomize.md +496 -0
- package/docs/tasks.B1.atomize.md +352 -0
- package/docs/tasks.B2.atomize.md +561 -0
- package/docs/tasks.B3.atomize.md +508 -0
- package/docs/tasks.B4.atomize.md +504 -0
- package/docs/tasks.C1.atomize.md +540 -0
- package/docs/tasks.C2.atomize.md +665 -0
- package/docs/tasks.C3.atomize.md +745 -0
- package/docs/tasks.C4.atomize.md +908 -0
- package/docs/tasks.C5.atomize.md +755 -0
- package/docs/tasks.D1.atomize.md +547 -0
- package/docs/tasks.D2.atomize.md +619 -0
- package/docs/tasks.D3.atomize.md +790 -0
- package/docs/tasks.E-Docs.atomize.md +1204 -0
- package/docs/tasks.atomize.md +189 -0
- package/docs/troubleshooting.md +855 -0
- package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +155 -0
- package/docs//345/274/200/345/217/221/344/273/273/345/212/241/350/256/241/345/210/222.md +110 -0
- package/docs//345/276/256/344/277/241/345/260/217/347/250/213/345/272/217/350/207/252/345/212/250/345/214/226API/345/256/214/346/225/264/346/226/207/346/241/243.md +894 -0
- package/docs//345/276/256/344/277/241/345/260/217/347/250/213/345/272/217/350/207/252/345/212/250/345/214/226/345/256/214/346/225/264/346/223/215/344/275/234/346/211/213/345/206/214.md +1885 -0
- package/docs//346/216/245/345/217/243/346/226/271/346/241/210.md +565 -0
- package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +380 -0
- package/package.json +87 -0
|
@@ -0,0 +1,1565 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool registration for MCP server
|
|
3
|
+
* Registers all automation tools with the MCP server
|
|
4
|
+
*
|
|
5
|
+
* Tool Categories:
|
|
6
|
+
* - Automator (4 tools): Connection and lifecycle management
|
|
7
|
+
* - MiniProgram (6 tools): Mini program-level operations
|
|
8
|
+
* - Page (8 tools): Page-level operations and data access
|
|
9
|
+
* - Element (23 tools): Element-level interactions, properties, and subclass operations
|
|
10
|
+
* - Assert (9 tools): Testing and verification utilities
|
|
11
|
+
* - Snapshot (3 tools): State capture and diagnostic utilities
|
|
12
|
+
* - Record (6 tools): Action recording and replay utilities
|
|
13
|
+
* - Network (6 tools): Network mock and testing utilities
|
|
14
|
+
*
|
|
15
|
+
* Total: 65 tools
|
|
16
|
+
*/
|
|
17
|
+
import { CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
18
|
+
import { ToolLogger } from '../core/tool-logger.js';
|
|
19
|
+
import * as automatorTools from './automator.js';
|
|
20
|
+
import * as miniprogramTools from './miniprogram.js';
|
|
21
|
+
import * as pageTools from './page.js';
|
|
22
|
+
import * as elementTools from './element.js';
|
|
23
|
+
import * as assertTools from './assert.js';
|
|
24
|
+
import * as snapshotTools from './snapshot.js';
|
|
25
|
+
import * as recordTools from './record.js';
|
|
26
|
+
import * as networkTools from './network.js';
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// AUTOMATOR TOOLS (Connection & Lifecycle)
|
|
29
|
+
// ============================================================================
|
|
30
|
+
export const AUTOMATOR_TOOLS = [
|
|
31
|
+
{
|
|
32
|
+
name: 'miniprogram_launch',
|
|
33
|
+
description: 'Launch WeChat Mini Program with automator',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
projectPath: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: 'Path to mini program project directory',
|
|
40
|
+
},
|
|
41
|
+
cliPath: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description: 'Path to WeChat DevTools CLI (optional, auto-detected on macOS)',
|
|
44
|
+
},
|
|
45
|
+
port: {
|
|
46
|
+
type: 'number',
|
|
47
|
+
description: 'Automation port (default: 9420)',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ['projectPath'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'miniprogram_connect',
|
|
55
|
+
description: 'Connect to an already running WeChat DevTools instance',
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
port: {
|
|
60
|
+
type: 'number',
|
|
61
|
+
description: 'Automation port (default: 9420)',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'miniprogram_disconnect',
|
|
68
|
+
description: 'Disconnect from miniprogram but keep IDE running',
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'miniprogram_close',
|
|
76
|
+
description: 'Close current mini program session and cleanup all resources',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
export const AUTOMATOR_TOOL_HANDLERS = {
|
|
84
|
+
miniprogram_launch: automatorTools.launch,
|
|
85
|
+
miniprogram_connect: automatorTools.connect,
|
|
86
|
+
miniprogram_disconnect: automatorTools.disconnect,
|
|
87
|
+
miniprogram_close: automatorTools.close,
|
|
88
|
+
};
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// MINIPROGRAM TOOLS (MiniProgram-level Operations)
|
|
91
|
+
// ============================================================================
|
|
92
|
+
export const MINIPROGRAM_TOOLS = [
|
|
93
|
+
{
|
|
94
|
+
name: 'miniprogram_navigate',
|
|
95
|
+
description: 'Navigate to a page using various navigation methods (navigateTo, redirectTo, reLaunch, switchTab, navigateBack)',
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
method: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
enum: ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab', 'navigateBack'],
|
|
102
|
+
description: 'Navigation method to use',
|
|
103
|
+
},
|
|
104
|
+
url: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: 'Target page URL (required for navigateTo, redirectTo, reLaunch, switchTab)',
|
|
107
|
+
},
|
|
108
|
+
delta: {
|
|
109
|
+
type: 'number',
|
|
110
|
+
description: 'Number of pages to go back (for navigateBack, default: 1)',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
required: ['method'],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'miniprogram_call_wx',
|
|
118
|
+
description: 'Call a WeChat API method (wx.*) in the mini program',
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
method: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'WeChat API method name (e.g., "showToast", "request")',
|
|
125
|
+
},
|
|
126
|
+
args: {
|
|
127
|
+
type: 'array',
|
|
128
|
+
description: 'Arguments to pass to the wx method',
|
|
129
|
+
items: {},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
required: ['method'],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'miniprogram_evaluate',
|
|
137
|
+
description: 'Evaluate JavaScript code in the mini program context',
|
|
138
|
+
inputSchema: {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
expression: {
|
|
142
|
+
type: 'string',
|
|
143
|
+
description: 'JavaScript expression or function to evaluate',
|
|
144
|
+
},
|
|
145
|
+
args: {
|
|
146
|
+
type: 'array',
|
|
147
|
+
description: 'Arguments to pass to the expression',
|
|
148
|
+
items: {},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
required: ['expression'],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'miniprogram_screenshot',
|
|
156
|
+
description: 'Take a screenshot of the mini program',
|
|
157
|
+
inputSchema: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: {
|
|
160
|
+
filename: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
description: 'Custom filename for the screenshot (optional, auto-generated if not provided)',
|
|
163
|
+
},
|
|
164
|
+
fullPage: {
|
|
165
|
+
type: 'boolean',
|
|
166
|
+
description: 'Whether to capture the full page (default: false)',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: 'miniprogram_get_page_stack',
|
|
173
|
+
description: 'Get the current page stack',
|
|
174
|
+
inputSchema: {
|
|
175
|
+
type: 'object',
|
|
176
|
+
properties: {},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'miniprogram_get_system_info',
|
|
181
|
+
description: 'Get system information',
|
|
182
|
+
inputSchema: {
|
|
183
|
+
type: 'object',
|
|
184
|
+
properties: {},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
export const MINIPROGRAM_TOOL_HANDLERS = {
|
|
189
|
+
miniprogram_navigate: miniprogramTools.navigate,
|
|
190
|
+
miniprogram_call_wx: miniprogramTools.callWx,
|
|
191
|
+
miniprogram_evaluate: miniprogramTools.evaluate,
|
|
192
|
+
miniprogram_screenshot: miniprogramTools.screenshot,
|
|
193
|
+
miniprogram_get_page_stack: miniprogramTools.getPageStack,
|
|
194
|
+
miniprogram_get_system_info: miniprogramTools.getSystemInfo,
|
|
195
|
+
};
|
|
196
|
+
// ============================================================================
|
|
197
|
+
// PAGE TOOLS (Page-level Operations)
|
|
198
|
+
// ============================================================================
|
|
199
|
+
export const PAGE_TOOLS = [
|
|
200
|
+
{
|
|
201
|
+
name: 'page_query',
|
|
202
|
+
description: 'Query a single element on the page',
|
|
203
|
+
inputSchema: {
|
|
204
|
+
type: 'object',
|
|
205
|
+
properties: {
|
|
206
|
+
selector: {
|
|
207
|
+
type: 'string',
|
|
208
|
+
description: 'CSS selector to query',
|
|
209
|
+
},
|
|
210
|
+
pagePath: {
|
|
211
|
+
type: 'string',
|
|
212
|
+
description: 'Page path (optional, defaults to current page)',
|
|
213
|
+
},
|
|
214
|
+
save: {
|
|
215
|
+
type: 'boolean',
|
|
216
|
+
description: 'Whether to save element reference (default: true)',
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
required: ['selector'],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'page_query_all',
|
|
224
|
+
description: 'Query all matching elements on the page',
|
|
225
|
+
inputSchema: {
|
|
226
|
+
type: 'object',
|
|
227
|
+
properties: {
|
|
228
|
+
selector: {
|
|
229
|
+
type: 'string',
|
|
230
|
+
description: 'CSS selector to query',
|
|
231
|
+
},
|
|
232
|
+
pagePath: {
|
|
233
|
+
type: 'string',
|
|
234
|
+
description: 'Page path (optional, defaults to current page)',
|
|
235
|
+
},
|
|
236
|
+
save: {
|
|
237
|
+
type: 'boolean',
|
|
238
|
+
description: 'Whether to save element references (default: true)',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
required: ['selector'],
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'page_wait_for',
|
|
246
|
+
description: 'Wait for a condition to be met (selector or timeout)',
|
|
247
|
+
inputSchema: {
|
|
248
|
+
type: 'object',
|
|
249
|
+
properties: {
|
|
250
|
+
condition: {
|
|
251
|
+
description: 'Selector (string) or timeout in ms (number)',
|
|
252
|
+
},
|
|
253
|
+
pagePath: {
|
|
254
|
+
type: 'string',
|
|
255
|
+
description: 'Page path (optional, defaults to current page)',
|
|
256
|
+
},
|
|
257
|
+
timeout: {
|
|
258
|
+
type: 'number',
|
|
259
|
+
description: 'Maximum wait time in ms (optional)',
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
required: ['condition'],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: 'page_get_data',
|
|
267
|
+
description: 'Get page data (optionally at a specific path)',
|
|
268
|
+
inputSchema: {
|
|
269
|
+
type: 'object',
|
|
270
|
+
properties: {
|
|
271
|
+
path: {
|
|
272
|
+
type: 'string',
|
|
273
|
+
description: 'Data path (optional, returns all data if not specified)',
|
|
274
|
+
},
|
|
275
|
+
pagePath: {
|
|
276
|
+
type: 'string',
|
|
277
|
+
description: 'Page path (optional, defaults to current page)',
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'page_set_data',
|
|
284
|
+
description: 'Set page data',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
type: 'object',
|
|
287
|
+
properties: {
|
|
288
|
+
data: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
description: 'Data object to set',
|
|
291
|
+
},
|
|
292
|
+
pagePath: {
|
|
293
|
+
type: 'string',
|
|
294
|
+
description: 'Page path (optional, defaults to current page)',
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
required: ['data'],
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: 'page_call_method',
|
|
302
|
+
description: 'Call a method on the page',
|
|
303
|
+
inputSchema: {
|
|
304
|
+
type: 'object',
|
|
305
|
+
properties: {
|
|
306
|
+
method: {
|
|
307
|
+
type: 'string',
|
|
308
|
+
description: 'Method name to call',
|
|
309
|
+
},
|
|
310
|
+
args: {
|
|
311
|
+
type: 'array',
|
|
312
|
+
description: 'Arguments to pass to the method',
|
|
313
|
+
items: {},
|
|
314
|
+
},
|
|
315
|
+
pagePath: {
|
|
316
|
+
type: 'string',
|
|
317
|
+
description: 'Page path (optional, defaults to current page)',
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
required: ['method'],
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
name: 'page_get_size',
|
|
325
|
+
description: 'Get page size (width, height, scrollHeight)',
|
|
326
|
+
inputSchema: {
|
|
327
|
+
type: 'object',
|
|
328
|
+
properties: {
|
|
329
|
+
pagePath: {
|
|
330
|
+
type: 'string',
|
|
331
|
+
description: 'Page path (optional, defaults to current page)',
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'page_get_scroll_top',
|
|
338
|
+
description: 'Get page scroll position',
|
|
339
|
+
inputSchema: {
|
|
340
|
+
type: 'object',
|
|
341
|
+
properties: {
|
|
342
|
+
pagePath: {
|
|
343
|
+
type: 'string',
|
|
344
|
+
description: 'Page path (optional, defaults to current page)',
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
];
|
|
350
|
+
export const PAGE_TOOL_HANDLERS = {
|
|
351
|
+
page_query: pageTools.query,
|
|
352
|
+
page_query_all: pageTools.queryAll,
|
|
353
|
+
page_wait_for: pageTools.waitFor,
|
|
354
|
+
page_get_data: pageTools.getData,
|
|
355
|
+
page_set_data: pageTools.setData,
|
|
356
|
+
page_call_method: pageTools.callMethod,
|
|
357
|
+
page_get_size: pageTools.getSize,
|
|
358
|
+
page_get_scroll_top: pageTools.getScrollTop,
|
|
359
|
+
};
|
|
360
|
+
// ============================================================================
|
|
361
|
+
// ELEMENT TOOLS (Element-level Interactions)
|
|
362
|
+
// ============================================================================
|
|
363
|
+
export const ELEMENT_TOOLS = [
|
|
364
|
+
{
|
|
365
|
+
name: 'element_tap',
|
|
366
|
+
description: 'Tap (click) an element',
|
|
367
|
+
inputSchema: {
|
|
368
|
+
type: 'object',
|
|
369
|
+
properties: {
|
|
370
|
+
refId: {
|
|
371
|
+
type: 'string',
|
|
372
|
+
description: 'Element reference ID from page_query',
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
required: ['refId'],
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: 'element_longpress',
|
|
380
|
+
description: 'Long press an element',
|
|
381
|
+
inputSchema: {
|
|
382
|
+
type: 'object',
|
|
383
|
+
properties: {
|
|
384
|
+
refId: {
|
|
385
|
+
type: 'string',
|
|
386
|
+
description: 'Element reference ID from page_query',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
required: ['refId'],
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: 'element_input',
|
|
394
|
+
description: 'Input text into an element (input/textarea only)',
|
|
395
|
+
inputSchema: {
|
|
396
|
+
type: 'object',
|
|
397
|
+
properties: {
|
|
398
|
+
refId: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
description: 'Element reference ID from page_query',
|
|
401
|
+
},
|
|
402
|
+
value: {
|
|
403
|
+
type: 'string',
|
|
404
|
+
description: 'Text value to input',
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
required: ['refId', 'value'],
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
name: 'element_get_text',
|
|
412
|
+
description: 'Get element text content',
|
|
413
|
+
inputSchema: {
|
|
414
|
+
type: 'object',
|
|
415
|
+
properties: {
|
|
416
|
+
refId: {
|
|
417
|
+
type: 'string',
|
|
418
|
+
description: 'Element reference ID from page_query',
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
required: ['refId'],
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: 'element_get_attribute',
|
|
426
|
+
description: 'Get element attribute (特性)',
|
|
427
|
+
inputSchema: {
|
|
428
|
+
type: 'object',
|
|
429
|
+
properties: {
|
|
430
|
+
refId: {
|
|
431
|
+
type: 'string',
|
|
432
|
+
description: 'Element reference ID from page_query',
|
|
433
|
+
},
|
|
434
|
+
name: {
|
|
435
|
+
type: 'string',
|
|
436
|
+
description: 'Attribute name to retrieve',
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
required: ['refId', 'name'],
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: 'element_get_property',
|
|
444
|
+
description: 'Get element property (属性)',
|
|
445
|
+
inputSchema: {
|
|
446
|
+
type: 'object',
|
|
447
|
+
properties: {
|
|
448
|
+
refId: {
|
|
449
|
+
type: 'string',
|
|
450
|
+
description: 'Element reference ID from page_query',
|
|
451
|
+
},
|
|
452
|
+
name: {
|
|
453
|
+
type: 'string',
|
|
454
|
+
description: 'Property name to retrieve',
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
required: ['refId', 'name'],
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: 'element_get_value',
|
|
462
|
+
description: 'Get element value',
|
|
463
|
+
inputSchema: {
|
|
464
|
+
type: 'object',
|
|
465
|
+
properties: {
|
|
466
|
+
refId: {
|
|
467
|
+
type: 'string',
|
|
468
|
+
description: 'Element reference ID from page_query',
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
required: ['refId'],
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
name: 'element_get_size',
|
|
476
|
+
description: 'Get element size (width, height)',
|
|
477
|
+
inputSchema: {
|
|
478
|
+
type: 'object',
|
|
479
|
+
properties: {
|
|
480
|
+
refId: {
|
|
481
|
+
type: 'string',
|
|
482
|
+
description: 'Element reference ID from page_query',
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
required: ['refId'],
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: 'element_get_offset',
|
|
490
|
+
description: 'Get element offset (position)',
|
|
491
|
+
inputSchema: {
|
|
492
|
+
type: 'object',
|
|
493
|
+
properties: {
|
|
494
|
+
refId: {
|
|
495
|
+
type: 'string',
|
|
496
|
+
description: 'Element reference ID from page_query',
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
required: ['refId'],
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
name: 'element_trigger',
|
|
504
|
+
description: 'Trigger an event on the element',
|
|
505
|
+
inputSchema: {
|
|
506
|
+
type: 'object',
|
|
507
|
+
properties: {
|
|
508
|
+
refId: {
|
|
509
|
+
type: 'string',
|
|
510
|
+
description: 'Element reference ID from page_query',
|
|
511
|
+
},
|
|
512
|
+
type: {
|
|
513
|
+
type: 'string',
|
|
514
|
+
description: 'Event type to trigger',
|
|
515
|
+
},
|
|
516
|
+
detail: {
|
|
517
|
+
type: 'object',
|
|
518
|
+
description: 'Event detail data (optional)',
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
required: ['refId', 'type'],
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: 'element_get_style',
|
|
526
|
+
description: 'Get element style value',
|
|
527
|
+
inputSchema: {
|
|
528
|
+
type: 'object',
|
|
529
|
+
properties: {
|
|
530
|
+
refId: {
|
|
531
|
+
type: 'string',
|
|
532
|
+
description: 'Element reference ID from page_query',
|
|
533
|
+
},
|
|
534
|
+
name: {
|
|
535
|
+
type: 'string',
|
|
536
|
+
description: 'Style property name to retrieve',
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
required: ['refId', 'name'],
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
name: 'element_touchstart',
|
|
544
|
+
description: 'Touch start on element',
|
|
545
|
+
inputSchema: {
|
|
546
|
+
type: 'object',
|
|
547
|
+
properties: {
|
|
548
|
+
refId: {
|
|
549
|
+
type: 'string',
|
|
550
|
+
description: 'Element reference ID from page_query',
|
|
551
|
+
},
|
|
552
|
+
touches: {
|
|
553
|
+
type: 'array',
|
|
554
|
+
description: 'Touch points currently on screen',
|
|
555
|
+
},
|
|
556
|
+
changedTouches: {
|
|
557
|
+
type: 'array',
|
|
558
|
+
description: 'Changed touch points',
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
required: ['refId', 'touches', 'changedTouches'],
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: 'element_touchmove',
|
|
566
|
+
description: 'Touch move on element',
|
|
567
|
+
inputSchema: {
|
|
568
|
+
type: 'object',
|
|
569
|
+
properties: {
|
|
570
|
+
refId: {
|
|
571
|
+
type: 'string',
|
|
572
|
+
description: 'Element reference ID from page_query',
|
|
573
|
+
},
|
|
574
|
+
touches: {
|
|
575
|
+
type: 'array',
|
|
576
|
+
description: 'Touch points currently on screen',
|
|
577
|
+
},
|
|
578
|
+
changedTouches: {
|
|
579
|
+
type: 'array',
|
|
580
|
+
description: 'Changed touch points',
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
required: ['refId', 'touches', 'changedTouches'],
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
name: 'element_touchend',
|
|
588
|
+
description: 'Touch end on element',
|
|
589
|
+
inputSchema: {
|
|
590
|
+
type: 'object',
|
|
591
|
+
properties: {
|
|
592
|
+
refId: {
|
|
593
|
+
type: 'string',
|
|
594
|
+
description: 'Element reference ID from page_query',
|
|
595
|
+
},
|
|
596
|
+
touches: {
|
|
597
|
+
type: 'array',
|
|
598
|
+
description: 'Touch points currently on screen',
|
|
599
|
+
},
|
|
600
|
+
changedTouches: {
|
|
601
|
+
type: 'array',
|
|
602
|
+
description: 'Changed touch points',
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
required: ['refId', 'touches', 'changedTouches'],
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
name: 'element_scroll_to',
|
|
610
|
+
description: 'Scroll to position (ScrollView only)',
|
|
611
|
+
inputSchema: {
|
|
612
|
+
type: 'object',
|
|
613
|
+
properties: {
|
|
614
|
+
refId: {
|
|
615
|
+
type: 'string',
|
|
616
|
+
description: 'Element reference ID from page_query',
|
|
617
|
+
},
|
|
618
|
+
x: {
|
|
619
|
+
type: 'number',
|
|
620
|
+
description: 'X coordinate',
|
|
621
|
+
},
|
|
622
|
+
y: {
|
|
623
|
+
type: 'number',
|
|
624
|
+
description: 'Y coordinate',
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
required: ['refId', 'x', 'y'],
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
name: 'element_scroll_width',
|
|
632
|
+
description: 'Get scroll width (ScrollView only)',
|
|
633
|
+
inputSchema: {
|
|
634
|
+
type: 'object',
|
|
635
|
+
properties: {
|
|
636
|
+
refId: {
|
|
637
|
+
type: 'string',
|
|
638
|
+
description: 'Element reference ID from page_query',
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
required: ['refId'],
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
name: 'element_scroll_height',
|
|
646
|
+
description: 'Get scroll height (ScrollView only)',
|
|
647
|
+
inputSchema: {
|
|
648
|
+
type: 'object',
|
|
649
|
+
properties: {
|
|
650
|
+
refId: {
|
|
651
|
+
type: 'string',
|
|
652
|
+
description: 'Element reference ID from page_query',
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
required: ['refId'],
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
name: 'element_swipe_to',
|
|
660
|
+
description: 'Swipe to index (Swiper only)',
|
|
661
|
+
inputSchema: {
|
|
662
|
+
type: 'object',
|
|
663
|
+
properties: {
|
|
664
|
+
refId: {
|
|
665
|
+
type: 'string',
|
|
666
|
+
description: 'Element reference ID from page_query',
|
|
667
|
+
},
|
|
668
|
+
index: {
|
|
669
|
+
type: 'number',
|
|
670
|
+
description: 'Target swiper index',
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
required: ['refId', 'index'],
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
name: 'element_move_to',
|
|
678
|
+
description: 'Move to position (MovableView only)',
|
|
679
|
+
inputSchema: {
|
|
680
|
+
type: 'object',
|
|
681
|
+
properties: {
|
|
682
|
+
refId: {
|
|
683
|
+
type: 'string',
|
|
684
|
+
description: 'Element reference ID from page_query',
|
|
685
|
+
},
|
|
686
|
+
x: {
|
|
687
|
+
type: 'number',
|
|
688
|
+
description: 'X coordinate',
|
|
689
|
+
},
|
|
690
|
+
y: {
|
|
691
|
+
type: 'number',
|
|
692
|
+
description: 'Y coordinate',
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
required: ['refId', 'x', 'y'],
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
name: 'element_slide_to',
|
|
700
|
+
description: 'Slide to value (Slider only)',
|
|
701
|
+
inputSchema: {
|
|
702
|
+
type: 'object',
|
|
703
|
+
properties: {
|
|
704
|
+
refId: {
|
|
705
|
+
type: 'string',
|
|
706
|
+
description: 'Element reference ID from page_query',
|
|
707
|
+
},
|
|
708
|
+
value: {
|
|
709
|
+
type: 'number',
|
|
710
|
+
description: 'Target slider value',
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
required: ['refId', 'value'],
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
name: 'element_call_context_method',
|
|
718
|
+
description: 'Call context method (ContextElement only)',
|
|
719
|
+
inputSchema: {
|
|
720
|
+
type: 'object',
|
|
721
|
+
properties: {
|
|
722
|
+
refId: {
|
|
723
|
+
type: 'string',
|
|
724
|
+
description: 'Element reference ID from page_query',
|
|
725
|
+
},
|
|
726
|
+
method: {
|
|
727
|
+
type: 'string',
|
|
728
|
+
description: 'Context method name',
|
|
729
|
+
},
|
|
730
|
+
args: {
|
|
731
|
+
type: 'array',
|
|
732
|
+
description: 'Arguments to pass to the method',
|
|
733
|
+
items: {},
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
required: ['refId', 'method'],
|
|
737
|
+
},
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
name: 'element_set_data',
|
|
741
|
+
description: 'Set data on custom element (CustomElement only)',
|
|
742
|
+
inputSchema: {
|
|
743
|
+
type: 'object',
|
|
744
|
+
properties: {
|
|
745
|
+
refId: {
|
|
746
|
+
type: 'string',
|
|
747
|
+
description: 'Element reference ID from page_query',
|
|
748
|
+
},
|
|
749
|
+
data: {
|
|
750
|
+
type: 'object',
|
|
751
|
+
description: 'Data object to set',
|
|
752
|
+
},
|
|
753
|
+
},
|
|
754
|
+
required: ['refId', 'data'],
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
name: 'element_call_method',
|
|
759
|
+
description: 'Call method on custom element (CustomElement only)',
|
|
760
|
+
inputSchema: {
|
|
761
|
+
type: 'object',
|
|
762
|
+
properties: {
|
|
763
|
+
refId: {
|
|
764
|
+
type: 'string',
|
|
765
|
+
description: 'Element reference ID from page_query',
|
|
766
|
+
},
|
|
767
|
+
method: {
|
|
768
|
+
type: 'string',
|
|
769
|
+
description: 'Method name',
|
|
770
|
+
},
|
|
771
|
+
args: {
|
|
772
|
+
type: 'array',
|
|
773
|
+
description: 'Arguments to pass to the method',
|
|
774
|
+
items: {},
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
required: ['refId', 'method'],
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
];
|
|
781
|
+
export const ELEMENT_TOOL_HANDLERS = {
|
|
782
|
+
element_tap: elementTools.tap,
|
|
783
|
+
element_longpress: elementTools.longpress,
|
|
784
|
+
element_input: elementTools.input,
|
|
785
|
+
element_get_text: elementTools.getText,
|
|
786
|
+
element_get_attribute: elementTools.getAttribute,
|
|
787
|
+
element_get_property: elementTools.getProperty,
|
|
788
|
+
element_get_value: elementTools.getValue,
|
|
789
|
+
element_get_size: elementTools.getSize,
|
|
790
|
+
element_get_offset: elementTools.getOffset,
|
|
791
|
+
element_trigger: elementTools.trigger,
|
|
792
|
+
element_get_style: elementTools.getStyle,
|
|
793
|
+
element_touchstart: elementTools.touchstart,
|
|
794
|
+
element_touchmove: elementTools.touchmove,
|
|
795
|
+
element_touchend: elementTools.touchend,
|
|
796
|
+
element_scroll_to: elementTools.scrollTo,
|
|
797
|
+
element_scroll_width: elementTools.scrollWidth,
|
|
798
|
+
element_scroll_height: elementTools.scrollHeight,
|
|
799
|
+
element_swipe_to: elementTools.swipeTo,
|
|
800
|
+
element_move_to: elementTools.moveTo,
|
|
801
|
+
element_slide_to: elementTools.slideTo,
|
|
802
|
+
element_call_context_method: elementTools.callContextMethod,
|
|
803
|
+
element_set_data: elementTools.setData,
|
|
804
|
+
element_call_method: elementTools.callMethod,
|
|
805
|
+
};
|
|
806
|
+
// ============================================================================
|
|
807
|
+
// ASSERT TOOLS (Testing & Verification)
|
|
808
|
+
// ============================================================================
|
|
809
|
+
export const ASSERT_TOOLS = [
|
|
810
|
+
{
|
|
811
|
+
name: 'assert_exists',
|
|
812
|
+
description: 'Assert that an element exists on the page',
|
|
813
|
+
inputSchema: {
|
|
814
|
+
type: 'object',
|
|
815
|
+
properties: {
|
|
816
|
+
selector: {
|
|
817
|
+
type: 'string',
|
|
818
|
+
description: 'CSS selector for the element',
|
|
819
|
+
},
|
|
820
|
+
pagePath: {
|
|
821
|
+
type: 'string',
|
|
822
|
+
description: 'Page path (optional, defaults to current page)',
|
|
823
|
+
},
|
|
824
|
+
},
|
|
825
|
+
required: ['selector'],
|
|
826
|
+
},
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
name: 'assert_not_exists',
|
|
830
|
+
description: 'Assert that an element does not exist on the page',
|
|
831
|
+
inputSchema: {
|
|
832
|
+
type: 'object',
|
|
833
|
+
properties: {
|
|
834
|
+
selector: {
|
|
835
|
+
type: 'string',
|
|
836
|
+
description: 'CSS selector for the element',
|
|
837
|
+
},
|
|
838
|
+
pagePath: {
|
|
839
|
+
type: 'string',
|
|
840
|
+
description: 'Page path (optional, defaults to current page)',
|
|
841
|
+
},
|
|
842
|
+
},
|
|
843
|
+
required: ['selector'],
|
|
844
|
+
},
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
name: 'assert_text',
|
|
848
|
+
description: 'Assert element text equals expected value',
|
|
849
|
+
inputSchema: {
|
|
850
|
+
type: 'object',
|
|
851
|
+
properties: {
|
|
852
|
+
refId: {
|
|
853
|
+
type: 'string',
|
|
854
|
+
description: 'Element reference ID from page_query',
|
|
855
|
+
},
|
|
856
|
+
expected: {
|
|
857
|
+
type: 'string',
|
|
858
|
+
description: 'Expected text value',
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
required: ['refId', 'expected'],
|
|
862
|
+
},
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
name: 'assert_text_contains',
|
|
866
|
+
description: 'Assert element text contains expected substring',
|
|
867
|
+
inputSchema: {
|
|
868
|
+
type: 'object',
|
|
869
|
+
properties: {
|
|
870
|
+
refId: {
|
|
871
|
+
type: 'string',
|
|
872
|
+
description: 'Element reference ID from page_query',
|
|
873
|
+
},
|
|
874
|
+
expected: {
|
|
875
|
+
type: 'string',
|
|
876
|
+
description: 'Expected substring',
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
required: ['refId', 'expected'],
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: 'assert_value',
|
|
884
|
+
description: 'Assert element value equals expected value',
|
|
885
|
+
inputSchema: {
|
|
886
|
+
type: 'object',
|
|
887
|
+
properties: {
|
|
888
|
+
refId: {
|
|
889
|
+
type: 'string',
|
|
890
|
+
description: 'Element reference ID from page_query',
|
|
891
|
+
},
|
|
892
|
+
expected: {
|
|
893
|
+
type: 'string',
|
|
894
|
+
description: 'Expected value',
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
required: ['refId', 'expected'],
|
|
898
|
+
},
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
name: 'assert_attribute',
|
|
902
|
+
description: 'Assert element attribute equals expected value',
|
|
903
|
+
inputSchema: {
|
|
904
|
+
type: 'object',
|
|
905
|
+
properties: {
|
|
906
|
+
refId: {
|
|
907
|
+
type: 'string',
|
|
908
|
+
description: 'Element reference ID from page_query',
|
|
909
|
+
},
|
|
910
|
+
name: {
|
|
911
|
+
type: 'string',
|
|
912
|
+
description: 'Attribute name',
|
|
913
|
+
},
|
|
914
|
+
expected: {
|
|
915
|
+
type: 'string',
|
|
916
|
+
description: 'Expected attribute value',
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
required: ['refId', 'name', 'expected'],
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
name: 'assert_property',
|
|
924
|
+
description: 'Assert element property equals expected value',
|
|
925
|
+
inputSchema: {
|
|
926
|
+
type: 'object',
|
|
927
|
+
properties: {
|
|
928
|
+
refId: {
|
|
929
|
+
type: 'string',
|
|
930
|
+
description: 'Element reference ID from page_query',
|
|
931
|
+
},
|
|
932
|
+
name: {
|
|
933
|
+
type: 'string',
|
|
934
|
+
description: 'Property name',
|
|
935
|
+
},
|
|
936
|
+
expected: {
|
|
937
|
+
description: 'Expected property value (any type)',
|
|
938
|
+
},
|
|
939
|
+
},
|
|
940
|
+
required: ['refId', 'name', 'expected'],
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
name: 'assert_data',
|
|
945
|
+
description: 'Assert page data equals expected value',
|
|
946
|
+
inputSchema: {
|
|
947
|
+
type: 'object',
|
|
948
|
+
properties: {
|
|
949
|
+
path: {
|
|
950
|
+
type: 'string',
|
|
951
|
+
description: 'Data path (optional, for nested data)',
|
|
952
|
+
},
|
|
953
|
+
expected: {
|
|
954
|
+
description: 'Expected data value (any type)',
|
|
955
|
+
},
|
|
956
|
+
pagePath: {
|
|
957
|
+
type: 'string',
|
|
958
|
+
description: 'Page path (optional, defaults to current page)',
|
|
959
|
+
},
|
|
960
|
+
},
|
|
961
|
+
required: ['expected'],
|
|
962
|
+
},
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
name: 'assert_visible',
|
|
966
|
+
description: 'Assert element is visible (has non-zero size)',
|
|
967
|
+
inputSchema: {
|
|
968
|
+
type: 'object',
|
|
969
|
+
properties: {
|
|
970
|
+
refId: {
|
|
971
|
+
type: 'string',
|
|
972
|
+
description: 'Element reference ID from page_query',
|
|
973
|
+
},
|
|
974
|
+
},
|
|
975
|
+
required: ['refId'],
|
|
976
|
+
},
|
|
977
|
+
},
|
|
978
|
+
];
|
|
979
|
+
export const ASSERT_TOOL_HANDLERS = {
|
|
980
|
+
assert_exists: assertTools.assertExists,
|
|
981
|
+
assert_not_exists: assertTools.assertNotExists,
|
|
982
|
+
assert_text: assertTools.assertText,
|
|
983
|
+
assert_text_contains: assertTools.assertTextContains,
|
|
984
|
+
assert_value: assertTools.assertValue,
|
|
985
|
+
assert_attribute: assertTools.assertAttribute,
|
|
986
|
+
assert_property: assertTools.assertProperty,
|
|
987
|
+
assert_data: assertTools.assertData,
|
|
988
|
+
assert_visible: assertTools.assertVisible,
|
|
989
|
+
};
|
|
990
|
+
// ============================================================================
|
|
991
|
+
// SNAPSHOT TOOLS (State Capture & Diagnostics)
|
|
992
|
+
// ============================================================================
|
|
993
|
+
export const SNAPSHOT_TOOLS = [
|
|
994
|
+
{
|
|
995
|
+
name: 'snapshot_page',
|
|
996
|
+
description: 'Capture complete page snapshot (data + screenshot)',
|
|
997
|
+
inputSchema: {
|
|
998
|
+
type: 'object',
|
|
999
|
+
properties: {
|
|
1000
|
+
pagePath: {
|
|
1001
|
+
type: 'string',
|
|
1002
|
+
description: 'Page path (optional, defaults to current page)',
|
|
1003
|
+
},
|
|
1004
|
+
filename: {
|
|
1005
|
+
type: 'string',
|
|
1006
|
+
description: 'Output filename (optional, auto-generated if not provided)',
|
|
1007
|
+
},
|
|
1008
|
+
includeScreenshot: {
|
|
1009
|
+
type: 'boolean',
|
|
1010
|
+
description: 'Whether to include screenshot (default: true)',
|
|
1011
|
+
},
|
|
1012
|
+
fullPage: {
|
|
1013
|
+
type: 'boolean',
|
|
1014
|
+
description: 'Whether to capture full page or viewport only (default: false)',
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
name: 'snapshot_full',
|
|
1021
|
+
description: 'Capture complete application snapshot (system info + page stack + current page)',
|
|
1022
|
+
inputSchema: {
|
|
1023
|
+
type: 'object',
|
|
1024
|
+
properties: {
|
|
1025
|
+
filename: {
|
|
1026
|
+
type: 'string',
|
|
1027
|
+
description: 'Output filename (optional, auto-generated if not provided)',
|
|
1028
|
+
},
|
|
1029
|
+
includeScreenshot: {
|
|
1030
|
+
type: 'boolean',
|
|
1031
|
+
description: 'Whether to include screenshot (default: true)',
|
|
1032
|
+
},
|
|
1033
|
+
fullPage: {
|
|
1034
|
+
type: 'boolean',
|
|
1035
|
+
description: 'Whether to capture full page or viewport only (default: false)',
|
|
1036
|
+
},
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
name: 'snapshot_element',
|
|
1042
|
+
description: 'Capture element snapshot (properties + optional screenshot)',
|
|
1043
|
+
inputSchema: {
|
|
1044
|
+
type: 'object',
|
|
1045
|
+
properties: {
|
|
1046
|
+
refId: {
|
|
1047
|
+
type: 'string',
|
|
1048
|
+
description: 'Element reference ID from page_query',
|
|
1049
|
+
},
|
|
1050
|
+
filename: {
|
|
1051
|
+
type: 'string',
|
|
1052
|
+
description: 'Output filename (optional, auto-generated if not provided)',
|
|
1053
|
+
},
|
|
1054
|
+
includeScreenshot: {
|
|
1055
|
+
type: 'boolean',
|
|
1056
|
+
description: 'Whether to include screenshot (default: false)',
|
|
1057
|
+
},
|
|
1058
|
+
},
|
|
1059
|
+
required: ['refId'],
|
|
1060
|
+
},
|
|
1061
|
+
},
|
|
1062
|
+
];
|
|
1063
|
+
export const SNAPSHOT_TOOL_HANDLERS = {
|
|
1064
|
+
snapshot_page: snapshotTools.snapshotPage,
|
|
1065
|
+
snapshot_full: snapshotTools.snapshotFull,
|
|
1066
|
+
snapshot_element: snapshotTools.snapshotElement,
|
|
1067
|
+
};
|
|
1068
|
+
// ============================================================================
|
|
1069
|
+
// RECORD TOOLS (Recording & Replay)
|
|
1070
|
+
// ============================================================================
|
|
1071
|
+
export const RECORD_TOOLS = [
|
|
1072
|
+
{
|
|
1073
|
+
name: 'record_start',
|
|
1074
|
+
description: 'Start recording user actions for later replay',
|
|
1075
|
+
inputSchema: {
|
|
1076
|
+
type: 'object',
|
|
1077
|
+
properties: {
|
|
1078
|
+
name: {
|
|
1079
|
+
type: 'string',
|
|
1080
|
+
description: 'Name for this recording sequence',
|
|
1081
|
+
},
|
|
1082
|
+
description: {
|
|
1083
|
+
type: 'string',
|
|
1084
|
+
description: 'Optional description of what this sequence does',
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
name: 'record_stop',
|
|
1091
|
+
description: 'Stop the current recording and save the sequence',
|
|
1092
|
+
inputSchema: {
|
|
1093
|
+
type: 'object',
|
|
1094
|
+
properties: {
|
|
1095
|
+
save: {
|
|
1096
|
+
type: 'boolean',
|
|
1097
|
+
description: 'Whether to save the sequence (default: true)',
|
|
1098
|
+
},
|
|
1099
|
+
},
|
|
1100
|
+
},
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
name: 'record_list',
|
|
1104
|
+
description: 'List all saved action sequences',
|
|
1105
|
+
inputSchema: {
|
|
1106
|
+
type: 'object',
|
|
1107
|
+
properties: {},
|
|
1108
|
+
},
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
name: 'record_get',
|
|
1112
|
+
description: 'Get details of a specific sequence',
|
|
1113
|
+
inputSchema: {
|
|
1114
|
+
type: 'object',
|
|
1115
|
+
properties: {
|
|
1116
|
+
sequenceId: {
|
|
1117
|
+
type: 'string',
|
|
1118
|
+
description: 'ID of the sequence to retrieve',
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
required: ['sequenceId'],
|
|
1122
|
+
},
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
name: 'record_delete',
|
|
1126
|
+
description: 'Delete a saved sequence',
|
|
1127
|
+
inputSchema: {
|
|
1128
|
+
type: 'object',
|
|
1129
|
+
properties: {
|
|
1130
|
+
sequenceId: {
|
|
1131
|
+
type: 'string',
|
|
1132
|
+
description: 'ID of the sequence to delete',
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
required: ['sequenceId'],
|
|
1136
|
+
},
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
name: 'record_replay',
|
|
1140
|
+
description: 'Replay a recorded action sequence',
|
|
1141
|
+
inputSchema: {
|
|
1142
|
+
type: 'object',
|
|
1143
|
+
properties: {
|
|
1144
|
+
sequenceId: {
|
|
1145
|
+
type: 'string',
|
|
1146
|
+
description: 'ID of the sequence to replay',
|
|
1147
|
+
},
|
|
1148
|
+
continueOnError: {
|
|
1149
|
+
type: 'boolean',
|
|
1150
|
+
description: 'Whether to continue replaying if an action fails (default: false)',
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
required: ['sequenceId'],
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
];
|
|
1157
|
+
export const RECORD_TOOL_HANDLERS = {
|
|
1158
|
+
record_start: recordTools.startRecording,
|
|
1159
|
+
record_stop: recordTools.stopRecording,
|
|
1160
|
+
record_list: recordTools.listSequences,
|
|
1161
|
+
record_get: recordTools.getSequence,
|
|
1162
|
+
record_delete: recordTools.deleteSequence,
|
|
1163
|
+
record_replay: recordTools.replaySequence,
|
|
1164
|
+
};
|
|
1165
|
+
// ============================================================================
|
|
1166
|
+
// NETWORK TOOLS (Network Mock & Testing)
|
|
1167
|
+
// ============================================================================
|
|
1168
|
+
export const NETWORK_TOOLS = [
|
|
1169
|
+
{
|
|
1170
|
+
name: 'network_mock_wx_method',
|
|
1171
|
+
description: 'Mock a WeChat API method (wx.*) for testing',
|
|
1172
|
+
inputSchema: {
|
|
1173
|
+
type: 'object',
|
|
1174
|
+
properties: {
|
|
1175
|
+
method: {
|
|
1176
|
+
type: 'string',
|
|
1177
|
+
description: 'WeChat API method name (e.g., "request", "getStorage")',
|
|
1178
|
+
},
|
|
1179
|
+
result: {
|
|
1180
|
+
description: 'Mock result to return',
|
|
1181
|
+
},
|
|
1182
|
+
type: {
|
|
1183
|
+
type: 'string',
|
|
1184
|
+
enum: ['success', 'fail'],
|
|
1185
|
+
description: 'Whether to mock as success or failure (default: success)',
|
|
1186
|
+
},
|
|
1187
|
+
},
|
|
1188
|
+
required: ['method', 'result'],
|
|
1189
|
+
},
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
name: 'network_restore_wx_method',
|
|
1193
|
+
description: 'Restore a previously mocked WeChat API method',
|
|
1194
|
+
inputSchema: {
|
|
1195
|
+
type: 'object',
|
|
1196
|
+
properties: {
|
|
1197
|
+
method: {
|
|
1198
|
+
type: 'string',
|
|
1199
|
+
description: 'WeChat API method name to restore',
|
|
1200
|
+
},
|
|
1201
|
+
},
|
|
1202
|
+
required: ['method'],
|
|
1203
|
+
},
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
name: 'network_mock_request',
|
|
1207
|
+
description: 'Mock wx.request to return specific data (convenience wrapper)',
|
|
1208
|
+
inputSchema: {
|
|
1209
|
+
type: 'object',
|
|
1210
|
+
properties: {
|
|
1211
|
+
data: {
|
|
1212
|
+
description: 'Response data to return (default: {})',
|
|
1213
|
+
},
|
|
1214
|
+
statusCode: {
|
|
1215
|
+
type: 'number',
|
|
1216
|
+
description: 'HTTP status code (default: 200)',
|
|
1217
|
+
},
|
|
1218
|
+
header: {
|
|
1219
|
+
type: 'object',
|
|
1220
|
+
description: 'Response headers (default: {})',
|
|
1221
|
+
},
|
|
1222
|
+
type: {
|
|
1223
|
+
type: 'string',
|
|
1224
|
+
enum: ['success', 'fail'],
|
|
1225
|
+
description: 'Whether to mock as success or failure (default: success)',
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
},
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
name: 'network_mock_request_failure',
|
|
1232
|
+
description: 'Mock wx.request to fail with specific error',
|
|
1233
|
+
inputSchema: {
|
|
1234
|
+
type: 'object',
|
|
1235
|
+
properties: {
|
|
1236
|
+
errMsg: {
|
|
1237
|
+
type: 'string',
|
|
1238
|
+
description: 'Error message (default: "request:fail")',
|
|
1239
|
+
},
|
|
1240
|
+
errno: {
|
|
1241
|
+
type: 'number',
|
|
1242
|
+
description: 'Error code (default: -1)',
|
|
1243
|
+
},
|
|
1244
|
+
},
|
|
1245
|
+
},
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
name: 'network_restore_request',
|
|
1249
|
+
description: 'Restore wx.request to original behavior',
|
|
1250
|
+
inputSchema: {
|
|
1251
|
+
type: 'object',
|
|
1252
|
+
properties: {},
|
|
1253
|
+
},
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
name: 'network_restore_all_mocks',
|
|
1257
|
+
description: 'Restore all mocked WeChat API methods at once',
|
|
1258
|
+
inputSchema: {
|
|
1259
|
+
type: 'object',
|
|
1260
|
+
properties: {},
|
|
1261
|
+
},
|
|
1262
|
+
},
|
|
1263
|
+
];
|
|
1264
|
+
export const NETWORK_TOOL_HANDLERS = {
|
|
1265
|
+
network_mock_wx_method: networkTools.mockWxMethod,
|
|
1266
|
+
network_restore_wx_method: networkTools.restoreWxMethod,
|
|
1267
|
+
network_mock_request: networkTools.mockRequest,
|
|
1268
|
+
network_mock_request_failure: networkTools.mockRequestFailure,
|
|
1269
|
+
network_restore_request: networkTools.restoreRequest,
|
|
1270
|
+
network_restore_all_mocks: networkTools.restoreAllMocks,
|
|
1271
|
+
};
|
|
1272
|
+
// ============================================================================
|
|
1273
|
+
// TOOL CATEGORIES
|
|
1274
|
+
// ============================================================================
|
|
1275
|
+
export const TOOL_CATEGORIES = {
|
|
1276
|
+
automator: {
|
|
1277
|
+
name: 'Automator',
|
|
1278
|
+
description: 'Connection and lifecycle management (4 tools)',
|
|
1279
|
+
tools: AUTOMATOR_TOOLS,
|
|
1280
|
+
handlers: AUTOMATOR_TOOL_HANDLERS,
|
|
1281
|
+
},
|
|
1282
|
+
miniprogram: {
|
|
1283
|
+
name: 'MiniProgram',
|
|
1284
|
+
description: 'Mini program-level operations (6 tools)',
|
|
1285
|
+
tools: MINIPROGRAM_TOOLS,
|
|
1286
|
+
handlers: MINIPROGRAM_TOOL_HANDLERS,
|
|
1287
|
+
},
|
|
1288
|
+
page: {
|
|
1289
|
+
name: 'Page',
|
|
1290
|
+
description: 'Page-level operations and data access (8 tools)',
|
|
1291
|
+
tools: PAGE_TOOLS,
|
|
1292
|
+
handlers: PAGE_TOOL_HANDLERS,
|
|
1293
|
+
},
|
|
1294
|
+
element: {
|
|
1295
|
+
name: 'Element',
|
|
1296
|
+
description: 'Element-level interactions and properties (23 tools)',
|
|
1297
|
+
tools: ELEMENT_TOOLS,
|
|
1298
|
+
handlers: ELEMENT_TOOL_HANDLERS,
|
|
1299
|
+
},
|
|
1300
|
+
assert: {
|
|
1301
|
+
name: 'Assert',
|
|
1302
|
+
description: 'Testing and verification utilities (9 tools)',
|
|
1303
|
+
tools: ASSERT_TOOLS,
|
|
1304
|
+
handlers: ASSERT_TOOL_HANDLERS,
|
|
1305
|
+
},
|
|
1306
|
+
snapshot: {
|
|
1307
|
+
name: 'Snapshot',
|
|
1308
|
+
description: 'State capture and diagnostic utilities (3 tools)',
|
|
1309
|
+
tools: SNAPSHOT_TOOLS,
|
|
1310
|
+
handlers: SNAPSHOT_TOOL_HANDLERS,
|
|
1311
|
+
},
|
|
1312
|
+
record: {
|
|
1313
|
+
name: 'Record',
|
|
1314
|
+
description: 'Action recording and replay utilities (6 tools)',
|
|
1315
|
+
tools: RECORD_TOOLS,
|
|
1316
|
+
handlers: RECORD_TOOL_HANDLERS,
|
|
1317
|
+
},
|
|
1318
|
+
network: {
|
|
1319
|
+
name: 'Network',
|
|
1320
|
+
description: 'Network mock and testing utilities (6 tools)',
|
|
1321
|
+
tools: NETWORK_TOOLS,
|
|
1322
|
+
handlers: NETWORK_TOOL_HANDLERS,
|
|
1323
|
+
},
|
|
1324
|
+
};
|
|
1325
|
+
// ============================================================================
|
|
1326
|
+
// CORE TOOLS (All tools combined for backward compatibility)
|
|
1327
|
+
// ============================================================================
|
|
1328
|
+
export const CORE_TOOLS = [
|
|
1329
|
+
...AUTOMATOR_TOOLS,
|
|
1330
|
+
...MINIPROGRAM_TOOLS,
|
|
1331
|
+
...PAGE_TOOLS,
|
|
1332
|
+
...ELEMENT_TOOLS,
|
|
1333
|
+
...ASSERT_TOOLS,
|
|
1334
|
+
...SNAPSHOT_TOOLS,
|
|
1335
|
+
...RECORD_TOOLS,
|
|
1336
|
+
...NETWORK_TOOLS,
|
|
1337
|
+
];
|
|
1338
|
+
export const CORE_TOOL_HANDLERS = {
|
|
1339
|
+
...AUTOMATOR_TOOL_HANDLERS,
|
|
1340
|
+
...MINIPROGRAM_TOOL_HANDLERS,
|
|
1341
|
+
...PAGE_TOOL_HANDLERS,
|
|
1342
|
+
...ELEMENT_TOOL_HANDLERS,
|
|
1343
|
+
...ASSERT_TOOL_HANDLERS,
|
|
1344
|
+
...SNAPSHOT_TOOL_HANDLERS,
|
|
1345
|
+
...RECORD_TOOL_HANDLERS,
|
|
1346
|
+
...NETWORK_TOOL_HANDLERS,
|
|
1347
|
+
};
|
|
1348
|
+
// ============================================================================
|
|
1349
|
+
// TOOL VALIDATION AND UTILITIES
|
|
1350
|
+
// ============================================================================
|
|
1351
|
+
/**
|
|
1352
|
+
* Validate that all tool definitions have corresponding handlers
|
|
1353
|
+
*/
|
|
1354
|
+
export function validateToolRegistration() {
|
|
1355
|
+
const errors = [];
|
|
1356
|
+
for (const tool of CORE_TOOLS) {
|
|
1357
|
+
if (!CORE_TOOL_HANDLERS[tool.name]) {
|
|
1358
|
+
errors.push(`Missing handler for tool: ${tool.name}`);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
for (const handlerName in CORE_TOOL_HANDLERS) {
|
|
1362
|
+
const hasTool = CORE_TOOLS.some((t) => t.name === handlerName);
|
|
1363
|
+
if (!hasTool) {
|
|
1364
|
+
errors.push(`Handler without tool definition: ${handlerName}`);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
return {
|
|
1368
|
+
valid: errors.length === 0,
|
|
1369
|
+
errors,
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Get tool statistics
|
|
1374
|
+
*/
|
|
1375
|
+
export function getToolStats() {
|
|
1376
|
+
return {
|
|
1377
|
+
total: CORE_TOOLS.length,
|
|
1378
|
+
categories: {
|
|
1379
|
+
automator: AUTOMATOR_TOOLS.length,
|
|
1380
|
+
miniprogram: MINIPROGRAM_TOOLS.length,
|
|
1381
|
+
page: PAGE_TOOLS.length,
|
|
1382
|
+
element: ELEMENT_TOOLS.length,
|
|
1383
|
+
assert: ASSERT_TOOLS.length,
|
|
1384
|
+
snapshot: SNAPSHOT_TOOLS.length,
|
|
1385
|
+
record: RECORD_TOOLS.length,
|
|
1386
|
+
network: NETWORK_TOOLS.length,
|
|
1387
|
+
},
|
|
1388
|
+
handlers: Object.keys(CORE_TOOL_HANDLERS).length,
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Get tool by name
|
|
1393
|
+
*/
|
|
1394
|
+
export function getToolByName(name) {
|
|
1395
|
+
return CORE_TOOLS.find((t) => t.name === name);
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Get tools by category
|
|
1399
|
+
*/
|
|
1400
|
+
export function getToolsByCategory(category) {
|
|
1401
|
+
return TOOL_CATEGORIES[category]?.tools || [];
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Supported capability names for tool registration
|
|
1405
|
+
*/
|
|
1406
|
+
export const SUPPORTED_CAPABILITIES = [
|
|
1407
|
+
'core', // All tools (default)
|
|
1408
|
+
'automator', // Connection and lifecycle
|
|
1409
|
+
'miniprogram', // MiniProgram-level operations
|
|
1410
|
+
'page', // Page-level operations
|
|
1411
|
+
'element', // Element interactions
|
|
1412
|
+
'assert', // Testing and verification
|
|
1413
|
+
'snapshot', // State capture
|
|
1414
|
+
'record', // Recording and replay
|
|
1415
|
+
'network', // Network mocking
|
|
1416
|
+
];
|
|
1417
|
+
/**
|
|
1418
|
+
* Register tools based on enabled capabilities
|
|
1419
|
+
* This function actually registers the tool handlers with the MCP server
|
|
1420
|
+
*/
|
|
1421
|
+
export function registerTools(server, options) {
|
|
1422
|
+
const { capabilities = ['core'], sessionId, getSession, deleteSession } = options;
|
|
1423
|
+
const tools = [];
|
|
1424
|
+
const handlers = {};
|
|
1425
|
+
// Validate tool registration
|
|
1426
|
+
const validation = validateToolRegistration();
|
|
1427
|
+
if (!validation.valid) {
|
|
1428
|
+
console.error('Tool registration validation failed:');
|
|
1429
|
+
validation.errors.forEach((err) => console.error(` - ${err}`));
|
|
1430
|
+
throw new Error('Tool registration validation failed');
|
|
1431
|
+
}
|
|
1432
|
+
// Register tools based on capabilities
|
|
1433
|
+
// 'core' includes all tools
|
|
1434
|
+
if (capabilities.includes('core')) {
|
|
1435
|
+
tools.push(...CORE_TOOLS);
|
|
1436
|
+
Object.assign(handlers, CORE_TOOL_HANDLERS);
|
|
1437
|
+
}
|
|
1438
|
+
else {
|
|
1439
|
+
// Register individual capability groups
|
|
1440
|
+
if (capabilities.includes('automator')) {
|
|
1441
|
+
tools.push(...AUTOMATOR_TOOLS);
|
|
1442
|
+
Object.assign(handlers, AUTOMATOR_TOOL_HANDLERS);
|
|
1443
|
+
}
|
|
1444
|
+
if (capabilities.includes('miniprogram')) {
|
|
1445
|
+
tools.push(...MINIPROGRAM_TOOLS);
|
|
1446
|
+
Object.assign(handlers, MINIPROGRAM_TOOL_HANDLERS);
|
|
1447
|
+
}
|
|
1448
|
+
if (capabilities.includes('page')) {
|
|
1449
|
+
tools.push(...PAGE_TOOLS);
|
|
1450
|
+
Object.assign(handlers, PAGE_TOOL_HANDLERS);
|
|
1451
|
+
}
|
|
1452
|
+
if (capabilities.includes('element')) {
|
|
1453
|
+
tools.push(...ELEMENT_TOOLS);
|
|
1454
|
+
Object.assign(handlers, ELEMENT_TOOL_HANDLERS);
|
|
1455
|
+
}
|
|
1456
|
+
if (capabilities.includes('assert')) {
|
|
1457
|
+
tools.push(...ASSERT_TOOLS);
|
|
1458
|
+
Object.assign(handlers, ASSERT_TOOL_HANDLERS);
|
|
1459
|
+
}
|
|
1460
|
+
if (capabilities.includes('snapshot')) {
|
|
1461
|
+
tools.push(...SNAPSHOT_TOOLS);
|
|
1462
|
+
Object.assign(handlers, SNAPSHOT_TOOL_HANDLERS);
|
|
1463
|
+
}
|
|
1464
|
+
if (capabilities.includes('record')) {
|
|
1465
|
+
tools.push(...RECORD_TOOLS);
|
|
1466
|
+
Object.assign(handlers, RECORD_TOOL_HANDLERS);
|
|
1467
|
+
}
|
|
1468
|
+
if (capabilities.includes('network')) {
|
|
1469
|
+
tools.push(...NETWORK_TOOLS);
|
|
1470
|
+
Object.assign(handlers, NETWORK_TOOL_HANDLERS);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
// Log registration stats
|
|
1474
|
+
console.error(`Registering ${tools.length} tools (capabilities: ${capabilities.join(', ')}):`);
|
|
1475
|
+
// Count tools by category in registered set
|
|
1476
|
+
const registeredCounts = {
|
|
1477
|
+
automator: tools.filter((t) => t.name.startsWith('miniprogram_launch') ||
|
|
1478
|
+
t.name.startsWith('miniprogram_connect') ||
|
|
1479
|
+
t.name.startsWith('miniprogram_disconnect') ||
|
|
1480
|
+
t.name.startsWith('miniprogram_close')).length,
|
|
1481
|
+
miniprogram: tools.filter((t) => t.name.startsWith('miniprogram_') &&
|
|
1482
|
+
!t.name.includes('launch') &&
|
|
1483
|
+
!t.name.includes('connect') &&
|
|
1484
|
+
!t.name.includes('disconnect') &&
|
|
1485
|
+
!t.name.includes('close')).length,
|
|
1486
|
+
page: tools.filter((t) => t.name.startsWith('page_')).length,
|
|
1487
|
+
element: tools.filter((t) => t.name.startsWith('element_')).length,
|
|
1488
|
+
assert: tools.filter((t) => t.name.startsWith('assert_')).length,
|
|
1489
|
+
snapshot: tools.filter((t) => t.name.startsWith('snapshot_')).length,
|
|
1490
|
+
record: tools.filter((t) => t.name.startsWith('record_')).length,
|
|
1491
|
+
network: tools.filter((t) => t.name.startsWith('network_')).length,
|
|
1492
|
+
};
|
|
1493
|
+
if (registeredCounts.automator > 0)
|
|
1494
|
+
console.error(` - Automator: ${registeredCounts.automator}`);
|
|
1495
|
+
if (registeredCounts.miniprogram > 0)
|
|
1496
|
+
console.error(` - MiniProgram: ${registeredCounts.miniprogram}`);
|
|
1497
|
+
if (registeredCounts.page > 0)
|
|
1498
|
+
console.error(` - Page: ${registeredCounts.page}`);
|
|
1499
|
+
if (registeredCounts.element > 0)
|
|
1500
|
+
console.error(` - Element: ${registeredCounts.element}`);
|
|
1501
|
+
if (registeredCounts.assert > 0)
|
|
1502
|
+
console.error(` - Assert: ${registeredCounts.assert}`);
|
|
1503
|
+
if (registeredCounts.snapshot > 0)
|
|
1504
|
+
console.error(` - Snapshot: ${registeredCounts.snapshot}`);
|
|
1505
|
+
if (registeredCounts.record > 0)
|
|
1506
|
+
console.error(` - Record: ${registeredCounts.record}`);
|
|
1507
|
+
if (registeredCounts.network > 0)
|
|
1508
|
+
console.error(` - Network: ${registeredCounts.network}`);
|
|
1509
|
+
// Register CallToolRequest handler
|
|
1510
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
1511
|
+
const { name, arguments: args } = request.params;
|
|
1512
|
+
// Get or create session using the unique session ID for this server instance
|
|
1513
|
+
// Each stdio transport connection has its own session
|
|
1514
|
+
const session = getSession(sessionId);
|
|
1515
|
+
try {
|
|
1516
|
+
// Route to appropriate tool handler
|
|
1517
|
+
const handler = handlers[name];
|
|
1518
|
+
if (!handler) {
|
|
1519
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
1520
|
+
}
|
|
1521
|
+
// Wrap handler with automatic logging if logger is available
|
|
1522
|
+
let wrappedHandler = handler;
|
|
1523
|
+
if (session.logger) {
|
|
1524
|
+
const toolLogger = new ToolLogger(session.logger, session.loggerConfig);
|
|
1525
|
+
wrappedHandler = toolLogger.wrap(name, handler);
|
|
1526
|
+
}
|
|
1527
|
+
// Execute handler (with logging if available)
|
|
1528
|
+
const result = await wrappedHandler(session, args);
|
|
1529
|
+
// Handle session deletion for close tool
|
|
1530
|
+
if (name === 'miniprogram_close' && deleteSession) {
|
|
1531
|
+
try {
|
|
1532
|
+
await deleteSession(sessionId);
|
|
1533
|
+
console.error(`Session ${sessionId} deleted after close`);
|
|
1534
|
+
}
|
|
1535
|
+
catch (error) {
|
|
1536
|
+
console.error(`Failed to delete session ${sessionId} after close:`, error);
|
|
1537
|
+
// Don't fail the close operation if cleanup fails
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
// Return formatted response
|
|
1541
|
+
return {
|
|
1542
|
+
content: [
|
|
1543
|
+
{
|
|
1544
|
+
type: 'text',
|
|
1545
|
+
text: JSON.stringify(result, null, 2),
|
|
1546
|
+
},
|
|
1547
|
+
],
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
catch (error) {
|
|
1551
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1552
|
+
return {
|
|
1553
|
+
content: [
|
|
1554
|
+
{
|
|
1555
|
+
type: 'text',
|
|
1556
|
+
text: `Error executing tool ${name}: ${errorMessage}`,
|
|
1557
|
+
},
|
|
1558
|
+
],
|
|
1559
|
+
isError: true,
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
return tools;
|
|
1564
|
+
}
|
|
1565
|
+
//# sourceMappingURL=index.js.map
|