MCP
view release on metacpan or search on metacpan
lib/MCP/Server.pm view on Meta::CPAN
An array reference containing registered tools.
=head2 transport
my $transport = $server->transport;
$server = $server->transport(MCP::Server::Transport::HTTP->new);
The transport layer used by the server, such as L<MCP::Server::Transport::HTTP> or L<MCP::Server::Transport::Stdio>.
=head2 version
my $version = $server->version;
$server = $server->version('1.0.0');
The version of the server.
=head1 METHODS
L<MCP::Tool> inherits all methods from L<Mojo::EventEmitter> and implements the following new ones.
=head2 handle
my $response = $server->handle($request, $context);
Handle a JSON-RPC request and return a response.
=head2 notify_list_changed
my $bool = $server->notify_list_changed('tools');
Broadcast a C<notifications/$kind/list_changed> JSON-RPC notification to all connected clients. Returns true on
success, or C<undef> if no notification could be delivered.
=head2 prompt
my $prompt = $server->prompt(
name => 'my_prompt',
description => 'A sample prompt',
arguments => [{name => 'foo', description => 'Whatever', required => 1}],
code => sub ($prompt, $args) { ... }
);
Register a new prompt with the server.
=head2 resource
my $resource = $server->resource(
uri => 'file://my_resource',
name => 'sample_resource',
description => 'A sample resource',
mime_type => 'text/plain',
code => sub ($resource) { ... }
);
Register a new resource with the server.
=head2 to_action
my $action = $server->to_action;
my $action = $server->to_action({streaming => 1});
Convert the server to a L<Mojolicious> action. Any options are passed through to the constructor of
L<MCP::Server::Transport::HTTP>; in particular, C<< streaming => 1 >> opts in to the server-to-client SSE stream
and explicit session termination.
=head2 to_stdio
$server->to_stdio;
Handles JSON-RPC requests over standard input/output.
=head2 tool
my $tool = $server->tool(
name => 'my_tool',
description => 'A sample tool',
input_schema => {type => 'object', properties => {foo => {type => 'string'}}},
code => sub ($tool, $args) { ... }
);
Register a new tool with the server.
=head1 SEE ALSO
L<MCP>, L<https://mojolicious.org>, L<https://modelcontextprotocol.io>.
=cut
( run in 1.144 second using v1.01-cache-2.11-cpan-5735350b133 )