@@ -8,6 +8,62 @@ function tool(name: string, overrides: Partial<Tool> = {}): Tool {
88}
99
1010describe ( "normalizeMcpToolCatalog" , ( ) => {
11+ it . each ( [
12+ [ "IDN hosts" , "https://bücher.example/value" , "https://xn--bcher-kva.example/value" ] ,
13+ [ "relative references" , "child" , "./child" ] ,
14+ [ "local fragments" , "#value" , "#value" ] ,
15+ [ "reserved path escapes" , "a%3Ab" , "a%3Ab" ] ,
16+ ] ) ( "validates tool output schemas with %s" , ( _label , id , ref ) => {
17+ const normalized = normalizeMcpToolCatalog (
18+ [
19+ tool ( "referenced" , {
20+ outputSchema : {
21+ $id : "https://schema.example/root" ,
22+ type : "object" ,
23+ definitions : { value : { $id : id , type : "string" } } ,
24+ properties : { value : { $ref : ref } } ,
25+ required : [ "value" ] ,
26+ } ,
27+ } ) ,
28+ ] ,
29+ createMcpJsonSchemaValidator ( ) ,
30+ ) ;
31+ const validate = normalized . metadata . validatorForCall ( "referenced" ) ! ;
32+
33+ expect ( ( ) => validate ( { content : [ ] , structuredContent : { value : "ok" } } ) ) . not . toThrow ( ) ;
34+ expect ( ( ) => validate ( { content : [ ] , structuredContent : { value : 1 } } ) ) . toThrow (
35+ "Structured content does not match the tool's output schema" ,
36+ ) ;
37+ } ) ;
38+
39+ it ( "keeps nested hostname escapes distinct when resolving tool output schemas" , ( ) => {
40+ const validate = createMcpJsonSchemaValidator ( ) . getValidator ( {
41+ $id : "https://schema.example/root" ,
42+ definitions : {
43+ encoded : { $id : "https://127%252e0%252e0%252e1/value" , const : "encoded" } ,
44+ plain : { $id : "https://127.0.0.1/value" , const : "plain" } ,
45+ } ,
46+ $ref : "https://127%252e0%252e0%252e1/value" ,
47+ } ) ;
48+
49+ expect ( validate ( "encoded" ) . valid ) . toBe ( true ) ;
50+ expect ( validate ( "plain" ) . valid ) . toBe ( false ) ;
51+ } ) ;
52+
53+ it . each ( [
54+ [ "encoded scheme delimiters" , "%2f%2fschema.example:/value" , "URI scheme is malformed" ] ,
55+ [ "invalid IPv6" , "https://[1:2:3::4::5]/value" , "URI host is malformed" ] ,
56+ [ "malformed percent escapes" , "https://schema.example/%ZZ" , "malformed percent-encoding" ] ,
57+ ] ) ( "rejects %s in tool output schema references" , ( _label , ref , error ) => {
58+ expect ( ( ) =>
59+ createMcpJsonSchemaValidator ( ) . getValidator ( {
60+ $id : "https://schema.example/root" ,
61+ definitions : { value : { $id : ref , type : "string" } } ,
62+ $ref : ref ,
63+ } ) ,
64+ ) . toThrow ( error ) ;
65+ } ) ;
66+
1167 it . each ( [
1268 {
1369 label : "trim-equivalent names" ,
0 commit comments