@@ -31,6 +31,7 @@ type Handler struct {
3131 inventoryFactoryFunc InventoryFactoryFunc
3232 oauthCfg * oauth.Config
3333 scopeFetcher scopes.FetcherInterface
34+ schemaCache * mcp.SchemaCache
3435}
3536
3637type HandlerOptions struct {
@@ -101,6 +102,10 @@ func NewHTTPMcpHandler(
101102 inventoryFactory = DefaultInventoryFactory (cfg , t , opts .FeatureChecker , scopeFetcher )
102103 }
103104
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+
104109 return & Handler {
105110 ctx : ctx ,
106111 config : cfg ,
@@ -112,6 +117,7 @@ func NewHTTPMcpHandler(
112117 inventoryFactoryFunc : inventoryFactory ,
113118 oauthCfg : opts .OAuthConfig ,
114119 scopeFetcher : scopeFetcher ,
120+ schemaCache : schemaCache ,
115121 }
116122}
117123
@@ -195,6 +201,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
195201 Resources : & mcp.ResourceCapabilities {},
196202 Prompts : & mcp.PromptCapabilities {},
197203 }
204+ so .SchemaCache = h .schemaCache
198205 },
199206 },
200207 })
0 commit comments