-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
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-f66cde0xxxxxOr use the branch reference:
replace github.com/modelcontextprotocol/go-sdk => github.com/SamMorrowDrums/go-sdk perf/phase2-schema-provider2. Run go mod tidy
go mod tidy3. (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
- Repository: https://github.com/SamMorrowDrums/go-sdk
- Branch:
perf/phase2-schema-provider - PR: feat: add SchemaProvider interface for zero-reflection schemas SamMorrowDrums/go-sdk#2
Dependencies
This builds on Phase 1: #1530
Copilot