Skip to main content
Glama

browser_add_init_script

Read-onlyIdempotent

Register JavaScript that runs BEFORE the page's own code, at document start, on every page opened afterwards in this identity's context. Use when browser.evaluate is too late — most often to hook window.fetch/XMLHttpRequest and capture a SPA's request bodies, which network_requests cannot show. Does NOT affect already-open pages: add the script first, then browser.open. Cannot be removed once added; it lives until the context is evicted or browser.close is called, and is put back by itself when the browser service restarts in between. Adding the same script again answers already_present and changes nothing.

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": {
      "script": "<script>"
    },
    "name": "browser_add_init_script"
  }
}

Input Schema

NameRequiredDescriptionDefault
scriptYes
in_workspaceNoRun this one call in this workspace id instead of the session's. Nothing is stored; other sessions are not affected.
identity_nameNo_anon

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / in_workspace
      Added value: +{
      +  "description": "Run this one call in this workspace id instead of the session's. Nothing is stored; other sessions are not affected.",
      +  "type": "integer"
      +}
  2. Added

TDQS

A4.5/5.0
Behavior3/5

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

Rich beyond the annotations: discloses irreversibility ('Cannot be removed once added'), lifetime (context eviction or browser.close), restart persistence, non-retroactivity, and the idempotent response token 'already_present'. However, this level of persistence is in tension with readOnlyHint=true — the description never reconciles that the call durably mutates context state while being advertised as a read, leaving the agent to resolve the conflict itself.

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?

Front-loaded with the action and timing, then when-to-use, then lifecycle caveats — no filler. Five distinct facts in roughly a hundred words, and the sibling contrast sits immediately after the purpose rather than buried.

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, so the description supplies the one return signal that matters ('already_present'). For a persistent, non-removable state change, it covers what an agent needs to call it safely and in the right order; the only omission is the readOnlyHint mismatch, which is an annotation problem rather than a description gap.

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 33%, so the description must carry weight: it fully explains the semantics of `script` (timing, scope, what it is used to hook) and scopes behavior to 'this identity's context,' which effectively explains `identity_name`. `in_workspace` is left entirely to the schema's own description, which is adequate but not reinforced.

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 — 'Register JavaScript that runs BEFORE the page's own code, at document start, on every page opened afterwards in this identity's context' — and explicitly contrasts with browser.evaluate ('too late') and network_requests ('cannot show'). An agent can distinguish it from every sibling without opening a schema.

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?

Names the alternative it replaces (browser.evaluate) and the condition selecting it, gives the canonical workflow ('add the script first, then browser.open'), and states an explicit exclusion ('Does NOT affect already-open pages'). Sequence guidance is unusual and valuable here.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.