-
Notifications
You must be signed in to change notification settings - Fork 170
Strip endpoint prefix from incoming request paths #3389
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
Conversation
…-from-request-paths
…g the actual path
…-from-request-paths
…-from-request-paths
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3389 +/- ##
==========================================
+ Coverage 64.85% 64.88% +0.03%
==========================================
Files 375 375
Lines 36626 36690 +64
==========================================
+ Hits 23753 23808 +55
- Misses 10999 11013 +14
+ Partials 1874 1869 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // Remove trailing slash, but keep "/" as "/" | ||
| if path != "/" { | ||
| path = strings.TrimSuffix(path, "/") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concern: I'm not sure this is correct, we should probably avoid doing this.
Some routers are not very strict (or are they? 🤷) and allow the user to specify a trailing slash in their paths, mapping /foo and /foo/ to different handlers. This is usually the case when/foo/{param} is accepted and an empty string is passed.
At the proxy level, knowing whether the trailing slash is desired or not requires intimate knowledge of the MCP server. We should let the Client shoot itself in the foot and let it figure out whether the trailing slash is required or not.
| // 1. Client makes direct request to proxy with prefix (e.g., /playwright/sse) | ||
| // 2. Ingress doesn't strip the prefix before forwarding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concern: could you clarify which scenario is solved by this?
My concern is that we would be adding logic that belongs to the load balancer or HTTP gateway, so I would gather a list of occurrences of these issues in the wild before introducing potentially confusing logic.
All major ingress controllers from both cloud providers and independent vendors (e.g. kong, istio, traefik, haproxy) support some form of prefix stripping in more or less convoluted ways.
|
@blkt I agree that the issue is more related to the infrastructure than the proxy itself. A better solution would be to address this at the infrastructure level. I’m going to close this PR. |
Summary
Implements automatic stripping of
endpointPrefixfrom incoming request paths in the transparent HTTP proxy. This enables ingress routing scenarios where requests arrive with a prefix (e.g.,/playwright/sse) that needs to be removed before forwarding to the backend MCP server.Changes
stripEndpointPrefix()function: Strips prefix from request paths with intelligent handlingmcpServerBasePathtracking: Tracks MCP server base path (fromremoteURLfor remote servers, or transport type for local servers)normalizePath()helper: Normalizes paths for consistent comparisonGetMCPServerBasePath()helper: Single source of truth for MCP server pathsBehavior
Normal Stripping
/playwright/ssewithendpointPrefix=/playwright,mcpServerBasePath=/sse→/sse✓Prefix Matches Server Path
/playwright/ssewithendpointPrefix=/playwright,mcpServerBasePath=/playwright→/playwright/sse(preserved) ✓/sse/sse/endpointwith both/sse→/sse/endpoint(strips duplicate) ✓Edge Cases
/Files Modified
pkg/transport/proxy/transparent/transparent_proxy.gopkg/transport/http.gopkg/transport/url.gopkg/transport/proxy/transparent/transparent_test.goTesting
Comprehensive test coverage with 20+ test cases covering all scenarios. All tests pass.