Skip to main content
Glama

run_js

Execute JavaScript in a shared tab’s own page context to read data missing from the outline or drive page APIs directly, returning the last expression’s result and awaiting promises.

Instructions

Run JavaScript in the page's own context (page globals are visible) and return the result of the last expression, awaited if it is a promise. Works on sites with a strict CSP. Use for reading data the outline does not show or driving page APIs directly.

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": {
      "code": "<code>"
    },
    "name": "run_js"
  }
}

Input Schema

NameRequiredDescriptionDefault
tabNoTab handle from list_tabs, e.g. "chrome:812". Optional when only one tab is shared.
codeYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4/5.0
Behavior4/5

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

With no annotations present, the description carries the full burden and does meaningful work: it discloses execution context (page globals visible), evaluation semantics (result of the last expression), async handling (awaited if a promise), and a non-obvious environmental trait (works under strict CSP). It does not disclose timeouts, error/exception behavior, or side-effect persistence, which matter for arbitrary code execution.

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, no filler: execution context and return semantics come first, then the usage trigger. Each clause carries distinct information and nothing is repeated from the schema or title.

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?

With no output schema, the description correctly explains what comes back (the last expression's value, resolved if a promise), so return semantics are covered. For a tool that executes arbitrary code in a live page, the remaining gap is failure modes and any execution limits, which an agent would want before invoking.

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 coverage is 50%: 'tab' is documented in the schema, but 'code' has no schema description. The description partly compensates by explaining how code is evaluated (last expression, awaited if a promise), which tells the agent to pass an expression rather than a full script. It adds no syntax, size, or error-shape guidance for the code payload, so it goes only modestly beyond the schema.

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 ('Run JavaScript') plus the critical execution scope ('in the page's own context, page globals are visible'), which is exactly the distinction an agent needs to pick an execution tool. It stops short of naming a sibling (e.g. run_script) to contrast an isolated-context variant, so differentiation is implied by scope rather than explicit.

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?

Gives a clear positive trigger: 'Use for reading data the outline does not show or driving page APIs directly' — that is a real when-to-use condition tied to a gap in other tools. It offers no when-not guidance, no prerequisites, and no named alternative for callers who don't want page-context side effects.

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