Skip to main content
Glama

evaluate_script

Execute a JavaScript function in a target page and return JSON-serializable results for browser automation, inspection, or data extraction.

Instructions

Evaluate a JavaScript function inside the target page. Returns the response as JSON, so returned values have to be JSON-serializable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoAn optional list of arguments to pass to the function.
pageIdYesTargets a specific page by ID.
filePathNoThe absolute or relative path to a file to save the script output to. If omitted, the output is returned inline.
functionYesA JavaScript function declaration to be executed by the tool in the target page. Example without arguments: `() => document.title` or `async () => await fetch("example.com")`. Example with arguments: `(el) => el.innerText`
dialogActionNoHandle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept.
waitForStableDomNoWhether to wait for the DOM to settle. Pass false if the script only reads data. Defaults to true.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

B3.2/5.0
Behavior3/5

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

readOnlyHint=false correctly signals this is not a safe read-only operation, and the description's note that arbitrary JS runs in the page is consistent with that. It adds the useful constraint that return values must be JSON-serializable, but says nothing about side effects on the page, error behavior, sandboxing/security boundaries, or that dialogs are auto-accepted by default.

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 short sentences, front-loaded with the core purpose followed by the return-value constraint. No filler, though the JSON note could be folded more tightly.

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

Completeness3/5

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

With no output schema, the description reasonably explains that output is JSON and can be saved via filePath (per schema). However, for a tool that executes arbitrary code in a browser page, the description omits side-effect/security context and error handling that an agent would want before invoking it.

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 pageId, function, args, filePath, dialogAction, and waitForStableDom are all documented in the schema itself. The description adds no parameter-level meaning beyond the JSON-serializable constraint, so baseline 3 applies.

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?

States a specific verb and resource: evaluate a JavaScript function inside the target page, and notes the result is returned as JSON. This distinguishes it from browsing siblings like click, fill, or take_snapshot. It does not, however, contrast itself against the other data-reading tools in the family.

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?

There is no explicit when-to-use or when-not-to-use guidance, and no alternatives are named (e.g. use click/fill for element interaction, take_snapshot for page content). The JSON-serializability note is a constraint on the return value, not selection guidance.

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