feat(proxy): enhance connection handling with method-based probing an…#3587
Merged
Conversation
…d OAuth error handling - Introduced method-based decision logic for connection probing, allowing for optimized handling of cached lists. - Implemented improved OAuth error handling to surface upstream 401 responses, enabling frontend OAuth popups for expired or missing credentials. - Updated proxy handshake logic to ensure efficient connection management and error reporting.
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Contributor
Release OptionsSuggested: Minor ( React with an emoji to override the release type:
Current version:
|
…hWithCache - Added a mechanism to throttle background revalidation of cached lists based on a minimum interval, preventing excessive upstream requests during frequent cache hits. - Introduced a new utility function, isRevalidationStale, to determine if a revalidation is due based on the last revalidation timestamp and the specified interval. - Updated fetchWithCache to utilize the new throttling logic, ensuring efficient cache management. - Enhanced tests to cover various scenarios for the new throttling behavior, including edge cases for interval settings.
- Enhanced the isRevalidationStale function to handle cases where lastMs is undefined, ensuring that revalidation is correctly marked as stale when it has never occurred. - Added comments for clarity on the throttling behavior and conditions for revalidation.
…ated tool polling - Implemented a new test to verify that repeated calls to the tools/list endpoint do not trigger unnecessary downstream handshakes, ensuring efficient connection management. - The test simulates multiple rapid polling requests and asserts that the number of downstream handshakes remains bounded, improving performance and resource utilization.
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.
…d OAuth error handling
What is this contribution about?
Screenshots/Demonstration
How to Test
Migration Notes
Review Checklist
Summary by cubic
Optimize MCP proxy connection handling by probing downstream only when needed, throttling background list revalidation, and surfacing OAuth 401s correctly. This cuts handshakes for cached list polls and reduces upstream load during frequent polling while still enabling frontend OAuth popups.
New Features
tools/list,resources/list, andprompts/list; always probeinitialize,tools/call, and reads; skip notifications andping.peekRpcMethodsafely reads the JSON-RPC method from POST bodies without consuming the stream and skips oversized bodies.isRevalidationStale; applied in the lazy client, auth transport, and connection tools. Added e2e coverage to ensure repeatedtools/listpolls don’t re-handshake.Bug Fixes
WWW-Authenticateresponses in proxy and handshake paths, enabling the frontend OAuth popup instead of returning JSON-RPC errors or 500s.Written for commit 15e5969. Summary will update on new commits.