NAME
MCP::Server::Transport::HTTP - HTTP transport for MCP servers
SYNOPSIS
use MCP::Client;
my $client = MCP::Client->new(url => 'http://localhost:3000/mcp');
$client->initialize_session;
my $tools = $client->list_tools;
DESCRIPTION
MCP::Client is a client for MCP (Model Context Protocol) that communicates with MCP servers over HTTP.
ATTRIBUTES
MCP::Client inherits all attributes from Mojo::Base and implements the following new ones.
name
my $name = $client->name;
$client = $client->name('PerlClient');
The name of the client, defaults to PerlClient
.
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.
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 Mojo::UserAgent.
url
my $url = $client->url;
$client = $client->url('http://localhost:3000/mcp');
The URL of the MCP server, defaults to http://localhost:3000/mcp
.
version
my $version = $client->version;
$client = $client->version('1.0.0');
The version of the client, defaults to 1.0.0
.
METHODS
MCP::Client inherits all methods from Mojo::Base and implements the following new ones.
build_request
my $request = $client->build_request('method_name', {param1 => 'value1'});
Builds a JSON-RPC request with the given method name and parameters.
build_notification
my $notification = $client->build_notification('method_name', {param1 => 'value1'});
Builds a JSON-RPC notification with the given method name and parameters.
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.
initialize_session
my $result = $client->initialize_session;
Initializes a session with the MCP server, setting up the protocol version and client information.
list_tools
my $tools = $client->list_tools;
Lists all available tools on the MCP server.
ping
my $result = $client->ping;
Sends a ping request to the MCP server to check connectivity.
send_request
my $response = $client->send_request($request);
Sends a JSON-RPC request to the MCP server and returns the response.
SEE ALSO
MCP, https://mojolicious.org, https://modelcontextprotocol.io.