Skip to content

Commit 3a66cf3

Browse files
go.mod: update jsonschema to v0.2.2 (#446)
This version of jsonschema fixes embedded structs. Fixes: #437
1 parent 728e0e3 commit 3a66cf3

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.0
44

55
require (
66
github.com/google/go-cmp v0.7.0
7-
github.com/google/jsonschema-go v0.2.1
7+
github.com/google/jsonschema-go v0.2.2
88
github.com/yosida95/uritemplate/v3 v3.0.2
99
golang.org/x/tools v0.34.0
1010
)

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.1 h1:Z3iINWAUmvS4+m9cMP5lWbn6WlX8Hy4rpUS4pULVliQ=
4-
github.com/google/jsonschema-go v0.2.1/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
3+
github.com/google/jsonschema-go v0.2.2 h1:qb9KM/pATIqIPuE9gEDwPsco8HHCTlA88IGFYHDl03A=
4+
github.com/google/jsonschema-go v0.2.2/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/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=

mcp/mcp_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,3 +1777,63 @@ func TestComplete(t *testing.T) {
17771777
t.Errorf("Complete() mismatch (-want +got):\n%s", diff)
17781778
}
17791779
}
1780+
1781+
// TestEmbeddedStructResponse performs a tool call to verify that a struct with
1782+
// an embedded pointer generates a correct, flattened JSON schema and that its
1783+
// response is validated successfully.
1784+
func TestEmbeddedStructResponse(t *testing.T) {
1785+
type foo struct {
1786+
ID string `json:"id"`
1787+
Name string `json:"name"`
1788+
}
1789+
1790+
// bar embeds foo
1791+
type bar struct {
1792+
*foo // Embedded - should flatten in JSON
1793+
Extra string `json:"extra"`
1794+
}
1795+
1796+
type response struct {
1797+
Data bar `json:"data"`
1798+
}
1799+
1800+
// testTool demonstrates an embedded struct in its response.
1801+
testTool := func(ctx context.Context, req *CallToolRequest, args any) (*CallToolResult, response, error) {
1802+
response := response{
1803+
Data: bar{
1804+
foo: &foo{
1805+
ID: "foo",
1806+
Name: "Test Foo",
1807+
},
1808+
Extra: "additional data",
1809+
},
1810+
}
1811+
return nil, response, nil
1812+
}
1813+
ctx := context.Background()
1814+
clientTransport, serverTransport := NewInMemoryTransports()
1815+
server := NewServer(&Implementation{Name: "testServer", Version: "v1.0.0"}, nil)
1816+
AddTool(server, &Tool{
1817+
Name: "test_embedded_struct",
1818+
}, testTool)
1819+
1820+
serverSession, err := server.Connect(ctx, serverTransport, nil)
1821+
if err != nil {
1822+
t.Fatal(err)
1823+
}
1824+
defer serverSession.Close()
1825+
1826+
client := NewClient(&Implementation{Name: "test-client"}, nil)
1827+
clientSession, err := client.Connect(ctx, clientTransport, nil)
1828+
if err != nil {
1829+
t.Fatal(err)
1830+
}
1831+
defer clientSession.Close()
1832+
1833+
_, err = clientSession.CallTool(ctx, &CallToolParams{
1834+
Name: "test_embedded_struct",
1835+
})
1836+
if err != nil {
1837+
t.Errorf("CallTool() failed: %v", err)
1838+
}
1839+
}

0 commit comments

Comments
 (0)