Skip to content

Conversation

@SamMorrowDrums
Copy link
Collaborator

Summary

Creates a shared mcp.SchemaCache in RunHTTPServer and passes it through to each per-request MCP Server via ServerOptions.SchemaCache.

Motivation

In streamable-http (stateless) mode, a new mcp.Server is created for every request. Without a shared cache, JSON schema reflection and resolution is repeated on every request for every tool. The go-sdk's SchemaCache (sync.Map-backed, goroutine-safe) caches these schemas across server instances, matching the pattern already used by the remote server.

Changes

  • pkg/http/server.go: Create mcp.NewSchemaCache() once at startup, pass via WithSchemaCache option
  • pkg/http/handler.go: Add SchemaCache field to Handler/HandlerOptions, WithSchemaCache option func, and set so.SchemaCache on per-request ServerOptions

Create a shared mcp.SchemaCache in RunHTTPServer and pass it through
to each per-request MCP Server via ServerOptions. This avoids repeated
JSON schema reflection and resolution when a new Server is created for
every request in stateless mode, matching the pattern used by the
remote server.
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner February 11, 2026 07:33
Copilot AI review requested due to automatic review settings February 11, 2026 07:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves performance in streamable-http (stateless) mode by introducing a shared mcp.SchemaCache that is reused across per-request mcp.Server instances, avoiding repeated JSON schema reflection/resolution work on every request.

Changes:

  • Create a single shared mcp.SchemaCache during HTTP server startup and pass it into the handler via a new option.
  • Extend the HTTP handler options/struct to carry the shared cache and apply it to each per-request mcp.ServerOptions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/http/server.go Instantiates a shared mcp.SchemaCache once and passes it into the HTTP MCP handler.
pkg/http/handler.go Adds handler/option plumbing for SchemaCache and sets it on each per-request mcp.ServerOptions.

Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
- uses: actions/setup-go@v6
with:
go-version: stable
go-version: '1.25'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter requires this

Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
inventoryFactoryFunc: inventoryFactory,
oauthCfg: opts.OAuthConfig,
scopeFetcher: scopeFetcher,
schemaCache: opts.SchemaCache,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there would be any scenario where we don't want a schema cache for HTTP?

I feel like we can drop the WithSchemaCache when initializing (still keeping WithSchemaCache), and init an empty schema cache by default?
I guess the default right now is without a schema cache, but is that a good default? Maybe if you explicitly don't want one being able to pass nil, but that is difficult to manage with the current way that Options work

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good question, I mean I don't think we want to make it optional, because in the end we're in control and we don't want it pluggable, it's our opinionated server after all. I'll spin off copilot to riff on that and see if we like it.

Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
@SamMorrowDrums SamMorrowDrums merged commit bbc675a into main Feb 11, 2026
16 checks passed
@SamMorrowDrums SamMorrowDrums deleted the sammorrowdrums/add-schema-cache-http branch February 11, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants