Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

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),
      ];
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is read-only or destructive, authentication needs, error handling, or what 'current page instance' entails (e.g., requires prior setup via mp_ensureConnection). The mention of 'parameters as an array' hints at input format but is insufficient for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences, front-loaded with the main action. It avoids redundancy but is under-specified rather than efficiently informative. Every sentence contributes, though more detail is needed.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (3 parameters, nested objects, no annotations, no output schema), the description is incomplete. It doesn't explain return values, error cases, or dependencies on other tools (e.g., mp_ensureConnection). For a tool that likely performs dynamic method calls, this leaves critical gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds minimal value. It implies 'args' parameter can be an array, but doesn't explain the three parameters (connection, method, args) or their semantics. The description fails to clarify what 'method' refers to or how 'connection' is used, leaving parameters largely undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '调用当前页面实例上暴露的方法。参数可以作为数组提供。' (Calls methods exposed on the current page instance. Parameters can be provided as an array.) states the action (calling methods) and resource (current page instance), but is vague about what 'methods' are and lacks differentiation from siblings like page_getData or page_setData. It's not tautological but provides only a generic purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives. It mentions 'current page instance' but doesn't clarify prerequisites (e.g., requires an active page connection) or contrast with sibling tools like element_callMethod or mp_callWx. Usage is implied but not well-defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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