NAME

AnyEvent::MCP::Client::Request - a request for client input

DESCRIPTION

An MCP server may need input from the client before it can finish a tool call. In that case on_request receives this object. You can retain it while a human answers a dialog, then call reply or error. A legacy incoming request uses the same interface.

The fields client, id, method, params, operation (the original local call, when known), protocol_version, finished and cancelled are accessible directly. Do not reply after cancellation.

Usually you encounter this object in an "on_request" in AnyEvent::MCP::Client callback, rather than constructing it:

on_request => sub {
   my ($client, $req) = @_;
   if ($req->{method} eq "elicitation/create") {
      $req->reply ({ action => "decline" });
   } else {
      $req->error (-32601, "Unsupported input method");
   }
},

For real human prompting, see AnyEvent::MCP::Permissions::Ask instead.

METHODS

$req->reply ($result)

Completes the input request with a result hash reference. Duplicate replies die. Protocol field spelling, such as resultType, is preserved.

$req->error ($code, $message, $data)

Reports a JSON-RPC error. $data is optional. For modern input this fails the local operation; for legacy requests it sends an error response.

$req->cancel

Marks the request finished and cancelled, releases its completion callback and calls $req->{on_cancel}->($req) when present. Repeated cancellation is harmless. Applications can use on_cancel to close an outstanding prompt.