Skip to content

perf: integrate go-sdk SchemaProvider interface (Phase 2) #1531

@SamMorrowDrums

Description

@SamMorrowDrums

Summary

Integrate the SchemaProvider interface optimization from the go-sdk fork to enable zero-reflection schema generation for performance-critical tools.

Background

Building on Phase 1 (schema caching), this phase adds an opt-in SchemaProvider interface that allows types to provide pre-computed schemas, completely avoiding runtime reflection.

Implementation

1. Update go.mod to use the fork

Add a replace directive to use the optimized fork:

replace github.com/modelcontextprotocol/go-sdk => github.com/SamMorrowDrums/go-sdk v0.0.0-20251204133000-f66cde0xxxxx

Or use the branch reference:

replace github.com/modelcontextprotocol/go-sdk => github.com/SamMorrowDrums/go-sdk perf/phase2-schema-provider

2. Run go mod tidy

go mod tidy

3. (Optional) Implement SchemaProvider for high-traffic tools

For tools that are called frequently, implement the SchemaProvider interface:

import "github.com/google/jsonschema-go/jsonschema"

type SearchRepositoriesInput struct {
    Query string `json:"query"`
    // ...
}

var searchReposSchema = &jsonschema.Schema{
    Type: "object",
    Properties: map[string]*jsonschema.Schema{
        "query": {Type: "string", Description: "Search query"},
    },
    Required: []string{"query"},
}

var searchReposResolved, _ = searchReposSchema.Resolve(nil)

func (SearchRepositoriesInput) MCPSchema() *jsonschema.Schema {
    return searchReposSchema
}

func (SearchRepositoriesInput) MCPResolvedSchema() *jsonschema.Resolved {
    return searchReposResolved
}

4. Verify all tests pass

go test ./...

Expected Impact

  • Without code changes: Automatic benefit from Phase 1 caching
  • With SchemaProvider: Zero reflection overhead for implemented types

Fork Branch

Dependencies

This builds on Phase 1: #1530

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions