Skip to content

Commit 7f76d2e

Browse files
committed
fix TypeSchemas
1 parent 9744f55 commit 7f76d2e

File tree

8 files changed

+22
-17
lines changed

8 files changed

+22
-17
lines changed

docs/server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ the `Tool.InputSchema` explicitly:
364364

365365
```go
366366
// Distinguished Go types allow custom schemas to be reused during inference.
367-
customSchemas := map[any]*jsonschema.Schema{
368-
Probability(0): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
369-
WeatherType(""): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
367+
customSchemas := map[reflect.Type]*jsonschema.Schema{
368+
reflect.TypeFor[Probability](): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
369+
reflect.TypeFor[WeatherType](): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
370370
}
371371
opts := &jsonschema.ForOptions{TypeSchemas: customSchemas}
372372
in, err := jsonschema.For[WeatherInput](opts)

examples/server/auth-middleware/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
)
99

1010
require (
11-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371 // indirect
11+
github.com/google/jsonschema-go v0.3.0 // indirect
1212
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
1313
)
1414

examples/server/auth-middleware/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeD
22
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
33
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
44
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371 h1:e1VCqWtKpTYBOBhPcgGV5whTlMFpTbH5Ghm56wpxBsk=
6-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
5+
github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q=
6+
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
77
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
88
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
99
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=

examples/server/rate-limiting/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
)
99

1010
require (
11-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371 // indirect
11+
github.com/google/jsonschema-go v0.3.0 // indirect
1212
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
1313
)
1414

examples/server/rate-limiting/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
22
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
3-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371 h1:e1VCqWtKpTYBOBhPcgGV5whTlMFpTbH5Ghm56wpxBsk=
4-
github.com/google/jsonschema-go v0.2.4-0.20250922144851-e08864c65371/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
3+
github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q=
4+
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
55
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
66
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
77
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=

examples/server/toolschemas/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func main() {
136136
// We don't need to do all this work: below, we use jsonschema.For to start
137137
// from the default schema.
138138
manual, err := newManualGreeter()
139+
if err != nil {
140+
log.Fatal(err)
141+
}
139142
server.AddTool(&mcp.Tool{
140143
Name: "manual greeting",
141144
InputSchema: inputSchema,

mcp/streamable_bench_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"net/http"
1010
"net/http/httptest"
11+
"reflect"
1112
"testing"
1213

1314
"github.com/google/jsonschema-go/jsonschema"
@@ -17,9 +18,9 @@ import (
1718
func BenchmarkStreamableServing(b *testing.B) {
1819
// This benchmark measures how fast we can handle a single tool on a
1920
// streamable server, including tool validation and stream management.
20-
customSchemas := map[any]*jsonschema.Schema{
21-
Probability(0): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
22-
WeatherType(""): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
21+
customSchemas := map[reflect.Type]*jsonschema.Schema{
22+
reflect.TypeFor[Probability](): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
23+
reflect.TypeFor[WeatherType](): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
2324
}
2425
opts := &jsonschema.ForOptions{TypeSchemas: customSchemas}
2526
in, err := jsonschema.For[WeatherInput](opts)

mcp/tool_example_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"log"
12+
"reflect"
1213
"time"
1314

1415
"github.com/google/jsonschema-go/jsonschema"
@@ -34,8 +35,8 @@ func ExampleAddTool_customMarshalling() {
3435
// In this case, you can use jsonschema.For along with jsonschema.ForOptions
3536
// to customize the schema inference for your custom type.
3637
inputSchema, err := jsonschema.For[Input](&jsonschema.ForOptions{
37-
TypeSchemas: map[any]*jsonschema.Schema{
38-
MyDate{}: {Type: "string"},
38+
TypeSchemas: map[reflect.Type]*jsonschema.Schema{
39+
reflect.TypeFor[MyDate](): {Type: "string"},
3940
},
4041
})
4142
if err != nil {
@@ -152,9 +153,9 @@ func ExampleAddTool_complexSchema() {
152153
// !+customschemas
153154

154155
// Distinguished Go types allow custom schemas to be reused during inference.
155-
customSchemas := map[any]*jsonschema.Schema{
156-
Probability(0): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
157-
WeatherType(""): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
156+
customSchemas := map[reflect.Type]*jsonschema.Schema{
157+
reflect.TypeFor[Probability](): {Type: "number", Minimum: jsonschema.Ptr(0.0), Maximum: jsonschema.Ptr(1.0)},
158+
reflect.TypeFor[WeatherType](): {Type: "string", Enum: []any{Sunny, PartlyCloudy, Cloudy, Rainy, Snowy}},
158159
}
159160
opts := &jsonschema.ForOptions{TypeSchemas: customSchemas}
160161
in, err := jsonschema.For[WeatherInput](opts)

0 commit comments

Comments
 (0)