Skip to content

fix: Add exception handling for POST request failures in StreamableHTTP #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Kulaxyz
Copy link

@Kulaxyz Kulaxyz commented Jun 23, 2025

Added exception handling in the _handle_post_request method to gracefully handle transport errors and return proper JSON-RPC error responses.

Motivation and Context

When an MCP server returns HTTP 5xx errors (e.g., when the server is down) after initial connection, these errors were not being propagated to the caller. This made it impossible for client applications to detect and handle server failures appropriately.

How Has This Been Tested?

  • Verified that HTTP exceptions are properly forwarded to read streams
  • Confirmed error responses are delivered immediately with correct JSON-RPC format
  • All existing transport tests continue to pass

Breaking Changes

no

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Strands SDK is an example of an implementation that is hanging when MCP Server is down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant