Fix Rack compatibility issues across versions 2.x and 3.x #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Rack compatibility issues across versions 2.x and 3.x
Summary
This PR addresses compatibility issues between Rack 2.x and 3.x versions in the FastMCP transport layer. The changes ensure that the gem works correctly with both major versions of Rack while maintaining backward compatibility.
Problem
The codebase had several incompatibilities with different Rack versions:
Rack::Headerswhile Rack 2.x usesRack::Utils::HeaderHashrack.hijackinterface changed between versionsSolution
1. Dynamic Header Class Selection
2. Rack Hijack Compatibility
rack.hijackreturns IO directlyrack.hijack_ioafter callingrack.hijack3. Request Body Safety
rewindmethod availability on request body4. Improved Test Infrastructure
be_json_rpc_response: Validates general JSON-RPC 2.0 responsesbe_json_rpc_error: Specifically tests error responses with chainable assertionsbe_default_ok_response: Tests plain text OK responsesRack::MockRequestandRack::MockResponseRack::Lintmiddleware in tests to ensure Rack complianceChanges
Modified Files
lib/mcp/transports/rack_transport.rb: Main compatibility fixeslib/mcp/transports/authenticated_rack_transport.rb: Header handling updatesspec/mcp/transports/*_spec.rb: Complete test suite overhaulspec/spec_helper.rb: Added support file loadingNew Files
spec/support/json_rpc_response_matcher.rb: General JSON-RPC response matcherspec/support/json_rpc_error_matcher.rb: Error-specific matcher with chainingspec/support/default_ok_response_matcher.rb: Plain text response matcherTesting
All tests have been updated and verified to pass with both:
The custom matchers provide better test readability and more informative failure messages:
Breaking Changes
None. All changes maintain backward compatibility.
Future Considerations