88 ghcontext "github.com/github/github-mcp-server/pkg/context"
99 "github.com/github/github-mcp-server/pkg/github"
1010 "github.com/github/github-mcp-server/pkg/http/middleware"
11+ "github.com/github/github-mcp-server/pkg/http/oauth"
1112 "github.com/github/github-mcp-server/pkg/inventory"
1213 "github.com/github/github-mcp-server/pkg/translations"
1314 "github.com/go-chi/chi/v5"
@@ -25,11 +26,13 @@ type Handler struct {
2526 t translations.TranslationHelperFunc
2627 githubMcpServerFactory GitHubMCPServerFactoryFunc
2728 inventoryFactoryFunc InventoryFactoryFunc
29+ oauthCfg * oauth.Config
2830}
2931
3032type HandlerOptions struct {
3133 GitHubMcpServerFactory GitHubMCPServerFactoryFunc
3234 InventoryFactory InventoryFactoryFunc
35+ OAuthConfig * oauth.Config
3336 FeatureChecker inventory.FeatureFlagChecker
3437}
3538
@@ -47,6 +50,12 @@ func WithInventoryFactory(f InventoryFactoryFunc) HandlerOption {
4750 }
4851}
4952
53+ func WithOAuthConfig (cfg * oauth.Config ) HandlerOption {
54+ return func (o * HandlerOptions ) {
55+ o .OAuthConfig = cfg
56+ }
57+ }
58+
5059func WithFeatureChecker (checker inventory.FeatureFlagChecker ) HandlerOption {
5160 return func (o * HandlerOptions ) {
5261 o .FeatureChecker = checker
@@ -83,14 +92,20 @@ func NewHTTPMcpHandler(
8392 t : t ,
8493 githubMcpServerFactory : githubMcpServerFactory ,
8594 inventoryFactoryFunc : inventoryFactory ,
95+ oauthCfg : opts .OAuthConfig ,
8696 }
8797}
8898
99+ func (h * Handler ) RegisterMiddleware (r chi.Router ) {
100+ r .Use (
101+ middleware .ExtractUserToken (h .oauthCfg ),
102+ middleware .WithRequestConfig ,
103+ )
104+ }
105+
89106// RegisterRoutes registers the routes for the MCP server
90107// URL-based values take precedence over header-based values
91108func (h * Handler ) RegisterRoutes (r chi.Router ) {
92- r .Use (middleware .WithRequestConfig )
93-
94109 // Base routes
95110 r .Mount ("/" , h )
96111 r .With (withReadonly ).Mount ("/readonly" , h )
@@ -154,7 +169,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
154169 Stateless : true ,
155170 })
156171
157- middleware . ExtractUserToken ()( mcpHandler ) .ServeHTTP (w , r )
172+ mcpHandler .ServeHTTP (w , r )
158173}
159174
160175func DefaultGitHubMCPServerFactory (r * http.Request , deps github.ToolDependencies , inventory * inventory.Inventory , cfg * github.MCPServerConfig ) (* mcp.Server , error ) {
0 commit comments