You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a WebSocket server transport (WebSocketServerTransport) to complement the existing WebSocketClientTransport, allowing MCP servers to communicate over WebSockets in addition to stdio and Streamable HTTP.
Motivation and Context
The SDK currently supports:
stdio-based transports, and
Streamable HTTP (SSE/JSON) transports,
as well as a WebSocket client transport.
However, there is no corresponding server-side WebSocket transport. This makes it harder to:
host MCP servers behind a WebSocket endpoint, or
integrate with environments where WebSockets are the preferred or only option.
This change introduces WebSocketServerTransport, which implements the shared Transport interface and allows MCP servers to accept WebSocket connections using the mcp subprotocol.
How Has This Been Tested?
Ran existing test cases
Example you can write once you’ve tested:
Ran npm run build and npm test.
Manually tested a simple MCP server using WebSocketServerTransport:
Started a server on ws://localhost:8787/mcp.
Connected using WebSocketClientTransport.
Verified JSON-RPC requests and responses flowed correctly in both directions.
Breaking Changes
No breaking changes are expected:
This adds a new transport implementation and an export.
Existing transports (stdio and Streamable HTTP) and APIs are unchanged.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Thanks for this. Per the discussion in #142, we're moving away from WebSocket transport in the SDK rather than adding to it, to avoid transport proliferation. The Transport interface is exported for custom implementations. If SEP-1288 lands at the spec level we'd revisit. This also targets the pre-monorepo src/ path. Closing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Add a WebSocket server transport (
WebSocketServerTransport) to complement the existingWebSocketClientTransport, allowing MCP servers to communicate over WebSockets in addition to stdio and Streamable HTTP.Motivation and Context
The SDK currently supports:
as well as a WebSocket client transport.
However, there is no corresponding server-side WebSocket transport. This makes it harder to:
This change introduces
WebSocketServerTransport, which implements the sharedTransportinterface and allows MCP servers to accept WebSocket connections using themcpsubprotocol.How Has This Been Tested?
Ran existing test cases
Example you can write once you’ve tested:
Ran
npm run buildandnpm test.Manually tested a simple MCP server using
WebSocketServerTransport:ws://localhost:8787/mcp.WebSocketClientTransport.Breaking Changes
No breaking changes are expected:
Types of changes
Checklist
Additional context
src/server/websocket.tsWebSocketServerTransportusing thewslibrary.mcpsubprotocol and validates incoming messages withJSONRPCMessageSchema.WebSocketServerTransportfromsrc/server/index.tsso it can be imported via@modelcontextprotocol/sdk/server.StdioServerTransport/WebSocketClientTransportpatterns for consistency.