@@ -69,5 +69,74 @@ int main()
6969 {" params" , Json{{" name" , " any" }}}};
7070 auto prompt_get_resp = handler (prompt_get);
7171 assert (prompt_get_resp[" result" ][" messages" ].is_array ());
72+
73+ // ---- Tool version metadata in tools/list ----
74+ {
75+ tools::ToolManager tm2;
76+ Json schema = {{" type" , " object" }, {" properties" , Json::object ()}};
77+ tools::Tool versioned{" versioned" , schema, Json (),
78+ [](const Json&) { return 42 ; }};
79+ versioned.set_version (" 2.0.0" );
80+ tm2.register_tool (versioned);
81+ tools::Tool plain{" plain" , schema, Json (),
82+ [](const Json&) { return 1 ; }};
83+ tm2.register_tool (plain);
84+
85+ auto handler2 = mcp::make_mcp_handler (" ver_test" , " 1.0.0" , tm2);
86+ auto list2 =
87+ handler2 (Json{{" jsonrpc" , " 2.0" }, {" id" , 10 }, {" method" , " tools/list" }});
88+ bool checked_versioned = false , checked_plain = false ;
89+ for (const auto & t : list2[" result" ][" tools" ])
90+ {
91+ if (t[" name" ] == " versioned" )
92+ {
93+ assert (t.contains (" version" ));
94+ assert (t[" version" ] == " 2.0.0" );
95+ checked_versioned = true ;
96+ }
97+ if (t[" name" ] == " plain" )
98+ {
99+ assert (!t.contains (" version" ));
100+ checked_plain = true ;
101+ }
102+ }
103+ assert (checked_versioned);
104+ assert (checked_plain);
105+ }
106+
107+ // ---- Output schema: null vs non-null distinction ----
108+ {
109+ tools::ToolManager tm3;
110+ Json schema = {{" type" , " object" }, {" properties" , Json::object ()}};
111+ // Json() = null → no outputSchema emitted
112+ tools::Tool no_schema{" no_schema" , schema, Json (),
113+ [](const Json&) { return 1 ; }};
114+ // Json{{"type","object"}} → outputSchema present
115+ tools::Tool with_schema{" with_schema" , schema, Json{{" type" , " object" }},
116+ [](const Json&) { return 1 ; }};
117+ tm3.register_tool (no_schema);
118+ tm3.register_tool (with_schema);
119+
120+ auto handler3 = mcp::make_mcp_handler (" schema_test" , " 1.0.0" , tm3);
121+ auto list3 =
122+ handler3 (Json{{" jsonrpc" , " 2.0" }, {" id" , 20 }, {" method" , " tools/list" }});
123+ bool checked_no = false , checked_with = false ;
124+ for (const auto & t : list3[" result" ][" tools" ])
125+ {
126+ if (t[" name" ] == " no_schema" )
127+ {
128+ assert (!t.contains (" outputSchema" ));
129+ checked_no = true ;
130+ }
131+ if (t[" name" ] == " with_schema" )
132+ {
133+ assert (t.contains (" outputSchema" ));
134+ checked_with = true ;
135+ }
136+ }
137+ assert (checked_no);
138+ assert (checked_with);
139+ }
140+
72141 return 0 ;
73142}
0 commit comments