@@ -24,8 +24,8 @@ import (
2424
2525// The baseline uses the public single-tool registration path, which does not
2626// install the tools/list encoder. Both paths select the same inventory first.
27- func schemaListServer (ctx context.Context , inv * inventory.Inventory , optimized bool , pageSize int ) * mcp.Server {
28- server := mcp .NewServer (& mcp.Implementation {Name : "schema-list" }, & mcp.ServerOptions {PageSize : pageSize })
27+ func schemaListServer (ctx context.Context , inv * inventory.Inventory , optimized bool , pageSize int , schemaCache * mcp. SchemaCache ) * mcp.Server {
28+ server := mcp .NewServer (& mcp.Implementation {Name : "schema-list" }, & mcp.ServerOptions {PageSize : pageSize , SchemaCache : schemaCache })
2929 if optimized {
3030 inv .RegisterTools (ctx , server , nil )
3131 } else {
@@ -49,12 +49,12 @@ type schemaListWire struct {
4949 Error json.RawMessage `json:"error"`
5050}
5151
52- func schemaListPages (ctx context.Context , t * testing.T , inv * inventory.Inventory , optimized bool , transport , protocol string , pageSize int ) ([][]byte , []string ) {
52+ func schemaListPages (ctx context.Context , t * testing.T , inv * inventory.Inventory , optimized bool , transport , protocol string , pageSize int , schemaCache * mcp. SchemaCache ) ([][]byte , []string ) {
5353 t .Helper ()
5454 var request func (string ) []byte
5555 switch transport {
5656 case "stdio" :
57- server := schemaListServer (ctx , inv , optimized , pageSize )
57+ server := schemaListServer (ctx , inv , optimized , pageSize , schemaCache )
5858 serverConn , clientConn := net .Pipe ()
5959 ss , err := server .Connect (ctx , & mcp.IOTransport {Reader : serverConn , Writer : serverConn }, nil )
6060 require .NoError (t , err )
@@ -74,8 +74,11 @@ func schemaListPages(ctx context.Context, t *testing.T, inv *inventory.Inventory
7474 require .NoError (t , err )
7575 request = exchange
7676 case "http" :
77+ // Reuse the fixed inventory's server across pages instead of repeating
78+ // SDK annotation validation for every stateless request.
79+ server := schemaListServer (ctx , inv , optimized , pageSize , schemaCache )
7780 handler := mcp .NewStreamableHTTPHandler (func (* http.Request ) * mcp.Server {
78- return schemaListServer ( ctx , inv , optimized , pageSize )
81+ return server
7982 }, & mcp.StreamableHTTPOptions {Stateless : true , JSONResponse : true })
8083 request = func (body string ) []byte {
8184 req := httptest .NewRequest (http .MethodPost , "/" , bytes .NewBufferString (body ))
@@ -122,6 +125,9 @@ func schemaListPages(ctx context.Context, t *testing.T, inv *inventory.Inventory
122125}
123126
124127func TestEncodedSchemasWireParity (t * testing.T ) {
128+ // Share immutable resolved schemas without changing either registration
129+ // path or the wire comparison.
130+ schemaCache := mcp .NewSchemaCache ()
125131 type selection struct {
126132 name string
127133 toolsets []string
@@ -189,8 +195,8 @@ func TestEncodedSchemasWireParity(t *testing.T) {
189195 wantNames = slices .Compact (wantNames )
190196 for _ , transport := range []string {"stdio" , "http" } {
191197 t .Run (transport , func (t * testing.T ) {
192- before , baselineNames := schemaListPages (ctx , t , inv , false , transport , protocol , 7 )
193- after , encodedNames := schemaListPages (ctx , t , inv , true , transport , protocol , 7 )
198+ before , baselineNames := schemaListPages (ctx , t , inv , false , transport , protocol , 7 , schemaCache )
199+ after , encodedNames := schemaListPages (ctx , t , inv , true , transport , protocol , 7 , schemaCache )
194200 assert .Equal (t , before , after , "complete JSON-RPC wire responses, including cursors and errors" )
195201 assert .Equal (t , wantNames , baselineNames )
196202 assert .Equal (t , wantNames , encodedNames )
@@ -228,7 +234,7 @@ func BenchmarkEncodedSchemas(b *testing.B) {
228234 name := map [bool ]string {false : "baseline" , true : "encoded" }[optimized ]
229235 b .Run (name , func (b * testing.B ) {
230236 b .Run ("ListTools" , func (b * testing.B ) {
231- cs := schemaListClient (b , schemaListServer (ctx , inv , optimized , 1000 ))
237+ cs := schemaListClient (b , schemaListServer (ctx , inv , optimized , 1000 , nil ))
232238 result , err := cs .ListTools (ctx , nil )
233239 require .NoError (b , err )
234240 payload , err := json .Marshal (result )
@@ -247,7 +253,7 @@ func BenchmarkEncodedSchemas(b *testing.B) {
247253 b .ReportAllocs ()
248254 for b .Loop () {
249255 st , ct := mcp .NewInMemoryTransports ()
250- server := schemaListServer (ctx , inv , optimized , 1000 )
256+ server := schemaListServer (ctx , inv , optimized , 1000 , nil )
251257 ss , err := server .Connect (ctx , st , nil )
252258 if err != nil {
253259 b .Fatal (err )
0 commit comments