Skip to content

Commit a0204a5

Browse files
committed
add husky for commits + pnpm exec husky init + move around mcp specifics + multi-sessions update in readme
1 parent f32fd05 commit a0204a5

File tree

12 files changed

+1236
-2380
lines changed

12 files changed

+1236
-2380
lines changed

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pnpm lint
2+
pnpm prettier:fix

README.md

Lines changed: 93 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -335,79 +335,73 @@ The Browserbase MCP server provides the following tools for browser automation:
335335

336336
### Multi-Session Management Tools
337337

338-
The server now supports managing multiple browser sessions in parallel, allowing you to control multiple browsers simultaneously:
338+
The server supports managing multiple independent browser sessions in parallel, allowing you to control multiple browsers simultaneously for complex automation workflows:
339339

340-
- **stagehand_session_create_multi**
341-
- Create a new independent Stagehand browser session
340+
#### Session Lifecycle Management
341+
342+
- **multi-browserbase_stagehand_session_create**
343+
- Create a new independent Stagehand browser session with full web automation capabilities
344+
- Each session is isolated with its own browser instance, cookies, and state
342345
- Inputs:
343-
- `name` (string, optional): Optional name for the session
344-
- `browserbaseSessionID` (string, optional): Resume an existing Browserbase session
345-
- `browserbaseSessionCreateParams` (object, optional): Custom Browserbase session parameters
346+
- `name` (string, optional): Human-readable name for tracking (e.g., 'login-flow', 'data-scraping')
347+
- `browserbaseSessionID` (string, optional): Resume an existing Browserbase session by ID
348+
- `browserbaseSessionCreateParams` (object, optional): Advanced Browserbase configuration
346349
- Output:
347-
- Session ID and Browserbase session ID
350+
- Session ID and Browserbase session ID with live debugger URL
348351

349-
- **stagehand_session_list**
350-
- List all active Stagehand browser sessions
352+
- **browserbase_stagehand_session_list**
353+
- List all currently active Stagehand browser sessions with detailed metadata
354+
- Shows session IDs, names, Browserbase session IDs, creation time, and age
351355
- No inputs required
352356
- Output:
353-
- List of active sessions with IDs, names, and metadata
357+
- Comprehensive list of active sessions with status information
354358

355-
- **stagehand_session_close_multi**
356-
- Close a specific Stagehand browser session
359+
- **multi-browserbase_stagehand_session_close**
360+
- Close and clean up a specific Stagehand browser session
361+
- Terminates browser instance, ends Browserbase session, and frees resources
357362
- Input:
358-
- `sessionId` (string): The session ID to close
363+
- `sessionId` (string): Exact session ID to close (cannot be undone)
359364
- Output:
360-
- Confirmation message
365+
- Confirmation message with session replay URL
366+
367+
#### Session-Specific Browser Automation
361368

362-
- **stagehand_navigate_session**
369+
All core browser automation tools are available with session-specific variants:
370+
371+
- **multi-browserbase_stagehand_navigate_session**
363372
- Navigate to a URL in a specific browser session
364373
- Inputs:
365374
- `sessionId` (string): The session ID to use
366375
- `url` (string): The URL to navigate to
367376

368-
- **stagehand_act_session**
369-
- Perform an action in a specific browser session
377+
- **multi-browserbase_stagehand_act_session**
378+
- Perform an action in a specific browser session using natural language
370379
- Inputs:
371380
- `sessionId` (string): The session ID to use
372-
- `action` (string): The action to perform
373-
- `variables` (object, optional): Variables for the action
381+
- `action` (string): The action to perform (e.g., "click the login button")
382+
- `variables` (object, optional): Variables for sensitive data in action templates
374383

375-
- **stagehand_extract_session**
376-
- Extract information from a specific browser session
384+
- **multi-browserbase_stagehand_extract_session**
385+
- Extract structured information from a specific browser session
377386
- Inputs:
378387
- `sessionId` (string): The session ID to use
379-
- `instruction` (string): What to extract
388+
- `instruction` (string): What to extract from the page
380389

