NAME

MCP::Tool - Tool container

SYNOPSIS

use MCP::Tool;

my $tool = MCP::Tool->new;

DESCRIPTION

MCP::Tool is a container for tools to be called.

ATTRIBUTES

MCP::Tool implements the following attributes.

code

my $code = $tool->code;
$tool    = $tool->code(sub { ... });

Tool code.

description

my $description = $tool->description;
$tool           = $tool->description('A brief description of the tool');

Description of the tool.

input_schema

my $schema = $tool->input_schema;
$tool      = $tool->input_schema({type => 'object', properties => {foo => {type => 'string'}}});

JSON schema for validating input arguments.

name

my $name = $tool->name;
$tool    = $tool->name('my_tool');

Name of the tool.

METHODS

MCP::Tool inherits all methods from Mojo::Base and implements the following new ones.

call

my $result = $tool->call($args, $context);

Calls the tool with the given arguments and context, returning a result. The result can be a promise or a direct value.

context

my $context = $tool->context;

Returns the context in which the tool is executed.

# Get controller for requests using the HTTP transport
my $c = $tool->context->{controller};

image_result

my $result = $tool->image_result($bytes, $options, $is_error);

Returns an image result in the expected format, optionally marking it as an error.

hese options are currently available:

annotations
annotations => {audience => ['user']}

Annotations for the image.

mime_type
mime_type => 'image/png'

Specifies the MIME type of the image, defaults to 'image/png'.

text_result

my $result = $tool->text_result('Some text', $is_error);

Returns a text result in the expected format, optionally marking it as an error.

validate_input

my $bool = $tool->validate_input($args);

Validates the input arguments against the tool's input schema. Returns true if validation failed.

SEE ALSO

MCP, https://mojolicious.org, https://modelcontextprotocol.io.