@@ -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