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));

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