-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
Summary
Integrate the mcpgen code generator from the go-sdk fork to generate zero-reflection schema implementations for all tool input types.
Background
Building on Phase 1 (schema caching) and Phase 2 (SchemaProvider interface), this phase uses the mcpgen code generator to automatically generate SchemaProvider implementations, achieving zero 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-20251204142831-b450c9exxxxxOr use the branch reference:
replace github.com/modelcontextprotocol/go-sdk => github.com/SamMorrowDrums/go-sdk perf/phase3-mcpgen2. Install mcpgen
go install github.com/SamMorrowDrums/go-sdk/cmd/mcpgen@perf/phase3-mcpgen3. Add go:generate directives to tool input types
For each package with tool input structs, add generate directives:
// pkg/github/search.go
//go:generate mcpgen -type=SearchRepositoriesInput,SearchCodeInput,SearchUsersInput4. Run go generate
go generate ./...This creates *_mcp_gen.go files with SchemaProvider implementations.
5. Verify all tests pass
go test ./...Example Generated Code
For a type like:
type CreateIssueInput struct {
Title string `json:"title" jsonschema:"required,description=Issue title"`
Body string `json:"body"`
}mcpgen generates:
// Code generated by mcpgen. DO NOT EDIT.
var _createissueinputSchema = &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"title": {Type: "string", Description: "Issue title"},
"body": {Type: "string"},
},
Required: []string{"title"},
}
var _createissueinputResolved, _ = _createissueinputSchema.Resolve(nil)
func (CreateIssueInput) MCPSchema() *jsonschema.Schema {
return _createissueinputSchema
}
func (CreateIssueInput) MCPResolvedSchema() *jsonschema.Resolved {
return _createissueinputResolved
}Expected Impact
- Zero runtime reflection for schema generation
- Pre-resolved schemas skip resolution step
- Compile-time validation of schema correctness
Fork Branch
- Repository: https://github.com/SamMorrowDrums/go-sdk
- Branch:
perf/phase3-mcpgen - PR: feat: add mcpgen code generator for zero-reflection schemas SamMorrowDrums/go-sdk#3
Dependencies
This builds on:
Copilot