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" or "https://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 extension listener, not an HTTP POST endpoint. HTTPS verifies the server certificate and hostname before sending the JSON hello. See "Reverse connections" in mcp-multibroker for setting up the other side.
METHODS
- $server->start
-
Attempt a connection immediately. Retry refused TCP connections every second, up to sixty attempts. Other failures during connection setup, including failed TLS verification, close the server immediately. Unexpected disconnects after establishment start a new retry period. 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.