@dorothywebb/any-browser-mcp
Version:
Any Browser MCP - Launch Chrome with your actual data in debug mode for comprehensive browser automation
244 lines (182 loc) ⢠7.17 kB
Markdown
# Organized Browser MCP Server
**A properly organized MCP server that NEVER auto-launches browsers and only connects to your existing browser when actually needed.**
## š”ļø Safety-First Design
This MCP server is designed with strict safety policies to ensure it:
- ā
**NEVER auto-launches browsers** - Zero risk of unwanted browser instances
- ā
**Only connects to existing browsers** - Respects your current browser setup
- ā
**Lazy initialization** - No connections until you actually use MCP tools
- ā
**VS Code startup friendly** - Won't slow down or interfere with VS Code startup
- ā
**User-controlled** - You decide when and how to use browser automation
## šļø Architecture Overview
### Core Components
1. **ConfigManager** (`src/core/ConfigManager.ts`)
- Enforces safety policies at configuration level
- Prevents any auto-launch configurations
- Provides consistent settings across the application
2. **LazyBrowserManager** (`src/core/LazyBrowserManager.ts`)
- Manages lazy initialization of browser connections
- Only connects when MCP tools are actually called
- Handles connection state and retry logic
3. **BrowserConnection** (`src/utils/BrowserConnection.ts`)
- Low-level browser connection utility
- Strict "existing browser only" policy
- Chrome DevTools Protocol (CDP) based communication
4. **MCP Server** (`src/server.ts`)
- Main MCP server implementation
- Exposes browser automation tools
- Integrates with lazy browser manager
## š§ Setup Instructions
### 1. Install Dependencies
```bash
cd organized_browser_mcp
npm install
```
### 2. Build the Project
```bash
npm run build
```
### 3. Start Your Browser with Debugging
**Before using the MCP server**, start your browser with debugging enabled:
**Chrome:**
```bash
# Close Chrome completely first, then:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
```
**Edge:**
```bash
msedge --remote-debugging-port=9222
```
**Linux Chrome:**
```bash
google-chrome --remote-debugging-port=9222
```
### 4. Configure VS Code
Add to your VS Code `settings.json`:
```json
{
"mcp.servers": [
{
"name": "organized-browser",
"command": "node",
"args": ["/path/to/organized_browser_mcp/bin/server.js"],
"env": {}
}
]
}
```
### 5. Test the Setup
1. **Start VS Code** - No browser should launch automatically ā
2. **Check MCP status** - Server should be ready but not connected ā
3. **Use a browser tool** - Now it connects to your existing browser ā
4. **Verify** - Should use your existing browser with all your data ā
## š ļø Available Tools
Once you use a browser tool (and lazy initialization connects), you have access to:
- `browser_navigate` - Navigate to URLs
- `browser_screenshot` - Take screenshots
- `browser_click` - Click elements
- `browser_type` - Type text
- `browser_get_content` - Extract page content
- `browser_list_pages` - List all open tabs
- `browser_status` - Get connection status
## š Debugging & Troubleshooting
### Check Browser Availability
```bash
# Test if your browser debugging is working:
curl http://localhost:9222/json/version
```
Should return browser information if properly configured.
### Enable Verbose Logging
```bash
node bin/server.js --verbose
```
### Common Issues
**"Browser not available"**
- Ensure browser is running with `--remote-debugging-port=9222`
- Check that port 9222 is not blocked by firewall
- Verify no other tools are using the debugging port
**"Connection timeout"**
- Browser might not have debugging enabled
- Try restarting browser with debugging flag
- Check browser process is actually running
## š”ļø Safety Features
### Configuration-Level Safety
```typescript
// These settings are ENFORCED regardless of config file:
autoLaunch: false, // Never auto-launch
allowLaunch: false, // Never allow launching
useExistingOnly: true, // Only existing browsers
initializeOnStartup: false, // Don't connect on startup
lazyInitialization: true, // Connect only when needed
neverLaunchBrowser: true, // Safety flag
requireExistingBrowser: true // Must have existing browser
```
### Code-Level Safety
- **LaunchBrowser() method throws error** - Prevents accidental launches
- **Connection checks before operations** - Validates browser availability
- **Graceful failure** - Clear error messages when browser not available
- **No automatic retries** - Won't keep trying to launch browsers
### Runtime Safety
- **Lazy initialization** - No connections until tool use
- **Connection validation** - Checks browser availability before connecting
- **Clear error messages** - Guides user to start browser manually
- **Graceful degradation** - Fails safely when browser not available
## š Project Structure
```
organized_browser_mcp/
āāā package.json # Dependencies and scripts
āāā tsconfig.json # TypeScript configuration
āāā config.json # Runtime configuration
āāā bin/
ā āāā server.js # CLI entry point
āāā src/
ā āāā server.ts # Main MCP server
ā āāā core/
ā ā āāā ConfigManager.ts # Configuration management
ā ā āāā LazyBrowserManager.ts # Lazy initialization logic
ā āāā utils/
ā ā āāā BrowserConnection.ts # Browser connection utility
ā āāā types/
ā āāā index.ts # TypeScript type definitions
āāā dist/ # Compiled JavaScript (after build)
```
## š How Lazy Initialization Works
### Before (ā Bad Behavior)
```
VS Code starts ā MCP server starts ā Immediately connects to browser
```
### After (ā
Good Behavior)
```
VS Code starts ā MCP server starts ā Waits quietly
User calls browser tool ā Lazy manager connects ā Tool executes
```
### Implementation Details
1. **Server Startup**: Only creates MCP server, no browser connections
2. **Tool Registration**: Tools are available but no browser access yet
3. **First Tool Call**: Triggers lazy initialization
4. **Browser Connection**: Connects to existing browser
5. **Tool Execution**: Performs the actual browser action
6. **Subsequent Tools**: Use existing connection
## šÆ Benefits
- ā
**Zero VS Code startup impact** - No browser operations during startup
- ā
**Respects user workflow** - Uses your actual browser with all data
- ā
**Safe by design** - Cannot accidentally launch browsers
- ā
**Clear error handling** - Helpful messages when browser not ready
- ā
**Predictable behavior** - Consistent "existing browser only" policy
- ā
**Professional MCP behavior** - Works like a proper service
## š§ Development
### Build
```bash
npm run build
```
### Development Mode
```bash
npm run dev
```
### Test Connection
```bash
node bin/server.js --verbose
```
## š License
MIT License - See LICENSE file for details.
---
**This MCP server prioritizes safety and user control over convenience. It will never surprise you by launching browsers automatically!** š”ļø