In Model Context Protocol (MCP) Streamable HTTP scenarios, requests for the same MCP session must reach the same function instance to maintain context consistency. MCP Streamable HTTP affinity routes requests that carry the same Mcp-Session-Id to the instance that initialized the session. This feature is based on MCP protocol versions 2025-03-26 and 2025-06-18.
When to use this feature
Use MCP Streamable HTTP affinity when your MCP server is stateful — that is, when it holds session context in memory and requires subsequent requests from the same client to land on the same instance.
| Scenario | Recommendation |
|---|---|
| Stateful MCP server (session context in memory) | Enable MCP Streamable HTTP affinity |
| Stateless MCP server (no in-memory session state) | No affinity needed |
| Using MCP HTTP with Server-Sent Events (SSE) transport | Not compatible — use a separate function |
Prerequisites
Before you begin, ensure that you have:
A Function Compute function whose code implements the MCP protocol specification
An HTTP trigger configured on that function (or the ability to create one)
Permissions to modify function configuration and trigger settings
How it works
A client sends a POST request to initialize a session. The function returns a
Mcp-Session-Idin the response header.Function Compute binds that session ID to the instance that handled the initialization request.
All subsequent requests that include the same
Mcp-Session-Idare routed to the same instance.When the client sends a DELETE request with the
Mcp-Session-Id, the system terminates the session and releases the instance's concurrency quota.
Enable MCP Streamable HTTP affinity
Step 1: Enable session affinity
Log on to the Function Compute console.
In the function list, select the target function or create a function.
When creating a function, you can configure Isolation and Affinity directly in the Advanced Configuration section.
On the Function Details page, click the Configuration tab.
In the Advanced Configuration section, click Isolation and Affinity to expand the panel.
Turn on the Session Affinity switch.
Step 2: Select the affinity type
In the session affinity configuration panel, select MCP Streamable HTTP Affinity.
Step 3: Configure the HTTP trigger
The MCP Streamable HTTP protocol requires three HTTP methods. On the Triggers tab, verify that your HTTP trigger supports all of the following:
| Method | Purpose | Required |
|---|---|---|
| POST | MCP requests and session initialization | Yes |
| DELETE | Session termination | Yes |
| GET | SSE persistent connections | Optional |
The DELETE method is required because clients terminate sessions by sending a DELETE request. Without it, the system rejects the request, the session cannot be released, and the associated concurrency quota remains locked.
Step 4: Configure session parameters
Set the following parameters to control session binding and resource usage:
| Parameter | Default | Range | Notes |
|---|---|---|---|
| Concurrent sessions per instance | 20 | 1–200 | Start with a lower value (such as 10) for testing; adjust for production. When the limit is reached, the system automatically creates a new instance. |
| Session lifecycle | 21,600 seconds (6 hours) | — | Maximum duration from session creation to automatic destruction. After this time, affinity is no longer guaranteed. |
| Session idle timeout | 1,800 seconds (30 minutes) | — | If no requests arrive for a session within this period, the session is automatically destroyed. |
After you enable session affinity, Concurrency per instance is automatically set to 200 and cannot be changed manually. This quota is shared by SSE persistent connections and POST requests.
Click Deploy to apply the configuration.
Limitations
Access methods: Supported only via an HTTP trigger or a custom domain name.
Protocol versions: The client and function must comply with MCP transport layer specifications for version
2025-03-26or2025-06-18.SSE incompatibility: Do not use MCP HTTP with SSE to call a function that has MCP Streamable HTTP affinity enabled. The session management mechanisms are incompatible and cause invocation failures.
SessionAPI management: Not supported.
General limits: See General limits and principles of session affinity for additional constraints.
Verify the configuration
Send requests to the function using a standard MCP client. Use the default HTTP trigger domain name or a custom domain name. For guidance on building an MCP client, see Build an MCP client in the official MCP documentation.
FAQ
Why is session affinity not routing requests to the same instance?
Check whether your HTTP trigger supports GET, POST, and DELETE. If any of these methods are missing, session initialization or termination may fail, breaking affinity. Also confirm that the client sends requests using the standard MCP Streamable HTTP transport — not the SSE-based transport.
How do I terminate a session?
Send a DELETE request with the Mcp-Session-Id header set to the session ID. The system purges the session and releases the associated concurrency resources.