This project provides a bridge between browser automation and the Model Context Protocol (MCP), enabling communication between a Node.js WebSocket server and a browser extension. It consists of two main components:
- socket-server/: A Node.js WebSocket server that exposes browser tab management tools via MCP.
- web-extension-mcp/: A browser extension that connects to the WebSocket server and executes tab-related commands.
.
├── socket-server/
│ ├── index.js # Main MCP WebSocket server
│ └── package.json # Server dependencies
└── web-extension-mcp/
├── background.js # Extension background script
└── manifest.json # Extension manifest
- Exposes browser tab management tools (query, create, reload, get current tab) via MCP.
- Communicates with browser extensions over WebSocket (default port: 8080).
- Implements tools using the @modelcontextprotocol/sdk and ws libraries.
- Connects to the local WebSocket server.
- Listens for tab management commands and executes them using browser APIs.
- Sends responses back to the server.
- Node.js (v18 or higher recommended)
- npm
- Firefox
cd /path/to/socket-server
npm install
To setup the socket server to be used:
{
"mcpServers": {
"browser-mcp": {
"command": "node",
"args": ["/path/to/socket-server/index.js"]
}
}
}- Open your browser and go to the extensions page (e.g.,
chrome://extensions/). - Enable "Developer mode".
- Click "Load unpacked" and select the
web-extension-mcpdirectory. - The extension will attempt to connect to the WebSocket server at
ws://localhost:8080.
Once both the server and extension are running:
- The server can send tab management commands (query, create, reload, get current tab) to the browser via the extension.
- The extension executes these commands and returns results over the WebSocket connection.
- socket-server/index.js: Implements the MCP server and WebSocket bridge. Tools are registered for tab management and communicate with the browser via WebSocket.
- web-extension-mcp/background.js: Handles WebSocket connection, receives commands, and interacts with browser tabs using the
browser.tabsAPI. - The extension expects the server to be running on
localhost:8080. - The server uses the zod library for schema validation.
- No external npm dependencies (uses browser APIs)
This project is licensed under the MIT License.