Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getWxml

Retrieve WXML code for elements in WeChat Mini Programs, including inner or outer markup and custom component elements, to inspect and debug page structures.

Instructions

获取元素 WXML。默认获取内部 WXML(element.wxml()),设置 outer 为 true 可获取包含元素本身的 WXML(element.outerWxml())。如需获取自定义组件内部元素的 WXML,请使用 innerSelector 参数:selector 设为组件 ID 选择器(如 #my-component),innerSelector 设为组件内部元素的选择器。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
outerNo

Implementation Reference

  • The handler function createGetElementWxmlTool that defines and returns the tool object with name 'element_getWxml', its description, parameters schema, and the execute function implementing the logic to get WXML or outerWxml of the element.
    function createGetElementWxmlTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_getWxml",
        description: "获取元素 WXML。默认获取内部 WXML(element.wxml()),设置 outer 为 true 可获取包含元素本身的 WXML(element.outerWxml())。如需获取自定义组件内部元素的 WXML,请使用 innerSelector 参数:selector 设为组件 ID 选择器(如 #my-component),innerSelector 设为组件内部元素的选择器。",
        parameters: getElementWxmlParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = getElementWxmlParameters.parse(rawArgs ?? {});
          return manager.withPage(
            context.log,
            { overrides: args.connection },
            async (page) => {
              const element = await resolveElement(
                page,
                args.selector,
                args.innerSelector
              );
    
              const methodName = args.outer ? "outerWxml" : "wxml";
              if (typeof element[methodName] !== "function") {
                throw new UserError(
                  `元素 "${args.selector}" 不支持获取 ${methodName}。`
                );
              }
    
              const wxml = await element[methodName]();
              return toTextResult(
                formatJson({
                  selector: args.selector,
                  innerSelector: args.innerSelector ?? null,
                  type: args.outer ? "outerWxml" : "wxml",
                  wxml: toSerializableValue(wxml),
                })
              );
            }
          );
        },
      };
    }
  • Zod schema defining the input parameters for the element_getWxml tool: selector, optional innerSelector, and optional outer flag.
    const getElementWxmlParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      outer: z.boolean().optional().default(false),
    });
  • src/tools.ts:7-13 (registration)
    Registration of element tools (including element_getWxml) via spreading createElementTools into the main tools array in createTools.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
  • src/index.ts:17-17 (registration)
    Final MCP server registration of all tools, including element_getWxml, by calling server.addTools(createTools(manager)).
    server.addTools(createTools(manager));
  • Local registration of the element_getWxml tool within the createElementTools function that returns the array of element tools.
    export function createElementTools(
      manager: WeappAutomatorManager
    ): AnyTool[] {
      return [
        createTapElementTool(manager),
        createInputTextTool(manager),
        createCallElementMethodTool(manager),
        createGetElementDataTool(manager),
        createSetElementDataTool(manager),
        createGetInnerElementTool(manager),
        createGetInnerElementsTool(manager),
        createGetElementSizeTool(manager),
        createGetElementWxmlTool(manager),
      ];
    }
Behavior3/5

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

With no annotations provided, the description carries full burden. It explains the default behavior (inner WXML) and how to modify it (outer parameter), plus special case for custom components. However, it doesn't disclose error conditions, performance characteristics, or what happens with invalid selectors. It provides some behavioral context but leaves gaps.

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

Conciseness5/5

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

The description is efficiently structured in two sentences: first explains core functionality with default/outer options, second explains specialized use case for custom components. Every sentence adds value with zero wasted words, making it easy to parse.

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

Completeness3/5

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

For a tool with 4 parameters (including a complex nested object), 0% schema coverage, and no output schema, the description provides good coverage for selector-related parameters but completely ignores the 'connection' parameter. This creates a significant gap in understanding how to establish the context for WXML retrieval.

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

Parameters4/5

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

With 0% schema description coverage, the description must compensate. It explains the semantics of 'outer' (inner vs outer WXML) and 'innerSelector' (for custom components), and implies 'selector' identifies the target element. However, it doesn't explain the complex 'connection' parameter at all, leaving a major gap in parameter understanding.

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 '获取' (get) and resource '元素 WXML' (element WXML), with specific details about what WXML is retrieved. It distinguishes from siblings by explaining this tool retrieves WXML content while other element_* tools handle methods, data, interactions, or navigation.

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 for when to use specific parameters (outer for outer WXML, innerSelector for custom components), but doesn't explicitly state when to choose this tool over alternatives like element_getData or page_getElement. It gives parameter-specific guidance but not overall tool selection 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