Unravel Engine C++ Reference
Loading...
Searching...
No Matches
mcp_tool_registry.cpp
Go to the documentation of this file.
1#include "mcp_tool_registry.h"
2
3#include "mcp_protocol.h"
4
5#include <logging/logging.h>
6
7namespace unravel::mcp
8{
9
11{
12 if(index_.count(tool.name) != 0)
13 {
14 tools_[index_[tool.name]] = std::move(tool);
15 return;
16 }
17 index_[tool.name] = tools_.size();
18 tools_.push_back(std::move(tool));
19}
20
21auto mcp_tool_registry::find(const std::string& name) const -> const mcp_tool*
22{
23 auto it = index_.find(name);
24 if(it == index_.end())
25 {
26 return nullptr;
27 }
28 return &tools_[it->second];
29}
30
31auto mcp_tool_registry::tools() const -> const std::vector<mcp_tool>&
32{
33 return tools_;
34}
35
37{
38 std::string out = "[";
39 for(size_t i = 0; i < tools_.size(); ++i)
40 {
41 const auto& tool = tools_[i];
42 if(i > 0)
43 {
44 out += ",";
45 }
46 out += fmt::format(R"({{"name":{},"description":{},"inputSchema":{}}})",
47 make_json_string(tool.name),
48 make_json_string(tool.description),
49 tool.input_schema_json.empty() ? R"({"type":"object","properties":{}})"
50 : tool.input_schema_json);
51 }
52 out += "]";
53 return out;
54}
55
56} // namespace unravel::mcp
auto find(const std::string &name) const -> const mcp_tool *
auto list_tools_json() const -> std::string
auto tools() const -> const std::vector< mcp_tool > &
std::string name
Definition hub.cpp:33
Hash specialization for batch_key to enable use in std::unordered_map.
auto make_json_string(const std::string &value) -> std::string