Skip to content

Commit bbc675a

Browse files
Make schema cache an opinionated default for HTTP handlers
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent ed30a1d commit bbc675a

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

pkg/http/handler.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type HandlerOptions struct {
4040
OAuthConfig *oauth.Config
4141
ScopeFetcher scopes.FetcherInterface
4242
FeatureChecker inventory.FeatureFlagChecker
43-
SchemaCache *mcp.SchemaCache
4443
}
4544

4645
type HandlerOption func(*HandlerOptions)
@@ -75,14 +74,6 @@ func WithFeatureChecker(checker inventory.FeatureFlagChecker) HandlerOption {
7574
}
7675
}
7776

78-
// WithSchemaCache sets a shared SchemaCache for the handler.
79-
// This avoids repeated schema reflection when a new MCP Server is created per request.
80-
func WithSchemaCache(cache *mcp.SchemaCache) HandlerOption {
81-
return func(o *HandlerOptions) {
82-
o.SchemaCache = cache
83-
}
84-
}
85-
8677
func NewHTTPMcpHandler(
8778
ctx context.Context,
8879
cfg *ServerConfig,
@@ -111,6 +102,10 @@ func NewHTTPMcpHandler(
111102
inventoryFactory = DefaultInventoryFactory(cfg, t, opts.FeatureChecker, scopeFetcher)
112103
}
113104

105+
// Create a shared schema cache to avoid repeated JSON schema reflection
106+
// when a new MCP Server is created per request in stateless mode.
107+
schemaCache := mcp.NewSchemaCache()
108+
114109
return &Handler{
115110
ctx: ctx,
116111
config: cfg,
@@ -122,7 +117,7 @@ func NewHTTPMcpHandler(
122117
inventoryFactoryFunc: inventoryFactory,
123118
oauthCfg: opts.OAuthConfig,
124119
scopeFetcher: scopeFetcher,
125-
schemaCache: opts.SchemaCache,
120+
schemaCache: schemaCache,
126121
}
127122
}
128123

pkg/http/server.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/github/github-mcp-server/pkg/translations"
2222
"github.com/github/github-mcp-server/pkg/utils"
2323
"github.com/go-chi/chi/v5"
24-
"github.com/modelcontextprotocol/go-sdk/mcp"
2524
)
2625

2726
// knownFeatureFlags are the feature flags that can be enabled via X-MCP-Features header.
@@ -135,12 +134,8 @@ func RunHTTPServer(cfg ServerConfig) error {
135134
serverOptions = append(serverOptions, WithScopeFetcher(scopeFetcher))
136135
}
137136

138-
// Create a shared schema cache to avoid repeated JSON schema reflection
139-
// when a new MCP Server is created per request in stateless mode.
140-
schemaCache := mcp.NewSchemaCache()
141-
142137
r := chi.NewRouter()
143-
handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg), WithSchemaCache(schemaCache))...)
138+
handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg))...)
144139
oauthHandler, err := oauth.NewAuthHandler(oauthCfg)
145140
if err != nil {
146141
return fmt.Errorf("failed to create OAuth handler: %w", err)

0 commit comments

Comments
 (0)