Skip to main content

Browser console log capture and control via MCP for Claude Code

Project description

MCP Browser

A professional Model Context Protocol (MCP) server that provides comprehensive browser automation and console log capture through Chrome extension integration. Features automated installation, DOM interaction capabilities, and seamless Claude Code integration.

๐Ÿš€ Quick Start (5 Minutes)

# 1. Clone and install with automated setup
git clone https://github.com/browserpymcp/mcp-browser.git
cd mcp-browser
./install.sh

# 2. Install Chrome extension
# Open chrome://extensions/ โ†’ Enable Developer mode โ†’ Load unpacked โ†’ Select extension/

# 3. Configure Claude Code integration
./setup-claude-code.sh

# 4. Start server and test DOM interaction
mcp-browser start
open tmp/demo_dom_interaction.html
# Ask Claude: "Fill out the demo form and submit it"

โœจ Features

Core Capabilities

  • ๐ŸŽฏ Advanced DOM Interaction: Click elements, fill forms, submit data, select dropdowns, wait for elements
  • ๐Ÿ“Š Console Log Capture: Real-time capture from all browser tabs with advanced filtering
  • ๐Ÿ“ท High-Quality Screenshots: Automated browser viewport captures via Playwright
  • ๐ŸŒ Smart Navigation: Programmatic browser navigation with URL validation
  • ๐Ÿ”„ Auto-Discovery: Dynamic port allocation (8875-8895) with collision avoidance
  • ๐Ÿค– AI-Ready: 11 MCP tools optimized for Claude Code browser automation

Technical Architecture

  • โšก Service-Oriented Architecture (SOA): Clean separation with dependency injection
  • ๐Ÿ”— WebSocket Communication: Real-time bidirectional browser communication
  • ๐Ÿ’พ JSONL Storage: Automatic log rotation (50MB) with 7-day retention
  • ๐ŸŽจ Chrome Extension: Visual connection status with real-time monitoring
  • ๐Ÿค– Claude Code Integration: 10 MCP tools for AI-driven browser automation

Installation & Deployment

  • ๐Ÿ“ฆ Zero-Config Setup: Single ./install.sh command handles everything
  • ๐Ÿ”ง Professional CLI: Complete process management (start/stop/status/logs/follow)
  • โš™๏ธ Smart Configuration: Auto-generated settings with sensible defaults
  • ๐Ÿงช Self-Verification: Built-in installation testing and demo capabilities
  • ๐Ÿ  Clean Organization: Isolated virtual environment and ~/.mcp-browser/ structure

Architecture

The project follows a Service-Oriented Architecture (SOA) with dependency injection:

  • WebSocket Service: Handles browser connections with port auto-discovery
  • Storage Service: Manages JSONL log files with rotation
  • Browser Service: Processes console messages and manages browser state
  • Screenshot Service: Playwright integration for screenshots
  • MCP Service: Exposes tools to Claude Code

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.8+ (with pip)
  • Chrome/Chromium browser
  • Git (for cloning)

1. Clone and Install

# Clone the repository
git clone https://github.com/browserpymcp/mcp-browser.git
cd mcp-browser

# Automated installation with venv setup
./install.sh

The installation script will:

  • โœ… Check system requirements
  • โœ… Create isolated virtual environment
  • โœ… Install all dependencies
  • โœ… Set up directory structure in ~/.mcp-browser/
  • โœ… Create command symlink for global access
  • โœ… Configure default settings

2. Install Chrome Extension

  1. Open Chrome โ†’ chrome://extensions/
  2. Enable "Developer mode" (top right)
  3. Click "Load unpacked"
  4. Select the extension/ folder from this project
  5. Verify extension icon appears with green connection indicator
  6. Extension auto-connects to server on port 8875-8895

3. Configure Claude Code Integration

# Automated Claude Code setup
./setup-claude-code.sh

This script will:

  • โœ… Verify MCP Browser installation and virtual environment
  • โœ… Test MCP server functionality with all 11 tools
  • โœ… Generate Claude Code configuration automatically
  • โœ… Validate WebSocket connectivity and extension support
  • โœ… Create demo files for immediate testing
  • โœ… Show clear next steps and verification commands

๐ŸŽฏ Usage

Professional CLI Commands

# Start the server
mcp-browser start

# Check status (shows ports, PIDs, logs)
mcp-browser status

# View logs
mcp-browser logs     # Last 50 lines
mcp-browser logs 100 # Last 100 lines
mcp-browser follow   # Real-time tail

# Stop the server
mcp-browser stop

# Restart (stop + start)
mcp-browser restart

# Run in MCP mode for Claude Code
mcp-browser mcp

# Show version and help
mcp-browser version
mcp-browser help

๐Ÿ› ๏ธ MCP Tools Available in Claude Code

MCP Browser provides 11 comprehensive tools for advanced browser automation and interaction:

