Skip to main content
Glama
Lokii0911
by Lokii0911

execute_script

Execute JavaScript in the active browser page and return a JSON-serializable result. Useful for scraping dynamic content, manipulating page state, or testing scripts directly.

Instructions

Execute JavaScript in the active page and return the JSON-serializable result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes
argsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The tool 'execute_script' is registered as an MCP tool via the @mcp.tool() decorator. It accepts a 'script' string and optional 'args' list, delegates to browser.execute_script via the _run helper.
    @mcp.tool()
    def execute_script(script: str, args: list[Any] | None = None) -> dict[str, Any]:
        """Execute JavaScript in the active page and return the JSON-serializable result."""
        return _run("execute_script", browser.execute_script, script, args)
  • The _run helper function wraps calls to browser methods with exception handling and conversion via _as_dict.
    def _run(action: str, func: Any, *args: Any, **kwargs: Any) -> Any:
        try:
            return _as_dict(func(*args, **kwargs))
        except BrowserError:
            logger.exception("Browser action failed: %s", action)
            raise
        except Exception as exc:
            logger.exception("Unexpected Selenium MCP error during %s", action)
            raise BrowserError(f"{action} failed: {exc}") from exc
  • The actual implementation of execute_script in BrowserManager. It acquires the lock, calls Selenium's driver.execute_script(script, *args), and returns the result.
    def execute_script(self, script: str, args: list[Any] | None = None) -> dict[str, Any]:
        with self._lock:
            result = self._require_driver().execute_script(script, *(args or []))
            return {"result": result}
Behavior2/5

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

The description only mentions execution and return of a JSON-serializable result, but fails to disclose error handling, async behavior, security restrictions, or what happens with non-serializable returns. Given no annotations, the description carries the full burden and is insufficient.

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 description is a single concise sentence. It is front-loaded and wastes no words, but could be slightly expanded for clarity without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite an output schema, the description lacks completeness for a powerful tool. No details on error states, return format beyond 'JSON-serializable', or execution context. The tool's complexity demands more context to ensure correct usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description does not explain the 'args' parameter beyond the schema. With 0% schema description coverage, the description should compensate but does not. It only implies 'script' is code, but adds no detail about how 'args' is used or how parameters interact.

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?

The description clearly states it executes JavaScript and returns a JSON-serializable result, specifying both the action and the resource. This distinguishes it from sibling tools that perform specific browser actions like clicking or navigating.

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 guidance is provided on when to use this tool versus alternatives. The description does not mention prerequisites, appropriate scenarios, or what to avoid, leaving the agent without context for decision making.

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

Install Server

Other Tools

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/Lokii0911/SeleniumMCP'

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