Skip to main content
Glama

webview_get_styles

Read-only

Retrieve computed CSS styles from elements in a Tauri app using CSS selectors, XPath, or text content matching.

Instructions

[Tauri Apps Only] Get computed CSS styles from elements in a Tauri app. Supports CSS selectors (default), XPath, and text content matching via the strategy parameter. Requires active driver_session. Targets the only connected app, or the default app if multiple are connected. Specify appIdentifier (port or bundle ID) to target a specific app. For browser style inspection, use Chrome DevTools MCP instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
windowIdNoWindow label to target (defaults to "main")
appIdentifierNoApp port or bundle ID to target. Defaults to the only connected app or the default app if multiple are connected.
selectorYesElement selector: CSS selector (default), XPath expression, text content, or ref ID
strategyNoSelector strategy: "css" (default) for CSS selectors, "xpath" for XPath expressions, "text" to find elements by text content, with fallback to placeholder, aria-label, and title attributes. Ref IDs (e.g., "ref=e3") work with any strategy.css
propertiesNoSpecific CSS properties to retrieve. If omitted, returns all computed styles
multipleNoWhether to get styles for all matching elements (true) or just the first (false)

Implementation Reference

  • Registration of the 'webview_get_styles' tool in the tools registry, including description, category, schema reference, and handler that delegates to getStyles().
    {
       name: 'webview_get_styles',
       description:
          '[Tauri Apps Only] Get computed CSS styles from elements in a Tauri app. ' +
          'Supports CSS selectors (default), XPath, and text content matching via the strategy parameter. ' +
          'Requires active driver_session. ' +
          MULTI_APP_DESC + ' ' +
          'For browser style inspection, use Chrome DevTools MCP instead.',
       category: TOOL_CATEGORIES.UI_AUTOMATION,
       schema: GetStylesSchema,
       annotations: {
          title: 'Get Styles in Tauri Webview',
          readOnlyHint: true,
          openWorldHint: false,
       },
       handler: async (args) => {
          const parsed = GetStylesSchema.parse(args);
    
          return await getStyles({
             selector: parsed.selector,
             strategy: parsed.strategy,
             properties: parsed.properties,
             multiple: parsed.multiple,
             windowId: parsed.windowId,
             appIdentifier: parsed.appIdentifier,
          });
       },
    },
  • The getStyles() handler function that builds and executes the style retrieval script in the target webview.
    export async function getStyles(options: GetStylesOptions): Promise<string> {
       const { selector, strategy, properties, multiple = false, windowId, appIdentifier } = options;
    
       const script = buildScript(SCRIPTS.getStyles, {
          selector,
          strategy: strategy ?? 'css',
          properties: properties || [],
          multiple,
       });
    
       try {
          return await executeInWebview(script, windowId, appIdentifier);
       } catch(error: unknown) {
          const message = error instanceof Error ? error.message : String(error);
    
          throw new Error(`Get styles failed: ${message}`);
       }
    }
  • Zod schema (GetStylesSchema) defining inputs: selector, strategy, properties (optional array), multiple (optional boolean), plus inherited windowId and appIdentifier.
    export const GetStylesSchema = WindowTargetSchema.extend({
       selector: z.string().describe('Element selector: CSS selector (default), XPath expression, text content, or ref ID'),
       strategy: selectorStrategyField,
       properties: z.array(z.string()).optional().describe('Specific CSS properties to retrieve. If omitted, returns all computed styles'),
       multiple: z.boolean().optional().default(false)
          .describe('Whether to get styles for all matching elements (true) or just the first (false)'),
    });
  • Helper script injected into the webview that resolves elements via window.__MCP__ and retrieves computed CSS styles (specific or all) using window.getComputedStyle().
    /**
     * Get computed CSS styles for elements
     *
     * @param {Object} params
     * @param {string} params.selector - CSS selector, XPath, text, or ref ID (e.g., "ref=e3") for element(s)
     * @param {string} params.strategy - Selector strategy: 'css', 'xpath', or 'text'
     * @param {string[]} params.properties - Specific CSS properties to retrieve
     * @param {boolean} params.multiple - Whether to get styles for all matching elements
     */
    (function(params) {
       const { selector, strategy, properties, multiple } = params;
    
       var elements;
    
       if (multiple) {
          elements = window.__MCP__.resolveAll(selector, strategy);
       } else {
          var el = window.__MCP__.resolveRef(selector, strategy);
          elements = el ? [el] : [];
       }
    
       if (!elements[0]) {
          throw new Error('Element not found: ' + selector);
       }
    
       const results = elements.map(function(element) {
          const styles = window.getComputedStyle(element);
    
          if (properties.length > 0) {
             const result = {};
             properties.forEach(function(prop) {
                result[prop] = styles.getPropertyValue(prop);
             });
             return result;
          }
    
          // Return all styles
          const allStyles = {};
          for (let i = 0; i < styles.length; i++) {
             const prop = styles[i];
             allStyles[prop] = styles.getPropertyValue(prop);
          }
          return allStyles;
       });
    
       return JSON.stringify(multiple ? results : results[0]);
    })
  • Registration of the get-styles script in the SCRIPTS map so it can be loaded by buildScript().
       getStyles: loadScript('get-styles'),
       focus: loadScript('focus'),
       findElement: loadScript('find-element'),
       domSnapshot: loadScript('dom-snapshot'),
       elementPicker: loadScript('element-picker'),
    } as const;
Behavior4/5

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

Beyond annotations (readOnlyHint, openWorldHint), description specifies Tauri-only scope and dependency on driver_session. No contradictions. Could mention potential side effects like no mutation, but readOnlyHint already covers that.

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?

Four sentences with no redundancy. Front-loaded with main purpose, followed by critical usage constraints and alternatives. Every sentence adds essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose, usage, constraints, and parameters comprehensively. Without an output schema, a brief note on return format (e.g., 'returns a map of property-value pairs') would be helpful, but the tool name makes the intent clear.

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

Parameters4/5

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

Schema covers 100% of parameters. Description adds value by explaining selector strategies in plain language, mentioning ref IDs cross-strategy, and describing the multiple parameter effect. This clarifies behavior beyond schema types.

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?

Clearly states it gets computed CSS styles from Tauri webview elements. Distinguishes from similar tools like webview_dom_snapshot and webview_get_pointed_element, and explicitly contrasts with browser DevTools.

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?

Provides explicit guidance: requires active driver_session, explains app targeting logic, and directs browser style work to Chrome DevTools MCP. This helps agents avoid misuse.

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/hypothesi/mcp-server-tauri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server