python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Streamable HTTP Transport Doesn't Handle 202 Accepted Responses

Open yadgire7 opened this issue 2 months ago • 0 comments

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

  1. Connect to an MCP server that returns 202 Accepted for POST requests
  2. Call session.list_tools() or any other JSON-RPC request method
  3. 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

yadgire7 avatar Nov 24 '25 22:11 yadgire7