A fully compliant MCP server implementation following the 2025-03-26 specification that provides browser automation capabilities through the Model Context Protocol.
- Protocol Version:
2025-03-26 - JSON-RPC 2.0: Strict adherence to JSON-RPC message format
- Stdio Transport: Clean implementation with zero stdout pollution
- Capability Negotiation: Proper initialization handshake
- Error Handling: Two-level error mechanism with
isErrorflag
Nine browser control tools with full schema validation:
- browser_navigate - Navigate to URLs
- browser_screenshot - Capture screenshots (full page or element)
- browser_click - Click elements via CSS selectors
- browser_type - Type text with optional field clearing
- browser_evaluate - Execute JavaScript (with security warning)
- browser_get_content - Get HTML/text content
- browser_audit - Run Lighthouse audits
- browser_wait - Wait for elements with timeout
- browser_get_console - Retrieve console logs by level
- Input Validation: All tools use JSON Schema validation
- Security Annotations: Warnings for dangerous operations
- Error Isolation: Tool errors don't crash the server
- Debug Logging: Optional stderr logging (MCP_DEBUG=1)
- Graceful Shutdown: Proper SIGTERM/SIGINT handling
Claude Code <--[JSON-RPC/stdio]--> MCP Server <--[HTTP]--> Browser Tools Server <--[WebSocket]--> Chrome Extension
-
Initialization
- Client sends
initializewith protocol version - Server responds with capabilities and tools support
- Client confirms with
initialized
- Client sends
-
Tool Discovery
- Client calls
tools/list - Server returns full tool schemas with titles and descriptions
- Client calls
-
Tool Execution
- Client calls
tools/callwith tool name and arguments - Server validates input against schema
- Server forwards to browser-tools HTTP server
- Results returned in MCP content format
- Client calls
Request Example:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "browser_navigate",
"arguments": {
"url": "https://example.com"
}
}
}Response Example:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{
"type": "text",
"text": "Navigation successful"
}]
}
}Error Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{
"type": "text",
"text": "Tool execution failed: Connection timeout"
}],
"isError": true
}
}{
"mcpServers": {
"browser-tools": {
"type": "stdio",
"command": "node",
"args": [
"/path/to/mcp-browser-tools-server.js"
],
"env": {
"BROWSER_TOOLS_PORT": "3024",
"MCP_DEBUG": "1"
}
}
}
}BROWSER_TOOLS_PORT: HTTP server port (default: 3024)MCP_DEBUG: Enable debug logging to stderr (1 to enable)
| Aspect | Original npm Package | Our 2025-Spec Server |
|---|---|---|
| Protocol Compliance | Violates stdio with console.log | 100% compliant, zero stdout pollution |
| Specification | Outdated implementation | 2025-03-26 specification |
| Error Handling | Console errors break protocol | Proper isError flag in responses |
| Tool Schemas | Basic definitions | Full schemas with validation |
| Security | No warnings | Annotations for dangerous operations |
| Debugging | Pollutes stdout | Clean stderr logging with MCP_DEBUG |
| Maintainability | External dependency | Full control, easy to update |
# Test initialization
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26"}}' | \
node mcp-browser-tools-server.js
# Test tool listing
echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | \
node mcp-browser-tools-server.js
# Enable debug mode
MCP_DEBUG=1 node mcp-browser-tools-server.js- Start browser-tools HTTP server:
./scripts/start-browser-tools.sh - Open Chrome with extension installed
- Restart Claude Code
- Test tools:
mcp__browser-tools__navigate, etc.
- MCP Specification: https://modelcontextprotocol.io/specification/2025-03-26
- Transport Details: https://modelcontextprotocol.io/specification/2025-03-26/basic/transports
- Tool Schemas: https://modelcontextprotocol.io/docs/concepts/tools
- JSON-RPC 2.0: https://www.jsonrpc.org/specification
-
Stdio Transport Rules:
- MUST NOT write to stdout except JSON-RPC messages
- Messages delimited by newlines
- UTF-8 encoding required
-
Tool Response Format:
- Always return
contentarray - Support multiple content types (text, image)
- Use
isError: truefor tool execution failures
- Always return
-
Capability Negotiation:
- Check client protocol version
- Respond with server capabilities
- Enable feature discovery
- Add resource support for browser state
- Implement prompt templates for common tasks
- Add batch operation support
- Implement rate limiting
- Add telemetry and metrics
This implementation provides a robust, specification-compliant MCP server for browser automation that:
- Fixes all stdio protocol violations
- Follows the latest 2025-03-26 specification
- Provides comprehensive tool support
- Ensures security and reliability
- Maintains full compatibility with browser-tools ecosystem
The clean implementation eliminates dependency on the broken npm package while providing superior functionality and maintainability.