SmartBrowserMCP

SmartBrowserMCP

A Model Context Protocol server for web automation that enables browser control, element interaction, content extraction, and monitoring using Playwright.

Category
访问服务器

README

SmartBrowserMCP

A Model Context Protocol (MCP) server that provides web automation capabilities through browser control tools.

Overview

SmartBrowserMCP is a TypeScript/Node.js server that implements the Model Context Protocol to expose browser automation functionality. It uses Playwright for browser management and provides tools for web testing, monitoring, and automation tasks.

Features

  • Browser Automation: Control web browsers programmatically
  • Element Interaction: Click elements by CSS selector, text content, or link text
  • Content Extraction: Extract text and HTML content from pages or specific elements
  • Page Navigation: Scroll pages and navigate web content
  • Console Monitoring: Check browser console logs and errors
  • Network Monitoring: Monitor network requests and responses
  • Screenshot Capture: Take screenshots of web pages
  • Task Execution: Execute custom automation tasks
  • Report Generation: Generate detailed reports of browser sessions
  • Session Management: Clear and manage browser sessions

Installation

npm install

Development

Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Create a .env file (optional):
    MCP_SERVER_PORT=3000
    MCP_SERVER_HOST=0.0.0.0
    MCP_TRANSPORT=stdio
    BROWSER_HEADLESS=true
    BROWSER_SLOW_MO=0
    BROWSER_TIMEOUT=30000
    LOG_LEVEL=info
    

Building

npm run build

Running

Development mode:

npm run dev

Production mode:

npm run build
npm start

Transport Modes

The server supports two transport modes controlled by the MCP_TRANSPORT environment variable:

STDIO Mode (Default)

For MCP clients like Claude Desktop, Cursor, and other MCP-compatible applications.

Run in STDIO mode:

# Default mode (no env var needed)
npm run build
npm start

# Explicit STDIO mode
MCP_TRANSPORT=stdio

HTTP Mode

For direct API usage and web-based integration.

Run in HTTP mode:

MCP_TRANSPORT=http

Using npm link (global command):

npm link
smartbrowser-mcp

MCP Client Configuration:

For Claude Desktop, add to your MCP config:

{
  "mcpServers": {
    "smartbrowser": {
      "command": "npx",
      "args": [
        "smartbrowsermcp@latest"
      ],
      "env": {
        "MCP_TRANSPORT": "stdio",
        "BROWSER_HEADLESS": "true"
      }
    }
  }
}

Visible Browser Mode: To see the browser automation in real-time, set BROWSER_HEADLESS to false:

{
  "mcpServers": {
    "smartbrowser": {
      "command": "npx",
      "args": [
        "smartbrowsermcp@latest"
      ],
      "env": {
        "MCP_TRANSPORT": "stdio",
        "BROWSER_HEADLESS": "false"
      }
    }
  }
}

Or using local path:

{
  "mcpServers": {
    "smartbrowser": {
      "command": "node",
      "args": ["/var/www/html/LMStudio/WebPilotMCP/dist/index.js"],
      "env": {
        "MCP_TRANSPORT": "stdio",
        "BROWSER_HEADLESS": "false"
      }
    }
  }
}

Mode Differences:

  • HTTP Mode: For direct API usage and testing. Server runs on configured port (default: 3000)
  • STDIO Mode: For MCP clients. Communicates via stdin/stdout using JSON-RPC protocol
  • Headless Mode (default): Browser runs in background, not visible to user
  • Visible Mode (BROWSER_HEADLESS=false): Browser window opens, users can watch automation

Available Tools

The server provides the following MCP tools:

  • executeTask: Execute custom automation tasks
  • checkConsole: Monitor browser console for logs and errors
  • checkNetwork: Monitor network activity
  • takeScreenshot: Capture screenshots of web pages
  • generateReport: Generate detailed session reports
  • clearSession: Clear browser session data
  • click_element: Click elements by CSS selector, text content, or link text
  • get_page_content: Extract text and HTML content from pages or specific elements
  • scrollPage: Scroll pages up/down or to specific positions

API Endpoints

  • GET /api/mcp: MCP server endpoint (SSE transport)
  • POST /api/mcp: MCP message handling endpoint
  • GET /: Server information endpoint
  • GET /health: Health check endpoint

Configuration

The server can be configured via environment variables:

Server Configuration

  • MCP_SERVER_PORT: Server port (default: 3000)
  • MCP_SERVER_HOST: Server host (default: 0.0.0.0)
  • MCP_TRANSPORT: Transport mode - stdio or http (default: stdio)

Browser Configuration

  • BROWSER_HEADLESS: Run browser in headless mode (default: true)
  • BROWSER_SLOW_MO: Slow down operations by specified milliseconds (default: 0)
  • BROWSER_TIMEOUT: Browser operation timeout in milliseconds (default: 30000)

Logging Configuration

  • LOG_LEVEL: Logging level (default: info)

Advanced Configuration

  • PLAYWRIGHT_BROWSERS_PATH: Custom path to Playwright browsers

Project Structure

src/
├── config/
│   └── server.ts          # Server configuration
├── services/
│   ├── browserManager.ts  # Browser instance management
│   └── inputSanitizer.ts  # Input sanitization utilities
├── tools/
│   ├── checkConsole.ts    # Console monitoring tool
│   ├── checkNetwork.ts    # Network monitoring tool
│   ├── clearSession.ts    # Session management tool
│   ├── clickElement.ts    # Element interaction tool
│   ├── executeTask.ts     # Custom task execution
│   ├── generateReport.ts  # Report generation tool
│   ├── getPageContent.ts  # Content extraction tool
│   ├── scrollPage.ts      # Page scrolling tool
│   └── takeScreenshot.ts # Screenshot capture tool
├── types/
│   ├── index.ts           # Type definitions
│   └── schemas.ts         # Zod schemas for validation
└── index.ts               # Main server entry point

Dependencies

  • @modelcontextprotocol/sdk: MCP SDK for server implementation
  • @modelcontextprotocol/server: MCP server utilities
  • playwright: Browser automation
  • express: Web server framework
  • zod: Schema validation
  • dotenv: Environment variable management
  • sanitize-html: HTML sanitization for security

License

ISC

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and questions, please use the project's issue tracker.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选