AnyEvent-MCP

 view release on metacpan or  search on metacpan

bin/anyevent-mcp-form-elicitation  view on Meta::CPAN

#!/opt/bin/perl

=head1 NAME

anyevent-mcp-form-elicitation - display an MCP elicitation form using YAD or a terminal

=head1 SYNOPSIS

   anyevent-mcp-form-elicitation <request.json >response.json

=head1 DESCRIPTION

Reads one UTF-8 JSON object containing MCP form elicitation parameters:
C<mode> (optional, C<form>), C<message> and C<requestedSchema>. It displays
the form using YAD, or uses C</dev/tty> if YAD cannot start. It writes one
ordinary MCP response to stdout:

   {"action":"accept","content":{"answer":"Some text"}}
   {"action":"decline"}
   {"action":"cancel"}

Exit status zero means a valid response, including decline or cancel.
Nonzero means invalid input or a helper failure; diagnostics go to stderr.
Closing a working dialog cancels the question and does not open another
prompt. Without YAD or a terminal the helper fails rather than inventing
an answer.

Forms contain at most 32 fields. Supported field types are strings,
single-select string enums (C<enum> or titled C<oneOf> values), booleans,
numbers and integers. Titles, descriptions, defaults, required fields,
string length limits and numeric bounds are supported. Unsupported schema
features, including string formats, nested objects, multi-select arrays and
URL elicitation, produce an error.

Text fields accept multiline answers. Optional unselected choices,
booleans and blank numbers are omitted; empty text is returned as an empty
string. In a terminal, enter C<<< << >>> to start multiline text, ending
with a line containing only C<.>. C<:cancel> and C<:decline> leave the form;
C<:omit> omits an optional field. Prefix a literal colon command with another
colon. A final confirmation lets you submit or edit the entered answers.

The helper does not speak an MCP transport or maintain continuation tokens.
It can be used directly from shell scripts or replaced by another executable
with the same stdin/stdout contract. MCP callers use
C<PERL_ANYEVENT_MCP_ELICITATION_HELPER> to select an alternative.

=head1 OPTIONS

=over

=item --tty

Display form on C</dev/tty>, never try YAD. Fails when terminal unavailable.
Cannot combine with C<--yad>.

=item --yad

Display form with YAD only; fails when unavailable. No terminal fallback.
Cannot combine with C<--tty>.

=item --help

Print short usage synopsis and exit.

=back

=cut

use common::sense;

use Getopt::Long ();
use JSON::XS ();
use Scalar::Util qw(looks_like_number);
use Text::ParseWords ();

use AnyEvent::MCP ();

Getopt::Long::GetOptions
   "tty"  => \my $tty_only,
   "yad"  => \my $yad_only,
   "help" => \my $help,
   or exit 2;



( run in 0.653 second using v1.01-cache-2.11-cpan-60884a8df76 )