diff --git a/pkg/http/handler.go b/pkg/http/handler.go index c45929a20..875d54bbb 100644 --- a/pkg/http/handler.go +++ b/pkg/http/handler.go @@ -40,7 +40,6 @@ type HandlerOptions struct { OAuthConfig *oauth.Config ScopeFetcher scopes.FetcherInterface FeatureChecker inventory.FeatureFlagChecker - SchemaCache *mcp.SchemaCache } type HandlerOption func(*HandlerOptions) @@ -75,14 +74,6 @@ func WithFeatureChecker(checker inventory.FeatureFlagChecker) HandlerOption { } } -// WithSchemaCache sets a shared SchemaCache for the handler. -// This avoids repeated schema reflection when a new MCP Server is created per request. -func WithSchemaCache(cache *mcp.SchemaCache) HandlerOption { - return func(o *HandlerOptions) { - o.SchemaCache = cache - } -} - func NewHTTPMcpHandler( ctx context.Context, cfg *ServerConfig, @@ -111,6 +102,10 @@ func NewHTTPMcpHandler( inventoryFactory = DefaultInventoryFactory(cfg, t, opts.FeatureChecker, scopeFetcher) } + // Create a shared schema cache to avoid repeated JSON schema reflection + // when a new MCP Server is created per request in stateless mode. + schemaCache := mcp.NewSchemaCache() + return &Handler{ ctx: ctx, config: cfg, @@ -122,7 +117,7 @@ func NewHTTPMcpHandler( inventoryFactoryFunc: inventoryFactory, oauthCfg: opts.OAuthConfig, scopeFetcher: scopeFetcher, - schemaCache: opts.SchemaCache, + schemaCache: schemaCache, } } diff --git a/pkg/http/server.go b/pkg/http/server.go index 058edaa3c..7397e54a8 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -21,7 +21,6 @@ import ( "github.com/github/github-mcp-server/pkg/translations" "github.com/github/github-mcp-server/pkg/utils" "github.com/go-chi/chi/v5" - "github.com/modelcontextprotocol/go-sdk/mcp" ) // knownFeatureFlags are the feature flags that can be enabled via X-MCP-Features header. @@ -135,12 +134,8 @@ func RunHTTPServer(cfg ServerConfig) error { serverOptions = append(serverOptions, WithScopeFetcher(scopeFetcher)) } - // Create a shared schema cache to avoid repeated JSON schema reflection - // when a new MCP Server is created per request in stateless mode. - schemaCache := mcp.NewSchemaCache() - r := chi.NewRouter() - handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg), WithSchemaCache(schemaCache))...) + handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg))...) oauthHandler, err := oauth.NewAuthHandler(oauthCfg) if err != nil { return fmt.Errorf("failed to create OAuth handler: %w", err)