AnyEvent-MCP
view release on metacpan or search on metacpan
lib/AnyEvent/MCP/Intro.pod view on Meta::CPAN
avoids that extra setup.
=head1 PICK A SERVER
For a local MCP client, configure it to launch the server that provides
the tools you want:
mcp-fs --stdio /home/alice/src/project
mcp-vim --stdio
mcp-webbrowser --stdio
mcp-ask-user --stdio
mcp-http --stdio
mcp-imap --stdio --name personal
C<--stdio> means the MCP client launches the process. Do not start a
separate copy in a terminal. For HTTP clients, use a running server and
its C<--print-url> instead, as explained below.
C<mcp-fs> reads, searches and changes files and runs commands in a sandbox.
The first walkthrough below uses this server.
C<mcp-vim> reads and edits live Vim buffers. Install the companion Vim plugin
and connect the editor to its listener; see L</Add a live Vim editor> and
L<mcp-vim/VIM PLUGIN INSTALLATION>.
C<mcp-webbrowser> works with explicitly approved browser tabs. Install
its companion userscript and connect each tab you want to expose; see
L</CONNECTED BROWSER PAGES>.
C<mcp-ask-user> lets the assistant ask you questions through a local
YAD or terminal dialog, or through the client's native form UI; see
L</Ask the client's human a question>.
C<mcp-http> makes HTTP(S) requests with method- and URL-scoped permissions.
It does not follow redirects automatically; see L</Use an HTTP request tool>.
C<mcp-imap> reads, searches and manages mailboxes. Configure the account
interactively before starting the server; see L</Read and organize mail>
and L<mcp-imap> for OAuth2 and account management.
To offer several servers over one MCP connection, use C<mcp-multibroker>.
It combines these servers with each other or with third-party MCP servers,
whether started locally over stdio or reached over HTTP. Their tools
appear under separate name prefixes; see L</COMBINING SERVERS> and
L<mcp-multibroker> for the full command syntax.
=head1 YOUR FIRST FILESYSTEM SERVER
Start with one project and one connection. You do not need a multibroker,
a hand-written configuration file or saved permission rules yet.
=head2 Choose stdio or HTTP
Use B<stdio> when your MCP client runs on the same machine and can launch
a server process. Configure the client to start the following command:
mcp-fs --stdio --name code /home/alice/src/project
The client starts this process and uses its stdin/stdout for MCP.
You do not start a second copy in a terminal, and there is no listener
URL or HTTP token to configure. Diagnostics go to stderr.
Clients that take a command and an argument array need these values:
command: mcp-fs
arguments: --stdio, --name, code, /home/alice/src/project
These describe separate arguments, not one shell command string.
Use an absolute executable path if the client cannot find C<mcp-fs>.
See L</CLIENT EXAMPLES> for examples of particular clients.
Use B<HTTP> when the client connects to an already-running server, or when
it cannot launch a local process. Start this in a terminal on the server
machine and leave it running:
mcp-fs --name code --bind :31741 /home/alice/src/project
In another terminal, obtain the matching connection URL:
mcp-fs --name code --bind :31741 --print-url
The second command prints a credential-bearing URL and exits without
opening a listener. Configure that URL in the client. The default address
is IPv4 loopback, so this example is reachable from the same machine only.
A hosted client needs a suitable tunnel or reachable endpoint; its own
C<localhost> is not your computer.
Repeat the same name and listener overrides when printing the URL.
Both commands must use the same user and configuration directory.
Port zero chooses an ephemeral port, which C<--print-url> cannot predict;
use an explicit port for this walkthrough.
The HTTP server generates and saves its private master secret when needed.
You can initialize it explicitly with C<anyevent-mcp init>, but that
command is unnecessary when configuration already exists and will refuse
to replace it. Keep the printed URL private: possession of its token
authenticates a client.
=head2 Make a useful request
Once your client reports that the server is connected, ask the LLM:
Show me the configured workdirs. List the top-level files in the
project, then read its README if it has one. Do not modify files
or run commands.
C<workdirs> returns the configured paths, sandbox grants, trusted mounts
and runtime paths. Listing names requests C<inspect> permission; reading
contents requests C<read> permission. Expect a permission prompt when
there is no saved rule allowing the operation.
Choose C<Allow once> for the first operation. The worker then runs with
the requested sandbox grants. A denial is a tool failure that the LLM
should report, rather than an empty file or a disconnected server.
See L</Your first permission dialog> for a walkthrough.
For a slightly larger task, ask:
Find TODO comments in this project and explain the three that look
most useful to address next. Do not modify files or run commands.
lib/AnyEvent/MCP/Intro.pod view on Meta::CPAN
environment; do not put a real key in a script, command line or example.
Associate the tunnel with the ChatGPT workspace where you want to use it.
For B<stdio>, put the server startup command in a small executable wrapper,
for example C</home/alice/bin/my-mcp>:
#!/bin/sh
exec mcp-multibroker --stdio \
code --- mcp-fs --name code /home/alice/src/project --- \
questions --- mcp-ask-user ---
With a tunnel installation providing C<tunnel-client-runtime>, run:
tunnel-client-runtime run \
--log.format=struct-text \
--log.level=warn \
--control-plane.tunnel-id=tunnel_... \
--mcp.connection-max-ttl=120s \
--mcp.command=/home/alice/bin/my-mcp
The tunnel starts the wrapper as its stdio MCP server. Do not start a
separate copy yourself. Make the wrapper executable and ensure its
programs and Perl modules are on the tunnel process's C<PATH>.
For B<HTTP>, instead start the server or multibroker separately:
mcp-multibroker --name tools --bind 127.0.0.1:16586 \
code 'stdio:mcp-fs --name code /home/alice/src/project'
Obtain the matching credential-bearing URL:
mcp-multibroker --name tools --bind 127.0.0.1:16586 --print-url
Then point the tunnel runtime at that URL, rather than a command:
tunnel-client-runtime run \
--log.format=struct-text \
--log.level=warn \
--control-plane.tunnel-id=tunnel_... \
--mcp.connection-max-ttl=120s \
--mcp.server-url=http://127.0.0.1:16586/TOKEN/
Replace C<TOKEN> with the actual URL path printed above, and keep it
private. In this mode, the multibroker must remain running separately;
the tunnel only connects to it. Both modes require the tunnel runtime
to remain active while the hosted client uses the server. Use B<one>
of C<--mcp.command> and C<--mcp.server-url>, not both.
In ChatGPT, add a custom MCP server using a Tunnel connection and select
the tunnel ID. Creation and visibility depend on the Platform and ChatGPT
workspace permissions. The tunnel client's CLI and supported configuration
forms can vary between releases; the examples above use the direct runtime
CLI rather than its optional profile setup. See
L<Secure MCP Tunnel|https://developers.openai.com/api/docs/guides/secure-mcp-tunnels>
for obtaining a tunnel, runtime, credentials and connecting it to ChatGPT.
=head1 TROUBLESHOOTING
=head2 The server does not start
Read stderr or the client's server log. Missing Perl modules, a missing
workdir, unsuitable utilities or an unavailable bubblewrap executable can
fail startup. Confirm that the client launches the same executable and
arguments you intended, with the expected C<PATH> and Perl installation.
For a local sandbox check, run from the project directory:
mcp-fs --exec-cmd workdir-read -- ls
This runs C<ls> with the named grants and trusted baseline mounts, without
MCP or saved permission rules. A failure here can identify a bubblewrap
or runtime problem. It does not test the client connection or approval UI.
C<--sandbox none> disables isolation and changes worker authority; it is
not a fix that preserves the same permission boundary.
=head2 The client cannot connect
For stdio, configure a command the client launches, rather than a URL.
A separately running stdio process is not the client's connection.
Do not put banners or diagnostics on stdout.
For HTTP, leave the server running and check its address and port.
C<--print-url> exits without starting it. Loopback binds accept local
connections only; hosted or remote clients need the appropriate route or
tunnel. An occupied port causes a listener error, so check the server log.
For reverse C<--connect> servers, check the connecting process's log as
well as the multibroker. C<https://> requires a certificate trusted by
the connecting process and a hostname matching the URL. A TLS error
stops that reverse server immediately; it does not retry with plaintext.
TCP connection refusal is retried for up to sixty attempts.
=head2 Authentication fails
Obtain the URL with the same name, bind/token overrides and configuration
environment as the running process. Use the complete path; the final
slash is optional for endpoints whose configured path ends in one.
A clean URL needs an accepted bearer token.
A multibroker child credential is not necessarily the upstream listener's
credential. C<--bearer> after a child pair and C<--token> before the pairs
configure different sides of the connection.
For IMAP OAuth2, obtaining an access token does not by itself prove that
IMAP authentication will work. Check the authorized browser account,
requested IMAP scope and saved C<user> name. Copy the complete redirected
address-bar URL after authorization, even when the browser displays an
unreachable loopback page.
If the server warns that it cannot save the master secret, another process
may derive a different token. Check write access to the global configuration.
Do not replace an existing secret simply to add a setting.
=head2 Connected, but there are no tools
Inspect the server's stderr for omitted utilities. mcp-fs's C<workdirs>
tool reports configuration even when a utility-dependent tool is absent.
For a multibroker, call C<discover-brokers> to see individual connection
errors, then C<list-tools> to refresh definitions.
A third-party child might require initialization or features this client
implementation does not support. See L<AnyEvent::MCP::Client> and its
transport documentation for limitations.
=head2 There is no approval dialog
First check whether the tool was denied by a saved rule or is waiting for
the client's own approval. An allowed operation needs no server prompt.
The default helper runs on the server machine. A background service may
have neither a usable display nor C</dev/tty>, even though your interactive
shell has both. Supply the appropriate display environment, a usable helper,
or C<--ask auto> with a modern client supporting form elicitation.
C<--ask mcp> reports an error if that support is absent.
Setting an asking mode cannot make an unsupported client display a form.
Check stderr and the tool error instead of assuming a missing dialog is
an approval.
=head2 It asks again after I chose allow
Allow-once covers one tool invocation, including its permission retries.
The next invocation asks again. Use allow-always to save a rule.
Inspect the saved rule's action, workdir and grants. Listing names and
reading contents are different actions. A rule for one exact workdir
spelling will not match a differently spelled startup argument.
A request for extra authority, such as networking, does not match a
workdir-read-only allow rule. Earlier ask or deny rules take precedence.
Confirm that the prompt's permanent rule was successfully saved and that
you are editing the rules for the actual child name, not merely its
multibroker prefix.
=head2 The worker cannot see a directory or executable
The worker sees granted mounts and trusted baseline mounts, not everything
the server process can see. Check C<workdirs> for the selected path, mounts
and runtime paths. A symlink target outside those mounts is unavailable.
The ordinary sandbox runtime includes C</usr>, C</bin> and system libraries,
but not C</opt>. For tools or libraries under C</opt>, add this to
C<[program mcp-fs]> in the private global configuration:
mount.opt = ro:/opt
This assumes C</opt> exists. Restart mcp-fs after changing trusted mounts.
If your worker Perl is C</opt/bin/perl>, you can also set
C<executable.perl = /opt/bin/perl> in that program section. Supply the
actual executable path: selecting it does not itself mount the
executable or its dependencies inside the worker.
A trusted mount supplies baseline access to every worker using it; a
writable mount likewise supplies baseline write authority.
An arbitrary command might also need its user's configuration or repository
credentials under HOME, or network access. Request the corresponding grants
when needed; do not assume C<workdir-read> includes them.
For example, CVS over SSH can use C<workdir-read> and C<ssh-agent>.
The latter includes network access, the agent socket and C<~/.ssh/known_hosts>,
without exposing private key files or the rest of HOME. The broker must
inherit C<SSH_AUTH_SOCK> from your environment. User-configured helpers
outside the runtime mounts need an explicit trusted mount.
An explicit exec grant array replaces the default rather than adding to it.
=head2 My configuration change seems to be ignored
Check which file and section the process actually selects. Global settings
use the server user's C<HOME>/C<XDG_CONFIG_HOME>. Instance names, program
basenames and multibroker prefixes serve different purposes.
Restart after changing startup settings, mounts or utilities. Permission
rules need no restart, but their order still matters. Refresh discovery
after a child restart; reconnect a client that retains an old tool list.
C<--print-url> reads the current configuration, which can differ from an
older running process.
( run in 1.306 second using v1.01-cache-2.11-cpan-60884a8df76 )