test: regression test for initialize hang on unexpected content-type

Closed
CH
3mo ago
+107-9

Summary

  • Adds a regression test (test_initialize_does_not_hang_on_unexpected_content_type) that directly reproduces the hang described in issue #2432
  • The test creates a minimal HTTP server that returns Content-Type: text/plain for all requests (including initialize) and asserts that session.initialize() raises MCPError immediately instead of blocking forever

The underlying fix is already present on main — _handle_post_request sends a proper JSONRPCError (with the matching request ID) when it encounters an unexpected content type, which lets ClientSession resolve the pending request instead of waiting indefinitely. This PR adds the missing test that exercises that code path for the initialize call specifically.

Test plan

  • tests/client/test_notification_response.py::test_initialize_does_not_hang_on_unexpected_content_type — new test passes
  • All existing test_notification_response.py tests continue to pass

Fixes #2432