Browser Tools MCP

repository·main·Indexed 27 days ago

https://github.com/agentdeskai/browser-tools-mcp

An MCP (Model Context Protocol) server that enables AI-powered applications to monitor and interact with a web browser. It allows agents to capture screenshots, monitor console logs, and run automated web audits for SEO, Performance, Accessibility, and Best Practices via a companion Node server and Chrome extension.

Tokens
10.7K
Snippets
23
Records
45
Agent score
92%

What's inside @agentdeskai/browser-tools-mcp

  1. BrowserTools MCP Architecture

    main

    The system consists of three layers to enable AI interaction with the browser:

    1. Chrome Extension: Captures screenshots, console logs, network activity, and DOM elements. It communicates via WebSockets to the Node Server.
    2. Node Server (browser-tools-server): Acts as middleware. It receives logs from the extension, processes requests from the MCP server, truncates data to fit token limits, and removes sensitive headers/cookies before sending data to the LLM.
    3. MCP Server (browser-tools-mcp): Implements the Model Context Protocol, providing standardized tools (like the audit tools mentioned above) to MCP-compatible clients like Cursor, Claude Desktop, Cline, or Zed.
  2. Puppeteer Service Features

    main

    The service includes the following capabilities:

    Cross-Platform Browser Support

    • Supports Windows, macOS, and Linux.
    • Detects Chrome, Edge, Brave, and Firefox.
    • Includes a fallback strategy for locating browser executables.

    Smart Browser Management

    • Uses a singleton browser instance with automatic cleanup.
    • Implements connection retry mechanisms.
    • Manages temporary user data directories with automatic cleanup.

    Rich Configuration Options

    • Custom browser paths.
    • Network condition emulation.
    • Device emulation (mobile, tablet, desktop).
    • Resource blocking.
    • Cookies and headers customization.
    • Locale and timezone emulation.
  3. Quickstart Guide for BrowserTools MCP

    main

    To use BrowserTools MCP, you must run three distinct components. Note that this project is no longer active; please use a different solution.

    1. Chrome Extension: Install the extension from the v1.2.0 release.
    2. MCP Server: Install this into your IDE (e.g., Cursor, Claude Desktop) using: npx @agentdeskai/browser-tools-mcp@latest
    3. Node Server: Run this in a separate terminal window to act as middleware: npx @agentdeskai/browser-tools-server@latest

    After setup, open Chrome DevTools and navigate to the BrowserToolsMCP panel.

    Troubleshooting:

    • If it fails, quit all Chrome processes entirely.
    • Restart the browser-tools-server.
    • Ensure only one instance of the Chrome DevTools panel is open.
    npx @agentdeskai/browser-tools-mcp@latest
    npx @agentdeskai/browser-tools-server@latest
  4. Request LLM Completions via Sampling

    main

    Sampling allows an MCP server to request LLM completions through the client. This enables agentic behaviors like decision-making or data generation.

    Note: This feature is not yet supported in the Claude Desktop client.

    Flow:

    1. Server sends sampling/createMessage request to the client.
    2. Client reviews/modifies the request.
    3. Client samples from an LLM.
    4. Client returns the result to the server.

    Key Parameters:

    • messages: Array of conversation history (role and content).
    • modelPreferences: Hints for the client (e.g., costPriority, speedPriority, intelligencePriority).
    • includeContext: Specifies context to include ("none", "thisServer", or "allServers").
    • systemPrompt: Optional system prompt request.
    {
    "method": "sampling/createMessage",
    "params": {
    "messages": [
    {
    "role": "user",
    "content": {
    "type": "text",
    "text": "What files are in the current directory?"
    }
    }
    ],
    "systemPrompt": "You are a helpful file system assistant.",
    "includeContext": "thisServer",
    "maxTokens": 100
    }
    }
  5. Create reusable Prompt templates

    main

    Prompts allow servers to define reusable templates and workflows that clients can surface to users. Prompts are user-controlled and can accept dynamic arguments and include context from resources.

    Prompt Structure

    A prompt definition includes:

    • name: Unique identifier.
    • description: Human-readable description.
    • arguments: An optional list of objects containing name, description, and required (boolean).
  6. Run Lighthouse-powered audits

    main

    The server provides AI-optimized audit capabilities for Accessibility, Performance, SEO, and Best Practices. All audits implement a "smart limit" to ensure high-impact issues are prioritized for AI consumption:

    • Critical issues: No limit (all issues shown)
    • Serious issues: Up to 15 items per issue
    • Moderate issues: Up to 10 items per issue
    • Minor issues: Up to 3 items per issue
  7. Handle MCP Resource Updates

    main

    MCP supports real-time updates for resources through two mechanisms:

    1. List changes: Servers notify clients when the available resource list changes using the notifications/resources/list_changed notification.
    2. Content changes: Clients can subscribe to specific resources using resources/subscribe. The server then sends notifications/resources/updated when the content changes. Clients can then fetch the latest content via resources/read and eventually resources/unsubscribe.
  8. Install the Browser Tools MCP Server

    main

    You can run the Browser Tools MCP Server using npx or install it globally via npm.

    Prerequisites:

    • Node.js 14 or higher
    • A running instance of the Browser Tools Server
    • Chrome or Chromium browser installed (required for audit functionality)
    npx @agentdeskai/browser-tools-mcp

    Or install globally:

    npm install -g @agentdeskai/browser-tools-mcp
  9. Use stdio Transport for Local Integrations

    main

    The stdio transport enables communication through standard input and output streams. This is the preferred method for building command-line tools, local integrations, or simple process communication via shell scripts.

    const server = new Server({
      name: "example-server",
      version: "1.0.0"
    }, {
      capabilities: {}
    });
    
    const transport = new StdioServerTransport();
    await server.connect(transport);