Skip to main content
Glama

execute_script

Run synchronous JavaScript in the current page to read multiple values or access page state like localStorage, computed styles, and element counts in one call.

Instructions

Run synchronous JavaScript in the current page and return its result (use a return statement); arguments are available as arguments[0], arguments[1], .... Useful for reading several values in one call, or page state no other tool exposes (localStorage, computed styles, element counts). The script runs with the page's privileges and can change the page; for user actions such as clicking and typing, prefer click and type so real events fire.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoJSON values passed to the script as arguments[0], arguments[1], ... (default none).
scriptYesJavaScript function body, e.g. 'return document.querySelectorAll(".inventory_item").length;'. Return plain JSON values (strings, numbers, booleans, arrays, objects).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.3.0
    • addedInput schema / properties / args / description
      Added value: +"JSON values passed to the script as arguments[0], arguments[1], ... (default none)."
    • addedInput schema / properties / script / description
      Added value: +"JavaScript function body, e.g. 'return document.querySelectorAll(\".inventory_item\").length;'. Return plain JSON values (strings, numbers, booleans, arrays, objects)."
  2. First observedv0.1.2

TDQS

A4.4/5.0
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well: it discloses synchronous execution, that arguments are positional, that the script 'runs with the page's privileges and can change the page' (mutation risk), and the real-event caveat. It stops short of error behavior, sandboxing/isolation, or what happens on exceptions.

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?

Three tight sentences, front-loaded with the core action and return contract, then usage, then the safety/alternative caveat. No filler and no repetition of sibling concerns.

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, so the description must explain return values — it does ('return its result', plain JSON values via the schema). For an arbitrary-code-execution tool with zero annotations, it covers scope, mutation risk, and alternatives well, though error/failure semantics remain unstated.

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 baseline is 3. The description reiterates the positional-argument convention and the return-statement requirement, which the schema already documents; it adds emphasis but little new syntax or format detail.

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 precise verb+resource ('Run synchronous JavaScript in the current page and return its result') and immediately pins down the contract with '(use a return statement)'. It is unmistakably distinct from siblings like get_text or get_attribute, since it is the only arbitrary-code escape hatch.

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?

Gives positive selection criteria ('reading several values in one call, or page state no other tool exposes (localStorage, computed styles, element counts)') and an explicit exclusion with a named alternative ('for user actions such as clicking and typing, prefer click and type so real events fire'). Both when-to-use and when-not-to-use are covered.

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