Title: Initialize call hangs forever if MCP server does not return a `Content-Type: text/plain` · Issue #2432 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Initialize call hangs forever if MCP server does not return a `Content-Type: text/plain` · Issue #2432 · modelcontextprotocol/python-sdk
X Title: Initialize call hangs forever if MCP server does not return a `Content-Type: text/plain` · Issue #2432 · 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 We had some timeouts o...
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/2432
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Initialize call hangs forever if MCP server does not return a `Content-Type: text/plain`","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\nWe had some timeouts on our server while using MCP client from the SDK.\nWhen users try to integrate our client with their MCP server, we do an `initialize` call to the server and we are waiting infinitely to the following:\n```\nsync with self:\n ...\n```\n\nAfter investigation, it seems the error happens when the MCP server is misconfigured, and returns something different than `Content-Type: text/event-stream` as a response from the `initialize` call.\n\nAlthough it is on the server side, the client should be able to fail immediately with a understandable error to warn the user something went wrong with the server's `initialize` output.\n \n\n### Example Code\n\n```Python\n# server.py\n\nfrom http.server import BaseHTTPRequestHandler, HTTPServer\n\nclass PlainTextHandler(BaseHTTPRequestHandler):\n def do_POST(self):\n length = int(self.headers.get(\"Content-Length\", 0))\n self.rfile.read(length)\n\n body = b\"this is not json\"\n self.send_response(200)\n self.send_header(\"Content-Type\", \"text/plain\")\n self.send_header(\"Content-Length\", str(len(body)))\n self.end_headers()\n self.wfile.write(body)\n\n def log_message(self, format, *args):\n print(f\"[server] {format % args}\")\n\nserver = HTTPServer((\"localhost\", 9000), PlainTextHandler)\nprint(\"[server] listening on http://localhost:9000\")\nserver.serve_forever()\n\n# client.py\nimport asyncio\nimport mcp\nfrom mcp.client.streamable_http import streamable_http_client\n\nasync def main():\n print(\"connecting…\")\n async with streamable_http_client(\"http://localhost:9000/mcp\") as (\n read_stream, write_stream, _,\n ):\n async with mcp.ClientSession(read_stream, write_stream) as session:\n await session.initialize() # ← hangs here forever\n\n print(\"done (you should never see this)\")\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\n- Python 3.12.12\n- MCP - 1.27.0\n```","author":{"url":"https://github.com/HenriChabert","@type":"Person","name":"HenriChabert"},"datePublished":"2026-04-13T09:34:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/2432/python-sdk/issues/2432"}
| 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:8d7fbfbd-fbbe-99e4-5f04-d08db77f7666 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C1B2:6C3F9:45A87D:649453:6A636E13 |
| html-safe-nonce | 49362ab7213757997818179b65b56e19141973bc9f04a51d4761747edc8c345c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUIyOjZDM0Y5OjQ1QTg3RDo2NDk0NTM6NkE2MzZFMTMiLCJ2aXNpdG9yX2lkIjoiMjE0OTE1MzM1Njk3NTkyNjgwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 72fa1e6952a753e04ba4f19349ab26d8b87b877ac2f18f5102105914e01f4cc5 |
| hovercard-subject-tag | issue:4253218415 |
| 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/2432/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1beb0f14210d729502de91434f88531277bce860eb23649b413223eae6e579cc/modelcontextprotocol/python-sdk/issues/2432 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1beb0f14210d729502de91434f88531277bce860eb23649b413223eae6e579cc/modelcontextprotocol/python-sdk/issues/2432 |
| 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 | HenriChabert |
| hostname | github.com |
| expected-hostname | github.com |
| None | e7b5617850fbcd6d10fe2b7c56398444bccb5f3a58a4a18c6d363971295bcd03 |
| 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 | aa341b3f432dc63fa9633042725aec601722a352 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width