Skip to main content
Glama
Saik0s

Browser-Use MCP Server

by Saik0s

run_browser_agent

Automate browser tasks and interactions using agent-based capabilities for efficient workflow integration and task execution.

Instructions

Handle run-browser-agent tool calls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
add_infosNo
taskYes

Implementation Reference

  • Registers the 'run_browser_agent' tool using the @server.tool() decorator on the FastMCP server instance.
    @server.tool()
  • The primary handler function for the 'run_browser_agent' MCP tool. It orchestrates browser/context creation, instantiates BrowserUseAgent with the provided task, executes the agent loop, handles shared resources, logging, errors, and cleanup based on settings, returning the agent's final result.
    @server.tool()
    async def run_browser_agent(ctx: Context, task: str) -> str:
        logger.info(f"Received run_browser_agent task: {task[:100]}...")
        agent_task_id = str(uuid.uuid4())
        final_result = "Error: Agent execution failed."
    
        browser_instance: Optional[CustomBrowser] = None
        context_instance: Optional[CustomBrowserContext] = None
        controller_instance: Optional[CustomController] = None
    
        try:
            async with resource_lock: # Protect shared resource access/creation
                browser_instance, context_instance = await get_browser_and_context()
                # For server, ask_human_callback is likely not interactive, can be None or a placeholder
                controller_instance = await get_controller(ask_human_callback=None)
    
            if not browser_instance or not context_instance or not controller_instance:
                 raise RuntimeError("Failed to acquire browser resources or controller.")
    
            main_llm_config = settings.get_llm_config()
            main_llm = internal_llm_provider.get_llm_model(**main_llm_config)
    
            planner_llm = None
            if settings.llm.planner_provider and settings.llm.planner_model_name:
                planner_llm_config = settings.get_llm_config(is_planner=True)
                planner_llm = internal_llm_provider.get_llm_model(**planner_llm_config)
    
            agent_history_json_file = None
            task_history_base_path = settings.agent_tool.history_path
    
            if task_history_base_path:
                task_specific_history_dir = Path(task_history_base_path) / agent_task_id
                task_specific_history_dir.mkdir(parents=True, exist_ok=True)
                agent_history_json_file = str(task_specific_history_dir / f"{agent_task_id}.json")
                logger.info(f"Agent history will be saved to: {agent_history_json_file}")
    
            agent_instance = BrowserUseAgent(
                task=task,
                llm=main_llm,
                browser=browser_instance,
                browser_context=context_instance,
                controller=controller_instance,
                planner_llm=planner_llm,
                max_actions_per_step=settings.agent_tool.max_actions_per_step,
                use_vision=settings.agent_tool.use_vision,
            )
    
            history: AgentHistoryList = await agent_instance.run(max_steps=settings.agent_tool.max_steps)
    
            if agent_history_json_file:
                agent_instance.save_history(agent_history_json_file)
    
            final_result = history.final_result() or "Agent finished without a final result."
            logger.info(f"Agent task completed. Result: {final_result[:100]}...")
    
        except Exception as e:
            logger.error(f"Error in run_browser_agent: {e}\n{traceback.format_exc()}")
            final_result = f"Error: {e}"
        finally:
            if not settings.browser.keep_open and not settings.browser.use_own_browser:
                logger.info("Closing browser resources for this call.")
                if context_instance:
                    await context_instance.close()
                if browser_instance:
                    await browser_instance.close()
                if controller_instance: # Close controller only if not shared
                    await controller_instance.close_mcp_client()
            elif settings.browser.use_own_browser: # Own browser, only close controller if not shared
                 if controller_instance and not (settings.browser.keep_open and controller_instance == shared_controller_instance):
                    await controller_instance.close_mcp_client()
        return final_result
Behavior1/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but provides zero information about what the tool actually does, whether it's read-only or destructive, what permissions are required, what side effects might occur, or what the expected behavior is. The description is essentially empty of behavioral information.

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

Conciseness2/5

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

While technically concise with just one short sentence, this is a case of under-specification rather than effective conciseness. The description is so minimal that it fails to communicate any useful information, making it ineffective despite its brevity. Every word in the description is wasted since it adds no value.

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

Completeness1/5

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

Given a tool with 2 parameters (0% documented in schema), no annotations, no output schema, and no sibling tools, the description is completely inadequate. It provides no information about purpose, usage, behavior, parameters, or expected outcomes. This leaves an AI agent with essentially no guidance on how to properly use this tool.

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

Parameters1/5

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

With 0% schema description coverage and two parameters (one required), the description provides absolutely no information about what the 'task' and 'add_infos' parameters mean, what format they should take, or how they affect the tool's operation. The description doesn't even mention that parameters exist, let alone explain their purpose or usage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Handle run-browser-agent tool calls' is a tautology that merely restates the tool name with minimal variation. It provides no information about what the tool actually does, what 'run-browser-agent' means, or what resources or operations are involved. This fails to communicate any meaningful purpose to an AI agent.

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

Usage Guidelines1/5

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

The description offers no guidance on when to use this tool, what context it's appropriate for, or what alternatives might exist. There's no mention of prerequisites, typical use cases, or any constraints that would help an agent decide when to invoke it versus other approaches.

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

Related 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/Saik0s/mcp-browser-use'

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