Core Browser Control

  1. browser_navigate(port, url) - Navigate browser to a URL

    • Port auto-discovery from active connections
    • Full URL validation and error handling
    • WebSocket command transmission
  2. browser_query_logs(port, last_n, level_filter) - Query console logs with advanced filtering

    • Filter by log level (error, warn, info, debug)
    • Limit number of results (default: 50)
    • Real-time and stored log retrieval
    • JSONL format with timestamps
  3. browser_screenshot(port, url?) - Capture high-quality viewport screenshots

    • Optional URL navigation before capture
    • Playwright-powered rendering
    • PNG format with metadata

Advanced DOM Interaction & Automation

  1. browser_click(port, selector/xpath/text) - Intelligent element clicking

    • CSS selectors, XPath expressions, or visible text
    • Automatic element visibility waiting
    • Click coordination and action verification
  2. browser_fill_field(port, selector/xpath, value) - Precise form field filling

    • Support for text inputs, textareas, and password fields
    • Automatic field clearing before input
    • Value validation and error reporting
  3. browser_fill_form(port, form_data, submit?) - Bulk form filling automation

    • Multiple fields filled in single operation
    • Optional automatic form submission
    • Field mapping by name, ID, or selector
    • Batch operation with rollback on errors
  4. browser_submit_form(port, selector/xpath?) - Smart form submission

    • Auto-detect forms or use specific selectors
    • Handle both button clicks and form.submit()
    • Wait for submission completion
  5. browser_get_element(port, selector/xpath/text) - Element information extraction

    • Retrieve text content, attributes, and properties
    • Element visibility and interaction state
    • Bounding box and position data
  6. browser_wait_for_element(port, selector, timeout?) - Dynamic content handling

    • Wait for elements to appear in DOM
    • Configurable timeout (default: 10s)
    • Essential for SPA and AJAX-heavy sites
  7. browser_select_option(port, selector, value/text/index) - Dropdown interaction

    • Select by value, visible text, or index
    • Support for both <select> and custom dropdowns
    • Multiple selection handling
  8. browser_evaluate_js(port, code) - Execute JavaScript in browser

    • Run custom JavaScript code in the browser context
    • Return values and handle execution results
    • Advanced automation and data extraction

Chrome Extension Features

The Chrome extension provides comprehensive browser integration:

Automatic Console Capture

  • Multi-tab monitoring: Captures console logs from all active browser tabs
  • Real-time buffering: Collects messages every 2.5 seconds for optimal performance
  • Level filtering: Supports error, warn, info, and debug message types
  • Automatic initialization: Self-starts on page load with verification message

Visual Connection Management

  • Status indicator: Toolbar icon shows connection state (green = connected, red = disconnected)
  • Port display: Shows active WebSocket port in extension popup
  • Auto-reconnection: Automatically reconnects on connection loss
  • Connection diagnostics: Real-time connection health monitoring

DOM Interaction Support

  • Element discovery: Supports CSS selectors, XPath, and text-based element finding
  • Form automation: Integrates with form filling and submission tools
  • Event handling: Manages click, input, and selection events
  • Wait mechanics: Handles dynamic content and AJAX loading

๐Ÿ—‚๏ธ File Structure

Project Structure

mcp-browser/
โ”œโ”€โ”€ install.sh                # Automated installation
โ”œโ”€โ”€ setup-claude-code.sh      # Claude Code integration
โ”œโ”€โ”€ test_installation.sh      # Installation verification
โ”œโ”€โ”€ demo.sh                   # Feature demonstration
โ”œโ”€โ”€ mcp-browser              # Professional CLI entry point
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ cli/main.py          # Enhanced CLI with process management
โ”‚   โ”œโ”€โ”€ container/           # Dependency injection container
โ”‚   โ”œโ”€โ”€ services/            # Service layer (SOA)
โ”‚   โ”‚   โ”œโ”€โ”€ browser_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ websocket_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ storage_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ mcp_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ screenshot_service.py
โ”‚   โ”‚   โ””โ”€โ”€ dom_interaction_service.py
โ”‚   โ””โ”€โ”€ models/              # Data models
โ”œโ”€โ”€ extension/               # Chrome extension
โ”œโ”€โ”€ tmp/
โ”‚   โ””โ”€โ”€ demo_dom_interaction.html  # Test page for DOM features
โ””โ”€โ”€ requirements.txt

Runtime Structure

~/.mcp-browser/
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ settings.json        # Configuration (auto-generated)
โ”œโ”€โ”€ logs/
โ”‚   โ”œโ”€โ”€ mcp-browser.log      # Main server log
โ”‚   โ””โ”€โ”€ [8875-8895]/         # Port-specific browser logs
โ”œโ”€โ”€ run/
โ”‚   โ””โ”€โ”€ mcp-browser.pid      # Process ID tracking
โ””โ”€โ”€ data/                    # JSONL storage with rotation
    โ””โ”€โ”€ [port]/
        โ”œโ”€โ”€ console.jsonl    # Current session logs
        โ””โ”€โ”€ console_20240921_*.jsonl  # Rotated archives

