@ricardodeazambuja/browser-mcp-server 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,596 @@
1
+ # Browser MCP Server
2
+
3
+ A universal browser automation MCP server using Playwright. Control Chrome programmatically through the Model Context Protocol.
4
+
5
+ **16 powerful browser automation tools** including navigation, clicking, typing, screenshots, console capture, and session recording.
6
+
7
+ ## Features
8
+
9
+ - ✅ **Smart Chrome Detection**: Automatically finds and uses system Chrome/Chromium
10
+ - ✅ **Three-Tier Strategy**: Antigravity Chrome → System Chrome → Playwright Chromium
11
+ - ✅ **Universal**: Works with Antigravity, Claude Desktop, and any MCP client
12
+ - ✅ **16 Tools**: Navigate, click, type, screenshot, console logs, and more
13
+ - ✅ **Auto-Install**: Playwright installed automatically via npm (no manual setup)
14
+ - ✅ **Safe**: Isolated browser profile (won't touch your personal Chrome)
15
+ - ✅ **Console Capture**: Debug JavaScript errors in real-time
16
+ - ✅ **Session Recording**: Playwright traces with screenshots, DOM, and network activity
17
+ - ✅ **Auto-Reconnect**: Handles browser crashes gracefully
18
+
19
+ ## Quick Reference
20
+
21
+ | Installation Method | Best For | Setup Time |
22
+ |-------------------|----------|------------|
23
+ | **NPM Package** | Production use, easy updates | 30 seconds |
24
+ | **Clone Repository** | Development, contributing | 2 minutes |
25
+ | **Direct Download** | Quick testing, minimal setup | 1 minute |
26
+
27
+ | MCP Client | Config File Location |
28
+ |------------|---------------------|
29
+ | **Claude Desktop** | `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)<br>`%APPDATA%/Claude/claude_desktop_config.json` (Windows) |
30
+ | **Antigravity** | `~/.gemini/antigravity/mcp_config.json` |
31
+ | **Claude Code** | Use `claude mcp add` command |
32
+ | **Gemini CLI** | Use `gemini mcp add` command |
33
+
34
+ **Key Points:**
35
+ - ✅ Requires Node.js >= 16.0.0
36
+ - ✅ Playwright installs automatically (via npm) or manually (via git clone)
37
+ - ✅ Automatically detects and uses system Chrome/Chromium
38
+ - ✅ Uses absolute paths in config files
39
+ - ✅ Isolated browser profile (won't touch personal Chrome)
40
+ - ✅ Restart MCP client after config changes
41
+
42
+ ## Quick Start
43
+
44
+ ### Installation
45
+
46
+ #### Method 1: NPM Package (Recommended)
47
+
48
+ ```bash
49
+ # Install globally (Playwright installs automatically)
50
+ npm install -g @ricardodeazambuja/browser-mcp-server
51
+
52
+ # Or use directly with npx (no installation needed)
53
+ npx @ricardodeazambuja/browser-mcp-server
54
+ ```
55
+
56
+ **Note:** Playwright is installed automatically as a dependency. The server will automatically detect and use your system Chrome/Chromium if available, or fall back to Playwright's Chromium.
57
+
58
+ #### Method 2: Clone Repository (For Development)
59
+
60
+ ```bash
61
+ # Clone the repository
62
+ git clone https://github.com/ricardodeazambuja/browser-mcp-server.git
63
+ cd browser-mcp-server
64
+
65
+ # Install dependencies (includes Playwright)
66
+ npm install
67
+
68
+ # Optional: Install Chromium browser if not using system Chrome
69
+ npx playwright install chromium
70
+ ```
71
+
72
+ #### Method 3: Direct Download (Single File)
73
+
74
+ ```bash
75
+ # Download the main file directly (no git required)
76
+ curl -o browser-mcp-server-playwright.js \
77
+ https://raw.githubusercontent.com/ricardodeazambuja/browser-mcp-server/main/browser-mcp-server-playwright.js
78
+
79
+ # Install Playwright
80
+ npm install playwright
81
+
82
+ # Optional: Install Chromium browser if not using system Chrome
83
+ npx playwright install chromium
84
+ ```
85
+
86
+ ### Usage with Claude Desktop
87
+
88
+ Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
89
+
90
+ **Using local installation:**
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "browser-tools": {
95
+ "command": "node",
96
+ "args": ["/absolute/path/to/browser-mcp-server-playwright.js"]
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ **Using NPM:**
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "browser-tools": {
107
+ "command": "npx",
108
+ "args": ["-y", "@ricardodeazambuja/browser-mcp-server"]
109
+ }
110
+ }
111
+ }
112
+ ```
113
+
114
+ **Note:** Replace `/absolute/path/to/` with the actual path where you installed the file.
115
+
116
+ ### Usage with Antigravity
117
+
118
+ Add to `~/.gemini/antigravity/mcp_config.json`:
119
+
120
+ **Using local installation:**
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "browser-tools": {
125
+ "command": "node",
126
+ "args": ["/home/username/.gemini/antigravity/browser-mcp-server-playwright.js"]
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ **Using NPM:**
133
+ ```json
134
+ {
135
+ "mcpServers": {
136
+ "browser-tools": {
137
+ "command": "npx",
138
+ "args": ["-y", "@ricardodeazambuja/browser-mcp-server"]
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ Then refresh MCP servers in Antigravity.
145
+
146
+ ### Usage with Claude Code
147
+
148
+ Add the browser-mcp-server using the Claude CLI:
149
+
150
+ **Using local installation:**
151
+ ```bash
152
+ # Install the MCP server with default isolated profile
153
+ claude mcp add --transport stdio browser \
154
+ -- node /absolute/path/to/browser-mcp-server-playwright.js
155
+
156
+ # Or with custom browser profile for more control
157
+ claude mcp add --transport stdio browser \
158
+ --env MCP_BROWSER_PROFILE=/path/to/custom/profile \
159
+ -- node /absolute/path/to/browser-mcp-server-playwright.js
160
+ ```
161
+
162
+ **Using NPM:**
163
+ ```bash
164
+ # Install using npx (no local installation needed)
165
+ claude mcp add --transport stdio browser \
166
+ -- npx -y @ricardodeazambuja/browser-mcp-server
167
+
168
+ # With custom browser profile
169
+ claude mcp add --transport stdio browser \
170
+ --env MCP_BROWSER_PROFILE=/path/to/custom/profile \
171
+ -- npx -y @ricardodeazambuja/browser-mcp-server
172
+ ```
173
+
174
+ **Verify installation:**
175
+ ```bash
176
+ # List all MCP servers
177
+ claude mcp list
178
+
179
+ # Check server status
180
+ claude mcp get browser
181
+ ```
182
+
183
+ **Example usage in Claude Code:**
184
+
185
+ ```bash
186
+ # Natural language commands
187
+ > Navigate to https://example.com and take a screenshot
188
+ > Click the login button and fill in the username field
189
+ > What's the text in the .main-content selector?
190
+
191
+ # Direct tool invocation via slash commands
192
+ > /mcp__browser__browser_navigate https://example.com
193
+ > /mcp__browser__browser_screenshot
194
+ ```
195
+
196
+ **Note:** The server uses an isolated browser profile at `/tmp/chrome-mcp-profile` by default, ensuring it won't access your personal Chrome cookies or data.
197
+
198
+ ### Usage with Gemini CLI
199
+
200
+ Add the browser-mcp-server using the Gemini CLI commands:
201
+
202
+ **Using local installation:**
203
+ ```bash
204
+ # Install the MCP server with default isolated profile
205
+ gemini mcp add browser node /absolute/path/to/browser-mcp-server-playwright.js
206
+
207
+ # Or with custom browser profile
208
+ gemini mcp add -e MCP_BROWSER_PROFILE=/path/to/custom/profile browser \
209
+ node /absolute/path/to/browser-mcp-server-playwright.js
210
+ ```
211
+
212
+ **Using NPM:**
213
+ ```bash
214
+ # Install using npx (no local installation needed)
215
+ gemini mcp add browser npx -y @ricardodeazambuja/browser-mcp-server
216
+
217
+ # With custom browser profile
218
+ gemini mcp add -e MCP_BROWSER_PROFILE=/path/to/custom/profile browser \
219
+ npx -y @ricardodeazambuja/browser-mcp-server
220
+ ```
221
+
222
+ **Management commands:**
223
+ ```bash
224
+ # List all configured MCP servers
225
+ gemini mcp list
226
+
227
+ # Remove the server if needed
228
+ gemini mcp remove browser
229
+ ```
230
+
231
+ **Example usage in Gemini CLI:**
232
+
233
+ ```bash
234
+ # Natural language commands
235
+ > Navigate to https://github.com and take a screenshot
236
+ > Click the search button and type "MCP servers"
237
+ > Get the text from the .repository-content selector
238
+
239
+ # The CLI will use the browser automation tools automatically
240
+ ```
241
+
242
+ **Advanced options:**
243
+
244
+ ```bash
245
+ # Add with specific scope (user vs project)
246
+ gemini mcp add -s user browser node /path/to/browser-mcp-server-playwright.js
247
+
248
+ # Add with timeout configuration
249
+ gemini mcp add --timeout 30000 browser node /path/to/browser-mcp-server-playwright.js
250
+
251
+ # Skip tool confirmation prompts (use with caution)
252
+ gemini mcp add --trust browser node /path/to/browser-mcp-server-playwright.js
253
+ ```
254
+
255
+ ## Available Tools (16)
256
+
257
+ ### Navigation & Interaction
258
+ 1. **browser_navigate(url)** - Navigate to a URL
259
+ 2. **browser_click(selector)** - Click an element
260
+ 3. **browser_type(selector, text)** - Type text into an input
261
+ 4. **browser_scroll(x?, y?)** - Scroll the page
262
+
263
+ ### Information Gathering
264
+ 5. **browser_screenshot(fullPage?)** - Capture screenshot
265
+ 6. **browser_get_text(selector)** - Get text from element
266
+ 7. **browser_get_dom(selector?)** - Get DOM structure
267
+ 8. **browser_evaluate(code)** - Execute JavaScript
268
+
269
+ ### Console Debugging ⭐ NEW
270
+ 9. **browser_console_start(level?)** - Start capturing console logs
271
+ 10. **browser_console_get(filter?)** - Get captured logs
272
+ 11. **browser_console_clear()** - Clear logs and stop
273
+
274
+ ### Advanced
275
+ 12. **browser_wait_for_selector(selector, timeout?)** - Wait for element
276
+ 13. **browser_resize_window(width, height)** - Resize browser window
277
+ 14. **browser_start_video_recording(path?)** - Start recording session (Playwright traces)
278
+ 15. **browser_stop_video_recording()** - Stop and save recording
279
+ 16. **browser_health_check()** - Verify browser connection
280
+
281
+ ## Examples
282
+
283
+ ### Navigate and Screenshot
284
+ ```javascript
285
+ // Agent uses:
286
+ browser_navigate("https://example.com")
287
+ browser_screenshot(fullPage: true)
288
+ ```
289
+
290
+ ### Debug JavaScript Errors
291
+ ```javascript
292
+ // Agent uses:
293
+ browser_console_start()
294
+ browser_navigate("https://myapp.com")
295
+ browser_click("#submit-button")
296
+ browser_console_get(filter: "error")
297
+ // Shows: ❌ [ERROR] Uncaught TypeError: ...
298
+ ```
299
+
300
+ ### Automate Form Submission
301
+ ```javascript
302
+ // Agent uses:
303
+ browser_navigate("https://example.com/login")
304
+ browser_type("#username", "user@example.com")
305
+ browser_type("#password", "secret")
306
+ browser_click("#login-button")
307
+ browser_wait_for_selector(".dashboard")
308
+ ```
309
+
310
+ ## How It Works
311
+
312
+ ### Three-Tier Browser Strategy (Automatic)
313
+
314
+ The server automatically chooses the best browser option:
315
+
316
+ **Tier 1 - Antigravity Mode:**
317
+ - Detects Chrome on port 9222
318
+ - Connects to existing Antigravity browser
319
+ - Uses Antigravity's browser profile
320
+ - No new browser window
321
+
322
+ **Tier 2 - System Chrome/Chromium:**
323
+ - Searches common locations: `/usr/bin/google-chrome`, `/usr/bin/chromium`, etc.
324
+ - Uses system-installed Chrome if found
325
+ - Saves ~275MB (no Chromium download needed)
326
+ - Uses isolated profile (`/tmp/chrome-mcp-profile`)
327
+
328
+ **Tier 3 - Playwright Chromium:**
329
+ - Falls back to Playwright's bundled Chromium
330
+ - Requires: `npx playwright install chromium`
331
+ - Uses isolated profile (`/tmp/chrome-mcp-profile`)
332
+ - New browser window appears
333
+
334
+ ### Safety Features
335
+
336
+ - **Isolated Profile**: Uses `/tmp/chrome-mcp-profile` (not your personal Chrome!)
337
+ - **No Setup Dialogs**: Silent startup with `--no-first-run` flags
338
+ - **Clean Environment**: No extensions, sync, or background updates
339
+ - **Reproducible**: Same behavior across systems
340
+
341
+ ## Security
342
+
343
+ This MCP server provides powerful browser automation capabilities. Please review these security considerations:
344
+
345
+ ### Isolated Browser Profile
346
+ - Uses `/tmp/chrome-mcp-profile` by default (configurable via `MCP_BROWSER_PROFILE`)
347
+ - **Does NOT access your personal Chrome data** (cookies, passwords, history)
348
+ - Each instance runs in a clean, isolated environment
349
+
350
+ ### Tool Safety
351
+
352
+ **browser_evaluate**: Executes arbitrary JavaScript in the browser context
353
+ - Code runs in browser sandbox (no access to your host system)
354
+ - Only executes when explicitly called by MCP client
355
+ - Requires user approval in most MCP clients
356
+ - **Recommendation**: Only use with trusted MCP clients and review code when possible
357
+
358
+ **browser_navigate**: Navigates to any URL
359
+ - Can visit any website the browser can access
360
+ - Uses isolated profile to prevent cookie/session theft
361
+ - **Recommendation**: Be cautious with URLs from untrusted sources
362
+
363
+ ### Debug Logs
364
+ - Server logs to `/tmp/mcp-browser-server.log`
365
+ - Logs may contain visited URLs and error messages
366
+ - Log file is cleared on system reboot (stored in `/tmp`)
367
+ - **Does NOT log** page content or sensitive data
368
+
369
+ ### Best Practices
370
+ - ✅ Only use with trusted MCP clients (Claude Desktop, Antigravity, etc.)
371
+ - ✅ Review automation scripts before execution when possible
372
+ - ✅ Use the default isolated profile (don't point to your personal Chrome)
373
+ - ✅ Report security issues via [GitHub Issues](https://github.com/ricardodeazambuja/browser-mcp-server/issues)
374
+
375
+ ## Configuration
376
+
377
+ ### Environment Variables
378
+
379
+ ```bash
380
+ # Custom browser profile location (optional)
381
+ export MCP_BROWSER_PROFILE="$HOME/.mcp-browser-profile"
382
+
383
+ # Then run the server
384
+ node browser-mcp-server-playwright.js
385
+ ```
386
+
387
+ ### MCP Config with Environment Variables
388
+
389
+ ```json
390
+ {
391
+ "mcpServers": {
392
+ "browser-tools": {
393
+ "command": "node",
394
+ "args": ["/path/to/browser-mcp-server-playwright.js"],
395
+ "env": {
396
+ "MCP_BROWSER_PROFILE": "/tmp/my-custom-profile"
397
+ }
398
+ }
399
+ }
400
+ }
401
+ ```
402
+
403
+ ## Troubleshooting
404
+
405
+ ### "No Chrome/Chromium browser found"
406
+
407
+ The server provides helpful error messages with multiple solutions:
408
+
409
+ **Option 1 - Install system Chrome/Chromium (Recommended):**
410
+ ```bash
411
+ # Ubuntu/Debian
412
+ sudo apt install google-chrome-stable
413
+ # or
414
+ sudo apt install chromium-browser
415
+
416
+ # Fedora
417
+ sudo dnf install google-chrome-stable
418
+
419
+ # macOS
420
+ brew install --cask google-chrome
421
+ ```
422
+
423
+ **Option 2 - Install Playwright's Chromium:**
424
+ ```bash
425
+ npm install playwright
426
+ npx playwright install chromium
427
+ ```
428
+
429
+ **Option 3 - Use with Antigravity:**
430
+ - Click the Chrome logo (top right) to launch browser
431
+ - The MCP server will automatically connect
432
+
433
+ ### Check Server Status
434
+
435
+ Use the `browser_health_check` tool to verify:
436
+ - Which mode is active (Antigravity / System Chrome / Playwright Chromium)
437
+ - Playwright source
438
+ - Browser profile location
439
+ - Current page URL
440
+
441
+ ### Check Server Status
442
+
443
+ Use the `browser_health_check` tool to verify:
444
+ - Connection mode (Antigravity vs Standalone)
445
+ - Playwright source
446
+ - Browser profile location
447
+ - Current page URL
448
+
449
+ ## Development
450
+
451
+ ### Project Structure
452
+
453
+ ```
454
+ browser-mcp-server/
455
+ ├── browser-mcp-server-playwright.js # Main server
456
+ ├── package.json # npm package config
457
+ ├── README.md # This file
458
+ └── LICENSE # MIT license
459
+ ```
460
+
461
+ ### Testing
462
+
463
+ ```bash
464
+ # Test server initialization
465
+ npm test
466
+
467
+ # Manual test
468
+ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' | node browser-mcp-server-playwright.js
469
+ ```
470
+
471
+ ### Debug Logging
472
+
473
+ Check `/tmp/mcp-browser-server.log` for detailed logs:
474
+ - Playwright loading attempts
475
+ - Browser connection/launch status
476
+ - Console capture events
477
+ - Tool execution
478
+
479
+ ## Technical Details
480
+
481
+ ### MCP Protocol
482
+ - Implements MCP 2024-11-05 protocol
483
+ - JSON-RPC 2.0 over stdio
484
+ - Supports `initialize`, `notifications/initialized`, `tools/list`, `tools/call`
485
+
486
+ ### Browser Control
487
+ - Uses Playwright for automation
488
+ - Connects via Chrome DevTools Protocol (CDP)
489
+ - Port 9222 for remote debugging
490
+
491
+ ### Chrome Launch Flags
492
+ ```bash
493
+ --remote-debugging-port=9222 # Enable CDP
494
+ --user-data-dir=/tmp/chrome-mcp-profile # Isolated profile
495
+ --no-first-run # Skip setup
496
+ --no-default-browser-check # No popups
497
+ --disable-fre # No first-run experience
498
+ --disable-sync # No Google sync
499
+ --disable-component-update # No auto-updates
500
+ # + more stability flags
501
+ ```
502
+
503
+ ## Compatibility
504
+
505
+ ### Tested With
506
+ - ✅ Antigravity
507
+ - ✅ Claude Desktop (macOS, Windows, Linux)
508
+ - ✅ Other MCP clients via stdio
509
+
510
+ ### Requirements
511
+ - Node.js >= 16.0.0
512
+ - Playwright ^1.57.0 (installed automatically via npm)
513
+ - Chrome/Chromium browser (automatically detected, or uses Playwright's Chromium)
514
+
515
+ ### Platforms
516
+ - ✅ Linux
517
+ - ✅ macOS
518
+ - ✅ Windows
519
+
520
+ ## Comparison with Other Tools
521
+
522
+ ### vs. Puppeteer MCP Servers
523
+ - ✅ More tools (16 vs typical 8-10)
524
+ - ✅ Console capture built-in
525
+ - ✅ Better error messages
526
+ - ✅ Hybrid mode (connect OR launch)
527
+
528
+ ### vs. Selenium Grid
529
+ - ✅ Simpler setup (no grid needed)
530
+ - ✅ MCP protocol integration
531
+ - ✅ Built for AI agents
532
+ - ✅ Lightweight (single process)
533
+
534
+ ### vs. Browser Extensions
535
+ - ✅ Works headlessly if needed
536
+ - ✅ No extension installation
537
+ - ✅ Programmable via MCP
538
+ - ✅ Works with any MCP client
539
+
540
+ ## Contributing
541
+
542
+ Contributions welcome! Please:
543
+ 1. Fork the repository
544
+ 2. Create a feature branch
545
+ 3. Make your changes
546
+ 4. Submit a pull request
547
+
548
+ ## License
549
+
550
+ MIT License - see LICENSE file
551
+
552
+ ## Credits
553
+
554
+ - Built with [Playwright](https://playwright.dev/)
555
+ - Implements [Model Context Protocol](https://modelcontextprotocol.io/)
556
+ - Originally developed for [Antigravity](https://antigravity.google/)
557
+
558
+ ## Support
559
+
560
+ - 🐛 [Report Issues](https://github.com/ricardodeazambuja/browser-mcp-server/issues)
561
+ - 💬 [Discussions](https://github.com/ricardodeazambuja/browser-mcp-server/discussions)
562
+ - 📧 Contact: Via GitHub Issues
563
+
564
+ ## Changelog
565
+
566
+ ### v1.0.3 (2025-12-26)
567
+ - ✅ **Documentation**: Updated README with v1.0.2 features and clearer installation instructions
568
+ - ✅ **Code Comments**: Updated header to reflect universal compatibility and all features
569
+ - ✅ **Package Files**: Included test suites and changelog in npm package
570
+
571
+ ### v1.0.2 (2025-12-26)
572
+ - ✅ **Smart Chrome Detection**: Automatically finds system Chrome/Chromium across Linux, macOS, Windows
573
+ - ✅ **Three-Tier Strategy**: Antigravity Chrome → System Chrome → Playwright Chromium
574
+ - ✅ **Auto-Install**: Playwright now installed automatically as dependency (via npm)
575
+ - ✅ **Better Errors**: Helpful error messages with platform-specific installation instructions
576
+ - ✅ **Resource Efficient**: Uses system Chrome when available (~275MB savings)
577
+ - ✅ **Test Suites**: Includes comprehensive test scripts
578
+ - ✅ **Auto-Reconnect**: Improved browser disconnection handling
579
+ - ✅ **Documentation**: Added detailed CHANGELOG-v1.0.2.md
580
+
581
+ ### v1.0.1 (2025-12-26)
582
+ - ✅ Fixed CLI bin path for npm installation
583
+ - ✅ Improved package configuration
584
+
585
+ ### v1.0.0 (2025-12-26)
586
+ - ✅ Initial release
587
+ - ✅ 16 browser automation tools
588
+ - ✅ Console capture (start/get/clear)
589
+ - ✅ Hybrid mode (connect OR launch)
590
+ - ✅ Safe Chrome launch with isolated profile
591
+ - ✅ Multi-source Playwright loading
592
+ - ✅ Universal compatibility (Antigravity + Claude Desktop + more)
593
+
594
+ ---
595
+
596
+ **Made with ❤️ for the MCP community**