Browser MCP Server

Browser MCP Server

Enables AI assistants to automate web browsers through Playwright, providing capabilities for navigation, content extraction, form filling, screenshot capture, and JavaScript execution. Supports multiple browser engines with comprehensive error handling and security features.

Category
访问服务器

README

Browser MCP Server

A Model Context Protocol (MCP) server that provides comprehensive browser automation capabilities using Playwright. This server enables AI assistants to interact with web pages through standardized MCP tools for navigation, content extraction, form filling, and screenshot capture.

🚀 Features

Core Browser Operations

  • Navigate to URLs with smart waiting strategies
  • Extract page content with customizable selectors
  • Take screenshots (full page, viewport, or specific elements)
  • Execute JavaScript with result capture
  • Click elements by CSS selectors
  • Fill forms automatically with validation

Advanced Capabilities

  • Multi-browser support (Chromium, Firefox, WebKit)
  • Request interception and monitoring
  • Viewport customization and responsive testing
  • Link extraction and URL processing
  • Error handling with detailed responses
  • Resource management and cleanup

📦 Installation

Prerequisites

  • Python 3.8 or higher
  • Node.js (for Playwright browser installation)

Install from Source

# Clone the repository
git clone <repository-url>
cd claude-browser-mcp

# Install dependencies
pip install -e .

# Install Playwright browsers
playwright install

Install from PyPI (when available)

pip install claude-browser-mcp
playwright install

🛠 Usage

As MCP Server

Start the server with stdio transport:

browser-mcp
# or
python -m src.server

Configuration

Configure the browser through environment variables:

export BROWSER_HEADLESS=true          # Run in headless mode
export BROWSER_TYPE=chromium          # Browser type (chromium/firefox/webkit)
export BROWSER_TIMEOUT=30000          # Default timeout in milliseconds

MCP Client Integration

Add to your MCP client configuration:

{
  "mcpServers": {
    "browser-automation": {
      "command": "browser-mcp",
      "args": []
    }
  }
}

🔧 Available Tools

navigate_to

Navigate to a specified URL with optional waiting.

{
  "name": "navigate_to",
  "arguments": {
    "url": "https://example.com",
    "wait_for": "selector", 
    "timeout": 30
  }
}

get_page_content

Extract text content from the current page.

{
  "name": "get_page_content", 
  "arguments": {
    "include_links": true,
    "selector": ".main-content"
  }
}

click_element

Click on elements by CSS selector.

{
  "name": "click_element",
  "arguments": {
    "selector": "button#submit",
    "timeout": 10
  }
}

fill_form

Fill form fields with data.

{
  "name": "fill_form",
  "arguments": {
    "fields": {
      "#email": "user@example.com",
      "#password": "secretpass"
    },
    "submit": true
  }
}

take_screenshot

Capture page screenshots.

{
  "name": "take_screenshot",
  "arguments": {
    "full_page": true,
    "selector": ".dashboard"
  }
}

execute_javascript

Run JavaScript in the browser context.

{
  "name": "execute_javascript", 
  "arguments": {
    "code": "document.title",
    "return_value": true
  }
}

📁 Project Structure

claude-browser-mcp/
├── src/
│   ├── __init__.py          # Package initialization
│   ├── server.py            # MCP server implementation
│   ├── browser.py           # Browser management
│   ├── actions.py           # High-level browser actions
│   └── utils.py             # Utility functions
├── requirements.txt         # Python dependencies
├── setup.py                 # Package configuration
└── README.md               # This file

🏗 Architecture

Server (server.py)

  • MCP server implementation with tool registration
  • Request routing and response formatting
  • Error handling and logging
  • Async tool execution

Browser Manager (browser.py)

  • Playwright browser lifecycle management
  • Context creation and configuration
  • Resource cleanup and recovery
  • Multi-browser support

Actions (actions.py)

  • High-level browser automation methods
  • Content extraction and processing
  • Form interaction and validation
  • Screenshot and JavaScript execution

Utils (utils.py)

  • HTML sanitization and cleaning
  • URL validation and normalization
  • Image processing and encoding
  • Data formatting utilities

🔒 Security Considerations

  • HTML sanitization removes dangerous scripts and attributes
  • URL validation prevents malicious redirects
  • Input validation for all user-provided data
  • Resource limits prevent excessive memory usage
  • Timeout controls prevent hanging operations

🐳 Docker Deployment

Quick Start with Docker

# Build and run with Docker Compose
docker-compose up browser-mcp

# Or build manually
./scripts/docker-build.sh
./scripts/start-container.sh

Production Deployment

# Build production image
docker build -t browser-mcp:latest .

# Run with optimal settings
docker run -d \
  --name browser-mcp \
  --init --ipc=host --shm-size=1gb \
  --memory=2g --cpus=1.0 \
  -v $(pwd)/screenshots:/app/screenshots \
  -v $(pwd)/downloads:/app/downloads \
  browser-mcp:latest

Development with Docker

# Development container with debugging
docker-compose --profile dev up browser-mcp-dev

# Access container
docker exec -it claude-browser-mcp-dev /bin/bash

Container Management

# Health check
./scripts/health-check.sh

# View logs
docker logs -f claude-browser-mcp

# Monitor resources
docker stats claude-browser-mcp

🚨 Error Handling

The server provides detailed error responses with:

  • Error categorization (timeout, validation, execution)
  • Context information (URL, selector, arguments)
  • Recovery suggestions where applicable
  • Logging for debugging and monitoring

📊 Response Format

All tools return standardized JSON responses:

{
  "success": true,
  "url": "https://example.com",
  "title": "Page Title",
  "data": "...",
  "metadata": {
    "timestamp": "...",
    "execution_time": "..."
  }
}

Error responses include:

{
  "success": false,
  "error": "Detailed error message",
  "tool": "tool_name",
  "arguments": {...},
  "timestamp": "..."
}

🛡 Environment Variables

Variable Default Description
BROWSER_HEADLESS true Run browser in headless mode
BROWSER_TYPE chromium Browser engine to use
BROWSER_TIMEOUT 30000 Default timeout (ms)

🤝 Development

Setting up Development Environment

# Install in development mode
pip install -e .[dev]

# Run tests
pytest tests/

# Format code
black src/

# Type checking
mypy src/

Adding New Tools

  1. Define tool schema in server.py
  2. Implement action method in actions.py
  3. Add utility functions in utils.py
  4. Update documentation and tests

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • Playwright for browser automation
  • MCP for the protocol specification
  • Anthropic for Claude and MCP development

📞 Support

  • Issues: Report bugs and request features on GitHub
  • Documentation: See inline code documentation
  • Community: Join MCP community discussions

Note: This is a foundational implementation. Additional features like request interception, advanced form handling, and performance optimizations can be added based on specific use cases.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选