Batch

  • id — the model's tool_call_id for this slot. Used only to re-stamp a de-duplicated answer, which is what keeps every result filed under the id of the call it answers.

  • concurrent — whether this call may run beside its neighbours. One False makes the whole batch serial.

  • key — the de-duplication identity from #sub argument-identity, or an undefined Str for a slot that must always run on its own.

  • work — the thunk that produces the answer. Called exactly once per distinct key in a concurrent batch, once per slot in a serial one, and on whatever thread the scheduler picked.

NAME

MCP::Server::Batch - how a batch of LLM tool calls is executed

DESCRIPTION

The scheduler behind MCP::Server.execute-tool-calls and MCP::Client.execute-tool-calls. It is shared so that the two bridges cannot drift: a toolkit plugged into a local server and the same toolkit reached over MCP have to answer a batch the same way, in the same order, with the same number of executions.

The contract

  • Results come back one per slot, in the caller's order, always. Order is never a consequence of how fast a tool answered.

  • A batch runs serially unless every call in it is annotated readOnlyHint and idempotentHint (concurrency-safe). One unannotated call — a write, a shell command, a question for the user — and the whole batch keeps the one-at-a-time ordering it has always had.

  • An eligible batch runs its distinct calls on at most :$concurrency workers, and identical calls execute once, the answer copied into every slot that asked for it with that slot's own tool_call_id.

  • Nothing is lazy. Every thunk has run by the time this returns.

EXAMPLES

use MCP::Server::Batch;

my @slots = @calls.map(-> %call {
    my %arguments = %call<arguments>;
    %(
        id         => %call<id>,
        concurrent => concurrency-safe(%annotations{%call<name>}),
        key        => argument-identity(%call<name>, %arguments),
        work       => -> { run-the-tool(%call<name>, %arguments) },
    );
});

my @results = run-tool-batch(@slots, concurrency => 4);

SEE ALSO

MCP::Server (the local bridge), MCP::Client (the remote one).

MCP::Server v0.7.0

MCP (Model Context Protocol) server framework for Raku

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

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::Server
  • MCP::Server::Batch
  • MCP::Server::CLI
  • MCP::Server::Context
  • MCP::Server::DSL
  • MCP::Server::Elicitation
  • MCP::Server::HTTP
  • MCP::Server::HTTP::Validation
  • MCP::Server::Prompt
  • MCP::Server::Protocol
  • MCP::Server::Resource
  • MCP::Server::Tool
  • MCP::Server::Tool::StrictKit
  • MCP::Server::Tool::TestKit
  • MCP::Server::Toolkit
  • MCP::Server::Transport
  • MCP::Server::Transport::Stdio
  • Metamodel::McpHOW

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.