Skip to main content
Glama

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
NameRequiredDescriptionDefault
connectionNo
methodYes
argsNo

Implementation Reference

  • 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), }) ); } ); },
  • 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(), });
  • 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), }) ); } ); }, }; }
  • 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), ]; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yfmeii/weapp-dev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server