AnyEvent-MCP
view release on metacpan or search on metacpan
bin/anyevent-mcp view on Meta::CPAN
=over
=item --config FILE
Use FILE instead of default global configuration
(C<$XDG_CONFIG_HOME/anyevent-mcp/global.ini>, or
C<~/.config/anyevent-mcp/global.ini>). Relevant to C<init> and user
management; rule management uses its own profile or pathname.
=item --program NAME
Select C<[program NAME]> for user management.
=item --instance NAME
Select C<[instance NAME]> for user management. Cannot combine with --program.
=item --help
Print command synopsis, available commands and configuration defaults,
then exit without running a command.
=back
=cut
use common::sense;
use Getopt::Long ();
use AnyEvent::MCP ();
use AnyEvent::MCP::Config ();
sub usage {
print <<'EOF';
Usage: anyevent-mcp [OPTIONS] COMMAND [ARGUMENTS]
manage-rules NAME delete/reorder rules in YAD
edit-rules NAME edit rules with VISUAL, EDITOR, sensible-editor, vi
manage-rules-file FILE manage an explicit rules file
edit-rules-file FILE edit an explicit rules file
init create a private configuration and master secret
create-user USER enable or rotate a managed user
revoke-user USER revoke a managed user
Options (before COMMAND):
--config FILE use a different global configuration file
--program NAME select [program NAME] for user management
--instance NAME select [instance NAME] for user management
--help show this help
User definitions inherit from [global] through [program NAME] to
[instance NAME]; narrower scopes override wider ones. Without --program
or --instance, user commands modify [global]. Revoked users remain
disabled until recreated with a new token generation. The implicit
global:default user is enabled initially.
Examples:
anyevent-mcp create-user chatgpt
anyevent-mcp --program mcp-fs create-user backup
anyevent-mcp --instance private revoke-user alice
anyevent-mcp revoke-user chatgpt
mcp-multibroker --print-urls # list all enabled user URLs
mcp-multibroker --print-url=chatgpt # show just chatgpt's URL
Server changes take effect after restart. The selected connect_user
(default: default) authenticates auxiliary browser/Vim/reverse connections.
Rule profiles are stored under $XDG_CONFIG_HOME/anyevent-mcp, falling back
to ~/.config/anyevent-mcp/rules (e.g. manage-rules fs-default).
Configuration defaults to ~/.config/anyevent-mcp/global.ini, or the
corresponding location under XDG_CONFIG_HOME. Use --help for this text.
A missing master secret is generated and saved automatically when a server
loads its configuration. Configuration format: see AnyEvent::MCP.
EOF
}
sub change_user {
my ($file, $section, $user, $command) = @_;
my $lock = AnyEvent::MCP::file_lock $file;
my $config = AnyEvent::MCP::Config->new (file => $file)->load ($lock);
my $values = $config->{section}{$section} ||= {};
my $key = "user.$user";
my $generation = $values->{$key};
if (defined $generation) {
$generation =~ /\A-?[1-9][0-9]*\z/ && length $generation < 18
or die "Invalid $key generation '$generation'\n";
$generation = 0 + $generation;
}
if ($command eq "create-user") {
die "$key already enabled in [$section]\n"
if defined $generation && $generation > 0 || !defined $generation && $section eq "global" && $user eq "default";
$generation = defined $generation ? -$generation + 1 : 1;
} else {
die "$key already revoked in [$section]\n" if defined $generation && $generation < 0;
if (!defined $generation) {
($section ne "global" || $user eq "default")
or die "$key is not enabled\n";
$generation = -1;
} else {
$generation = -$generation;
}
}
$values->{$key} = $generation;
$config->save;
close $lock or die "$file: $!\n";
print "$section: $user generation " . abs ($generation)
. ($generation > 0 ? " enabled\n" : " revoked\n");
}
Getopt::Long::Configure ("no_auto_abbrev", "no_ignore_case", "require_order");
Getopt::Long::GetOptions
"config=s" => \my $file,
"program=s" => \my $program,
"instance=s" => \my $instance,
( run in 0.911 second using v1.01-cache-2.11-cpan-99fa8243a42 )