Skip to content

Commit 203ebb3

Browse files
committed
return auth handler to lib version
1 parent 840b41e commit 203ebb3

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

pkg/http/oauth/oauth.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
package oauth
44

55
import (
6-
"encoding/json"
76
"fmt"
87
"net/http"
98
"strings"
109

1110
"github.com/github/github-mcp-server/pkg/http/headers"
1211
"github.com/go-chi/chi/v5"
12+
"github.com/modelcontextprotocol/go-sdk/auth"
1313
"github.com/modelcontextprotocol/go-sdk/oauthex"
1414
)
1515

@@ -95,34 +95,21 @@ func (h *AuthHandler) RegisterRoutes(r chi.Router) {
9595

9696
func (h *AuthHandler) metadataHandler() http.Handler {
9797
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
98-
// CORS headers for browser-based clients
99-
w.Header().Set("Access-Control-Allow-Origin", "*")
100-
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
101-
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
102-
103-
if r.Method == http.MethodOptions {
104-
w.WriteHeader(http.StatusNoContent)
105-
return
106-
}
107-
if r.Method != http.MethodGet {
108-
w.WriteHeader(http.StatusMethodNotAllowed)
109-
return
110-
}
111-
11298
resourcePath := resolveResourcePath(
11399
strings.TrimPrefix(r.URL.Path, OAuthProtectedResourcePrefix),
114100
h.cfg.ResourcePath,
115101
)
116102
resourceURL := h.buildResourceURL(r, resourcePath)
117103

118-
w.Header().Set("Content-Type", "application/json")
119-
_ = json.NewEncoder(w).Encode(&oauthex.ProtectedResourceMetadata{
104+
metadata := &oauthex.ProtectedResourceMetadata{
120105
Resource: resourceURL,
121106
AuthorizationServers: []string{h.cfg.AuthorizationServer},
122107
ResourceName: "GitHub MCP Server",
123108
ScopesSupported: SupportedScopes,
124109
BearerMethodsSupported: []string{"header"},
125-
})
110+
}
111+
112+
auth.ProtectedResourceMetadataHandler(metadata).ServeHTTP(w, r)
126113
})
127114
}
128115

0 commit comments

Comments
 (0)