Skip to main content
Glama

javascript

Executes a single expression in a specified browser tab and returns its final value, awaiting promises to extract page data or verify interactions.

Instructions

Run JavaScript in the page and return the value of the last expression (a promise is awaited). Top-level return and await are not allowed: to use await, end with an async function call, e.g. (async () => { const r = await fetch(url); return r.status; })(). Write the code as ONE expression (an arrow function call is fine): some sites forbid eval, and there only a single expression, or statements ending in return, will work.

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

Input Schema

NameRequiredDescriptionDefault
codeYes
tabIdYesTab ID, from tabs_list or tab_create

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.8

TDQS

A3.9/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. It helpfully discloses that some sites forbid eval and that only a single expression or statements ending in return will work, which is real behavioral context. It omits error behavior on thrown exceptions, whether the code runs in an isolated/content-script world versus the page's main world, and any CSP caveats.

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 purpose and return semantics, then constraints. Slight redundancy: the 'ONE expression' instruction repeats the earlier top-level return/await prohibition, and the closing clause is a bit run-on, but nothing is wasted.

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 two-parameter execution tool with no output schema and no annotations, the description covers return value, code form, and site-level eval restrictions adequately; tabId comes from the schema. Missing only exception/error reporting and execution context, minor gaps.

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 only 50%: tabId is documented in the schema, but the code parameter has no schema description. The description compensates well by explaining what form code must take — single expression, async function call for awaiting, optional trailing return. Meaning beyond the schema is genuinely added for the undocumented parameter.

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 — run JavaScript in the page — plus the precise return convention (value of the last expression, awaited if a promise). That is unambiguous and clearly distinct from DOM-manipulation siblings such as click, type, or navigate.

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?

Offers solid how-to constraints (no top-level return/await, use an async IIFE, write one expression) but gives no guidance about when to prefer it over siblings like click, type, or form_input. The agent must infer when JS execution is the right choice versus a purpose-built tool.

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