toolloop

NAME

toolloop.raku - one tool namespace over a local toolkit and a remote MCP server

SYNOPSIS

raku -Ilib -It/lib -I../MCP-Server/lib -I../LLM-Chat/lib -I../Template-Jinja2/lib \
     examples/toolloop.raku

DESCRIPTION

An end-to-end run of the thing this distribution exists for: a model asks for tools, some of them run in this process and some of them run inside a server that is a separate operating-system process, and neither the model nor the loop driving it can tell which is which.

Three parts:

  • A local toolkit — an ordinary MCP::Server with two tools and no transport at all. It never serialises anything; the registry calls its bridge methods directly.

  • A remote server — t/lib/fixture-server.raku, spawned as a child process and spoken to over stdio by an MCP::Client. Its tools come from MCP::Client::Test::TestKit.

  • A scripted model — a LLM::Chat::Backend that emits a fixed sequence of tool calls instead of talking to an API, so the run is deterministic and costs nothing.

MCP::Client::Registry puts the first two behind one prefixed namespace and hands the pair of bridge methods to LLM::Chat::ToolLoop.

LLM::Chat is deliberately not a dependency of this distribution — the bridge is a shape (tools-for-llm / execute-tool-calls), not a coupling. That is why this example is run with an explicit -I../LLM-Chat/lib rather than against an installed MCP::Client.

Why a scripted backend

LLM::Chat::Backend::Mock replays canned text: its @.responses are Str, and nothing in it sets tool_calls or a tool_calls finish reason, so it can never drive a tool round. ScriptedBackend below is the smallest backend that can — one step per backend call, each step either a list of tool calls or the final text — and is adapted from the one in LLM-Chat's own t/17-tool-loop.rakutest.

MCP::Client v0.5.0

talk to an MCP server, in either protocol era

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

MCP::Server:ver<0.6.0+>:auth<zef:apogee>JSON::Fast:ver<0.19+>:auth<cpan:TIMOTIMO>Cro::HTTP:ver<0.8.11+>:auth<zef:cro>:api<0>MIME::Base64:ver<1.2.5+>:auth<zef:raku-community-modules>

Test Dependencies

Provides

  • MCP::Client
  • MCP::Client::Cache
  • MCP::Client::Correlator
  • MCP::Client::Exceptions
  • MCP::Client::Leases
  • MCP::Client::Leases::Table
  • MCP::Client::Policy
  • MCP::Client::Policy::Commands
  • MCP::Client::Policy::Floor
  • MCP::Client::Policy::Grants
  • MCP::Client::Policy::Rules
  • MCP::Client::Protocol
  • MCP::Client::Reasons
  • MCP::Client::Registry
  • MCP::Client::SSE
  • MCP::Client::Transport
  • MCP::Client::Transport::HTTP
  • MCP::Client::Transport::Stdio
  • MCP::Client::UnknownKeys

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.