NAME

AnyEvent::MCP::Server::Connect - reverse-connecting MCP JSONL server

DESCRIPTION

This JSONL server connects to a multibroker's HTTP/extension listener using connect => "http://host:port/token/alias". It sends ["mcp-connect", token, alias] and then ordinary MCP JSONL messages. The TCP initiator remains the MCP server; the multibroker is the MCP client.

This is useful when the MCP server must connect outward, rather than exposing its own HTTP listener. The multibroker can accept connections under an alias that becomes a tool-name prefix. For a standalone server, AnyEvent::MCP::Server::Simple handles the startup details; use this object directly if your application already owns its event loop.

use AnyEvent;
use AnyEvent::MCP::Server::Connect;

my $server = AnyEvent::MCP::Server::Connect->new (
   connect => "http://127.0.0.1:31740/TOKEN/files",
   toolsets => [$tools],
);
$server->start;
AE::cv->recv;

$tools is an AnyEvent::MCP::Server::Toolset registered by your application. The URL identifies a raw-TCP extension listener, despite its http:// spelling; it is not an HTTP POST endpoint. See "Reverse connections" in mcp-multibroker for setting up the other side.

METHODS

$server->start

Attempt a connection immediately. Retry failures every second, up to sixty attempts, and start a new retry period after an established connection closes. Exhaustion closes the server. Outstanding requests are cancelled, not replayed.

$server->close

Cancel pending connections and retries, close streams and cancel requests. Connecting remotely grants no managed child-shutdown authority.