python-sdk
python-sdk copied to clipboard
Streamable HTTP Transport Doesn't Handle 202 Accepted Responses
Initial Checks
- [x] I confirm that I'm using the latest version of MCP Python SDK
- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
The StreamableHTTPTransport._handle_post_request() method returns immediately when receiving a 202 Accepted HTTP status code without making the required GET request to retrieve the SSE stream, causing session.list_tools() and other JSON-RPC requests to timeout indefinitely.
Steps to Reproduce
- Connect to an MCP server that returns
202 Acceptedfor POST requests - Call
session.list_tools()or any other JSON-RPC request method - Observe that the call times out after the configured timeout period
Example Code
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
async def test():
server_url = "https://example.com/mcp" # Server that returns 202 Accepted
async with streamablehttp_client(server_url) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
# This will timeout if server returns 202 Accepted
tools = await asyncio.wait_for(session.list_tools(), timeout=30.0)
asyncio.run(test())
Python & MCP Python SDK
Python: 3.12.x
SDK: 1.22.0