Skip to main content
Glama

Run JavaScript

eval_js

Evaluate JavaScript expressions in a page's main world and return awaited results as JSON to inspect application state or DOM.

Instructions

Evaluates an expression in the page's main world and answers with its value as JSON (promises are awaited). For reading app state or the DOM; prefer click and type for input, which pages see as real.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "expression": "<expression>"
    },
    "name": "eval_js"
  }
}

Input Schema

NameRequiredDescriptionDefault
expressionYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior4/5

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

With no annotations, the description carries the full load and does disclose key traits: execution context (page main world), async handling ('promises are awaited'), and response encoding (JSON value). It leaves gaps on failure modes — what happens on a thrown exception, on non-serializable return values, or whether side effects on page state persist — which matter for an arbitrary-code tool.

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?

Two sentences with zero filler; the core behavior and return format come first, then the routing caveat. Nothing is repeated from the schema or restated from the name.

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 one-parameter, no-output-schema tool this covers what it does, where it runs, how results come back, and when to avoid it. The only missing piece an agent might need is error/exception behavior and return-value serialization limits.

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 coverage is 0% on a single parameter, so the description must compensate, and it does: the argument is an expression evaluated in the page's main world, may return a promise (awaited), and its result is serialized to JSON. It stops short of stating serialization constraints or whether the expression may be a multi-statement body rather than a single expression.

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 and resource ('Evaluates an expression in the page's main world') plus the return contract ('answers with its value as JSON'). The mention of 'prefer click and type for input' implicitly separates it from the interaction siblings, so an agent can tell this is the read/execute primitive rather than an input simulator.

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 an explicit when-to-use ('For reading app state or the DOM') and an explicit when-not with the named alternatives ('prefer click and type for input, which pages see as real'). The rationale for the exclusion — synthetic events are detectable — is stated, which is exactly what an agent needs to choose correctly.

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