Skip to content

Fix: Support multiple concurrent HTTP transports#1

Open
frank-ih wants to merge 1 commit into
missbjs:mainfrom
frank-ih:fix/multiple-http-connections
Open

Fix: Support multiple concurrent HTTP transports#1
frank-ih wants to merge 1 commit into
missbjs:mainfrom
frank-ih:fix/multiple-http-connections

Conversation

@frank-ih
Copy link
Copy Markdown

Problem

The MCP server was using a singleton Server instance for all HTTP transport connections. When Chrome extension held an SSE connection, Claude Code's HTTP requests would fail with:

Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.

Root Cause

The getMcpServer() function returned a singleton Server instance that could only have ONE active transport connection at a time. When Chrome extension connected via SSE (using the singleton), Claude Code's subsequent HTTP request tried to connect to the same singleton, causing the error.

Solution

  1. Added createMcpServer() factory function - Creates a NEW Server instance per HTTP transport connection. This allows multiple concurrent connections without conflicts.

  2. Modified HTTP route handlers to use createMcpServer():

    • POST /mcp - Creates new server for each initialize request
    • GET /sse - Creates new server for each SSE connection
  3. Kept getMcpServer() for backward compatibility with stdio transport (Chrome Native Messaging).

Files Changed

  • src/mcp/mcp-server.ts - Added createMcpServer() factory
  • dist/mcp/mcp-server.js - Compiled output
  • dist/server/index.js - Updated route handlers to use createMcpServer()

Testing

  • Verified that curl requests work correctly after server restart
  • Verified that Chrome extension and curl can connect simultaneously
  • Verified that the "Already connected" error no longer occurs with concurrent connections

Co-Authored-By: Claude [email protected]

The MCP server was using a singleton Server instance for all HTTP
transport connections. When Chrome extension held an SSE connection,
Claude Code's HTTP requests would fail with "Already connected to
a transport" error.

Solution:
- Add createMcpServer() factory function that creates a NEW Server
  instance per HTTP transport
- Modify HTTP route handlers (POST /mcp, GET /sse) to use
  createMcpServer() instead of getMcpServer()
- Keep getMcpServer() for backward compatibility with stdio transport

This allows Chrome extension and Claude Code to simultaneously
connect to the HTTP server without conflicts.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants