Skip to content

Commit 7abbc53

Browse files
committed
switch to chi group
1 parent 3990325 commit 7abbc53

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

pkg/http/handler.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,11 @@ func NewHTTPMcpHandler(
9393
// RegisterRoutes registers the routes for the MCP server
9494
// URL-based values take precedence over header-based values
9595
func (h *Handler) RegisterRoutes(r chi.Router) {
96-
mcpRouter := chi.NewRouter()
97-
mcpRouter.Use(middleware.WithRequestConfig)
98-
99-
mcpRouter.Mount("/", h)
96+
r.Mount("/", h)
10097
// Mount readonly and toolset routes
101-
mcpRouter.With(withToolset).Mount("/x/{toolset}", h)
102-
mcpRouter.With(withReadonly, withToolset).Mount("/x/{toolset}/readonly", h)
103-
mcpRouter.With(withReadonly).Mount("/readonly", h)
104-
105-
r.Mount("/", mcpRouter)
98+
r.With(withToolset).Mount("/x/{toolset}", h)
99+
r.With(withReadonly, withToolset).Mount("/x/{toolset}/readonly", h)
100+
r.With(withReadonly).Mount("/readonly", h)
106101
}
107102

108103
// withReadonly is middleware that sets readonly mode in the request context

pkg/http/handler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
ghcontext "github.com/github/github-mcp-server/pkg/context"
1212
"github.com/github/github-mcp-server/pkg/github"
1313
"github.com/github/github-mcp-server/pkg/http/headers"
14+
"github.com/github/github-mcp-server/pkg/http/middleware"
1415
"github.com/github/github-mcp-server/pkg/inventory"
1516
"github.com/github/github-mcp-server/pkg/translations"
1617
"github.com/go-chi/chi/v5"
@@ -262,6 +263,7 @@ func TestHTTPHandlerRoutes(t *testing.T) {
262263

263264
// Create router and register routes
264265
r := chi.NewRouter()
266+
r.Use(middleware.WithRequestConfig)
265267
handler.RegisterRoutes(r)
266268

267269
// Create request

pkg/http/server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/github/github-mcp-server/pkg/github"
15+
"github.com/github/github-mcp-server/pkg/http/middleware"
1516
"github.com/github/github-mcp-server/pkg/http/oauth"
1617
"github.com/github/github-mcp-server/pkg/lockdown"
1718
"github.com/github/github-mcp-server/pkg/translations"
@@ -113,11 +114,20 @@ func RunHTTPServer(cfg ServerConfig) error {
113114
if err != nil {
114115
return fmt.Errorf("failed to create OAuth handler: %w", err)
115116
}
116-
oauthHandler.RegisterRoutes(r)
117-
logger.Info("OAuth protected resource endpoints registered", "baseURL", cfg.BaseURL)
118117

119118
handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, WithOAuthConfig(oauthCfg))
120-
handler.RegisterRoutes(r)
119+
120+
// MCP routes with middleware
121+
r.Group(func(r chi.Router) {
122+
r.Use(middleware.WithRequestConfig)
123+
handler.RegisterRoutes(r)
124+
})
125+
126+
// OAuth routes without MCP middleware
127+
r.Group(func(r chi.Router) {
128+
oauthHandler.RegisterRoutes(r)
129+
})
130+
logger.Info("OAuth protected resource endpoints registered", "baseURL", cfg.BaseURL)
121131

122132
addr := fmt.Sprintf(":%d", cfg.Port)
123133
httpSvr := http.Server{

0 commit comments

Comments
 (0)