|
1 | 1 |
|
2 | 2 | #include <json.hpp> |
3 | 3 | #include "handler.hpp" |
4 | | -#include "params.hpp" |
5 | 4 |
|
6 | 5 | #ifdef LLAMA_USE_CURL |
7 | 6 | # include "mcp_sse_transport.hpp" |
8 | 7 | #endif |
9 | 8 |
|
10 | 9 | #include "mcp_stdio_transport.hpp" |
11 | 10 |
|
12 | | -using json = toolcall::json; |
| 11 | +using json = nlohmann::json; |
13 | 12 |
|
14 | 13 | std::shared_ptr<toolcall::handler> toolcall::create_handler(const toolcall::params & params) { |
15 | | - std::shared_ptr<toolcall::handler> result; |
| 14 | + std::shared_ptr<toolcall::handler> handler; |
16 | 15 |
|
17 | 16 | auto tools = params.tools(); |
18 | 17 | auto choice = params.choice(); |
19 | | - bool has_uri = std::holds_alternative<std::string>(tools); |
20 | | - if (has_uri) { |
| 18 | + if (params.has_uri()) { |
21 | 19 | #ifdef LLAMA_USE_CURL |
22 | | - auto tools_str = std::get<std::string>(tools); |
23 | | - if (! tools_str.empty()) { |
24 | | - result.reset(new toolcall::handler(std::make_unique<toolcall::mcp_impl>(tools_str, choice))); |
25 | | - } |
| 20 | + handler.reset(new toolcall::handler(std::make_unique<toolcall::mcp_impl>(tools, choice))); |
26 | 21 | #endif |
27 | 22 | } else { |
28 | | - auto tools_ptr = std::get<toolcall::json_ptr>(tools); |
29 | | - if (tools_ptr != nullptr) { |
30 | | - result.reset(new toolcall::handler(std::make_unique<toolcall::loopback_impl>(*tools_ptr, choice))); |
31 | | - } |
| 23 | + handler.reset(new toolcall::handler(std::make_unique<toolcall::loopback_impl>(tools, choice))); |
32 | 24 | } |
33 | 25 |
|
34 | | - return result; |
| 26 | + return handler; |
35 | 27 | } |
36 | 28 |
|
37 | | -json toolcall::handler::tool_list() { |
| 29 | +std::string toolcall::handler::tool_list() { |
38 | 30 | return impl_->tool_list(); |
39 | 31 | } |
40 | 32 |
|
41 | | -toolcall::action toolcall::handler::call(const json & request, json & response) { |
| 33 | +toolcall::action toolcall::handler::call(const std::string & request, std::string & response) { |
42 | 34 | last_action_ = impl_->call(request, response); |
43 | 35 | return last_action_; |
44 | 36 | } |
45 | 37 |
|
46 | | -const toolcall::tool_choice_t & toolcall::handler::tool_choice() const { |
| 38 | +const std::string & toolcall::handler::tool_choice() const { |
47 | 39 | return impl_->tool_choice(); |
48 | 40 | } |
49 | 41 | toolcall::action toolcall::handler::last_action() const { |
50 | 42 | return last_action_; |
51 | 43 | } |
52 | 44 |
|
53 | 45 | #ifdef LLAMA_USE_CURL |
54 | | -toolcall::mcp_impl::mcp_impl(std::string server_uri, tool_choice_t tool_choice) |
| 46 | +toolcall::mcp_impl::mcp_impl(std::string server_uri, std::string tool_choice) |
55 | 47 | : handler_impl(tool_choice), |
56 | 48 | transport_(new mcp_sse_transport(server_uri)) |
57 | 49 | { |
58 | 50 | transport_->start(); |
59 | 51 | } |
60 | 52 | #else |
61 | | -toolcall::mcp_impl::mcp_impl(std::string /*server_uri*/, tool_choice_t tool_choice) |
| 53 | +toolcall::mcp_impl::mcp_impl(std::string /*server_uri*/, std::string tool_choice) |
62 | 54 | : handler_impl(tool_choice) |
63 | 55 | { |
64 | 56 | } |
65 | 57 | #endif |
66 | 58 |
|
67 | | -toolcall::mcp_impl::mcp_impl(std::vector<std::string> argv, tool_choice_t tool_choice) |
| 59 | +toolcall::mcp_impl::mcp_impl(std::vector<std::string> argv, std::string tool_choice) |
68 | 60 | : handler_impl(tool_choice), |
69 | 61 | transport_(new mcp_stdio_transport(argv)) |
70 | 62 | { |
71 | 63 | transport_->start(); |
72 | 64 | } |
73 | 65 |
|
74 | | -json toolcall::mcp_impl::tool_list() { |
| 66 | +std::string toolcall::mcp_impl::tool_list() { |
75 | 67 | // Construct tools/list call and send to transport |
76 | 68 | return json{};// TODO |
77 | 69 | } |
78 | 70 |
|
79 | | -toolcall::action toolcall::mcp_impl::call(const json & /*request*/, json & /*response*/) { |
| 71 | +toolcall::action toolcall::mcp_impl::call(const std::string & /*request*/, std::string & /*response*/) { |
80 | 72 | // Construct tool call and send to transport |
81 | 73 | return toolcall::ACCEPT; // TODO |
82 | 74 | } |
0 commit comments