feat: add multi-session support for concurrent Chrome instances #899
+878
−133
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add multi-session support allowing multiple independent Chrome browser instances to run simultaneously, each identified by a unique
sessionId. This enables parallel browser automation workflows (e.g., testing multiple pages side-by-side, comparing environments) without needing multiple MCP server processes.Motivation
The current architecture supports only a single Chrome browser instance per server. This limits use cases where an MCP client needs to interact with multiple browser contexts concurrently — for example, comparing two web pages, running parallel test suites, or managing multiple authenticated sessions.
Changes
New files
src/SessionManager.ts— Core session lifecycle manager with per-sessionMutex, auto-purge on browser disconnect, orphan prevention, and graceful shutdownsrc/tools/session.ts— Three new tools:create_session,list_sessions,close_sessiontests/SessionManager.test.ts— 17 E2E tests covering creation, retrieval, listing, closing, parallel isolation, mutex serialization, auto-purge, and shutdown rejectionModified files
src/main.ts— Replaced singletonbrowser/contextwithSessionManager. AddedregisterBrowserTool()wrapper that transparently injectssessionIdinto every existing tool's Zod schema and resolves the correct session'sMcpContext— original tool handlers remain unmodifiedsrc/tools/categories.ts— AddedSESSIONcategorysrc/tools/tools.ts— Registered session tools, exportedsessionToolNamessetDesign decisions
registerBrowserTool()wraps each tool, injectingsessionIdinto the schema and resolving the correctMcpContextbefore calling the unmodified handlerisolated: trueforced: All sessions use isolated Chrome profiles to prevent conflictsMap<string, SessionInfo>sessionIdschema (prevents conflicts)Error handling
McpContext.from()fails afterlaunch(), the browser is closedcloseSession()acquires the session mutex before closingprocess.once('SIGINT'/'SIGTERM')with#shuttingDownguard and 10s timeoutbrowser.on('disconnected')instanceof Error(no unsafeerr?.message)Test results
Breaking changes
All existing browser tools now require a mandatory
sessionIdparameter. Clients must callcreate_sessionfirst to obtain a session ID before using any other tool.