Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_setData

Update rendering data for custom components in WeChat Mini Programs using selector targeting to modify component states during development.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
dataYes

Implementation Reference

  • Full tool object returned by createSetElementDataTool, including the execute handler that resolves the element using resolveElement, calls element.setData with the provided data, computes updated data keys, and returns a textual confirmation.
    return {
      name: "element_setData",
      description: "设置组件实例渲染数据,仅自定义组件可以使用。需要 automator 0.6.0 和基础库 2.9.0 及以上版本。使用 ID 选择器(如 #my-component)定位自定义组件。",
      parameters: setElementDataParameters,
      execute: async (rawArgs, context: ToolContext) => {
        const args = setElementDataParameters.parse(rawArgs ?? {});
        return manager.withPage(
          context.log,
          { overrides: args.connection },
          async (page) => {
            const element = await resolveElement(
              page,
              args.selector,
              args.innerSelector
            );
    
            await element.setData(args.data);
            const dataKeys = Object.keys(args.data ?? {});
            return toTextResult(
              `已更新组件数据键: ${dataKeys.length ? dataKeys.join(", ") : "(无)"}。`
            );
          }
        );
      },
    };
  • Zod schema for tool parameters: connection container, selector (required string), optional innerSelector (string), and data (record of unknown).
    const setElementDataParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      data: z.record(z.unknown()),
    });
  • The createElementTools function registers the element_setData tool by including createSetElementDataTool(manager) in its returned array of 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 createTools function registers all tools, including element tools (thus element_setData) by spreading createElementTools(manager).
    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?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions version requirements and selector syntax, but doesn't describe what '设置组件实例渲染数据' actually does behaviorally - whether it overwrites existing data, merges with existing data, triggers re-rendering, or has side effects. For a mutation tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 - three sentences that each convey distinct information: purpose, version requirements, and selector syntax. It's front-loaded with the core purpose. However, the second sentence about version requirements could potentially be moved to a separate constraints section for better structure.

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?

For a mutation tool with no annotations, no output schema, complex nested parameters (including a 12-property connection object), and 0% schema description coverage, the description is inadequate. It doesn't explain what the tool returns, how the data parameter should be structured, what the connection object does, or provide error handling context. The description leaves too many critical questions unanswered for proper tool usage.

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 (including a complex nested 'connection' object with 12 sub-properties), the description provides almost no parameter guidance. It only mentions '使用 ID 选择器' which relates to the 'selector' parameter. The critical 'data' parameter (required) and 'innerSelector' parameter get no explanation, and the complex 'connection' object is completely undocumented in the description.

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: '设置组件实例渲染数据' (sets component instance rendering data). It specifies the target ('自定义组件' - custom components) and mentions the ID selector syntax for targeting. However, it doesn't explicitly differentiate from sibling tools like 'page_setData' or 'element_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 和基础库 2.9.0 及以上版本'). It also specifies the selector format ('使用 ID 选择器'). However, it doesn't explicitly state when to use this versus alternatives like 'page_setData' or provide clear exclusion criteria beyond the custom component limitation.

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