Skip to content

401 in Streamable HTTP should be handled gracefully #1295

@somaraani

Description

@somaraani

Initial Checks

Description

Currently, streamable_http will call response.raise_for_status() when handling POST requests. (ref).

This means that a 401 will bubble up and cause the entire program to crash.

While a 401 on server initialize could warrant an exception, we have a use case where a MCP server will return 401 for specific unauthorized operations, and allow others.

This should be handled gracefully, similar to how _handle_unexpected_content_type works, returning a JSONRPC message outlining an unauthorized exception was thrown.

This would let an agent or other client handle it instead of crashing the program.

Python & MCP Python SDK

Python 3.12 and MCP SDK v1.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions