Skip to main content
Glama

session_eval

Evaluate a JavaScript expression on an open session's current page and return the JSON result, or a structured error when the expression throws.

Instructions

Evaluate a JavaScript expression on the session's current page.

Requires a session opened with profile_start first. A page-JS error is data to read, not a tool failure: the daemon returns {"ok": false, "error", "error_type"} instead of raising when the expression throws.

Args: name: identity name, exactly as profiles_list reports it. expr: the JavaScript expression to evaluate in the page, e.g. "document.title" or "document.querySelectorAll('a').length".

Returns the {ok, result} envelope: {"ok": true, "result": } on success. result is whatever the expression evaluates to as JSON — string, number, boolean, object, array, or null — not necessarily a string; do not assume its type. Fails with a readable message (raises, rather than the {ok: false} envelope above) if the session is not open (409 — call profile_start first) or the identity does not exist (404).

Input Schema

NameRequiredDescriptionDefault
exprYes
nameYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.5

TDQS

A4.7/5.0
Behavior5/5

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

With no annotations, the description carries the full burden and does so well: it discloses that page-JS errors return an {ok:false, error, error_type} envelope rather than raising, versus 409/404 conditions that do raise. It also warns that the result type is not necessarily a string, which prevents a common misparse.

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?

Front-loaded with the core action and the error-handling caveat, and the Args block adds real semantics rather than restating types. Slightly longer than necessary — the Args section partly repeats parameter mentions in the prose — but nothing is wasted.

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

Completeness5/5

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

No output schema exists, yet the description fully specifies the return envelope, the variable type of `result`, and the two distinct failure modes. Nothing an agent needs to call this correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate, and it does: it defines `name` as the identity name exactly as profiles_list reports it, and gives two concrete `expr` examples ("document.title", "document.querySelectorAll('a').length").

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 ('Evaluate') and resource ('a JavaScript expression on the session's current page'), which separates it cleanly from siblings like session_goto, session_click_selector, or session_snapshot. An agent can pick this tool without opening the schema.

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?

Explicitly names the prerequisite ('Requires a session opened with profile_start first') and reinforces it in the failure path ('409 — call profile_start first'). It doesn't contrast against alternative page-inspection siblings like session_snapshot, but the usage context is unambiguous.

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