Skip to content

Conversation

m7mdhka
Copy link
Contributor

@m7mdhka m7mdhka commented Sep 28, 2025

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.

servers using the WebSocket transport
@m7mdhka m7mdhka force-pushed the feature/mcp-websocket-client branch from ff95d0e to d5e0852 Compare September 28, 2025 13:37
Copy link
Collaborator

@DouweM DouweM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m7mdhka Thanks Mohamed, left a comment. Also note that this will need tests and docs.

return self.url == value.url


class MCPServerWebSocket(_MCPServerHTTP):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this inherit from MCPServer instead of _MCPServerHTTP if it overrides most of what that class does?

@DouweM
Copy link
Collaborator

DouweM commented Sep 30, 2025

@Kludex Would it make sense to support this while modelcontextprotocol/modelcontextprotocol#1288 is still in review, but the feature is available on the Python SDK?

@m7mdhka
Copy link
Contributor Author

m7mdhka commented Sep 30, 2025

@DouweM Thanks for pointing that out. Since this feature is still under review in modelcontextprotocol/modelcontextprotocol#1288, I agree it makes sense to hold off until it becomes production-ready. I’ll keep track of its progress in the MCP repo and update this PR once it’s a stable feature we can reliably depend on.

@DouweM DouweM marked this pull request as draft September 30, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSockets MCP Client Support
3 participants