Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getInnerElement

Retrieve elements within custom components in WeChat Mini Programs by first locating the component with an ID selector, then accessing its internal elements for automation tasks.

Instructions

在元素范围内获取元素,相当于 element.$(selector)。重要:操作自定义组件内部元素时,必须先通过 ID 选择器(如 #my-component)定位自定义组件,然后使用此工具获取组件内部的元素。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
targetSelectorYes

Implementation Reference

  • The execute handler function for the 'element_getInnerElement' tool. It resolves the parent element, queries the inner element using element.$(targetSelector), extracts tagName, text, and outerWxml, and returns them in JSON format.
    execute: async (rawArgs, context: ToolContext) => {
      const args = getInnerElementParameters.parse(rawArgs ?? {});
      return manager.withPage(
        context.log,
        { overrides: args.connection },
        async (page) => {
          const element = await resolveElement(
            page,
            args.selector,
            args.innerSelector
          );
    
          if (typeof element.$ !== "function") {
            throw new UserError(
              `元素 "${args.selector}" 不支持查询内部元素。`
            );
          }
    
          const innerElement = await element.$(args.targetSelector);
          if (!innerElement) {
            throw new UserError(
              `在元素 "${args.selector}" 内未找到选择器 "${args.targetSelector}" 对应的元素。`
            );
          }
    
          const tagName = innerElement.tagName || null;
          const text = typeof innerElement.text === "function"
            ? await innerElement.text().catch(() => null)
            : null;
          const outerWxml = typeof innerElement.outerWxml === "function"
            ? await innerElement.outerWxml().catch(() => null)
            : null;
    
          return toTextResult(
            formatJson({
              parentSelector: args.selector,
              parentInnerSelector: args.innerSelector ?? null,
              targetSelector: args.targetSelector,
              tagName: toSerializableValue(tagName),
              text: toSerializableValue(text),
              outerWxml: toSerializableValue(outerWxml),
            })
          );
        }
      );
    },
  • Zod schema defining the input parameters for the tool: selector (required), innerSelector (optional), targetSelector (required).
    const getInnerElementParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      targetSelector: z.string().trim().min(1),
    });
  • src/tools.ts:7-13 (registration)
    Top-level registration in createTools where createElementTools (containing element_getInnerElement) is included in the full tools array.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
  • Registration of the tool creator function createGetInnerElementTool within the element tools group.
    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),
      ];
    }
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. While it mentions the custom component workflow constraint, it doesn't describe what the tool actually returns (element object? properties?), error conditions, performance characteristics, or whether it's read-only vs. mutating. The description provides some operational context but leaves critical behavioral aspects unspecified.

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 two sentences. The first states the core purpose, the second provides important usage guidance. No wasted words, though it could be slightly more structured by separating the general purpose from the specific constraint.

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 (4 parameters with nested objects, no output schema, no annotations), the description is insufficient. It explains the 'what' and provides one constraint, but doesn't address parameter meanings, return values, error handling, or how this differs from similar tools. For a tool with this level of parameter complexity, more context 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 4 parameters (2 required), the description provides no information about any parameters. It doesn't explain what 'selector', 'targetSelector', 'innerSelector', or the complex 'connection' object represent. The description mentions selectors in general terms but doesn't map to specific parameters or explain their relationships.

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 tool's purpose: '在元素范围内获取元素' (get element within element scope), which is a specific verb+resource combination. It distinguishes from siblings like element_getInnerElements (plural) by focusing on single element retrieval. However, it doesn't explicitly differentiate from page_getElement which might have similar functionality.

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 explicit guidance on when to use this tool: '操作自定义组件内部元素时,必须先通过 ID 选择器定位自定义组件,然后使用此工具获取组件内部的元素' (when operating on custom component inner elements, must first locate via ID selector, then use this tool). This gives clear context for custom component scenarios. However, it doesn't mention when NOT to use it or explicitly compare to alternatives like element_getInnerElements.

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