381-
- **stagehand_observe_session**
382-
- Observe elements in a specific browser session
390+
- **multi-browserbase_stagehand_observe_session**
391+
- Observe and find actionable elements in a specific browser session
383392
- Inputs:
384393
- `sessionId` (string): The session ID to use
385-
- `instruction` (string): What to observe
386-
- `returnAction` (boolean, optional): Whether to return the action
387-
388-
### Multi-Session Example
389-
390-
Here's an example of using multiple browser sessions in parallel:
391-
392-
```javascript
393-
// Create two sessions
394-
const searchSession = await createSession({ name: "Search Engine" });
395-
const newsSession = await createSession({ name: "News Reader" });
396-
397-
// Navigate both sessions in parallel
398-
await Promise.all([
399-
navigateSession(searchSession.id, "https://google.com"),
400-
navigateSession(newsSession.id, "https://news.ycombinator.com")
401-
]);
394+
- `instruction` (string): What to observe (e.g., "find the login button")
395+
- `returnAction` (boolean, optional): Whether to return the action to perform
402396

403-
// Perform actions on both sessions
404-
await actSession(searchSession.id, "Search for 'AI tools'");
405-
const news = await extractSession(newsSession.id, "Extract top 5 headlines");
397+
#### Multi-Session Use Cases
406398

407-
// Clean up
408-
await closeSession(searchSession.id);
409-
await closeSession(newsSession.id);
410-
```
399+
- **Parallel Data Collection**: Run multiple scraping sessions simultaneously across different websites
400+
- **A/B Testing**: Compare user flows across different browser sessions with varying configurations
401+
- **Authentication Workflows**: Maintain separate authenticated sessions for different user accounts
402+
- **Cross-Site Operations**: Perform coordinated actions across multiple websites or applications
403+
- **Load Testing**: Simulate multiple users interacting with web applications concurrently
404+
- **Backup Sessions**: Keep fallback sessions ready in case primary sessions encounter issues
411405

412406
### Resources
413407

@@ -425,21 +419,26 @@ mcp-server-browserbase/
425419
│ ├── config.ts # Configuration management and CLI parsing
426420
│ ├── context.ts # Context class managing Stagehand instances
427421
│ ├── sessionManager.ts # Browserbase session lifecycle management
422+
│ ├── stagehandStore.ts # Multi-session store for managing parallel browser sessions
428423
│ ├── program.ts # CLI program setup using Commander.js
429424
│ ├── transport.ts # HTTP/SSE and STDIO transport handlers
430425
│ ├── server.ts # Server list management
431-
│ ├── resources.ts # Screenshot resource management
432-
│ ├── prompts.ts # Prompt templates for MCP clients
433426
│ ├── utils.ts # Utility functions
434-
│ └── tools/ # Tool definitions and implementations
435-
│ ├── act.ts # Stagehand action execution tool
436-
│ ├── extract.ts # Page content extraction tool
437-
│ ├── navigate.ts # URL navigation tool
438-
│ ├── observe.ts # Element observation tool
439-
│ ├── screenshot.ts # Screenshot capture tool
440-
│ ├── session.ts # Session management tools
441-
│ ├── tool.ts # Tool type definitions
442-
│ └── utils.ts # Tool utility functions
427+
│ ├── mcp/ # MCP protocol implementations
428+
│ │ ├── prompts.ts # Prompt templates and handlers for MCP clients
429+
│ │ └── resources.ts # Resource management (screenshots) with URI-based access
430+
│ ├── tools/ # Tool definitions and implementations
431+
│ │ ├── act.ts # Stagehand action execution tool
432+
│ │ ├── extract.ts # Page content extraction tool
433+
│ │ ├── navigate.ts # URL navigation tool
434+
│ │ ├── observe.ts # Element observation tool
435+
│ │ ├── screenshot.ts # Screenshot capture tool
436+
│ │ ├── session.ts # Single session management tools
437+
│ │ ├── multiSession.ts # Multi-session management and session-aware tools
438+
│ │ ├── tool.ts # Tool type definitions and interfaces
439+
│ │ └── index.ts # Tool exports and registration
440+
│ └── types/ # TypeScript type definitions
441+
│ └── types.ts # Shared type definitions for sessions and configurations
443442
├── dist/ # Compiled JavaScript output
444443
├── assets/ # Images and documentation assets
445444
├── cli.js # Executable entry point for CLI usage
@@ -471,13 +470,24 @@ mcp-server-browserbase/
471470

472471
**server.ts** - Server list management providing factory patterns for server creation and handling multiple concurrent connections.
473472

474-
### Tools & Resources
473+
**stagehandStore.ts** - Multi-session store managing parallel browser sessions with lifecycle tracking, automatic cleanup, and session metadata.
474+
475+
### MCP Protocol Specifics Implementation
476+
477+
**mcp/prompts.ts** - Prompt template definitions and handlers implementing the MCP prompts specification with argument substitution.
478+
479+
**mcp/resources.ts** - Resource management implementing the MCP resources specification, handling screenshot storage, URI resolution, and base64-encoded data serving.
475480

