Skip to main content
Glama

eval_js

Execute JavaScript expressions in a specific browser tab and receive the evaluated result as JSON. Ideal for extracting precise values or running custom logic without fetching entire page content.

Instructions

Run a JavaScript expression in a tab and return its value as JSON.

The expression's value is returned, so write document.title, not return document.title. Promises are awaited on the CDP backend.

Do not use this to dump document.body.innerText — read_tab and query_dom answer those questions for a fraction of the tokens.

Args: expression: A JavaScript expression. tab_id: Exact tab id. url_pattern: Regex matched against tab URLs. timeout_ms: Per-call timeout.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tab_idNo
expressionYes
timeout_msNo
url_patternNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.4/5.0
Behavior3/5

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

It usefully discloses that the expression's value (not a return statement) is returned, that Promises are awaited, and that results are JSON. With no annotations, though, it never states that running arbitrary JS in a tab can mutate the page or mentions auth/error behavior, leaving the side-effect profile implicit.

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 definition is front-loaded with the core action, then adds return-value semantics, a targeted anti-usage note, and a compact Args list. Every sentence carries actionable information and none pad the text.

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 4-parameter eval tool with no annotations, the description covers purpose, all args, JSON return, promise handling, and token-aware routing. It is only slightly incomplete in not calling out that eval can change page state or what happens with missing/invalid tab targets, but the output schema removes the need to explain return shape.

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 description coverage is 0%, so the Args section is the only semantic source, and it defines all four params beyond their titles. 'url_pattern: Regex matched against tab URLs' and 'timeout_ms: Per-call timeout' are genuinely new; only the relationship between tab_id and url_pattern is left unspecified.

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 opening sentence names a specific verb (Run) and resource (JavaScript expression in a tab) and states the result format (JSON). It also clearly distinguishes this from read_tab/query_dom by warning against using it for DOM text dumps.

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?

It gives an explicit when-not with named alternatives: 'Do not use this to dump document.body.innerText — read_tab and query_dom answer those questions for a fraction of the tokens.' This is model-level routing guidance, not just a feature list.

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