Tool

NAME

MCP::Server::Tool - Tool registration helpers

DESCRIPTION

Provides a builder-style DSL and wrapper class for registering MCP tools.

FUNCTIONS

sub tool(--> ToolBuilder)

Create a new tool builder. Chain methods to define the tool, then call .build to produce a RegisteredTool.

my $t = tool()
        .name('add')
        .description('Add two numbers')
        .number-param('a', description => 'First', :required)
        .number-param('b', description => 'Second', :required)
        .handler(-> :%params { %params<a> + %params<b> })
        .build;

sub validate-tool-name(Str $name)

Validate that a tool name matches the MCP spec pattern: ^[a-zA-Z0-9_-]{1,64}$. Dies on invalid names.

CLASSES

ToolBuilder

Fluent builder for tool definitions. Available chain methods:

  • .name(Str) — Tool name (required).

  • .description(Str) — Human-readable description.

  • .input-schema(%schema) — Raw JSON Schema for input.

  • .output-schema(%schema) — JSON Schema for structured output.

  • .string-param(Str, :$description, :$required, :$enum) — Add a string parameter.

  • .number-param(Str, :$description, :$required) — Add a number parameter.

  • .integer-param(Str, :$description, :$required) — Add an integer parameter.

  • .boolean-param(Str, :$description, :$required) — Add a boolean parameter.

  • .array-param(Str, :$description, :$required, :%items) — Add an array parameter.

  • .object-param(Str, :$description, :$required, :%properties) — Add an object parameter.

  • .annotations(...) — Set tool annotations (title, readOnly, destructive, etc.).

  • .handler(&callable) — The handler block (required).

  • .build(-- RegisteredTool)> — Finalize the tool.

RegisteredTool

Wrapper holding a Tool definition and its handler.

  • .to-tool(-- Tool)> — Get the tool definition for listing.

  • .call(%arguments -- CallToolResult)> — Call the handler with arguments.

MCP v0.33.6

Model Context Protocol SDK for Raku - Build MCP servers and clients

Authors

  • Waclaw Kusnierczyk

License

MIT

Dependencies

JSON::FastCro::HTTPMIME::Base64

Provides

  • MCP
  • MCP::Client
  • MCP::JSONRPC
  • MCP::OAuth
  • MCP::OAuth::Client
  • MCP::OAuth::Server
  • MCP::Server
  • MCP::Server::Prompt
  • MCP::Server::Resource
  • MCP::Server::Tool
  • MCP::Transport::Base
  • MCP::Transport::SSE
  • MCP::Transport::Stdio
  • MCP::Transport::StreamableHTTP
  • MCP::Types

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.