MCP Protocol to Replace Existing HTTP+SSE Solution with Streamable HTTP Transport Protocol!

In the digital age, the efficiency and stability of data transmission are key drivers of technological advancement. The MCP (Model Context Protocol), as an important part of the AI ecosystem, introduces a revolutionary change in data interaction by adopting the Streamable HTTP transport mechanism. This article will delve into the Streamable HTTP of the MCP protocol, exploring the entire process from session negotiation to formal data transmission, discussing its technical architecture, protocol content, implementation methods, and impact on AI applications.

Technical Architecture

The MCP protocol adopts a client-server architecture, with core components including:

  1. MCP Host: Applications that include the MCP client, such as Claude Desktop, Cursor IDE, and other AI tools.
  2. MCP Client: The protocol implementation that maintains a 1:1 connection with the server within the host.
  3. MCP Server: A lightweight program that exposes specific functions through standardized protocols, which can be a local Node.js/Python program or a remote service.MCP Protocol to Replace Existing HTTP+SSE Solution with Streamable HTTP Transport Protocol!

The MCP server provides three categories of standard capabilities:

  • Resources: Such as file reading and API data retrieval.
  • Tools: Third-party services or functional functions, such as Git operations and browser control.
  • Prompts: Predefined task templates that enhance model performance in specific scenarios.

Protocol Content of Streamable HTTP

Streamable HTTP, as a significant update to the MCP protocol, aims to address the limitations of the traditional HTTP+SSE solution while retaining its advantages. Its core content includes the following aspects:

  1. Unified Message Entry: All messages from clients to servers are sent through the <span>/message</span> endpoint, eliminating the need for a dedicated SSE endpoint.
  2. Dynamic Upgrade of SSE Stream: The server can upgrade requests sent from the client to <span>/message</span> to an SSE connection as needed for push notifications or requests.
  3. Session Management Mechanism: Clients establish sessions with the server through the <span>Mcp-Session-Id</span> in the request header, and the server can choose whether to maintain session state.
  4. Support for Stateless Servers: The server can choose to operate completely statelessly, no longer needing to maintain long-term connections.MCP Protocol to Replace Existing HTTP+SSE Solution with Streamable HTTP Transport Protocol!

Implementation Method

From Session Negotiation to Formal Data Transmission

1. Session Negotiation

Session negotiation is the initial phase of Streamable HTTP communication, where the client and server establish a session through the following steps:

  1. Client Sends Initialization Request: The client sends an <span>InitializeRequest</span> message via HTTP POST to the MCP server’s <span>/message</span> endpoint, carrying protocol version and client capability information.
  2. Server Responds to Initialization: After receiving the request, the server returns an <span>InitializeResult</span> message containing the supported protocol version, server capabilities, and session ID (<span>Mcp-Session-Id</span>).
  3. Client Sends Initialized Notification: After receiving the server’s response, the client sends an <span>Initialized</span> notification to inform the server that initialization is complete.

Example: Client Sends Initialization Request

POST /message HTTP/1.1
Host: mcp.example.com
Content-Type: application/json
Accept: text/event-stream, application/json

{"jsonrpc": "2.0", "method": "initialize", "params": {"clientInfo": {"name": "MCP Client", "version": "1.0"}, "capabilities": {}}}

Example: Server Responds to Initialization

HTTP/1.1 200 OK
Content-Type: application/json
Mcp-Session-Id: 12345

{"jsonrpc": "2.0", "id": 1, "result": {"serverInfo": {"name": "MCP Server", "version": "1.0"}, "capabilities": {}}}

Example: Client Sends Initialized Notification

POST /message HTTP/1.1
Host: mcp.example.com
Content-Type: application/json
Accept: text/event-stream, application/json
Mcp-Session-Id: 12345

{"jsonrpc": "2.0", "method": "initialized", "params": {}}

2. Formal Data Transmission

Once the session is established, the client and server can proceed with formal communication through the following steps:

  1. Client Sends Message: The client sends a JSON-RPC message via HTTP POST to the MCP server’s <span>/message</span> endpoint, carrying the session identifier <span>Mcp-Session-Id</span>.
  2. Server Processes Request and Responds: The server processes the message based on the request content and returns a response via SSE stream or JSON object.
  3. Dynamic Upgrade to SSE Stream: If real-time message push is needed, the server can upgrade the connection to an SSE stream.
  4. Reconnect and Data Recovery: If network fluctuations cause a connection interruption, the client can reconnect with the <span>Last-Event-ID</span> to replay unsent messages based on that ID.

Example: Client Sends Message

POST /message HTTP/1.1
Host: mcp.example.com
Content-Type: application/json
Accept: text/event-stream, application/json
Mcp-Session-Id: 12345

{"jsonrpc": "2.0", "id": 1, "method": "get_file", "params": {"path": "/example.txt"}}

Example: Server Responds and Upgrades to SSE Stream

HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
Mcp-Session-Id: 12345

data: {"jsonrpc": "2.0", "id": 1, "result": "File content here"}

Example: Client Reconnects

GET /message HTTP/1.1
Host: mcp.example.com
Accept: text/event-stream
Last-Event-ID: 12345
Mcp-Session-Id: 12345

Example: Server Replays Unsent Messages

data: {"jsonrpc": "2.0", "id": 2, "result": "Continued content here"}

Comparison with Traditional HTTP+SSE

  • Improved Real-time Performance: By using independent POST for each message and continuous SSE stream transmission, the client can receive server responses in real-time, significantly reducing system latency.
  • Connection Flexibility and Fault Tolerance: Utilizing reconnection strategies like Last-Event-ID ensures seamless message transmission even in fluctuating network environments.
  • Flexible Session Management: The encrypted session ID enhances security and reliability for cross-device and cross-process communication.
  • Compatibility and Extensibility: It is compatible with legacy HTTP+SSE use cases while providing standardized interfaces for future custom transport protocols.

Application Scenarios

  • Efficient Collaboration of Autonomous Agents: Streamable HTTP can achieve low-latency communication, message retransmission mechanisms, and flexible scalability in future AI systems, especially in the collaborative work of autonomous agents, ensuring a more real-time and efficient decision-making process.
  • Distributed AI Platforms and Data Collaboration: Streamable HTTP provides cross-platform data synchronization, high concurrency support, and secure session management for distributed AI platforms, ensuring the timeliness and integrity of data exchange.

Future Outlook

With the widespread adoption of Streamable HTTP, the MCP protocol is expected to become a core infrastructure in the AI ecosystem. Its standardized and open characteristics will promote deep interconnectivity between different vendors and platforms, breaking down information silos and fostering cross-industry collaboration. Meanwhile, as technology continues to evolve, Streamable HTTP will continuously optimize in terms of security, fault tolerance mechanisms, and provide users with more stable and efficient data transmission guarantees.

Conclusion

The MCP protocol, by introducing the Streamable HTTP transport mechanism, not only addresses many issues of traditional transmission methods but also provides a solid technical foundation for the future development of AI applications. Whether in the collaborative work of autonomous agents or the data exchange of distributed AI platforms, Streamable HTTP demonstrates its unique advantages. It is foreseeable that as this technology matures and is applied, the MCP protocol will play an increasingly important role in the global AI ecosystem.

Leave a Comment