MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / setup

Method setup

tools/server/server-tools.cpp:712–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

710}
711
712void server_tools::setup(const std::vector<std::string> & enabled_tools) {
713 if (!enabled_tools.empty()) {
714 std::unordered_set<std::string> enabled_set(enabled_tools.begin(), enabled_tools.end());
715 auto all_tools = build_tools();
716
717 tools.clear();
718 for (auto & t : all_tools) {
719 if (enabled_set.count(t->name) > 0 || enabled_set.count("all") > 0) {
720 tools.push_back(std::move(t));
721 }
722 }
723 }
724
725 handle_get = [this](const server_http_req &) -> server_http_res_ptr {
726 auto res = std::make_unique<server_http_res>();
727 try {
728 json result = json::array();
729 for (const auto & t : tools) {
730 result.push_back(t->to_json());
731 }
732 res->data = safe_json_to_str(result);
733 } catch (const std::exception & e) {
734 SRV_ERR("got exception: %s\n", e.what());
735 res->status = 500;
736 res->data = safe_json_to_str(format_error_response(e.what(), ERROR_TYPE_SERVER));
737 }
738 return res;
739 };
740
741 handle_post = [this](const server_http_req & req) -> server_http_res_ptr {
742 auto res = std::make_unique<server_http_res>();
743 try {
744 json body = json::parse(req.body);
745 std::string tool_name = body.at("tool").get<std::string>();
746 json params = body.value("params", json::object());
747 json result = invoke(tool_name, params);
748 res->data = safe_json_to_str(result);
749 } catch (const json::exception & e) {
750 res->status = 400;
751 res->data = safe_json_to_str(format_error_response(e.what(), ERROR_TYPE_INVALID_REQUEST));
752 } catch (const std::exception & e) {
753 SRV_ERR("got exception: %s\n", e.what());
754 res->status = 500;
755 res->data = safe_json_to_str(format_error_response(e.what(), ERROR_TYPE_SERVER));
756 }
757 return res;
758 };
759}
760
761json server_tools::invoke(const std::string & name, const json & params) {
762 for (auto & t : tools) {

Callers 1

mainFunction · 0.80

Calls 11

build_toolsFunction · 0.85
safe_json_to_strFunction · 0.85
format_error_responseFunction · 0.85
endMethod · 0.80
countMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
to_jsonMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected