page_callMethod
Execute methods exposed on WeChat Mini Program page instances by specifying method names and passing parameters as arrays for programmatic interaction.
Instructions
调用当前页面实例上暴露的方法。参数可以作为数组提供。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | ||
| method | Yes | ||
| args | No |
Implementation Reference
- src/tools/page.ts:166-183 (handler)The execute handler for the "page_callMethod" tool. It parses the input arguments, calls the page.callMethod with the specified method and args, and returns a formatted JSON result.execute: async (rawArgs, context: ToolContext) => { const args = callPageMethodParameters.parse(rawArgs ?? {}); const callArgs = args.args ?? []; return manager.withPage<ContentResult>( context.log, { overrides: args.connection }, async (page) => { const result = await page.callMethod(args.method, ...callArgs); return toTextResult( formatJson({ method: args.method, arguments: callArgs, result: toSerializableValue(result), }) ); } ); },
- src/tools/page.ts:24-27 (schema)Zod schema defining the input parameters for the "page_callMethod" tool: method (string) and optional args (array).const callPageMethodParameters = connectionContainerSchema.extend({ method: z.string().trim().min(1), args: z.array(z.unknown()).optional(), });
- src/tools/page.ts:161-185 (registration)Factory function that creates and configures the "page_callMethod" tool, including name, description, schema, and execute handler.function createCallPageMethodTool(manager: WeappAutomatorManager): AnyTool { return { name: "page_callMethod", description: "调用当前页面实例上暴露的方法。参数可以作为数组提供。", parameters: callPageMethodParameters, execute: async (rawArgs, context: ToolContext) => { const args = callPageMethodParameters.parse(rawArgs ?? {}); const callArgs = args.args ?? []; return manager.withPage<ContentResult>( context.log, { overrides: args.connection }, async (page) => { const result = await page.callMethod(args.method, ...callArgs); return toTextResult( formatJson({ method: args.method, arguments: callArgs, result: toSerializableValue(result), }) ); } ); }, }; }
- src/tools/page.ts:42-51 (registration)Registers the "page_callMethod" tool by including it in the array of page tools returned by createPageTools.export function createPageTools(manager: WeappAutomatorManager): AnyTool[] { return [ createGetElementTool(manager), createWaitForElementTool(manager), createWaitForTimeoutTool(manager), createGetPageDataTool(manager), createSetPageDataTool(manager), createCallPageMethodTool(manager), ]; }
- src/tools.ts:7-13 (registration)Aggregates all tools, including page tools (which contain page_callMethod), into a single tools array.export function createTools(manager: WeappAutomatorManager): AnyTool[] { return [ ...createApplicationTools(manager), ...createPageTools(manager), ...createElementTools(manager), ]; }