Add generic PrefixHandlers to transport config #3524
Merged
+503
−29
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.
Summary
This PR adds a generic
PrefixHandlerscapability to the transport layer, enabling components to mount HTTP handlers at specific path prefixes on the proxy's HTTP server. This is a foundational change that enables the embedded authorization server (RFC-0031) to register OAuth2/OIDC endpoints alongside MCP proxy traffic without requiring transport-specific code changes.Why
The embedded authorization server integration requires mounting OAuth endpoints (e.g.,
/oauth/*,/.well-known/oauth-authorization-server) on the same HTTP server that handles MCP proxy traffic. Rather than coupling the transport layer to the auth server, this PR introduces a generic route-mounting mechanism that keeps the transport package agnostic to handler types while enabling flexible route composition.Changes
PrefixHandlersfield intypes.Config- a map of path prefixes to HTTP handlersPrefixHandlersflows throughFactory.Create()→HTTPTransport→TransparentProxyTransparentProxy.Start()- prefix handlers are mounted before the catch-all proxy handler, relying on Go's ServeMux longest-match routing for correct precedence/.well-known/oauth-protected-resource) instead of the entire/.well-known/prefix, allowing prefix handlers to register other well-known endpointsRelated