App-MCP-CLI
view release on metacpan or search on metacpan
lib/App/MCP/CLI/Client.pm view on Meta::CPAN
# reply body, if any (some servers answer inline instead of on the stream).
sub _send {
my ($self, $msg) = @_;
my $raw = $self->{json}->encode($msg);
$self->_debug('->', $raw);
if ($self->is_sse) {
die "The SSE connection is closed.\n" if $self->{closed};
my $res = $self->{ua}->post($self->{post_url}, {
headers => { 'content-type' => 'application/json', %{ $self->{headers} } },
content => $raw,
});
unless ($res->{success}) {
my $detail = $res->{status} == 599 ? " - $res->{content}" : '';
$detail =~ s/\s+\z//;
die "MCP HTTP request failed ($res->{status} $res->{reason})$detail\n";
}
return unless length($res->{content} // '');
my $m = eval { $self->{json}->decode($res->{content}) };
lib/App/MCP/CLI/Command/interactive.pm view on Meta::CPAN
my $system_prompt = "You are an AI assistant with access to these local tools:\n"
. $json->encode($tools) . "\n"
. "If the user request requires a tool, respond ONLY with a JSON object like: {\"action\":\"call_tool\",\"tool\":\"tool_name\",\"arguments\":{...}}\n"
. "If no tool is needed, respond with: {\"action\":\"reply\",\"answer\":\"your text answer here\"}\n"
. "Respond with valid raw JSON only, no markdown blocks.";
my $res = $ua->post(
_ollama_url(),
{
headers => { 'content-type' => 'application/json' },
content => $json->encode({
model => $self->{model},
prompt => "$system_prompt\n\nUser Question: $query",
stream => JSON::MaybeXS::false()
})
}
);
if ($res->{success}) {
# Raw text body resides inside the 'content' key
lib/App/MCP/CLI/Command/interactive.pm view on Meta::CPAN
my $ua = HTTP::Tiny->new(timeout => 30);
my $json = JSON::MaybeXS->new(utf8 => 1);
my $prompt = "The user asked: '$query'. The tool returned this raw result data:\n$result\n"
. "Provide a brief, natural language response answering the user's question based on this data.";
my $res = $ua->post(
_ollama_url(),
{
headers => { 'content-type' => 'application/json' },
content => $json->encode({
model => $self->{model},
prompt => $prompt,
stream => JSON::MaybeXS::false()
})
}
);
if ($res->{success}) {
my $body = eval { $json->decode($res->{content}) };
( run in 1.151 second using v1.01-cache-2.11-cpan-99fa8243a42 )