Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getData

Retrieve rendered data from custom components in WeChat Mini Programs using ID selectors to inspect component state during development.

Instructions

获取组件实例渲染数据,仅自定义组件可以使用。需要 automator 0.6.0 和基础库 2.9.0 及以上版本。使用 ID 选择器(如 #my-component)定位自定义组件。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
pathNo

Implementation Reference

  • The handler function createGetElementDataTool that creates the tool object with name, description, parameters schema, and the execute logic which resolves the element and fetches its data using element.data().
    function createGetElementDataTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_getData",
        description: "获取组件实例渲染数据,仅自定义组件可以使用。需要 automator 0.6.0 和基础库 2.9.0 及以上版本。使用 ID 选择器(如 #my-component)定位自定义组件。",
        parameters: getElementDataParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = getElementDataParameters.parse(rawArgs ?? {});
          return manager.withPage(
            context.log,
            { overrides: args.connection },
            async (page) => {
              const element = await resolveElement(
                page,
                args.selector,
                args.innerSelector
              );
    
              const data = await element.data(args.path);
              return toTextResult(
                formatJson({
                  selector: args.selector,
                  innerSelector: args.innerSelector ?? null,
                  path: args.path ?? null,
                  data: toSerializableValue(data),
                })
              );
            }
          );
        },
      };
    }
  • Zod schema defining the input parameters: selector, optional innerSelector, and optional path for the data.
    const getElementDataParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      path: z.string().trim().min(1).optional(),
    });
  • Local registration of element_getData tool within the createElementTools function, which returns an array of 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),
      ];
    }
  • src/tools.ts:7-13 (registration)
    Top-level registration where createElementTools is called to include the element tools, including element_getData, in the overall tools array.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions version requirements and selector format, it doesn't describe what 'rendering data' includes, whether this is a read-only operation, error conditions, or performance characteristics. The description provides basic constraints but lacks details about what the tool actually returns or how it behaves.

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 reasonably concise with three sentences that each add value: purpose statement, version requirements, and selector example. It's front-loaded with the core purpose. However, the second sentence about version requirements could be integrated more smoothly, and there's some room for tighter phrasing.

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 annotations, no output schema), the description is insufficient. It doesn't explain the return value format, doesn't cover most parameters, and provides minimal behavioral context. For a data retrieval tool with multiple parameters and no structured output documentation, this leaves significant gaps for an AI agent to understand how to use it effectively.

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 for undocumented parameters. The description only mentions the 'selector' parameter ('使用 ID 选择器定位自定义组件'), ignoring the other 3 parameters (connection, innerSelector, path) and the complex nested connection object. This leaves most parameters semantically unexplained, failing to compensate for the schema coverage 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 component instance rendering data). It specifies the target resource (custom components) and the action (get data). However, it doesn't explicitly differentiate from siblings like 'element_getInnerElement' or 'page_getData' beyond mentioning it's for custom components only.

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

Usage Guidelines3/5

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

The description provides some usage context: '仅自定义组件可以使用' (only custom components can use it) and mentions version requirements (automator 0.6.0 and base library 2.9.0+). It also gives an example selector format ('#my-component'). However, it doesn't explain when to use this versus alternatives like 'page_getData' or 'element_getInnerElement', nor does it provide explicit exclusions or prerequisites beyond version requirements.

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