AnyEvent-MCP
view release on metacpan or search on metacpan
bin/anyevent-mcp-askpermission view on Meta::CPAN
returns your choice to the server. You do not normally run it yourself.
To change saved rules later, use C<anyevent-mcp manage-rules NAME> or
C<anyevent-mcp edit-rules NAME>.
=head1 PERMISSION PROMPTS
The helper tries YAD first, leaving display backend selection to GTK.
If YAD cannot start, it asks on C</dev/tty>. Closing a working dialog,
terminal EOF, or having neither interface available means deny once.
Server, tool, action, current dimension values and reason are shown as read-only
GTK labels when present, including the multibroker alias when available.
The requested sandbox grants appear together on one line. The initial YAD
form also has a C<Denial reason (optional)> field above four choices:
C<Deny once>, C<Deny always...>, C<Allow always...>, C<Allow once>.
The persistent rule editor creates a selector for each named permission
dimension with multiple offered scopes, using the server's labels and matchers.
The action being authorized is repeated above the scope selectors.
Single-choice scopes are applied automatically without a selector. For example,
the workdir dimension may offer this workdir or any configured workdir.
When a previously saved scope is still offered, the rule editor preselects it
instead of the first choice. The user must still explicitly save every rule.
The initial permission decision remains deny-once by default.
The scopes affect saved rule matching, not the current call's sandbox grants.
One-time decisions are on the outside; C<Deny once>
uses YAD's default OK response. Closing the dialog also denies once.
The persistent choices open a separate rule editor for grant and scope
settings, including exact requested-file scope on deny rules. Rules can last
indefinitely (the default), 900 seconds or 16 hours. Expired rules disappear
when the rules are read and are removed from disk on the next ordinary save.
The reason
is included in a denial result but is ignored on an allowance.
Optional display-only request C<details> maps plain labels to Unicode text,
for example C<< { "View patch" => $diff } >>. Each entry appears as a size
summary and a button. YAD adds an ellipsis to the label and opens a separate,
read-only, resizable, monospace text window without dismissing the approval dialog.
Content is written to a private temporary UTF-8 file, never interpolated
into a command; control characters are escaped. The helper limits each
preview to 65536 Unicode characters and identifies incomplete previews.
Terminal and native MCP prompts include the same bounded text inline.
Display-only details never constrain or become part of persistent permission rules; an
C<allow-always> rule for C<perl -> permits future, different stdin scripts.
YAD uses GTK, so you can select a dark theme externally by setting
C<GTK_THEME=Adwaita:dark> in the server's environment before starting it.
The permission helper inherits that setting and passes it to YAD; the
theme is not changed for unrelated applications.
In a terminal, the four decisions are single-letter shortcuts and C<m>
edits the optional denial reason. Closing the dialog, cancelling or an unavailable
terminal denies once. Rule management remains separate:
C<anyevent-mcp manage-rules NAME> or C<anyevent-mcp edit-rules NAME>.
=head1 HELPER PROTOCOL
The helper reads one permission request on stdin and writes one JSON
decision on stdout. Servers invoke it through
L<AnyEvent::MCP::Permissions::Ask>, which describes the helper interface
and how to select a replacement helper. YAD's stderr is suppressed;
startup failure is detected from its exit status.
=head1 OPTIONS
=over
=item --manage-rules FILE
Open YAD rule list for FILE in evaluation order. Delete or reorder selected
rules. File lock protects updates; changes fail if list changed elsewhere.
Cannot combine with C<--edit-rules> or prompt-mode flags.
=item --edit-rules FILE
Edit permission rules in FILE using C<$VISUAL>, C<$EDITOR>,
C<sensible-editor> or C<vi>. Does not validate or overwrite editor output.
Cannot combine with C<--manage-rules> or prompt-mode flags.
=item --tty
Prompt only on C</dev/tty>, without YAD fallback. Unavailable terminal
denies access. Cannot combine with C<--yad> or rule-management flags.
=item --yad
Prompt only with YAD, without terminal fallback. Unavailable YAD
denies access. Cannot combine with C<--tty> or rule-management flags.
=item --help
Print short usage synopsis and exit.
=back
Without explicit C<--tty> or C<--yad>, prompts try YAD first, then
C</dev/tty> only if YAD cannot start. Closing or declining a working
dialog never triggers fallback.
=cut
use common::sense;
use Getopt::Long ();
use Text::ParseWords ();
use File::Temp ();
use JSON::XS ();
use AnyEvent::MCP ();
use AnyEvent::MCP::Permissions::Ask ();
use AnyEvent::MCP::Server::Permissions ();
Getopt::Long::GetOptions
"manage-rules=s" => \my $rules_file,
"edit-rules=s" => \my $edit_file,
"tty" => \my $tty_only,
"yad" => \my $yad_only,
"help" => \my $help,
or exit 2;
@ARGV || defined $rules_file && defined $edit_file
( run in 0.833 second using v1.01-cache-2.11-cpan-60884a8df76 )