@@ -2,7 +2,6 @@ package http
22
33import  (
44	"context" 
5- 	"encoding/json" 
65	"errors" 
76	"net/http" 
87	"os" 
@@ -19,11 +18,10 @@ import (
1918)
2019
2120const  (
22- 	oauthProtectedResourceEndpoint  =  "/.well-known/oauth-protected-resource" 
23- 	healthEndpoint                  =  "/healthz" 
24- 	mcpEndpoint                     =  "/mcp" 
25- 	sseEndpoint                     =  "/sse" 
26- 	sseMessageEndpoint              =  "/message" 
21+ 	healthEndpoint      =  "/healthz" 
22+ 	mcpEndpoint         =  "/mcp" 
23+ 	sseEndpoint         =  "/sse" 
24+ 	sseMessageEndpoint  =  "/message" 
2725)
2826
2927func  Serve (ctx  context.Context , mcpServer  * mcp.Server , staticConfig  * config.StaticConfig , oidcProvider  * oidc.Provider ) error  {
@@ -46,39 +44,7 @@ func Serve(ctx context.Context, mcpServer *mcp.Server, staticConfig *config.Stat
4644	mux .HandleFunc (healthEndpoint , func (w  http.ResponseWriter , r  * http.Request ) {
4745		w .WriteHeader (http .StatusOK )
4846	})
49- 	mux .HandleFunc (oauthProtectedResourceEndpoint , func (w  http.ResponseWriter , r  * http.Request ) {
50- 		w .Header ().Set ("Content-Type" , "application/json" )
51- 
52- 		var  authServers  []string 
53- 		if  staticConfig .AuthorizationURL  !=  ""  {
54- 			authServers  =  []string {staticConfig .AuthorizationURL }
55- 		} else  {
56- 			// Fallback to Kubernetes API server host if authorization_server is not configured 
57- 			if  apiServerHost  :=  mcpServer .GetKubernetesAPIServerHost (); apiServerHost  !=  ""  {
58- 				authServers  =  []string {apiServerHost }
59- 			}
60- 		}
61- 
62- 		response  :=  map [string ]interface {}{
63- 			"authorization_servers" :    authServers ,
64- 			"authorization_server" :     authServers [0 ],
65- 			"scopes_supported" :         mcpServer .GetEnabledTools (),
66- 			"bearer_methods_supported" : []string {"header" },
67- 		}
68- 
69- 		if  staticConfig .ServerURL  !=  ""  {
70- 			response ["resource" ] =  staticConfig .ServerURL 
71- 		}
72- 
73- 		if  staticConfig .JwksURL  !=  ""  {
74- 			response ["jwks_uri" ] =  staticConfig .JwksURL 
75- 		}
76- 
77- 		w .WriteHeader (http .StatusOK )
78- 		if  err  :=  json .NewEncoder (w ).Encode (response ); err  !=  nil  {
79- 			http .Error (w , err .Error (), http .StatusInternalServerError )
80- 		}
81- 	})
47+ 	mux .HandleFunc (oauthProtectedResourceEndpoint , OAuthProtectedResourceHandler (mcpServer , staticConfig ))
8248
8349	ctx , cancel  :=  context .WithCancel (ctx )
8450	defer  cancel ()
0 commit comments