Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getInnerElements

Retrieve multiple elements within a specified component in WeChat Mini Programs using CSS selectors for automated testing and development workflows.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
targetSelectorYes

Implementation Reference

  • The main handler for 'element_getInnerElements' tool. It parses arguments, resolves the parent element, checks if $$ method is available, queries inner elements with targetSelector, extracts tagName and text for each, and returns formatted JSON with parent info, count, and elements details.
    function createGetInnerElementsTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_getInnerElements",
        description: "在元素范围内获取元素数组,相当于 element.$$(selector)。重要:操作自定义组件内部元素时,必须先通过 ID 选择器(如 #my-component)定位自定义组件,然后使用此工具获取组件内部的元素数组。",
        parameters: getInnerElementsParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = getInnerElementsParameters.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 innerElements = await element.$$(args.targetSelector);
              if (!Array.isArray(innerElements)) {
                throw new UserError(
                  `在元素 "${args.selector}" 内查询选择器 "${args.targetSelector}" 失败。`
                );
              }
    
              const elementsInfo = await Promise.all(
                innerElements.map(async (el, index) => {
                  const tagName = el.tagName || null;
                  const text = typeof el.text === "function"
                    ? await el.text().catch(() => null)
                    : null;
                  return {
                    index,
                    tagName: toSerializableValue(tagName),
                    text: toSerializableValue(text),
                  };
                })
              );
    
              return toTextResult(
                formatJson({
                  parentSelector: args.selector,
                  parentInnerSelector: args.innerSelector ?? null,
                  targetSelector: args.targetSelector,
                  count: innerElements.length,
                  elements: elementsInfo,
                })
              );
            }
          );
        },
      };
    }
  • Zod schema defining the input parameters for the tool: selector (required), innerSelector (optional), targetSelector (required), extending shared connectionContainerSchema.
    const getInnerElementsParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      targetSelector: z.string().trim().min(1),
    });
  • Registration of the 'element_getInnerElements' tool via createGetInnerElementsTool(manager) within the exported createElementTools function that returns all element-related 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 the full burden. It discloses that this tool retrieves multiple elements (数组/array) and has a specific workflow for custom components (ID selector first). However, it doesn't mention behavioral traits like whether this is a read-only operation (implied by '获取'/get), error conditions, performance implications, or what happens if no elements match. The analogy to 'element.$$(selector)' adds technical context but assumes familiarity with that syntax.

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 sized with two sentences. The first sentence states the core purpose clearly, and the second provides important usage context. Both sentences earn their place by adding value. It's front-loaded with the main functionality. Minor improvement could be made by explicitly naming parameters, but it's efficient overall.

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?

Given 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It covers the tool's purpose and a key usage scenario well, but doesn't address parameter meanings, return values (beyond '数组'/array), error handling, or how it differs from similar tools like element_getInnerElement. For a tool with this complexity and lack of structured documentation, it should provide more comprehensive guidance.

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?

Schema description coverage is 0%, so the description must compensate. It mentions 'selector' implicitly through the analogy to element.$$(selector) and references ID selectors for custom components, but doesn't explain the four parameters (connection, selector, innerSelector, targetSelector) or their relationships. The description adds some meaning about selector usage but leaves most parameters undocumented, failing to adequately compensate for the schema gap.

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 an array of elements within an element scope). It specifies the action (获取/get) and resource (元素数组/element array) with the scope constraint (在元素范围内/within element scope). However, it doesn't explicitly differentiate from sibling tools like element_getInnerElement (singular) or page_getElement, which might retrieve single elements or from different contexts.

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 usage: '操作自定义组件内部元素时,必须先通过 ID 选择器定位自定义组件,然后使用此工具获取组件内部的元素数组' (when operating on custom component inner elements, must first locate the custom component via ID selector, then use this tool to get the inner element array). This gives practical guidance on prerequisites (ID selector first) and context (custom components). It doesn't explicitly state when NOT to use it or name alternatives like element_getInnerElement for single elements, but the context is well-defined.

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