Skip to main content
Glama
WebDriverIO MCP Server

WebDriverIO MCP Server

Official

execute_script

Runs JavaScript in the current browser page or an Appium mobile command with arguments, returning values or elements for custom automation tasks; use dedicated tools for standard clicks and typing.

Instructions

Runs JavaScript in the page (return a value; string args that match a selector are passed as elements) or, on Appium, a "mobile: " with args. Prefer the dedicated tools for clicks and typing.

Input Schema

NameRequiredDescriptionDefault
argsNoScript arguments, or the mobile command's parameters
scriptYesJavaScript, or "mobile: <command>" on Appium
sessionNoTarget session: map name or sessionId. Omit to use the default session.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv4.1.0
    • addedInput schema / properties / session
      Added value: +{
      +  "description": "Target session: map name or sessionId. Omit to use the default session.",
      +  "type": "string"
      +}
  2. Changed2 schema fields changedv4.0.1
    • changedInput schema / properties / args / description
      Previous value: -"Arguments to pass to the script. For browser: element selectors or values. For mobile commands: command-specific parameters as objects."New value: +"Script arguments, or the mobile command's parameters"
    • changedInput schema / properties / script / description
      Previous value: -"JavaScript code (browser) or mobile command string like \"mobile: pressKey\" (Appium)"New value: +"JavaScript, or \"mobile: <command>\" on Appium"
  3. Addedv3.11.1
  4. Removedv3.11.0
  5. Added
  6. Removedv3.5.1
  7. Addedv3.4.4
  8. Removedv3.4.1
  9. First observedv2.5.0

TDQS

A4.3/5.0
Behavior4/5

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

Annotations only declare destructiveHint=false, so the description carries most of the burden and delivers real behavior: the script may `return` a value, and string args matching a selector are auto-resolved to elements. The Appium command format is also disclosed. Missing: that this executes arbitrary code with the page's privileges and typically returns the script's return value only.

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?

Two sentences, both earning their place: the first defines the two execution modes and the return/argument behavior, the second gives the routing preference. Dense in the first sentence but front-loaded and free of filler.

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?

No output schema exists, and the description compensates by saying `return` a value is how results come back. Session targeting and arg mechanics are covered between schema and description. A brief note on error behavior or the privilege of arbitrary code execution would make it fully complete for a script-execution tool.

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?

With 100% schema coverage the baseline is 3, but the description adds semantics the schema lacks: the `script` string is JavaScript in web mode or a "mobile: <command>" in Appium, and string entries in `args` that match selectors are converted to elements. That coercion rule is not stated anywhere in the schema.

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?

States a specific verb+resource: runs JavaScript in the page, or a "mobile: <command>" on Appium. It also implicitly distinguishes itself from click_element/set_value by naming the dedicated alternatives, so an agent knows this is the escape-hatch execution tool rather than a UI interaction tool.

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

Usage Guidelines4/5

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

"Prefer the dedicated tools for clicks and typing" explicitly routes the agent away from this tool for common interactions and establishes it as the fallback. It also splits usage between web (JS with return) and Appium (mobile: command) modes. It stops short of saying when script execution is actually warranted (e.g., reading page state not exposed by snapshot).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.