MCP::Tool(3pm)

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.

  annotations
  my $annotations = $tool->annotations;
  $tool           = $tool->annotations({title => '...'});

Optional annotations for the tool which provide additional metadata about the tool behavior.

  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.

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

JSON schema for validating output results.

METHODS
MCP::Tool inherits all methods from MCP::Primitive and implements the following new ones.

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

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

These options are currently available:

mime_type
      mime_type => 'audio/wav'

    Specifies the MIME type of the audio, defaults to "audio/wav".

  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.

  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.

These 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".

  resource_link_result
  my $result = $tool->resource_link_result($uri, $options, $is_error);

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

These options are currently available:

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

    Annotations for the resource link.

description
      description => 'A brief description of the resource'

    Description of the resource.

mime_type
      mime_type => 'text/x-perl'

    Specifies the MIME type of the resource, defaults to "text/plain".

name
      name => 'Resource Name'

    Name of the resource.

  structured_result
  my $result = $tool->structured_result({foo => 'bar'}, $is_error);

Returns a structured result in the format of "output_schema", optionally marking it as an error.

  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>.