MCP
view release on metacpan or search on metacpan
lib/MCP/Client.pm view on Meta::CPAN
The name of the client, defaults to C<PerlClient>.
=head2 session_id
my $session_id = $client->session_id;
$client = $client->session_id('12345');
The session ID for the client, used to maintain state across requests.
=head2 ua
my $ua = $client->ua;
$client = $client->ua(Mojo::UserAgent->new);
The user agent used for making HTTP requests, defaults to a new instance of L<Mojo::UserAgent>.
=head2 url
my $url = $client->url;
$client = $client->url('http://localhost:3000/mcp');
The URL of the MCP server, defaults to C<http://localhost:3000/mcp>.
=head2 version
my $version = $client->version;
$client = $client->version('1.0.0');
The version of the client, defaults to C<1.0.0>.
=head1 METHODS
L<MCP::Client> inherits all methods from L<Mojo::Base> and implements the following new ones.
=head2 build_request
my $request = $client->build_request('method_name', {param1 => 'value1'});
Builds a JSON-RPC request with the given method name and parameters.
=head2 build_notification
my $notification = $client->build_notification('method_name', {param1 => 'value1'});
Builds a JSON-RPC notification with the given method name and parameters.
=head2 call_tool
my $result = $client->call_tool('tool_name');
my $result = $client->call_tool('tool_name', {arg1 => 'value1'});
Calls a tool on the MCP server with the specified name and arguments, returning the result.
=head2 delete_session
my $bool = $client->delete_session;
Send a C<DELETE> request to terminate the current session on the MCP server, and clear the local
L</"session_id">. Returns true on success, or C<undef> if no session is active. The server only honors this when it
was configured with C<< streaming => 1 >>.
=head2 get_prompt
my $result = $client->get_prompt('prompt_name');
my $result = $client->get_prompt('prompt_name', {arg1 => 'value1'});
Get a prompt from the MCP server with the specified name and arguments, returning the result.
=head2 initialize_session
my $result = $client->initialize_session;
Initializes a session with the MCP server, setting up the protocol version and client information.
=head2 list_prompts
my $prompts = $client->list_prompts;
Lists all available prompts on the MCP server.
=head2 list_resources
my $resources = $client->list_resources;
Lists all available resources on the MCP server.
=head2 list_tools
my $tools = $client->list_tools;
Lists all available tools on the MCP server.
=head2 ping
my $result = $client->ping;
Sends a ping request to the MCP server to check connectivity.
=head2 read_resource
my $result = $client->read_resource('file:///path/to/resource.txt');
Reads a resource from the MCP server with the specified URI, returning the result.
=head2 send_request
my $response = $client->send_request($request);
Sends a JSON-RPC request to the MCP server and returns the response.
=head1 SEE ALSO
L<MCP>, L<https://mojolicious.org>, L<https://modelcontextprotocol.io>.
=cut
( run in 1.227 second using v1.01-cache-2.11-cpan-5735350b133 )