Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_callMethod

Invoke a method on a custom component instance in a WeChat mini program, enabling automated testing and interaction with component-specific behaviors.

Instructions

调用组件实例指定方法,仅自定义组件可以使用。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
methodYes
argsNo

Implementation Reference

  • The main handler/executor for the element_callMethod tool. It resolves an element via selector/innerSelector, calls element.callMethod(args.method, ...callArgs), and returns the result as formatted JSON.
    function createCallElementMethodTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_callMethod",
        description: "调用组件实例指定方法,仅自定义组件可以使用。",
        parameters: callElementMethodParameters,
        execute: async (rawArgs, context: ToolContext) =>
          withUserErrorResult(async () => {
          const args = callElementMethodParameters.parse(rawArgs ?? {});
          return manager.withPage(
            context.log,
            { overrides: args.connection },
            async (page) => {
              const element = await resolveElement(
                page,
                args.selector,
                args.innerSelector
              );
    
              const callArgs = args.args ?? [];
              const result = await element.callMethod(args.method, ...callArgs);
              return toTextResult(
                formatJson({
                  selector: args.selector,
                  innerSelector: args.innerSelector ?? null,
                  method: args.method,
                  arguments: callArgs,
                  result: toSerializableValue(result),
                })
              );
            }
          );
          }),
      };
    }
  • Input parameter schema (Zod) for element_callMethod: requires selector (string), optional innerSelector (string), method (string), and optional args (array of unknown values).
    const callElementMethodParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      method: z.string().trim().min(1),
      args: z.array(z.unknown()).optional(),
    });
  • Registration: createElementTools() includes createCallElementMethodTool(manager) in the array of tools on line 100.
    export function createElementTools(
      manager: WeappAutomatorManager
    ): AnyTool[] {
      return [
        createTapElementTool(manager),
        createInputTextTool(manager),
        createCallElementMethodTool(manager),
        createGetElementDataTool(manager),
        createSetElementDataTool(manager),
        createGetInnerElementTool(manager),
        createGetInnerElementsTool(manager),
        createGetElementWxmlTool(manager),
        createGetElementStylesTool(manager),
        createScrollToTool(manager),
        createGetAttributesTool(manager),
        createGetBoundingClientRectTool(manager),
      ];
    }
  • src/tools.ts:7-13 (registration)
    Top-level registration: createTools() exports createElementTools(manager) which ultimately exposes the element_callMethod tool.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
  • connectionContainerSchema used as base schema for the tool parameters, defined in common helpers.
    export const connectionContainerSchema = z.object({
      connection: connectionOverridesSchema.optional(),
    });
Behavior2/5

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

With no annotations, the description carries full burden. It only states the action without disclosing behavioral traits like destructiveness, side effects, or failure behavior. The brevity leaves the agent guessing about important behavioral aspects.

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 a single concise sentence that is front-loaded with the action. It avoids unnecessary words, though it could be more informative without losing conciseness.

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 tool's complexity (5 parameters, nested connection object, no output schema), the description is severely incomplete. It omits crucial context such as what methods are valid, how args should be structured, and what the return value is.

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

Parameters1/5

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

Schema description coverage is 0%, and the description does not explain any parameter beyond the schema itself. Parameters like connection, method, args, and innerSelector are left entirely undocumented, forcing reliance on the raw schema which is insufficient.

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

Purpose5/5

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

The description clearly states the verb 'call' and the resource 'component instance specified method', and adds the constraint 'only custom components can be used', which distinguishes it from sibling tools like page_callMethod and other element manipulation tools.

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

Usage Guidelines3/5

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

The description provides some guidance by noting that it is only for custom components, implying it should not be used for native components. However, it does not mention alternatives or when not to use this tool, lacking explicit usage context.

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