Feature: Add WebSocket Transport for MCP Servers #3017
Draft
+79
−3
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.
Closes #3016
Description:
Summary
This pull request introduces support for WebSocket as a transport mechanism for MCP servers by adding a new
MCPServerWebSocket
class. This provides a robust alternative to the existing HTTP-based transports (SSE and Streamable HTTP).Motivation
In many production environments, especially within containerized services like Kubernetes, HTTP-based transports can lead to challenges with session management and load balancing. Sticky sessions are often required to ensure that requests for a given session ID are routed to the same pod, which can cause uneven load distribution and complications when pods are restarted or scaled.
As detailed in #3016 , using WebSockets for the MCP connection establishes a stable, long-lived, and stateful connection between the client and a specific server instance. This avoids the need for complex load balancer configurations and resolves issues related to session persistence being "nailed to the pod," leading to a more resilient and scalable architecture.
This implementation directly addresses feedback from users who rely on WebSockets as their primary connection method for MCP servers.