Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

page_waitElement

Waits for a specified selector's element to appear on a WeChat Mini Program page, ensuring elements are available before interaction. Use for page-level elements only.

Instructions

等待指定选择器的元素出现在页面上。注意:此方法不适用于自定义组件内部元素,仅能等待页面级别的元素。如需等待自定义组件内部元素,请使用 page_waitTimeout 配合 element 相关工具进行轮询检查。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes

Implementation Reference

  • Defines the tool handler for 'page_waitElement'. The execute function validates input, acquires the page via manager.withPage, waits for the element with page.waitFor(selector), and returns a success message.
    function createWaitForElementTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "page_waitElement",
        description: "等待指定选择器的元素出现在页面上。注意:此方法不适用于自定义组件内部元素,仅能等待页面级别的元素。如需等待自定义组件内部元素,请使用 page_waitTimeout 配合 element 相关工具进行轮询检查。",
        parameters: waitForElementParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = waitForElementParameters.parse(rawArgs ?? {});
          return manager.withPage<ContentResult>(
            context.log,
            { overrides: args.connection },
            async (page) => {
              await page.waitFor(args.selector);
              return toTextResult(`已等待元素选择器 "${args.selector}" 出现。`);
            }
          );
        },
      };
    }
  • Zod schema defining the input parameters for the page_waitElement tool: a connection container and a required selector string.
    const waitForElementParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
    });
  • Registers the page_waitElement tool by including createWaitForElementTool(manager) in the array of page tools returned by createPageTools.
    export function createPageTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        createGetElementTool(manager),
        createWaitForElementTool(manager),
        createWaitForTimeoutTool(manager),
        createGetPageDataTool(manager),
        createSetPageDataTool(manager),
        createCallPageMethodTool(manager),
      ];
    }
  • src/tools.ts:7-13 (registration)
    Aggregates and registers page tools (including page_waitElement) by spreading createPageTools(manager) into the full tools array.
    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 page_waitElement, to the FastMCP server.
    server.addTools(createTools(manager));
Behavior3/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. It discloses that this tool is for waiting (implying it's non-destructive and likely read-only), specifies limitations (doesn't work for custom components), and mentions an alternative approach. However, it doesn't describe timeout behavior, error conditions, or what 'appear' means precisely (e.g., visibility vs existence).

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 appropriately concise with two sentences. The first sentence states the core purpose, and the second provides crucial usage limitations and alternatives. Every sentence earns its place with no wasted words.

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 the complexity (2 parameters with one being a nested object with 12 properties), 0% schema coverage, no annotations, and no output schema, the description is incomplete. It does well on purpose and guidelines but lacks details about parameters, return values, and behavioral specifics like timeout handling. For a waiting tool with complex connection requirements, more context would be helpful.

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 2 parameters (one complex nested object), the description adds minimal value. It mentions '指定选择器' (specified selector) which hints at the 'selector' parameter, but provides no details about the 'connection' object or its many sub-properties. The description doesn't explain what these parameters do or how they affect the waiting behavior.

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 tool's purpose: '等待指定选择器的元素出现在页面上' (wait for an element with a specified selector to appear on the page). It specifies the verb ('等待' - wait) and resource ('元素' - element), and distinguishes it from siblings by explicitly mentioning it doesn't work for custom component elements, unlike other element-related tools.

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

Usage Guidelines5/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 vs alternatives: '此方法不适用于自定义组件内部元素,仅能等待页面级别的元素。如需等待自定义组件内部元素,请使用 page_waitTimeout 配合 element 相关工具进行轮询检查' (This method is not applicable to elements inside custom components, only page-level elements. To wait for custom component internal elements, use page_waitTimeout with element-related tools for polling). This clearly defines the scope and provides an alternative approach.

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