Exceptions
NAME
MCP::Client::Exceptions - the typed failures thrown by MCP::Client
DESCRIPTION
Every failure this distribution raises on its own behalf is an
X::MCP::Client, so one CATCH clause separates "the MCP conversation went
wrong" from "the code around it went wrong". The subclasses carry the context
you would otherwise have to scrape back out of a message string: the exit code
and last words of a server process that died, the version list a server said it
would accept, the JSON-RPC error code and data payload the server sent.
The failures
X::MCP::Client::Timeoutā a request outlived its budget. Carriesseconds, andmethod/idwhen the caller registered them.X::MCP::Client::ServerGoneā the server process exited (or the HTTP connection died) with requests in flight. Carriesexit-code,signal,commandandstderr-tail, the tail of the child's stderr ring buffer ā which is usually the only place the real reason is written.X::MCP::Client::Protocolā the peer said something the protocol does not allow, or answered with a JSON-RPC error. Carriescodeand the verbatimdatapayload when it came off the wire.X::MCP::Client::UnsupportedVersionā no overlap between the versions we speak and the versions the server speaks. Carriesrequestedandsupported.X::MCP::Client::Cancelledā a request was abandoned by the caller.X::MCP::Client::InputLoopExceededā a multi round-trip request kept asking for input pastmax-input-rounds.X::MCP::Client::TransportClosedā the transport was closed, either bycloseor by a failure that took the connection with it.X::MCP::Client::SpawnFailedā the server command could not be started.
EXAMPLES
Distinguish "this server is broken" from "this call is slow":
use MCP::Client::Exceptions;
{
CATCH {
when X::MCP::Client::Timeout {
note "gave up on {.method // 'request'} after {.seconds}s";
}
when X::MCP::Client::ServerGone {
note "server died (exit {.exit-code // '?'})";
note " last words: {.stderr-tail}" if .stderr-tail.chars;
}
when X::MCP::Client {
note "MCP failure: {.^name}: {.message}";
}
}
# ... an MCP::Client call ...
}
Read the machine-readable half of a protocol error rather than its message:
CATCH {
when X::MCP::Client::Protocol {
if .code == -32022 { # UNSUPPORTED_PROTOCOL_VERSION
note "server offers: " ~ (.data<supported> // []).join(', ');
}
}
}