Skip to main content
Glama

Run JavaScript

javascript_tool

Run JavaScript in a browser tab's page context to inspect or modify the DOM, read window variables, and evaluate expressions with top-level await.

Instructions

Execute JavaScript in the page's context (DOM, window, page variables). REPL semantics: top-level await works and the value of the last expression is returned — write the expression you want (e.g. document.title or await fetch(url).then(r => r.json())) rather than return ....

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": {
      "tabId": "<tabId>",
      "text": "<text>"
    },
    "name": "javascript_tool"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesJavaScript code to run.
tabIdYesTab ID from tabs_context / tabs_create.
actionNo'javascript_exec' (accepted for compatibility).

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

A3.6/5.0
Behavior3/5

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

With no annotations, the description carries the full burden, and it does disclose real behavioral traits: code runs in the page's own context with DOM/window access, top-level await resolves, and the last expression's value is the return. It omits side-effect risk (arbitrary page mutation), error/thrown-exception behavior, and any timeout or CSP restriction — significant gaps for an unannotated execute-anything 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, front-loaded with what it does, followed by the one non-obvious calling convention. The inline examples replace several sentences of explanation, and no wording is wasted.

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?

Return semantics are covered in lieu of an output schema, which is good, but for an unannotated tool that runs arbitrary code in a live tab the definition says nothing about error surfacing, timeouts, or whether the page is mutated. Adequate to call it correctly, thin on consequences.

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 100%, so the baseline is 3, but the description genuinely adds meaning about the `text` parameter: it is evaluated as a REPL expression whose value is returned, not a function body, with a concrete example. That materially changes how an agent authors the string, beyond the schema's terse 'JavaScript code to run.'

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 — 'Execute JavaScript in the page's context' — and narrows scope with '(DOM, window, page variables)', which tells an agent this is live page-context evaluation rather than static extraction. It does not contrast itself with siblings like get_page_text or read_page, so an agent must infer that boundary.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives strong guidance on HOW to write the call (expression form, top-level await, no `return`), but nothing on WHEN to pick this over read_page, get_page_text, or read_console_messages. Usage is implied by the 'page context' framing rather than stated as a selection rule.

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