Skip to main content
Glama

tauri_webview_get_styles

Read-only

Retrieve computed CSS styles from elements in Tauri applications for UI debugging and testing purposes. Specify CSS selectors to inspect element styling during development.

Instructions

[Tauri Apps Only] Get computed CSS styles from elements in a Tauri app. Requires active tauri_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.
selectorYesCSS selector for element(s) to get styles from
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

  • Main handler function: destructures options, builds execution script using SCRIPTS.getStyles, and executes it via executeInWebview in the target webview.
    export async function getStyles(options: GetStylesOptions): Promise<string> {
       const { selector, properties, multiple = false, windowId, appIdentifier } = options;
    
       const script = buildScript(SCRIPTS.getStyles, {
          selector,
          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 defining input parameters for the tool, extending WindowTargetSchema.
    export const GetStylesSchema = WindowTargetSchema.extend({
       selector: z.string().describe('CSS selector for element(s) to get styles from'),
       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)'),
    });
  • Tool registration entry in the central TOOLS array, binding schema and handler with metadata.
    {
       name: 'tauri_webview_get_styles',
       description:
          '[Tauri Apps Only] Get computed CSS styles from elements in a Tauri app. ' +
          'Requires active tauri_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,
             properties: parsed.properties,
             multiple: parsed.multiple,
             windowId: parsed.windowId,
             appIdentifier: parsed.appIdentifier,
          });
       },
    },
  • Injected JavaScript IIFE: selects elements by CSS selector, retrieves computed styles (specific properties or all), returns JSON string.
    /**
     * Get computed CSS styles for elements
     *
     * @param {Object} params
     * @param {string} params.selector - CSS selector for element(s)
     * @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, properties, multiple } = params;
    
       const elements = multiple
          ? Array.from(document.querySelectorAll(selector))
          : [document.querySelector(selector)];
    
       if (!elements[0]) {
          throw new Error(`Element not found: ${selector}`);
       }
    
       const results = elements.map(element => {
          const styles = window.getComputedStyle(element);
    
          if (properties.length > 0) {
             const result = {};
             properties.forEach(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]);
    })
Behavior4/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, indicating a safe, bounded operation. The description adds valuable context beyond annotations: the prerequisite of an active tauri_driver_session, targeting logic for connected apps, and the distinction from browser tools. No contradictions with annotations exist.

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 efficiently structured in three sentences: context/prerequisites, targeting behavior, and alternative guidance. Each sentence adds distinct value with zero redundancy, making it easy to parse and front-loaded with critical 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?

For a read-only tool with full schema coverage and no output schema, the description is largely complete. It covers prerequisites, targeting logic, and alternatives. A slight gap exists in not explicitly describing the return format (e.g., style object structure), but annotations and context mitigate this.

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?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description mentions appIdentifier targeting logic but doesn't add semantic details beyond what the schema provides. The baseline score of 3 is appropriate given the comprehensive schema coverage.

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 specific action ('Get computed CSS styles from elements') and resource ('in a Tauri app'), distinguishing it from sibling tools like tauri_webview_execute_js or tauri_webview_screenshot. It explicitly mentions the Tauri-specific context and contrasts with browser alternatives.

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 ('Tauri Apps Only', 'Requires active tauri_driver_session') and when not to ('For browser style inspection, use Chrome DevTools MCP instead'). It also clarifies targeting behavior for single vs. multiple connected apps.

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