Skip to content

Conversation

@amirejaz
Copy link
Contributor

Summary

Implements automatic stripping of endpointPrefix from 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

  • Added stripEndpointPrefix() function: Strips prefix from request paths with intelligent handling
  • Added mcpServerBasePath tracking: Tracks MCP server base path (from remoteURL for remote servers, or transport type for local servers)
  • Added normalizePath() helper: Normalizes paths for consistent comparison
  • Updated proxy director: Strips prefix before forwarding requests to backend
  • Added GetMCPServerBasePath() helper: Single source of truth for MCP server paths

Behavior

Normal Stripping

  • /playwright/sse with endpointPrefix=/playwright, mcpServerBasePath=/sse/sse

Prefix Matches Server Path

  • /playwright/sse with endpointPrefix=/playwright, mcpServerBasePath=/playwright/playwright/sse (preserved) ✓
  • /sse/sse/endpoint with both /sse/sse/endpoint (strips duplicate) ✓

Edge Cases

  • Prefix not at start → no change
  • Exact match → /
  • Empty prefix/path → no change

Files Modified

  • pkg/transport/proxy/transparent/transparent_proxy.go
  • pkg/transport/http.go
  • pkg/transport/url.go
  • pkg/transport/proxy/transparent/transparent_test.go

Testing

Comprehensive test coverage with 20+ test cases covering all scenarios. All tests pass.

@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Jan 21, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 21, 2026
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 44.68085% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.88%. Comparing base (8571282) to head (250e991).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
pkg/transport/http.go 0.00% 48 Missing ⚠️
pkg/transport/url.go 71.42% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amirejaz amirejaz changed the title Strip endpoint prefix only when it differs from MCP server base path Strip endpoint prefix from incoming request paths Jan 22, 2026
Comment on lines +393 to +396
// Remove trailing slash, but keep "/" as "/"
if path != "/" {
path = strings.TrimSuffix(path, "/")
}
Copy link
Contributor

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.

Comment on lines +408 to +409
// 1. Client makes direct request to proxy with prefix (e.g., /playwright/sse)
// 2. Ingress doesn't strip the prefix before forwarding
Copy link
Contributor

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.

@amirejaz
Copy link
Contributor Author

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

@amirejaz amirejaz closed this Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants