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.