@@ -193,6 +193,71 @@ test("Effect tool schemas resolve escaped definition names", () => {
193193 expect ( JSON . stringify ( definition ( tool ) . inputSchema ) ) . not . toContain ( "$defs" )
194194} )
195195
196+ test ( "repeat steps reuse converted schemas instead of rebuilding them" , ( ) => {
197+ const builds : Array < string > = [ ]
198+ const portable = {
199+ "~standard" : {
200+ version : 1 ,
201+ vendor : "test" ,
202+ validate : ( value : unknown ) => ( { value } ) ,
203+ jsonSchema : {
204+ input : ( ) => {
205+ builds . push ( "input" )
206+ return { type : "object" }
207+ } ,
208+ output : ( ) => {
209+ builds . push ( "output" )
210+ return { type : "string" }
211+ } ,
212+ } ,
213+ } ,
214+ }
215+ const effect : Info = {
216+ name : "effect" ,
217+ description : "Effect tool" ,
218+ input : Schema . Struct ( { value : Schema . String } ) ,
219+ output : Schema . Struct ( { ok : Schema . Boolean } ) ,
220+ execute : ( ) => Effect . succeed ( { output : { ok : true } } ) ,
221+ }
222+ const step = ( ) => [
223+ // Snapshots recreate some tools, such as CodeMode's, around the same schemas each step.
224+ definition ( { ...effect } ) ,
225+ definition ( { ...effect , name : "portable" , input : portable , output : portable } ) ,
226+ ]
227+
228+ const first = step ( )
229+ const before = builds . length
230+ const second = step ( )
231+
232+ expect ( builds . length ) . toBe ( before )
233+ second . forEach ( ( item , index ) => {
234+ expect ( item . inputSchema ) . toBe ( first [ index ] . inputSchema )
235+ expect ( item . outputSchema ) . toBe ( first [ index ] . outputSchema )
236+ } )
237+ } )
238+
239+ test ( "cached definitions serialize byte-identically to freshly built ones" , ( ) => {
240+ const Item = Schema . Struct ( { id : Schema . String } ) . annotate ( { identifier : "Item" } )
241+ const tool : Info = {
242+ name : "pinned.tool" ,
243+ description : "Pinned" ,
244+ options : { namespace : "mcp.server" } ,
245+ input : Schema . Struct ( {
246+ offset : Schema . optionalKey ( Schema . Int . check ( Schema . isGreaterThanOrEqualTo ( 0 ) ) ) ,
247+ items : Schema . Array ( Item ) ,
248+ } ) ,
249+ output : Schema . Struct ( { } ) . annotate ( { description : "Nothing" } ) ,
250+ execute : ( ) => Effect . succeed ( { content : "unused" } ) ,
251+ }
252+ // Serialized by the uncached implementation; key order matters for provider prompt caches.
253+ const expected =
254+ '{"type":"tool","name":"mcp_server_pinned_tool","description":"Pinned","inputSchema":{"type":"object","properties":{"offset":{"type":"integer","minimum":0},"items":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"],"additionalProperties":false}}},"required":["items"],"additionalProperties":false},"outputSchema":{"not":{"type":"null"},"description":"Nothing"}}'
255+
256+ expect ( JSON . stringify ( definition ( tool ) ) ) . toBe ( expected )
257+ expect ( JSON . stringify ( definition ( tool ) ) ) . toBe ( expected )
258+ expect ( JSON . stringify ( definition ( { ...tool } ) ) ) . toBe ( expected )
259+ } )
260+
196261test . each ( [ "Lookup Input" , "café" , "A/B~C% D#E" ] ) (
197262 "Effect tool schemas inline URI-encoded definition %s" ,
198263 ( identifier ) => {
0 commit comments