Skip to content

feat(proxy): enhance connection handling with method-based probing an…#3587

Merged
pedrofrxncx merged 4 commits into
mainfrom
mcp-proxy-cache
May 30, 2026
Merged

feat(proxy): enhance connection handling with method-based probing an…#3587
pedrofrxncx merged 4 commits into
mainfrom
mcp-proxy-cache

Conversation

@pedrofrxncx
Copy link
Copy Markdown
Collaborator

@pedrofrxncx pedrofrxncx commented May 30, 2026

…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.

What is this contribution about?

Describe your changes and why they're needed.

Screenshots/Demonstration

Add screenshots or a Loom video if your changes affect the UI.

How to Test

Provide step-by-step instructions for reviewers to test your changes:

  1. Step one
  2. Step two
  3. Expected outcome

Migration Notes

If this PR requires database migrations, configuration changes, or other setup steps, document them here. Remove this section if not applicable.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

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

    • Method-based handshake probing with cache-aware skipping for tools/list, resources/list, and prompts/list; always probe initialize, tools/call, and reads; skip notifications and ping.
    • peekRpcMethod safely reads the JSON-RPC method from POST bodies without consuming the stream and skips oversized bodies.
    • Throttled background revalidation of cached lists with a minimum interval (30s default) via isRevalidationStale; applied in the lazy client, auth transport, and connection tools. Added e2e coverage to ensure repeated tools/list polls don’t re-handshake.
  • Bug Fixes

    • Surface upstream OAuth 401s as WWW-Authenticate responses 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.

Review in cubic

…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.
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

Release Options

Suggested: Minor (2.374.0) — based on feat: prefix

React with an emoji to override the release type:

Reaction Type Next Version
👍 Prerelease 2.373.4-alpha.1
🎉 Patch 2.373.4
❤️ Minor 2.374.0
🚀 Major 3.0.0

Current version: 2.373.3

Note: If multiple reactions exist, the smallest bump wins. If no reactions, the suggested bump is used (default: patch).

…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.
@pedrofrxncx pedrofrxncx enabled auto-merge (squash) May 30, 2026 03:14
@pedrofrxncx pedrofrxncx merged commit 8fbd400 into main May 30, 2026
20 checks passed
@pedrofrxncx pedrofrxncx deleted the mcp-proxy-cache branch May 30, 2026 03:14
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