Approved · 0 retained findingsgithub/github-mcp-server#2900
feat(http): add --authorization-server flag to override OAuth AS URL
Input
PR author’s description
Summary
Adds a --authorization-server CLI flag (and GITHUB_AUTHORIZATION_SERVER env var) to the http subcommand, allowing operators to override the authorization server URL advertised in the OAuth Protected…
PR diff
Current GitHub diff ↗+ // AuthorizationServer overrides the authorization server URL advertised in the+ // OAuth Protected Resource Metadata (/.well-known/oauth-protected-resource).+ // When set, this URL is used instead of the one derived from the GitHub host.+ // Useful when deploying behind an OAuth proxy (e.g. for GHES, which does not
Browse 6 changed files
pkg/http/server.go+17 −5
@@ -53,6 +53,13 @@ type ServerConfig struct { // This is used to restore the original path when a proxy strips a base path before forwarding. ResourcePath string + // AuthorizationServer overrides the authorization server URL advertised in the+ // OAuth Protected Resource Metadata (/.well-known/oauth-protected-resource).+ // When set, this URL is used instead of the one derived from the GitHub host.+ // Useful when deploying behind an OAuth proxy (e.g. for GHES, which does not+ // natively support RFC 8414 / RFC 7591 / PKCE).+ AuthorizationServer string+ // TrustProxyHeaders indicates whether X-Forwarded-Host and X-Forwarded-Proto // should be honored when constructing OAuth resource metadata URLs. Only // enable this when the server is deployed behind a trusted proxy that sets@@ -190,11 +197,7 @@ func RunHTTPServer(cfg ServerConfig) error { } // Register OAuth protected resource metadata endpoints- oauthCfg := &oauth.Config{- BaseURL: cfg.BaseURL,- ResourcePath: cfg.ResourcePath,- TrustProxyHeaders: cfg.TrustProxyHeaders,- }+ oauthCfg := newOAuthConfig(cfg) serverOptions := []HandlerOption{ WithInventoryFactory(inventoryFactory),@@ -256,6 +259,15 @@ func RunHTTPServer(cfg ServerConfig) error { return nil } +func newOAuthConfig(cfg ServerConfig) *oauth.Config {+ return &oauth.Config{+ BaseURL: cfg.BaseURL,+ ResourcePath: cfg.ResourcePath,+ TrustProxyHeaders: cfg.TrustProxyHeaders,+ AuthorizationServer: cfg.AuthorizationServer,+ }+}+ // resolveListenAddress returns the address string passed to http.Server. // When host is empty the server binds to all interfaces on the given port; // otherwise host and port are joined into a single address.
pkg/http/server_test.go+34 −0
@@ -9,6 +9,7 @@ import ( ghcontext "github.com/github/github-mcp-server/pkg/context" "github.com/github/github-mcp-server/pkg/github"+ "github.com/github/github-mcp-server/pkg/http/oauth" "github.com/github/github-mcp-server/pkg/inventory" "github.com/github/github-mcp-server/pkg/utils" "github.com/stretchr/testify/assert"@@ -44,6 +45,39 @@ func TestRunHTTPServerRejectsInvalidStaticTools(t *testing.T) { } } +func TestNewOAuthConfig(t *testing.T) {+ tests := []struct {+ name string+ authorizationServer string+ }{+ {+ name: "unset preserves host-derived authorization server",+ },+ {+ name: "explicit override is propagated",+ authorizationServer: "https://oauth-proxy.example.com",+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ cfg := newOAuthConfig(ServerConfig{+ BaseURL: "https://mcp.example.com",+ ResourcePath: "/mcp",+ TrustProxyHeaders: true,+ AuthorizationServer: tt.authorizationServer,+ })++ assert.Equal(t, &oauth.Config{+ BaseURL: "https://mcp.example.com",+ ResourcePath: "/mcp",+ TrustProxyHeaders: true,+ AuthorizationServer: tt.authorizationServer,+ }, cfg)+ })+ }+}+ func TestInitGlobalToolScopeMapUsesHost(t *testing.T) { tests := []struct { name string
docs/streamable-http.md+27 −0
@@ -92,6 +92,33 @@ github-mcp-server http --trust-proxy-headers Equivalent environment variable: `GITHUB_TRUST_PROXY_HEADERS=1`. Only enable this when the upstream proxy is trusted to set or strip these headers; otherwise prefer `--base-url`. When `--base-url` is set, it always takes precedence and `--trust-proxy-headers` has no effect. +### With an OAuth Proxy (GHES / non-standard authorization server)++When deploying against GitHub Enterprise Server, GHES does not natively support the OAuth extensions required by MCP (RFC 8414 metadata discovery, RFC 7591 Dynamic Client Registration, PKCE). In this case you can run a separate OAuth proxy that implements the MCP OAuth spec and forwards authentication to GHES. Use `--authorization-server` to advertise the proxy's URL in the protected resource metadata instead of the one derived from `--gh-host`:++```bash+github-mcp-server http \+ --gh-host https://github.example.com \+ --base-url https://mcp.example.com \+ --authorization-server https://mcp.example.com/oauth-proxy+```++The `authorization_servers` field in the protected resource metadata will then point at your proxy:++```json+{+ "resource": "https://mcp.example.com",+ "authorization_servers": [+ "https://mcp.example.com/oauth-proxy"+ ],+ ...+}+```++Equivalent environment variable: `GITHUB_AUTHORIZATION_SERVER=https://mcp.example.com/oauth-proxy`.++When neither the flag nor environment variable is set, the server preserves the existing behavior and derives the authorization server from `--gh-host`. The override only changes the URL advertised in OAuth protected resource metadata; it does not change token validation or the GitHub API host.+ ## Client Configuration ### Using OAuth Authentication
Outcome
Why this verdict
approve — No checked defect was established by the available proof adapters.
Lens advisories (not part of the checked findings):
- historical_risk: main_test.go:TestAuthorizationServerConfigurationIsHTTPOnly tests that the authorization-server flag is HTTP-only, suggesting historical OAuth URL injection bugs in similar flags.
Lens disagreements (not adjudicated):
- complexity_maintainability vs change_quality on
seed:input-document— complexity_maintainability and change_quality disagree on this entity - change_quality vs test_strategy on
seed:input-document— change_quality and test_strategy disagree on this entity
Lens coverage: 6 delivered
The recorded observations did not become verified findings.
Evidence and perspectives
Observation · Historical riskmain_test.go:TestAuthorizationServerConfigurationIsHTTPOnly tests that the authorization-server flag is HTTP-only, suggesting historical OAuth URL injection bugs in similar flags.
Recorded location cmd/github-mcp-server/main_test.go:44
Observation · Architectural coherenceTests for AuthorizationServer configuration are split between main.go and oauth_test.go with different verification strategies: main_test.go verifies HTTP-only constraint while oauth_test.go tests default URL fallback, creating inconsistent testing patterns for the same configuration feature.
Recorded location cmd/github-mcp-server/main_test.go:44