mcp-browser-automation
# mcp-browser-automation
An MCP (Model Context Protocol) server for generic browser automation using Playwright. Exposes a headless Chromium instance as a set of callable tools so that MCP clients — such as AI coding assistants — can navigate pages, inspect elements, execute JavaScript, capture screenshots, and monitor console logs and network traffic.
## Requirements
- Node.js 18+
- npm
## Installation
```bash
npm install
npx playwright install chromium
```
## Usage
```bash
npm run build
npm start
```
Or for development with hot reload:
```bash
npm run dev
```
The server listens on **stdin/stdout** using the MCP stdio transport. Configure your MCP client to launch it as a subprocess.
**Claude Desktop:**
```json
{
"mcpServers": {
"browser-automation": {
"command": "npx",
"args": ["github:ritesh-jain/MCP-Browser-Automation"]
}
}
}
```
**Opencode:**
```json
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mcp-browser-automation": {
"type": "local",
"enabled": true,
"command": [
"npx",
"github:ritesh-jain/MCP-Browser-Automation"
]
}
}
}
```
## Tools
| Tool | Description |
|---|---|
| `navigate` | Navigate to a URL. Supports custom viewport and mobile emulation. |
| `capture_screenshot` | Take a full-page screenshot (saved to `screenshots/`). |
| `get_console_logs` | Retrieve browser console logs. Optionally clear after read. |
| `get_network_traffic` | Retrieve network requests and responses. Optionally clear after read. |
| `execute_js` | Execute arbitrary JavaScript in the page context. |
| `interact` | Click, type, fill, or select on a CSS selector. |
| `inspect_element` | Return tag name, id, class, inner text, outer HTML, and computed styles for an element. |
## Project Structure
```
src/
types.ts Shared type definitions
McpServer.ts MCP protocol layer — tool registration and dispatch
BrowserManager.ts Playwright orchestration — browser lifecycle and page interactions
index.ts Entry point
```
## How It Works
1. `index.ts` creates an `McpBrowserServer` and connects via `StdioServerTransport`.
2. An MCP client discovers tools via the `ListTools` request and calls them via `CallToolRequest`.
3. `McpBrowserServer` lazily initializes the browser on the first tool call and delegates to `BrowserManager`.
4. The browser stays open across calls, enabling multi-step interactions on the same page.
## License
ISC
TDQS
Scored across 7 tools
Each tool targets a distinct browser capability: navigation, screenshot, console logs, network traffic, JS execution, element interaction, and element inspection. There is no meaningful overlap between them; even interact and inspect_element are clearly differentiated as action vs. introspection.
Tool names are predominantly snake_case with a verb-first pattern (navigate, interact, inspect_element, execute_js). Minor inconsistency exists in the prefix: get_console_logs and get_network_traffic use 'get_', while capture_screenshot uses 'capture_' instead of 'get_'. Overall the pattern is readable and predictable.
Seven tools is a well-scoped set for browser automation, covering essential operations without excess. This is within the ideal 3-15 range and each tool serves a distinct purpose.
The tool surface covers core browser automation needs: navigation, screenshots, logs, network, JavaScript execution, and element interactions/inspection. Some advanced features like tab management, cookie handling, or explicit waiting are missing, but execute_js can compensate, and the common workflows are complete.