Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

element_getStyles

Retrieve specific CSS style values from a WeChat Mini Program element by specifying the element selector and an array of style property names.

Instructions

获取元素的样式值。names 为样式名数组(如 ['color', 'fontSize', 'backgroundColor'])。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
selectorYes
innerSelectorNo
namesYes

Implementation Reference

  • The createGetElementStylesTool function defines the 'element_getStyles' tool handler. It takes rawArgs, parses them with getElementStylesParameters, resolves the element via selector/innerSelector, iterates over requested style names using element.style(name), and returns the styles as a JSON result.
    function createGetElementStylesTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "element_getStyles",
        description: "获取元素的样式值。names 为样式名数组(如 ['color', 'fontSize', 'backgroundColor'])。",
        parameters: getElementStylesParameters,
        execute: async (rawArgs, context: ToolContext) =>
          withUserErrorResult(async () => {
          const args = getElementStylesParameters.parse(rawArgs ?? {});
          return manager.withPage(
            context.log,
            { overrides: args.connection },
            async (page) => {
              const element = await resolveElement(
                page,
                args.selector,
                args.innerSelector
              );
    
              if (typeof element.style !== "function") {
                throw new UserError(
                  `元素 "${args.selector}" 不支持获取样式。`
                );
              }
    
              const styles: Record<string, unknown> = {};
    
              await Promise.all(
                args.names.map(async (name) => {
                  try {
                    styles[name] = await element.style(name);
                  } catch {
                    styles[name] = null;
                  }
                })
              );
    
              return toTextResult(
                formatJson({
                  selector: args.selector,
                  innerSelector: args.innerSelector ?? null,
                  styles,
                })
              );
            }
          );
          }),
      };
    }
  • Zod schema for element_getStyles parameters: selector (required string), innerSelector (optional string), and names (array of strings representing style property names).
    const getElementStylesParameters = connectionContainerSchema.extend({
      selector: z.string().trim().min(1),
      innerSelector: z.string().trim().min(1).optional(),
      names: z.array(z.string().trim().min(1)),
    });
  • The tool is registered in the createToolsByCategory function which returns an array of all element tools; createGetElementStylesTool(manager) is called at line 106.
      manager: WeappAutomatorManager
    ): AnyTool[] {
      return [
        createTapElementTool(manager),
        createInputTextTool(manager),
        createCallElementMethodTool(manager),
        createGetElementDataTool(manager),
        createSetElementDataTool(manager),
        createGetInnerElementTool(manager),
        createGetInnerElementsTool(manager),
        createGetElementWxmlTool(manager),
        createGetElementStylesTool(manager),
        createScrollToTool(manager),
        createGetAttributesTool(manager),
        createGetBoundingClientRectTool(manager),
      ];
    }
Behavior1/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 fails to disclose any behavioral traits such as whether it returns computed styles, possible side effects, or error conditions. The description is minimal and does not help the agent understand tool behavior beyond the basic action.

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 very concise (one short sentence), but it lacks structure. It front-loads the purpose but omits important details. For a single-sentence description, it is efficient but not comprehensive.

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 tool's complexity (4 parameters, nested connection object, no output schema), the description is incomplete. It does not explain how to use the 'connection' parameter, what the return value looks like, or any constraints. The agent would lack sufficient context to use it correctly.

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%. The description only explains one of four parameters ('names') with an example. It does not explain 'selector', 'innerSelector', or the complex 'connection' object. The agent would need to infer the meaning from parameter names alone.

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 style values). It specifies the 'names' parameter as an array of style names, differentiating from sibling tools like element_getAttributes or element_getData. However, it does not explicitly distinguish from other getters.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives (e.g., element_getAttributes for attributes). It does not mention prerequisites or typical use cases. The description is purely functional.

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