Title: 401 in Streamable HTTP should be handled gracefully · Issue #1295 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: 401 in Streamable HTTP should be handled gracefully · Issue #1295 · modelcontextprotocol/python-sdk
X Title: 401 in Streamable HTTP should be handled gracefully · Issue #1295 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description Currently, streamable_...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1295
X: @github
Domain: redirect.github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"401 in Streamable HTTP should be handled gracefully","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nCurrently, `streamable_http` will call `response.raise_for_status()` when handling POST requests. [(ref)](https://github.com/modelcontextprotocol/python-sdk/blob/9a8592e7d4d69b785df8b5d9d7b694cb6cbb149f/src/mcp/client/streamable_http.py#L278).\n\nThis means that a 401 will bubble up and cause the entire program to crash. \n\nWhile 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.\n\nThis should be handled gracefully, similar to how [`_handle_unexpected_content_type`](https://github.com/modelcontextprotocol/python-sdk/blob/9a8592e7d4d69b785df8b5d9d7b694cb6cbb149f/src/mcp/client/streamable_http.py#L340C15-L340C46) works, returning a JSONRPC message outlining an unauthorized exception was thrown.\n\nThis would let an agent or other client handle it instead of crashing the program.\n\n\n### Python & MCP Python SDK\n\n```Text\nPython 3.12 and MCP SDK v1.13.1\n```","author":{"url":"https://github.com/somaraani","@type":"Person","name":"somaraani"},"datePublished":"2025-08-22T21:31:45Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/1295"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a271e3bc-f1fe-57a1-4ce8-6658a9874435 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5D4:2B0D42:003C:007D:6B056A28 |
| html-safe-nonce | 7da082d84f2f57f345b159e322233cb5bbf9f9ec6abf8149cc9e107b78caedfd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUQ0OjJCMEQ0MjowMDNDOjAwN0Q6NkIwNTZBMjgiLCJ2aXNpdG9yX2lkIjoiMjg4NDEzNDUwOTI4MjIwNzEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f5c743e4ffdeb323fa91daecf267a95af5ea1b61afb9cdeaf6ded575d0ee826e |
| hovercard-subject-tag | issue:3346829678 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1295/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad622a438535c3692765ae6fc7fac43188ddb8d7824d909d1c5b350d5baebc1d/modelcontextprotocol/python-sdk/issues/1295 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad622a438535c3692765ae6fc7fac43188ddb8d7824d909d1c5b350d5baebc1d/modelcontextprotocol/python-sdk/issues/1295 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | somaraani |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1be5cc09efdd4833c24a4ffa71d698e3999fa09071e159fe14c2c08e41c98331 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f6d69234e682c947a48074340e69d45d5901de31 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width