NAME

AnyEvent::MCP::Extension - authenticated non-HTTP connections on an MCP listener

DESCRIPTION

The HTTP listeners used by the bundled servers can also accept private raw-TCP protocols on the same port. This helper authenticates the initial JSON handshake and passes the already-buffered connection to its protocol handler; it does not implement HTTP or MCP dispatch.

mcp-multibroker uses this mechanism for reverse-connecting MCP servers. Vim editor and browser connections can also share an MCP HTTP listener, but they use WebSocket upgrades rather than this raw JSON hello protocol. Ordinary MCP clients should use AnyEvent::MCP::Client::HTTP or AnyEvent::MCP::Client::JSONL, not this extension protocol.

my ($host, $port, $token, $alias) =
   AnyEvent::MCP::Extension::parse_url
      "http://127.0.0.1:31740/TOKEN/files";

The returned address is for a raw TCP extension connection, not an HTTP request. See AnyEvent::MCP::Server::Connect for the MCP user of it.

FUNCTIONS

AnyEvent::MCP::Extension::accept $handle, [$token...], $callback->($handle, $hello), $reject->($handle)

Read one bounded newline-terminated JSON array beginning with a protocol name and accepted token. Authenticate before calling the protocol-specific handler. Invalid hellos close the connection. The callback takes ownership of the same handle, including buffered bytes after the hello. Remaining array fields belong to the selected protocol. An optional $reject callback releases any listener ownership on rejection; otherwise the handle is destroyed.

($host, $port, $token, $alias) = AnyEvent::MCP::Extension::parse_url $url

Parse http://host:port/token/alias, including bracketed IPv6 hosts. The URL names a raw TCP extension endpoint sharing an HTTP listener; no HTTP request is sent. Tokens use the ordinary listener token syntax and aliases use ASCII letters, digits, underscores and hyphens.