Skip to content

Commit 80e6790

Browse files
committed
Only include SSE transport when LLAMA_CURL is set
1 parent 376fbba commit 80e6790

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

common/toolcall/handler.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
#include "handler.hpp"
3-
#include "mcp_sse_transport.hpp"
3+
4+
#ifdef LLAMA_USE_CURL
5+
# include "mcp_sse_transport.hpp"
6+
#endif
7+
48
#include "mcp_stdio_transport.hpp"
59

610
using json = toolcall::json;
@@ -22,11 +26,12 @@ std::shared_ptr<toolcall::handler> toolcall::create_handler(const toolcall::para
2226
auto choice = params.choice();
2327
bool has_uri = std::holds_alternative<std::string>(tools);
2428
if (has_uri) {
29+
#ifdef LLAMA_USE_CURL
2530
auto tools_str = std::get<std::string>(tools);
2631
if (! tools_str.empty()) {
2732
result.reset(new toolcall::handler(std::make_unique<toolcall::mcp_impl>(tools_str, choice)));
2833
}
29-
34+
#endif
3035
} else {
3136
auto tools_ptr = std::get<toolcall::json_ptr>(tools);
3237
if (tools_ptr != nullptr) {
@@ -39,14 +44,24 @@ std::shared_ptr<toolcall::handler> toolcall::create_handler(const toolcall::para
3944

4045
void toolcall::params::tools(std::string tools) {
4146
try {
42-
if (tools.empty() || starts_with(tools, "mcp+http")) {
47+
48+
if (tools.empty()) {
4349
tools_ = std::move(tools);
4450

51+
} else if (starts_with(tools, "mcp+http")) {
52+
#ifdef LLAMA_USE_CURL
53+
tools_ = std::move(tools);
54+
#else
55+
throw std::invalid_argument(
56+
"Model Context Protocol (MCP) only works when llama.cpp is compiled with libcurl");
57+
#endif
4558
} else {
4659
tools_ = std::make_shared<json>(json::parse(tools));
4760
auto tools_ptr = std::get<std::shared_ptr<json>>(tools_);
4861
if (! tools_ptr->is_array()) {
49-
throw std::invalid_argument("tools must be a valid JSON array");
62+
throw std::invalid_argument(
63+
"tools must be a URL of the form \"mcp+http(s)://hostname[:port]/\""
64+
", or a valid JSON array containing tool definitions");
5065
}
5166
}
5267

@@ -99,12 +114,19 @@ toolcall::action toolcall::handler::last_action() const {
99114
return last_action_;
100115
}
101116

117+
#ifdef LLAMA_USE_CURL
102118
toolcall::mcp_impl::mcp_impl(std::string server_uri, tool_choice_t tool_choice)
103119
: handler_impl(tool_choice),
104120
transport_(new mcp_sse_transport(server_uri))
105121
{
106122
transport_->start();
107123
}
124+
#else
125+
toolcall::mcp_impl::mcp_impl(std::string /*server_uri*/, tool_choice_t tool_choice)
126+
: handler_impl(tool_choice)
127+
{
128+
}
129+
#endif
108130

109131
toolcall::mcp_impl::mcp_impl(std::vector<std::string> argv, tool_choice_t tool_choice)
110132
: handler_impl(tool_choice),

0 commit comments

Comments
 (0)