Skip to main content
Glama

Run Code in Browser

run_code_in_browser
Destructive

Run a TypeScript snippet inside the RUNNING APP's preview document in the user's open Floot editor (document/window ARE the live app's DOM — query document directly; do NOT look for a preview iframe, there is none from the snippet's point of view). Use it to read the live app's DOM — measuring elements, reading computed styles, inspecting rendered output. The preview is a cross-origin iframe inside the editor page, so DOM reads and clicks made from the editor page do not reach the app; this tool runs the snippet inside the preview document itself. _floot.* helpers are available. The snippet MUST export default async function and return a string — the returned value is the tool result (unlike run_code_in_vm, which is a plain script returning stdout). It can import project files by relative path from the root (e.g. ./helpers/foo). Requires the user to have the project open in the editor — fails fast with guidance if no browser is connected; prefer run_code_in_vm for anything that doesn't need the DOM. Simple interaction checks work well: element.click() a button, await a beat, then read the resulting DOM/state to verify a flow end-to-end — do this instead of asking the user to test basic interactions. Multi-step e2e journeys and typed text input are where simulation gets unreliable (React controlled inputs ignore assigned values) — leave THOSE to the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesA TypeScript module that exports a default async function returning a string; that string is the tool result. Runs at the project root, so import other files by relative path. No top-level `return` (it's a module, not a function body) and no React hooks (not a component). Example: export default async function () { const el = document.querySelector("main"); return JSON.stringify({ width: el?.clientWidth ?? null }); }
projectIdYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.4/5.0
Behavior4/5

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

Annotations declare destructiveHint=true and openWorldHint=true, so the mutation surface is flagged. The description adds real value beyond that: the fails-fast-on-disconnected-browser behavior, the cross-origin iframe constraint, and the returned-string contract. Minor gap: it doesn't state that arbitrary code execution can mutate app state through clicks, though 'destructiveHint' covers the safety profile.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The content is dense and useful, but the description is long-winded with parenthetical asides ('(unlike run_code_in_vm, which is a plain script returning stdout)'). Front-loading is good, but some sentences could be tightened.

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?

No output schema, so the returned-string contract must be stated — and it is. No annotations cover the iframe/editor context, and the description covers it thoroughly. Remaining gap is the undocumented projectId, which matters for invocation.

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 50%, with projectId undocumented in the schema. The description compensates by clarifying the code parameter's contract (module exporting a default async function, returns a string, runs at project root, imports by relative path), though projectId itself remains unexplained.

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 execution context ('Run a TypeScript snippet inside the RUNNING APP's preview document'), and explicitly disambiguates from the sibling run_code_in_vm. An agent knows exactly what this does and how it differs.

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?

Provides explicit when/when-not routing: 'prefer run_code_in_vm for anything that doesn't need the DOM', names simple interaction checks as good fits, and calls out multi-step e2e journeys and typed input as cases to leave to the user. This is exemplary guidance.

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.

Resources