Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getSize

Retrieve width and height measurements for elements in WeChat mini programs, including components using innerSelector for precise targeting.

Instructions

获取元素大小(宽度和高度)。如需获取自定义组件内部元素的大小,请使用 innerSelector 参数:selector 设为组件 ID 选择器(如 #my-component),innerSelector 设为组件内部元素的选择器。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo

Implementation Reference

  • The execute handler for the element_getSize tool. It resolves the element using the provided selector(s), calls element.size() to get dimensions, and formats the result as JSON text.
    execute: async (rawArgs, context: ToolContext) => {
      const args = getElementSizeParameters.parse(rawArgs ?? {});
      return manager.withPage(
        context.log,
        { overrides: args.connection },
        async (page) => {
          const element = await resolveElement(
            page,
            args.selector,
            args.innerSelector
          );
    
          if (typeof element.size !== "function") {
            throw new UserError(
              `元素 "${args.selector}" 不支持获取大小。`
            );
          }
    
          const size = await element.size();
          return toTextResult(
            formatJson({
              selector: args.selector,
              innerSelector: args.innerSelector ?? null,
              width: toSerializableValue(size.width),
              height: toSerializableValue(size.height),
            })
          );
        }
      );
    },
  • Zod schema for input validation of the element_getSize tool parameters: selector and optional innerSelector, extending connection schema.
    const getElementSizeParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
    });
  • Factory function that defines and returns the complete tool object for 'element_getSize', including name, description, schema, and handler.
    function createGetElementSizeTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_getSize",
        description: "获取元素大小(宽度和高度)。如需获取自定义组件内部元素的大小,请使用 innerSelector 参数:selector 设为组件 ID 选择器(如 #my-component),innerSelector 设为组件内部元素的选择器。",
        parameters: getElementSizeParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = getElementSizeParameters.parse(rawArgs ?? {});
          return manager.withPage(
            context.log,
            { overrides: args.connection },
            async (page) => {
              const element = await resolveElement(
                page,
                args.selector,
                args.innerSelector
              );
    
              if (typeof element.size !== "function") {
                throw new UserError(
                  `元素 "${args.selector}" 不支持获取大小。`
                );
              }
    
              const size = await element.size();
              return toTextResult(
                formatJson({
                  selector: args.selector,
                  innerSelector: args.innerSelector ?? null,
                  width: toSerializableValue(size.width),
                  height: toSerializableValue(size.height),
                })
              );
            }
          );
        },
      };
    }
  • Registers element_getSize tool within the createElementTools function by including its factory in the tools array.
    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)
    Aggregates and registers all tools, including element tools (containing element_getSize), in the top-level createTools function.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
  • src/index.ts:17-17 (registration)
    Final registration of all tools, including element_getSize, to the FastMCP server.
    server.addTools(createTools(manager));
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the basic operation (getting width and height) and a specific use case for innerSelector, but lacks critical behavioral information. It doesn't mention whether this is a read-only operation, what happens if the element doesn't exist, whether it requires specific permissions, or what the return format looks like. For a tool with no annotation coverage, this leaves significant behavioral 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 perfectly concise and well-structured. The first sentence states the core purpose, and the second sentence provides specific usage guidance for a common scenario. Every word serves a purpose with zero redundancy. The information is front-loaded with the main functionality stated first.

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 (3 parameters including a nested object), 0% schema description coverage, no annotations, and no output schema, the description is insufficiently complete. It explains one parameter's use case but leaves the most complex parameter (connection) and the required parameter (selector) undocumented. For a tool that likely interacts with a browser/application and returns dimensional data, more context about the connection requirements and return format would be needed for proper use.

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

Parameters3/5

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

The description adds meaningful context for the innerSelector parameter by explaining when and how to use it with custom components. However, with 0% schema description coverage and 3 total parameters (connection, selector, innerSelector), the description only addresses one parameter's semantics. The critical 'selector' parameter (which is required) and the complex 'connection' object receive no explanation in the description, leaving significant gaps in parameter understanding.

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 size - width and height). It specifies the exact resource (element) and action (get size), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like element_getData or element_getWxml, which prevents a perfect score.

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 usage guidance for a specific scenario: '如需获取自定义组件内部元素的大小,请使用 innerSelector 参数' (if you need to get the size of an element inside a custom component, use the innerSelector parameter). This gives explicit context for when to use the innerSelector parameter. However, it doesn't provide guidance on when to use this tool versus alternatives like element_getInnerElement or page_getElement, which are relevant sibling tools.

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