Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_callMethod

Execute specific methods on custom component instances in WeChat Mini Programs using ID selectors like #my-component to trigger component behaviors during development.

Instructions

调用组件实例指定方法,仅自定义组件可以使用。需要 automator 0.6.0 和基础库 2.9.0 及以上版本。使用 ID 选择器(如 #my-component)定位自定义组件。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
methodYes
argsNo

Implementation Reference

  • The execute handler for the 'element_callMethod' tool. Parses arguments, resolves the target element using resolveElement helper, calls the specified method on the element with provided arguments, and returns a JSON-formatted result including the call outcome.
    execute: async (rawArgs, context: ToolContext) => {
      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),
            })
          );
        }
      );
    },
  • Zod schema defining the input parameters for the element_callMethod tool: selector (required), innerSelector (optional), method (required), and args (optional array).
    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(),
    });
  • The element_callMethod tool is registered in the createElementTools function by including createCallElementMethodTool(manager) in the returned array of tools.
    createCallElementMethodTool(manager),
  • src/tools.ts:11-11 (registration)
    createElementTools (which includes element_callMethod) is registered in the top-level createTools function.
    ...createElementTools(manager),
  • src/index.ts:17-17 (registration)
    The complete set of tools including element_callMethod is registered to the FastMCP server.
    server.addTools(createTools(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 for behavioral disclosure. It mentions version requirements and selector syntax, but doesn't describe what happens during method invocation, error conditions, whether this is a read or write operation, or what the expected outcome looks like. For a method invocation tool with 5 parameters and complex nested objects, this is insufficient behavioral context.

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 appropriately concise with three sentences that each add value: the core functionality, version requirements, and selector guidance. It's front-loaded with the main purpose and avoids unnecessary verbiage. However, the technical Chinese terminology might require translation for some agents.

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 with nested objects, no output schema, no annotations), the description is incomplete. It doesn't explain what the tool returns, how to interpret results, error handling, or the purpose of most parameters. For a method invocation tool in what appears to be a web automation/testing context, more guidance about expected behaviors and outcomes is needed.

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?

With 0% schema description coverage and 5 parameters including a complex nested 'connection' object with 12 properties, the description provides almost no parameter guidance. It mentions '使用 ID 选择器' (using ID selector) which hints at the 'selector' parameter, but doesn't explain 'method', 'args', 'innerSelector', or the extensive connection configuration. The description fails to compensate for the complete lack of schema documentation.

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

Purpose4/5

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

The description clearly states the action ('调用组件实例指定方法' - call component instance specified method) and resource ('自定义组件' - custom components), making the purpose understandable. It distinguishes from siblings like element_getData or element_setData by focusing on method invocation rather than data retrieval or modification. However, it doesn't explicitly differentiate from page_callMethod which appears to be a similar sibling tool.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool: only for custom components, requiring specific versions (automator 0.6.0 and base library 2.9.0 or higher), and using ID selectors. It doesn't explicitly mention when NOT to use it or name alternatives like page_callMethod, but the custom component restriction provides meaningful guidance.

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