77#include " fastmcpp/server/server.hpp"
88#include " fastmcpp/tools/manager.hpp"
99#include " fastmcpp/tools/tool.hpp"
10+ #include " interactions_fixture.hpp"
1011
1112#include < cassert>
1213#include < iostream>
@@ -19,116 +20,8 @@ using namespace fastmcpp;
1920// Test Server Fixture - creates a server with multiple tools
2021// ============================================================================
2122
22- std::shared_ptr<server::Server> create_interaction_server ()
23- {
24- auto srv = std::make_shared<server::Server>();
25-
26- // Tool: add - basic arithmetic
27- srv->route (
28- " tools/list" ,
29- [](const Json&)
30- {
31- Json tools = Json::array ();
32-
33- tools.push_back (
34- Json{{" name" , " add" },
35- {" description" , " Add two numbers" },
36- {" inputSchema" , Json{{" type" , " object" },
37- {" properties" , Json{{" x" , {{" type" , " integer" }}},
38- {" y" , {{" type" , " integer" }}}}},
39- {" required" , Json::array ({" x" , " y" })}}}});
40-
41- tools.push_back (
42- Json{{" name" , " greet" },
43- {" description" , " Greet a person" },
44- {" inputSchema" , Json{{" type" , " object" },
45- {" properties" , Json{{" name" , {{" type" , " string" }}}}},
46- {" required" , Json::array ({" name" })}}}});
47-
48- tools.push_back (Json{{" name" , " error_tool" },
49- {" description" , " Always fails" },
50- {" inputSchema" , Json{{" type" , " object" }}}});
51-
52- tools.push_back (Json{{" name" , " list_tool" },
53- {" description" , " Returns a list" },
54- {" inputSchema" , Json{{" type" , " object" }}}});
55-
56- tools.push_back (Json{{" name" , " nested_tool" },
57- {" description" , " Returns nested data" },
58- {" inputSchema" , Json{{" type" , " object" }}}});
59-
60- tools.push_back (Json{
61- {" name" , " optional_params" },
62- {" description" , " Has optional params" },
63- {" inputSchema" ,
64- Json{{" type" , " object" },
65- {" properties" , Json{{" required_param" , {{" type" , " string" }}},
66- {" optional_param" ,
67- {{" type" , " string" }, {" default" , " default_value" }}}}},
68- {" required" , Json::array ({" required_param" })}}}});
69-
70- return Json{{" tools" , tools}};
71- });
23+ // create_interaction_server moved to interactions_fixture.hpp
7224
73- srv->route (
74- " tools/call" ,
75- [](const Json& in)
76- {
77- std::string name = in.at (" name" ).get <std::string>();
78- Json args = in.value (" arguments" , Json::object ());
79-
80- if (name == " add" )
81- {
82- int x = args.at (" x" ).get <int >();
83- int y = args.at (" y" ).get <int >();
84- int result = x + y;
85- return Json{{" content" , Json::array ({Json{{" type" , " text" },
86- {" text" , std::to_string (result)}}})},
87- {" structuredContent" , Json{{" result" , result}}},
88- {" isError" , false }};
89- }
90- if (name == " greet" )
91- {
92- std::string greeting = " Hello, " + args.at (" name" ).get <std::string>() + " !" ;
93- return Json{{" content" , Json::array ({Json{{" type" , " text" }, {" text" , greeting}}})},
94- {" isError" , false }};
95- }
96- if (name == " error_tool" )
97- {
98- return Json{
99- {" content" , Json::array ({Json{{" type" , " text" }, {" text" , " Test error" }}})},
100- {" isError" , true }};
101- }
102- if (name == " list_tool" )
103- {
104- return Json{
105- {" content" , Json::array ({Json{{" type" , " text" }, {" text" , " [\" x\" ,2]" }}})},
106- {" structuredContent" , Json{{" result" , Json::array ({" x" , 2 })}}},
107- {" isError" , false }};
108- }
109- if (name == " nested_tool" )
110- {
111- Json nested = {{" level1" , {{" level2" , {{" value" , 42 }}}}}};
112- return Json{
113- {" content" , Json::array ({Json{{" type" , " text" }, {" text" , nested.dump ()}}})},
114- {" structuredContent" , Json{{" result" , nested}}},
115- {" isError" , false }};
116- }
117- if (name == " optional_params" )
118- {
119- std::string req = args.at (" required_param" ).get <std::string>();
120- std::string opt = args.value (" optional_param" , " default_value" );
121- return Json{
122- {" content" , Json::array ({Json{{" type" , " text" }, {" text" , req + " :" + opt}}})},
123- {" isError" , false }};
124- }
125- return Json{
126- {" content" , Json::array ({Json{{" type" , " text" }, {" text" , " Unknown tool" }}})},
127- {" isError" , true }};
128- });
129-
130- return srv;
131- }
13225
13326// ============================================================================
13427// TestTools - Basic tool operations
0 commit comments