Automated Installation Benefits

  • Zero-configuration setup: ./install.sh handles everything automatically
  • Virtual environment isolation: No system Python pollution
  • Port auto-discovery: Finds available ports in 8875-8895 range
  • Self-verification: Built-in installation testing and validation
  • Professional CLI: Complete process management with status monitoring

Development

Single-Path Workflows

This project follows the "ONE way to do ANYTHING" principle. Use these commands:

# ONE way to install
make install

# ONE way to develop
make dev

# ONE way to test
make test

# ONE way to build
make build

# ONE way to format code
make lint-fix

# See all available commands
make help

๐Ÿงช Testing the Installation

# Run comprehensive installation test
./test_installation.sh

# Run feature demonstration
./demo.sh

# Test DOM interaction with demo page
open tmp/demo_dom_interaction.html
# Then use Claude Code tools to interact with the demo page:
# - "Fill the username field with 'testuser'"
# - "Click the test button"
# - "Fill the entire form and submit it"
# - "Select 'Canada' from the country dropdown"
# - "Wait for the dynamic content to appear after clicking the button"

โšก 5-Minute Complete Setup

# 1. Clone and install everything
git clone https://github.com/browserpymcp/mcp-browser.git
cd mcp-browser
./install.sh  # Handles venv, dependencies, directories, CLI setup

# 2. Load Chrome extension (30 seconds)
# chrome://extensions/ โ†’ Developer mode โ†’ Load unpacked โ†’ select extension/

# 3. Configure Claude Code integration
./setup-claude-code.sh  # Auto-generates config, tests all tools

# 4. Start and test immediately
mcp-browser start
open tmp/demo_dom_interaction.html
# Ask Claude:
# "Fill out the demo form with test data"
# "Click the test button and wait for results"
# "Select Canada from the country dropdown"
# "Submit the form and capture the console output"

Running Tests

# Run all tests with coverage
make test

# Run specific test types
make test-unit
make test-integration
make test-extension

Configuration

Environment variables:

  • BROWSERPYMCP_PORT_START: Starting port for auto-discovery (default: 8875)
  • BROWSERPYMCP_PORT_END: Ending port for auto-discovery (default: 8895)
  • BROWSERPYMCP_LOG_LEVEL: Logging level (default: INFO)
  • BROWSERPYMCP_STORAGE_PATH: Base storage path (default: ~/.browserPYMCP/browser)

Troubleshooting

Extension Not Connecting

  1. Check server is running: browserpymcp status
  2. Verify port in extension popup (should show 8875-8895)
  3. Check Chrome DevTools console for errors
  4. Ensure localhost connections are allowed

No Console Logs Captured

  1. Verify extension is installed and enabled
  2. Refresh the target web page
  3. Check extension popup for connection status
  4. Look for test message: "[BrowserPyMCP] Console capture initialized"

Screenshot Failures

  1. Ensure Playwright is installed: playwright install chromium
  2. Check system has required dependencies
  3. Verify port number matches an active browser

License

MIT License - see LICENSE file for details

Documentation

This project follows comprehensive documentation standards for optimal AI agent understanding:

For AI Agents (Claude Code)

  • CLAUDE.md - Priority-based instructions for AI agents working on this codebase
  • CODE_STRUCTURE.md - Detailed architecture analysis and patterns

For Developers

Quick Reference

Contributing

Contributions are welcome! Please follow the single-path development workflow:

  1. Setup: make setup (installs deps + pre-commit hooks)
  2. Develop: make dev (start development server)
  3. Quality: make quality (run all linting and tests)
  4. Submit: Create feature branch and submit pull request

All code must pass make quality before submission. The pre-commit hooks will automatically format and lint your code.

Support

For issues and questions:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_browser-1.0.1.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_browser-1.0.1-py3-none-any.whl (56.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_browser-1.0.1.tar.gz.

File metadata

  • Download URL: mcp_browser-1.0.1.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_browser-1.0.1.tar.gz
Algorithm Hash digest
SHA256 67b8304aa1f4760383d2481a7844d1a08a5f0cad101932f2e2518a8d56d05618
MD5 a64b0b0335e1cde5f4db590df368fd13
BLAKE2b-256 1fc7befd207c0c83f1a5e7b585fdaf32302f13d1b4bfdf441d0e2d8a648798f8

See more details on using hashes here.

File details

Details for the file mcp_browser-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_browser-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_browser-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 490c7d7344b06f4424f45047d631125565634f17fd33b1e7b6d6d5f80a415ccd
MD5 918b8449f2c83bc6af8c2290cf7ff810
BLAKE2b-256 dcb07129af486eba47918d7907e42defc8a0f69a8d35dc4970eb6adaa8f040d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page