Fix Rack compatibility issues across versions 2.x and 3.x#154
Open
ericproulx wants to merge 1 commit intoyjacquin:mainfrom
Open
Fix Rack compatibility issues across versions 2.x and 3.x#154ericproulx wants to merge 1 commit intoyjacquin:mainfrom
ericproulx wants to merge 1 commit intoyjacquin:mainfrom
Conversation
- Update Ruby version to 3.4.2 in .ruby-version - Fix header handling to use proper Rack header classes based on version - Use Rack::Headers for Rack 3.x and Rack::Utils::HeaderHash for Rack 2.x - Ensure headers are properly frozen and duplicated when used - Fix rack.hijack handling for SSE connections - Rack 3.x returns IO directly from hijack call - Rack 2.x uses separate hijack_io property - Add support for request body rewind safety check - Improve test infrastructure with custom RSpec matchers: - be_json_rpc_response: General JSON-RPC 2.0 response matcher - be_json_rpc_error: Specific error response matcher with chaining - be_default_ok_response: Plain text OK response matcher - Update all transport specs to use proper Rack::MockRequest and matchers - Ensure all tests pass under both Rack 2.x and 3.x versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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