476-
**tools/** - Individual tool implementations with type-safe schemas including browser automation (navigate, act, extract, observe, screenshot) and session management tools.
481+
### Tools & Types
477482

478-
**resources.ts** - Screenshot resource management with in-memory storage, URI resolution, and base64-encoded PNG data serving.
483+
**tools/** - Individual tool implementations with type-safe Zod schemas including:
484+
- Core browser automation tools (navigate, act, extract, observe, screenshot)
485+
- Single session management tools (session.ts)
486+
- Multi-session management and session-aware tool variants (multiSession.ts)
487+
- Tool type definitions and interfaces (tool.ts)
488+
- Centralized tool exports and registration (index.ts)
479489

480-
**prompts.ts** - Prompt template definitions and retrieval system for MCP clients.
490+
**types/types.ts** - Shared TypeScript type definitions for sessions, configurations, and MCP protocol structures.
481491

482492
**utils.ts** - Message sanitization utilities ensuring proper JSON formatting for MCP messages.
483493

@@ -492,22 +502,38 @@ mcp-server-browserbase/
492502
This server implements the following MCP capabilities:
493503

494504
- **Tools**: 14 tools for comprehensive browser automation
495-
- 5 Stagehand tools: navigate, act, extract, observe, screenshot
496-
- 2 Session management tools: create and close Browserbase sessions
505+
- 5 Core Stagehand tools: navigate, act, extract, observe, screenshot
506+
- 2 Single-session management tools: create and close Browserbase sessions
497507
- 7 Multi-session tools: create, list, close, navigate, act, extract, observe with specific sessions
498508
- **Prompts**: Prompt templates for common automation tasks
499509
- **Resources**: Screenshot resource management with URI-based access
500510

511+
### Session Management Architecture
512+
513+
The server supports two session management approaches:
514+
515+
1. **Single Session Mode**: Traditional approach with one active browser session
516+
- Tools: `browserbase_session_create`, `browserbase_session_close`
517+
- Simpler for basic automation tasks
518+
- Automatically manages the active session
519+
520+
2. **Multi-Session Mode**: Advanced approach with multiple parallel browser sessions
521+
- Tools: `multi-browserbase_stagehand_session_create`, `multi-browserbase_stagehand_session_close`, `browserbase_stagehand_session_list`
522+
- Session-specific variants of all core tools (with `_session` suffix)
523+
- Ideal for complex workflows requiring parallel browser instances
524+
- Each session maintains independent state, cookies, and browser context
525+
501526
## Key Features
502527

503528
- **AI-Powered Automation**: Natural language commands for web interactions
504529
- **Multi-Model Support**: Works with OpenAI, Claude, Gemini, and more
505-
- **Session Management**: Create, manage, and persist browser sessions
530+
- **Advanced Session Management**: Single and multi-session support for parallel browser automation
506531
- **Screenshot Capture**: Full-page and element-specific screenshots
507532
- **Data Extraction**: Intelligent content extraction from web pages
508533
- **Proxy Support**: Enterprise-grade proxy capabilities
509534
- **Stealth Mode**: Advanced anti-detection features
510535
- **Context Persistence**: Maintain authentication and state across sessions
536+
- **Parallel Workflows**: Run multiple browser sessions simultaneously for complex automation tasks
511537

512538
For more information about the Model Context Protocol, visit:
513539

@@ -518,4 +544,4 @@ For more information about the Model Context Protocol, visit:
518544

519545
Licensed under the MIT License.
520546

521-
Copyright 2025 Browserbase, Inc.
547+
Copyright 2025 Browserbase, Inc.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"scripts": {
2222
"build": "tsc && shx chmod +x dist/*.js",
23-
"prepare": "npm run build",
23+
"prepare": "husky",
2424
"watch": "tsc --watch",
2525
"lint": "eslint . --ext .ts",
2626
"prettier:check": "prettier --check .",
@@ -37,10 +37,11 @@
3737
"eslint": "^9.29.0",
3838
"eslint-plugin-react": "^7.37.5",
3939
"globals": "^16.2.0",
40+
"husky": "^9.1.7",
4041
"prettier": "^3.6.1",
4142
"shx": "^0.3.4",
4243
"typescript": "^5.6.2",
4344
"typescript-eslint": "^8.35.0"
4445
},
45-
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
46+
"packageManager": "pnpm@10.12.4+sha512.5ea8b0deed94ed68691c9bad4c955492705c5eeb8a87ef86bc62c74a26b037b08ff9570f108b2e4dbd1dd1a9186fea925e527f141c648e85af45631074680184"
4647
}

0 commit comments

Comments
 (0)