modelcontextprotocol / modelcontextprotocol/python-sdk

401 in Streamable HTTP should be handled gracefully

Open
#1,295 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 ready for work
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/mcp/client/streamable_http.py at the POST handling around response.raise_for_status(), then compare it with _handle_unexpected_content_type. Trace how HTTP errors become client results; done means a 401 from an unauthorized operation produces a JSON-RPC unauthorized error message that the client can handle without crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.