Skip to content

Streamable HTTP Transport Doesn't Handle 202 Accepted Responses #1661

@yadgire7

Description

@yadgire7

Initial Checks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs confirmationNeeds confirmation that the PR is actually required or needed.questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions