NAME

AnyEvent::MCP::Client::HTTP - MCP over AnyEvent::HTTP

SYNOPSIS

use AnyEvent::MCP::Client::HTTP;

my $client = AnyEvent::MCP::Client::HTTP->new (
   name => "example", url => $url, bearer => $token,
   timeout => 30,
);

DESCRIPTION

Use this transport to talk to an MCP server through HTTP. The caller supplies the endpoint and, if needed, credentials; the common Client layer handles discovery and tool calls. Unlike a browser, this client does not follow redirects or silently retry requests. A redirected request could disclose credentials to another host, and retrying a tool call could perform an operation twice.

FIRST CALL

For a bundled MCP server already listening on HTTP, use the full URL it prints with --print-url:

use AnyEvent;
use AnyEvent::MCP::Client::HTTP;

my $client = AnyEvent::MCP::Client::HTTP->new (
   url => "http://127.0.0.1:31740/TOKEN/",
);
my $cv = AE::cv;
$client->call (workdirs => {}, sub { $cv->send (@_) });
my ($success, $result) = $cv->recv;
$success or die "$result->{message}\n";
!$result->{isError} or die "$result->{content}[0]{text}\n";

Replace the example URL with the actual credential-bearing URL. The common AnyEvent::MCP::Client layer negotiates MCP and handles callbacks. A successful JSON-RPC exchange can still return a tool error as isError; always inspect both.

METHODS

$client = AnyEvent::MCP::Client::HTTP->new (%config)

Accepts the common AnyEvent::MCP::Client options and these transport options. Options are flat, rather than nested in an HTTP configuration hash.

url => $url

Complete endpoint URL, optionally including a URL-path token. Required unless supplied by the named client configuration.

bearer => $token

Supplies Authorization: Bearer TOKEN. Without it, the URL alone is used; a bearer token is not inferred from a URL. The server must accept the selected credential. With the bundled servers, the URL-path token and bearer header present the same static credential.

name => $name

Loads url, bearer and timeout defaults from [client NAME]. Explicit constructor arguments override them, including explicitly undefined credentials. Without a name no global configuration is accessed.

timeout => $seconds

HTTP inactivity timeout, defaulting to 300 seconds. Use the common request_timeout option for an overall tool-call deadline.

headers => { %headers }

Additional HTTP headers. Protocol headers and an explicitly configured bearer header are supplied by this module.

max_size => $bytes

Bounds a JSON response or an individual buffered SSE event, defaulting to 16 MiB. SSE notifications are delivered incrementally rather than after the HTTP response ends.

proxy, tls_ctx, handle_params, sessionid, on_prepare, on_connect and tcp_connect are passed to AnyEvent::HTTP. No HTTP cookies or Basic authentication are supplied by this module. Redirects and automatic HTTP retries are disabled.

Legacy session IDs are retained from initialization. An expired session fails outstanding requests; a later operation can initialize again. Legacy GET streams and the old separate SSE endpoint transport are not implemented.