Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions pkg/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type HandlerOptions struct {
OAuthConfig *oauth.Config
ScopeFetcher scopes.FetcherInterface
FeatureChecker inventory.FeatureFlagChecker
SchemaCache *mcp.SchemaCache
}

type HandlerOption func(*HandlerOptions)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -122,7 +117,7 @@ func NewHTTPMcpHandler(
inventoryFactoryFunc: inventoryFactory,
oauthCfg: opts.OAuthConfig,
scopeFetcher: scopeFetcher,
schemaCache: opts.SchemaCache,
schemaCache: schemaCache,
}
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading