In Model Context Protocol (MCP) Streamable HTTP scenarios, requests for the same MCP session must be routed to the same function instance to ensure context consistency. The MCP Streamable HTTP affinity feature is based on MCP protocol versions 2025-03-26 and 2025-06-18. The system parses the Mcp-Session-Id field in the HTTP response header to establish a session binding. This routes requests that carry the same Mcp-Session-Id to the instance that initialized the session. This feature is suitable for scenarios that use MCP Streamable HTTP transport.
Core configuration
On the function configuration page, go to Advanced Configuration > Isolation and Affinity, enable the Session Affinity switch, select MCP Streamable HTTP Affinity, and configure Concurrent sessions per instance. Ensure that the HTTP trigger supports the GET, POST, and DELETE methods, and then click Deploy to enable the feature.
A client initializes a session by sending a POST request and obtains the Mcp-Session-Id from the response header. Subsequent requests that carry this ID are routed to the same instance.
Scope
General limits: For more information, see General limits and principles of session affinity.
Protocol version requirements: This feature supports MCP protocol versions
2025-03-26and2025-06-18. The client and function must comply with the transport layer specifications of the corresponding version.Compatibility: Do not use MCP HTTP with Server-Sent Events (SSE) to invoke a function that has MCP Streamable HTTP affinity enabled. The session management mechanisms are incompatible and will cause invocation failures.
Access method limits: This feature only supports access through an HTTP trigger or a custom domain name.
HTTP trigger configuration requirements: The HTTP trigger must support the
GET,POST, andDELETEmethods.Why the DELETE method is required
A client can actively terminate a session by sending aDELETErequest. Function Compute then revokes the session's resources, including the instance's concurrent quota. If the DELETE method is not enabled, the system rejects the request, and the session cannot be released normally.Request limits:
A single instance can process multiple sessions simultaneously. The default value is 20, and the maximum is 200. When the number of sessions bound to a single instance reaches this limit, the system automatically creates a new instance.
Multiple sessions share the instance's concurrency quota of 200. This quota is shared by both SSE persistent connections and POST requests.
SessionAPI management is not supported.
Configure MCP Streamable HTTP affinity
Flow overview
Configuring MCP Streamable HTTP affinity involves four steps: enabling session affinity, selecting the MCP Streamable HTTP type, configuring the HTTP trigger, and configuring parameters before deployment. Ensure that the function code implements the MCP protocol specification.
Enable session affinity
Log on to the Function Compute console.
Navigate to the function list and select the target function or create a function.
When creating a function, you can configure the Isolation and Affinity configuration item in the Advanced Configuration section.
On the Function Details page, click the Configuration tab.
In the Advanced Configuration section, find the Isolation and Affinity configuration item.
Click Isolation and Affinity to expand the configuration panel.
Turn on the Session Affinity switch.
Select the MCP Streamable HTTP affinity type
In the session affinity configuration area, select the MCP Streamable HTTP Affinity radio button.
The system automatically displays the configuration options for MCP Streamable HTTP affinity.
Configure the HTTP trigger
Purpose: Ensure that the HTTP trigger supports the request methods required by the MCP Streamable HTTP protocol.
Procedure:
On the function details page, click the Triggers tab.
Check for or create an HTTP trigger.
Ensure that the trigger supports the following request methods:
GET: For SSE persistent connections (optional).
POST: For MCP requests and session initialization (required).
DELETE: For terminating sessions (required).
Configure session parameters
Purpose: Set the number of sessions, lifecycle, and idle timeout to control session binding and resource usage.
Procedure:
Concurrent sessions per instance: The maximum number of sessions that a single instance can process concurrently.
Default value: 20
Value range: 1 to 200
Suggestion: Set a smaller value, such as 10, for testing scenarios. For production environments, adjust the value as needed.
Session lifecycle: The maximum duration of a session from creation to destruction.
Default value: 21,600 seconds (6 hours)
Description: After this time, the system automatically destroys the session, and affinity is no longer guaranteed.
Session idle timeout: Specifies the duration after which an idle session is automatically destroyed.
Default value: 1,800 seconds (30 minutes)
Description: If no requests are received for a session for a period longer than this duration, the session is considered idle and is automatically destroyed.
Click the Deploy button to save the configuration.
Important:
After you enable session affinity, the system automatically sets the Concurrency per instance to 200. This is the default value and cannot be manually changed.
Ensure that the HTTP trigger supports the GET, POST, and DELETE methods. The DELETE method is used to terminate sessions.
Verify the MCP Streamable HTTP affinity configuration
To verify the affinity configuration, send requests to the function using a standard MCP client. You can use the default HTTP trigger domain name or a custom domain name provided by Function Compute. For more information, see the official MCP document Build an MCP client.
FAQ
Why is MCP Streamable HTTP affinity not working?
Possible causes:
The HTTP trigger does not support the GET, POST, and DELETE methods.
Requests are not sent using the standard MCP protocol.
Troubleshooting steps:
Check whether the HTTP trigger supports the GET, POST, and DELETE methods.
Ensure that requests are sent using the standard MCP Streamable protocol.
How do I terminate a session?
Method:
A client terminates a session by sending a DELETE request.
The request header must include the
Mcp-Session-Idfield.The system then purges the session and releases the associated resources.