Title: Cannot handle `Unexpected content type` when initializing MCP session · Issue #1382 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Cannot handle `Unexpected content type` when initializing MCP session · Issue #1382 · modelcontextprotocol/python-sdk
X Title: Cannot handle `Unexpected content type` when initializing MCP session · Issue #1382 · 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 When trying to connect...
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/1382
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot handle `Unexpected content type` when initializing MCP session","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\nWhen trying to connect to an MCP server using `streamablehttp_client` and `ClientSession`, the client prints `Unexpected content type` error if the server responds with anything other than the expected MCP JSON stream (e.g. error page, misconfigured endpoint, etc.).\n\nThis makes it difficult to handle cases where the server is not reachable or not serving MCP correctly, since no exception is raised.\n\n### Example Code\n\n```Python\nimport asyncio\nfrom mcp.client.streamable_http import streamablehttp_client\nfrom mcp import ClientSession\n\nasync def main():\n async with streamablehttp_client(\n url=\"http://localhost:3001/mcp\",\n ) as (read, write, _):\n async with ClientSession(read, write) as session:\n try:\n await session.initialize()\n except Exception as e:\n print(f\"Failed to initialize MCP session: {e}\")\n return\n print(\"MCP session initialized\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Output\n\n```\nUnexpected content type: text/html; charset=utf-8\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\npython 3.13.5\nmcp 1.14.1\n```","author":{"url":"https://github.com/bystepii","@type":"Person","name":"bystepii"},"datePublished":"2025-09-19T23:08:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1382/python-sdk/issues/1382"}
| 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:541cbb74-07c1-ccd7-f277-f71abe115d27 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8154:37660C:13DE0FD:1C60E58:6A63466D |
| html-safe-nonce | 75d16568fc1ab882618c05d68a06fa73d3cf3e3e1ea45412babddfa472a641b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTU0OjM3NjYwQzoxM0RFMEZEOjFDNjBFNTg6NkE2MzQ2NkQiLCJ2aXNpdG9yX2lkIjoiODQ4MTc5MzcwMzg4Nzk4MDE0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | beff75547ae07dcac14d969eceeeb9499f7f955ca657d01c6c198532c9c160e3 |
| hovercard-subject-tag | issue:3436161778 |
| 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/1382/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c93d79875048682712fb7a68c6aafa402cbd97e983231d75828bf661cbf64d3/modelcontextprotocol/python-sdk/issues/1382 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c93d79875048682712fb7a68c6aafa402cbd97e983231d75828bf661cbf64d3/modelcontextprotocol/python-sdk/issues/1382 |
| 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 | bystepii |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| 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 | 990295d92a4cc7b63fbbd83a046217cd7d77d49c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width