Skip to main content
Glama

browser-evaluate

Execute JavaScript in the live browser context to extract data, run function logic, and inspect specific DOM elements via CSS selectors.

Instructions

Evaluates JavaScript code directly in the browser context and returns the result. Supports expressions, function strings, and complex code with automatic execution handling. Can target the entire page or work with element handles for precise DOM manipulation.

Examples:

  • Simple expression: "document.title"

  • Arrow function: "() => document.querySelectorAll('a').length"

  • Regular function: "function() { return document.body.children.length; }"

  • Function with arguments: "(tag) => document.getElementsByTagName(tag).length"

  • Complex code: "() => { const divs = document.querySelectorAll('div'); return { count: divs.length, hasClass: divs[0]?.className }; }"

  • Async function: "async () => { const res = await fetch('/api'); return res.json(); }"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoOptional arguments to pass to the JavaScript function. Can be primitives, objects, arrays, or element references. Example: { url: "https://example.com", count: 5 }
elementNoCSS selector to target specific element for evaluation
timeoutNoExecution timeout in milliseconds (default: 30000)
functionYesJavaScript code to execute (expression or function string). Examples: - Expression: "document.title" - Arrow function: "() => document.querySelectorAll('a').length" - Regular function: "function() { return document.body.children.length; }" - With arguments: "(tag) => document.getElementsByTagName(tag).length" - Async function: "async () => { const res = await fetch('/api'); return res.json(); }"
contextIdNoBrowser ID to execute on (uses most recent browser if not provided)
returnTypeNoExpected return type for better serialization (default: auto)

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.1.0

TDQS

B3.4/5.0
Behavior4/5

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

With no annotations provided, the description carries the burden of behavioral disclosure, and it does a solid job: it states that arbitrary JavaScript is evaluated, that expressions, functions, async functions, and complex code are supported, that results are returned, and that execution can target the whole page or an element. It does not warn about side effects or serialization edge cases, but the examples and execution modes give an agent a clear picture of how the tool behaves.

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?

The core purpose is front-loaded in the first sentence, and the examples are useful for conveying accepted code shapes. Some redundancy exists because the examples in the description mirror those already present in the schema's function property, but the description remains compact and scannable rather than bloated.

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?

The description covers the main invocation contract and code formats, and the schema fills in the remaining parameter semantics. However, there is no output schema and no mention of how results are serialized or what error behavior looks like, which leaves some ambiguity for a complex JavaScript-evaluation tool. It is adequate for basic use but not fully complete.

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?

The input schema covers all six parameters with descriptive text, including detailed examples for the function parameter and explanations for args, element, timeout, contextId, and returnType. The description adds little beyond what the schema already provides, so the baseline score of 3 is appropriate.

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?

The description clearly states that this tool evaluates JavaScript in the browser context and returns a result, with explicit mention of targeting either the page or a specific element. It is distinct in function from the sibling DOM inspection and screenshot tools, but it does not explicitly differentiate itself from execute-browser-commands, so it falls just short of a 5.

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

Usage Guidelines2/5

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

No explicit guidance is given about when to choose this tool over alternatives such as execute-browser-commands, get-element-properties, or capture-screenshot. The examples illustrate accepted code formats but do not state when this tool is the right choice or when a sibling would be better.

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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/iflow-mcp/ESnark-vite-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server