ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-MCP/lib/AnyEvent/MCP/Intro.pod
Revision: 1.20
Committed: Wed Oct 21 16:24:16 2026 UTC (13 days, 2 hours ago) by root
Branch: MAIN
Changes since 1.19: +23 -5 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.5 AnyEvent::MCP::Intro - using MCP servers, clients and permissions
4 root 1.1
5     =head1 DESCRIPTION
6    
7 root 1.5 You can use the servers in this distribution without writing any Perl.
8     This walkthrough starts with one filesystem server, connects it to an MCP
9     client, and makes a useful request. Once that works, it explains persistent
10     configuration, permissions and combining several servers.
11 root 1.1
12 root 1.5 If you want to write a small server yourself, continue with
13     L<AnyEvent::MCP::Server::Simple/TUTORIAL>. Applications needing their own
14     connection management or dispatch can use the modules described in
15     L<AnyEvent::MCP/MODULES>.
16 root 1.1
17 root 1.5 The examples use C</home/alice/src/project> as an existing project directory.
18     Replace it with your own absolute path. Commands shown here are commands
19     for you to run; requests addressed to the LLM are shown separately.
20    
21     =head1 INSTALLATION
22    
23     Install the Perl distribution and the external programs used by the
24     servers. Installing one does not install the other.
25    
26     For mcp-fs, install Linux bubblewrap and the filesystem utilities. On
27     Debian or Ubuntu, for example:
28    
29     sudo apt install bubblewrap findutils grep patch sed perl yad
30    
31     C<yad> is optional: it supplies graphical permission dialogs.
32     Without a usable YAD dialog, the helper tries C</dev/tty>; if neither is
33     available, it denies the request. Bubblewrap's executable is C<bwrap>.
34     The machine must allow the unprivileged user namespaces it needs.
35    
36     mcp-fs detects its utilities at startup and omits tools whose utilities
37     are unavailable or unsuitable. It requires bubblewrap by default.
38     See L<mcp-fs/TRUSTED CONFIGURATION> for explicit utility paths and
39     L<mcp-fs/LIMITATIONS> for the sandbox's limits.
40    
41     If you have an unpacked distribution or source checkout, run these commands
42     in its top-level directory:
43    
44     perl Makefile.PL
45     make
46     make test
47     make install
48    
49     C<perl Makefile.PL> reports missing Perl dependencies. Install those with
50     your usual package manager or CPAN client before continuing. For example,
51     the main non-core dependencies can be installed with:
52    
53 root 1.19 cpan AnyEvent AnyEvent::HTTP AnyEvent::WebSocket::Server \
54     AnyEvent::WebSocket::Message common::sense JSON::XS
55 root 1.5
56     Use the same Perl installation for dependency installation, building and
57     running the servers. A module installed for the system Perl might not be
58     available to a Perl installed under C</opt>. C<make install> needs write
59     access to the selected Perl's installation directories; use an appropriate
60     local Perl installation or run that final step with the required privileges.
61    
62 root 1.15 Installation puts C<mcp-fs>, C<mcp-multibroker>, C<mcp-vim>, C<mcp-webbrowser>,
63 root 1.5 C<mcp-ask-user>, C<anyevent-mcp> and C<anyevent-mcp-askpermission> in the
64     selected executable directory. Make that directory available in the
65     environment of your MCP client, or configure absolute executable paths.
66     A desktop application need not have the same C<PATH> as your shell.
67    
68     To try an uninstalled source tree after installing its dependencies, you
69     can run a program with the source library path:
70    
71     perl -Ilib bin/mcp-fs --stdio --name code /home/alice/src/project
72    
73     Do this from the distribution directory. When configuring a client to
74     start such a command, account for the client's working directory or use
75     absolute paths to Perl, C<lib> and the script. An installed executable
76     avoids that extra setup.
77    
78 root 1.19 =head1 PICK A SERVER
79 root 1.15
80 root 1.19 For a local MCP client, configure it to launch the server that provides
81     the tools you want:
82 root 1.15
83 root 1.19 mcp-fs --stdio /home/alice/src/project
84     mcp-vim --stdio
85 root 1.15 mcp-webbrowser --stdio
86 root 1.19 mcp-ask-user --stdio
87    
88     C<--stdio> means the MCP client launches the process. Do not start a
89     separate copy in a terminal. For HTTP clients, use a running server and
90     its C<--print-url> instead, as explained below.
91    
92     C<mcp-fs> reads, searches and changes files and runs commands in a sandbox.
93     The first walkthrough below uses this server.
94    
95     C<mcp-vim> reads and edits live Vim buffers. Install the companion Vim plugin
96     and connect the editor to its listener; see L</Add a live Vim editor> and
97     L<mcp-vim/VIM PLUGIN INSTALLATION>.
98 root 1.15
99 root 1.19 C<mcp-webbrowser> works with explicitly approved browser tabs. Install
100     its companion userscript and connect each tab you want to expose; see
101     L</CONNECTED BROWSER PAGES>.
102 root 1.16
103 root 1.19 C<mcp-ask-user> lets the assistant ask you questions through a local
104     YAD or terminal dialog, or through the client's native form UI; see
105     L</Ask the client's human a question>.
106 root 1.15
107 root 1.20 To offer several servers over one MCP connection, use C<mcp-multibroker>.
108     It combines these servers with each other or with third-party MCP servers,
109     whether started locally over stdio or reached over HTTP. Their tools
110     appear under separate name prefixes; see L</COMBINING SERVERS> and
111     L<mcp-multibroker> for the full command syntax.
112 root 1.15
113 root 1.5 =head1 YOUR FIRST FILESYSTEM SERVER
114    
115     Start with one project and one connection. You do not need a multibroker,
116     a hand-written configuration file or saved permission rules yet.
117    
118     =head2 Choose stdio or HTTP
119    
120     Use B<stdio> when your MCP client runs on the same machine and can launch
121     a server process. Configure the client to start the following command:
122    
123     mcp-fs --stdio --name code /home/alice/src/project
124    
125     The client starts this process and uses its stdin/stdout for MCP.
126     You do not start a second copy in a terminal, and there is no listener
127     URL or HTTP token to configure. Diagnostics go to stderr.
128    
129     Clients that take a command and an argument array need these values:
130    
131     command: mcp-fs
132     arguments: --stdio, --name, code, /home/alice/src/project
133    
134     These describe separate arguments, not one shell command string.
135     Use an absolute executable path if the client cannot find C<mcp-fs>.
136     See L</CLIENT EXAMPLES> for examples of particular clients.
137    
138     Use B<HTTP> when the client connects to an already-running server, or when
139     it cannot launch a local process. Start this in a terminal on the server
140     machine and leave it running:
141    
142     mcp-fs --name code --bind :31741 /home/alice/src/project
143    
144     In another terminal, obtain the matching connection URL:
145    
146     mcp-fs --name code --bind :31741 --print-url
147    
148     The second command prints a credential-bearing URL and exits without
149     opening a listener. Configure that URL in the client. The default address
150     is IPv4 loopback, so this example is reachable from the same machine only.
151     A hosted client needs a suitable tunnel or reachable endpoint; its own
152     C<localhost> is not your computer.
153    
154     Repeat the same name and listener overrides when printing the URL.
155     Both commands must use the same user and configuration directory.
156     Port zero chooses an ephemeral port, which C<--print-url> cannot predict;
157     use an explicit port for this walkthrough.
158    
159     The HTTP server generates and saves its private master secret when needed.
160     You can initialize it explicitly with C<anyevent-mcp init>, but that
161     command is unnecessary when configuration already exists and will refuse
162     to replace it. Keep the printed URL private: possession of its token
163     authenticates a client.
164    
165     =head2 Make a useful request
166    
167     Once your client reports that the server is connected, ask the LLM:
168    
169     Show me the configured workdirs. List the top-level files in the
170 root 1.19 project, then read its README if it has one. Do not modify files
171     or run commands.
172 root 1.5
173     C<workdirs> returns the configured paths, sandbox grants, trusted mounts
174     and runtime paths. Listing names requests C<inspect> permission; reading
175     contents requests C<read> permission. Expect a permission prompt when
176     there is no saved rule allowing the operation.
177    
178     Choose C<Allow once> for the first operation. The worker then runs with
179     the requested sandbox grants. A denial is a tool failure that the LLM
180     should report, rather than an empty file or a disconnected server.
181    
182     For a slightly larger task, ask:
183    
184     Find TODO comments in this project and explain the three that look
185     most useful to address next. Do not modify files or run commands.
186    
187     This can use C<find>, C<grep> and C<read-lines>. You need not write MCP
188     requests yourself. If a client offers its own tool-approval prompt, that
189     is an additional client policy; it does not replace mcp-fs's permissions.
190    
191 root 1.19 =head2 Give the server a purpose
192    
193     To explain why an instance exists, provide a short purpose:
194    
195     mcp-fs --stdio --name memory \
196     --custom-instructions 'Use this server to retrieve and store persistent memory.' \
197     /home/alice/memory
198    
199     For persistent configuration, use C<custom_instructions> in the global
200     configuration's C<[program mcp-fs]> or C<[instance memory]> section. Instance
201     settings override program settings; the command line overrides both.
202     This purpose appears first in the advertised MCP instructions so a model can
203     decide whether to discover the server's tools.
204    
205     Servers using C<AnyEvent::MCP::Server::Simple> also expose the instance
206     purpose and complete operating instructions as a C<meta-instructions> tool
207     description. Calling that tool returns the complete text when a client
208     truncates descriptions. Clients that understand MCP server instructions
209     still receive a short purpose or routing hint at discovery time, followed
210     by an automatic pointer to the full instructions in the tool description.
211    
212 root 1.5 =head2 Understand the workdir
213    
214     The directory passed at startup tells mcp-fs which workdir to expose.
215     It does not grant permission for every operation in that directory.
216     Each operation still requests its action and sandbox grants.
217    
218     With one workdir, tools can omit the C<workdir> argument. With several:
219    
220     mcp-fs --stdio --name code /home/alice/src/project /home/alice/notes
221    
222 root 1.14 tools select one using a persistent positive integer ID, a numeric string
223     or an exact configured/resolved path returned by C<workdirs>. The
224     C<workdirs> and C<resolved_workdirs> objects use these IDs as keys.
225     Relative tool paths are relative to that selection. Permission rules
226     continue to use the configured path, not its numeric ID.
227    
228     IDs are shared across filesystem servers in
229     C<$XDG_CONFIG_HOME/anyevent-mcp/fs-workdir-ids.json>, or under
230     C<$HOME/.config> by default. They identify resolved absolute paths and
231 root 1.15 survive restarts and argument reordering. Startup resolves IDs once and
232     reserves new allocations under the lock. A timer runs immediately and every
233     5.25 days to reread the registry and refresh the server's fixed assignments.
234     Other entries expire after seven days and their IDs may be reused. Restart
235     servers after manually changing the registry.
236 root 1.5
237     C<workdir-read> exposes the selected workdir read-only.
238     C<workdir-write> makes it writable and implies read access.
239     A path in another configured workdir requires all-workdirs authority;
240     a path elsewhere requires suitable home/world or shared-tmp authority.
241     A symlink cannot make an unmounted target appear inside the sandbox.
242    
243     Prefer separate, non-overlapping workdirs. Overlapping mounts have
244     unspecified access effects. See L<mcp-fs/SANDBOX GRANTS> before granting
245     access beyond the selected workdir.
246    
247 root 1.6 =head2 Inspect version-control changes
248    
249     For a Git, SVN, CVS or Mercurial working copy, ask the LLM to use
250     C<vcs-diff> and C<vcs-status>, with C<backend> set to C<git>, C<svn>, C<cvs>
251     or C<hg>. C<workdirs> reports the available clients. These tools accept
252     filenames and construct the command themselves; no shell pipeline or arbitrary
253     VCS options need to be approved.
254    
255     For example:
256    
257     Show the CVS diff for this project, limited to 200 lines.
258     Then show its status, keeping stdout lines matching "File:|Status:".
259    
260     These operations have their own permission actions. They request read access
261 root 1.19 to the selected workdir. CVS additionally requests the C<ssh-agent> grant,
262     which includes network access, the agent socket and C<known_hosts>, but not
263     general home-directory access. Read permission for ordinary file tools does
264     not automatically authorize a VCS operation.
265 root 1.6
266     For arbitrary C<exec> commands, the same output options are available:
267     C<grep> filters stdout using PCRE, C<max_lines> limits matching stdout lines,
268     and C<max_bytes> bounds returned bytes per stream. Prefer these options to a
269     shell wrapper that mixes execution and output processing. Stderr is unfiltered,
270     and exit status still describes the original command.
271    
272     Defaults return at most 2000 stdout lines and 64 KiB per stream. Raw capture
273     has a separate 1 MiB limit per stream. A true C<capture_truncated> means
274     output was omitted before filtering or collection ended on timeout, so absent
275     matches do not prove the omitted output had none. See L<mcp-fs/Command output>
276     for all result flags and limits.
277    
278 root 1.5 =head1 CONFIGURING YOUR SETUP
279    
280     There are three different things to configure: how the client connects,
281     how the server runs, and which operations the user allows. Changing one
282     does not necessarily change the other two.
283    
284     =head2 Where each setting belongs
285 root 1.1
286     =over
287    
288 root 1.5 =item Directories to expose
289    
290     Pass workdirs on the mcp-fs startup command. For a stdio server, that
291     command belongs in the client's server configuration. For an HTTP server,
292     it belongs in the command used to run the service.
293 root 1.1
294 root 1.5 =item Connection transport
295 root 1.1
296 root 1.5 The client launches a command for stdio or connects to a URL for HTTP.
297     C<--stdio> selects the former for mcp-fs and the multibroker.
298 root 1.1
299 root 1.5 =item Listener address, port and tokens
300 root 1.1
301 root 1.5 Use C<[instance NAME]> in the global configuration or command-line
302     C<--bind> and C<--token> overrides.
303 root 1.1
304 root 1.5 =item Trusted mounts and utility paths
305    
306     For mcp-fs, use C<[program NAME]> defaults and C<[instance NAME]>
307     overrides in the global configuration.
308    
309     =item Allowed operations and sandbox grants
310    
311     Use the permission rules file, normally created through approval dialogs.
312     This file is separate from the global configuration.
313    
314     =item Location of permission prompts
315    
316 root 1.12 Use C<--ask helper>, C<--ask tty>, C<--ask yad>, C<--ask auto> or C<--ask mcp>, or set
317 root 1.5 C<PERL_ANYEVENT_MCP_PERMISSION_ASK> in the server's environment.
318    
319     =item Combined server connections
320    
321     Put prefix/server pairs on the multibroker startup command. HTTP child
322     credentials can also use C<[client PREFIX]> in the global configuration.
323 root 1.1
324     =back
325    
326 root 1.5 =head2 One complete named configuration
327    
328     The global file is C<$XDG_CONFIG_HOME/anyevent-mcp/global.ini>, falling
329     back to C<$HOME/.config/anyevent-mcp/global.ini>. Settings are UTF-8
330     C<key = value> lines; values are unquoted. Whole-line C<#> and C<;>
331     comments are allowed. See L<AnyEvent::MCP/GLOBAL CONFIGURATION> for the
332     complete format.
333    
334     Start with the existing file, preserving its C<[global]> secret.
335     If you have no file yet, C<anyevent-mcp init> creates it privately.
336 root 1.19 Add this section:
337 root 1.5
338     [instance code]
339     bind = 127.0.0.1:31741
340    
341     Now start:
342    
343     mcp-fs --name code /home/alice/src/project
344    
345     and retrieve its URL with:
346    
347     mcp-fs --name code --print-url
348    
349     Both use C<[instance code]>. No explicit token is needed: the server
350     derives one from its name and the existing master secret.
351    
352     For this setup:
353    
354     instance settings: [instance code]
355     selected workdir: /home/alice/src/project
356 root 1.8 permission file: ~/.config/anyevent-mcp/rules/fs-code.ini
357 root 1.5 rule-manager profile: fs-code
358    
359     The permission pathname above assumes the default configuration directory.
360     C<anyevent-mcp manage-rules fs-code> opens the graphical rule manager;
361     C<anyevent-mcp edit-rules fs-code> opens the file in your editor.
362    
363 root 1.19 Settings shared by all mcp-fs instances go in C<[program mcp-fs]>.
364     Instance settings override program settings.
365    
366 root 1.5 Keep global configuration and rule files owned by the server user and
367     private, normally mode 0600. C<--config FILE> on C<anyevent-mcp init>
368     selects that command's output file; it does not make the servers use an
369     arbitrary alternate file. Use the same C<HOME>/C<XDG_CONFIG_HOME>
370     environment when running the server and its management commands.
371    
372     =head2 Names, prefixes and profiles
373    
374     C<--name code> selects instance settings, derived HTTP credentials and
375 root 1.8 mcp-fs's C<rules/fs-code.ini>. Without C<--name>, mcp-fs uses C<default>,
376     giving profile C<fs-default>. Two processes with the same program, name and
377 root 1.5 configuration share credentials and rules, even if their workdirs differ.
378    
379     A multibroker prefix, such as C<files>, only routes tools: C<grep> becomes
380     C<files.grep>. It does not rename the child server or select its rules.
381     For example:
382    
383     mcp-multibroker files \
384     'stdio:mcp-fs --name code /home/alice/src/project'
385    
386     The tools are C<files.*>, but the child still uses instance C<code>
387     and rule-manager profile C<fs-code>. The multibroker's own C<--name>
388     selects its upstream listener settings.
389 root 1.1
390 root 1.5 =head2 Configuration changes and restarts
391 root 1.1
392 root 1.5 Command-line listener options override the named global settings.
393     For mcp-fs trusted settings, an instance entry overrides the corresponding
394     program entry; an empty instance mount value suppresses the inherited mount.
395 root 1.1
396 root 1.5 Workdirs, mounts, utility paths, listener settings and tokens are read at
397     startup. Change the file or startup command, then restart the affected
398     server. The multibroker also needs restarting to change its prefix/server
399     pairs; refreshing discovery does not change those pairs.
400    
401     Permission rules are reread on permission checks, so editing them does
402     not require a restart. A client's displayed tool list can still be cached.
403     After restarting a child, refresh tool discovery or reconnect the client
404     as described in L</COMBINING SERVERS>.
405    
406     =head1 PERMISSIONS IN PRACTICE
407    
408     HTTP authentication establishes that the client may connect.
409     Permission checks decide whether a tool may perform an operation.
410     A correct token therefore does not prevent permission prompts.
411    
412     =head2 What the prompt means
413    
414     The prompt describes an action, paths or command, a reason and sandbox
415     grants. For filesystem tools, the actions are:
416    
417 root 1.6 inspect stat, list, find
418     read file-read, read-lines, grep
419     write file-write, file-patch
420     manage path-op
421     exec arbitrary command execution
422     vcs-diff working-copy differences
423     vcs-status working-copy status
424 root 1.5
425     The action and grants are independent. Allowing C<read> does not allow
426     C<write>, even if a worker grant permits both kinds of filesystem access.
427     C<exec> runs arbitrary commands; it is not a classification of supposedly
428     safe command prefixes.
429    
430     Choose allow/deny once, or always. Closing the dialog denies once.
431     An optional denial reason is returned with the error; it is not added to
432 root 1.13 successful tool results. An always choice opens a rule editor. Choose an
433     indefinite lifetime (the default), 900 seconds or 16 hours. Finite lifetimes
434     are stored as C<expires> Unix timestamps. Expired rules disappear on every
435     read; the next ordinary save removes them from disk. Expiry affects future
436     permission checks, not operations already authorized.
437 root 1.5 Filesystem allow rules can select grants and the selected workdir when
438     the authority depends on it. Deny rules can also select an exact affected
439     path. Exec offers persistent command/argv subjects.
440    
441     For exec, C<View stdin...> lets you inspect supplied input without closing
442 root 1.9 the approval dialog. Filesystem and Vim patch tools similarly offer
443     C<View patch...>, including the target file or editor and buffer. Longer
444     text is shown as an explicitly incomplete preview. These are YAD button
445     labels; other interfaces can show the details inline.
446     That input is display-only: an exec allow rule does
447 root 1.5 not constrain future stdin. Allowing an interpreter command can therefore
448     allow a different script on its next invocation.
449    
450     A worker accessing several paths requests their combined sandbox authority
451     once. If the chosen grants are insufficient, it fails before starting.
452    
453     =head2 Save a useful read-only policy
454    
455     After trying individual operations, you might want the LLM to inspect and
456     read the project without asking each time, while keeping changes subject
457 root 1.8 to approval. Put these rules in C<rules/fs-code.ini>, or create equivalent
458 root 1.5 allow rules through the prompt:
459    
460     [rule]
461     decision=allow
462     action=inspect
463     workdir=/home/alice/src/project
464     sandbox-grants=workdir-read
465    
466     [rule]
467     decision=allow
468     action=read
469     workdir=/home/alice/src/project
470     sandbox-grants=workdir-read
471    
472     [rule]
473     decision=deny
474     action=exec
475 root 1.1
476 root 1.5 Use the exact workdir spelling passed at server startup. Absolute startup
477     paths make this easier. If creating the rules file manually, ensure it
478     belongs to the server user and is private before making another request.
479     For the default configuration directory:
480 root 1.1
481 root 1.8 chmod 600 ~/.config/anyevent-mcp/rules/fs-code.ini
482 root 1.1
483 root 1.5 Use the corresponding XDG path when configured. Without matching rules, write and manage operations
484     still ask. The final rule denies command execution outright; omit it if you
485     want execution to ask instead.
486 root 1.1
487 root 1.5 Rules run in order, stopping at the first match. An allow rule matches only
488     when its grants cover the request, including implications.
489     C<workdir-write> implies C<workdir-read>; C<network> remains independent.
490     Action and subject match exactly unless beginning with C<^>, which selects
491     a Perl regular expression. Workdir matching is always exact.
492     An explicit C<ask> rule can override later allow rules.
493    
494     These allow rules authorize sandbox access to the selected workdir.
495     They cannot confine authority to one file or a subtree inside it.
496     Filesystem operations do not offer persistent path subjects.
497     An exact C<path> matcher is available for deny rules only.
498     Trusted runtime and configured mounts remain baseline access independently
499     of these grants. See L<mcp-fs/TRUSTED CONFIGURATION>.
500    
501     =head2 Change or remove saved rules
502    
503     Use:
504    
505     anyevent-mcp manage-rules fs-code
506     anyevent-mcp edit-rules fs-code
507    
508     The first command lets you delete and reorder rules in YAD.
509     The second uses C<$VISUAL>, C<$EDITOR>, C<sensible-editor> or C<vi>.
510     An earlier deny or ask rule can explain why adding a later allow rule
511     does not change the result.
512    
513     For a custom application with another rule pathname, use:
514    
515     anyevent-mcp manage-rules-file /path/to/rules.ini
516     anyevent-mcp edit-rules-file /path/to/rules.ini
517    
518     A failed attempt to save a permanent rule is an error, not a successful
519     permanent approval. The file must remain private and owned by the server
520     user. For full syntax and programming interfaces, see
521     L<AnyEvent::MCP::Server::Permissions>.
522    
523     =head2 Choose where to ask
524    
525     The default C<helper> mode runs C<anyevent-mcp-askpermission> on the server
526     machine. It tries YAD, then C</dev/tty>, then denies if neither can be used.
527     The helper inherits the server's display environment.
528 root 1.12 C<--ask tty> and C<--ask yad> instead force the built-in terminal or YAD
529     interface. They ignore custom helper settings and never try another
530     interface. These modes work for permission prompts and ordinary forms,
531     including forms handled by a multibroker.
532 root 1.5 C<PERL_ANYEVENT_MCP_PERMISSION_HELPER> selects a different executable.
533    
534     For a modern client supporting MCP form elicitation, you can instead use:
535    
536     mcp-fs --stdio --name code --ask auto /home/alice/src/project
537    
538     C<auto> uses the client's form support when advertised for that request,
539     otherwise the local helper. C<mcp> requires that support and fails when
540     unavailable. It does not silently fall back. Use client-side permission
541     approval only when that client is a trusted authority to grant access.
542    
543     To set the default for servers using the shared permission engine:
544    
545     PERL_ANYEVENT_MCP_PERMISSION_ASK=auto \
546     mcp-fs --stdio --name code /home/alice/src/project
547    
548     An explicit application C<ask> setting or C<--ask> overrides the environment.
549     For spawned stdio children, C<mcp-multibroker --ask auto> passes this
550     default to them. It cannot change the environment of an independently
551     running HTTP server.
552    
553 root 1.7 The multibroker can handle form elicitation locally for both stdio and HTTP
554     children. C<--ask helper> selects local dialogs even if the upstream client
555     advertises native forms; C<--ask mcp> forwards forms upstream, and C<auto>
556     uses native forms when advertised. If a client claims support but silently
557     declines questions, use C<helper>. A decline never causes a fallback prompt.
558    
559     Standalone C<mcp-ask-user> also supports these modes and defaults to the
560     local helper. A question is different from an approval: answering it does
561     not grant a filesystem worker any authority.
562 root 1.5
563     =head1 COMBINING SERVERS
564    
565 root 1.20 Once the first connection works, C<mcp-multibroker> lets you give the
566     client one connection for several MCP servers. It works with the servers
567     in this distribution and with third-party MCP servers, including ones
568     written in other languages. Each downstream server can be a local
569     subprocess communicating over stdio or an existing HTTP endpoint; you
570     can mix both in one broker. The broker discovers their tools and
571     forwards calls to the appropriate server without changing how that
572     server implements its tools.
573    
574     For example, combine two filesystem instances:
575 root 1.5
576     mcp-multibroker --name tools --bind :31740 \
577     code 'stdio:mcp-fs --name code /home/alice/src/project' \
578     notes 'stdio:mcp-fs --name notes /home/alice/notes'
579    
580     Quote each C<stdio:> shell command as one argument.
581     The broker supplies the child's stdio environment and starts ordinary
582     children lazily, on first use. The explicit child names give them separate
583     permission profiles C<fs-code> and C<fs-notes>.
584    
585     Obtain the upstream HTTP URL with:
586    
587     mcp-multibroker --name tools --bind :31740 --print-url
588    
589     Configure this URL in place of the client's old direct connection.
590     The client can now see C<code.grep>, C<code.read-lines>, C<notes.find>
591     and other prefixed tools. It does not need a separate connection to each
592     child.
593    
594     For a client launching the multibroker locally, configure:
595    
596     mcp-multibroker --stdio --name tools \
597     code 'stdio:mcp-fs --name code /home/alice/src/project' \
598     notes 'stdio:mcp-fs --name notes /home/alice/notes'
599    
600     C<--stdio> selects the upstream connection. The child commands still use
601     C<stdio:>; that selects each downstream connection independently.
602     No upstream HTTP URL is needed in this case.
603    
604 root 1.20 The same setup can include Vim, browser pages, a third-party stdio
605     server or a remote HTTP service. See L</Add an HTTP child> for an
606     example mixing local and remote servers, and L<mcp-multibroker/DOWNSTREAM
607     SERVERS> for the complete syntax, including direct argv execution,
608     credentials and per-child options.
609    
610 root 1.5 =head2 Discover and refresh tools
611    
612     Ask the LLM:
613    
614     Call discover-brokers and list-tools, then show me which servers
615     are available and what each is for.
616    
617 root 1.17 C<discover-brokers> returns advertised instructions (which may be short),
618     no instructions, or an error for each configured server.
619     C<list-tools> requests current tool definitions, including any prefixed
620     C<meta-instructions> tools and their full instruction descriptions;
621 root 1.5 unreachable servers are omitted. A reachable server can still fail later.
622    
623     If the client still has an old direct tool list, C<call-tool> can invoke
624     an exact prefixed name found by C<list-tools>. Refresh the client's MCP
625     connection if it continues to hide newly available tools.
626    
627 root 1.15 Discovery queries configured servers and currently registered reverse
628     connections. Changing the static downstream command still requires a restart.
629    
630     =head2 Let a server connect to the multibroker
631    
632     To add independently started servers without editing the multibroker command,
633     keep its HTTP/extension listener active alongside stdio:
634    
635     mcp-multibroker --stdio --listen --bind 127.0.0.1:31740
636     mcp-multibroker --bind 127.0.0.1:31740 --print-url
637    
638     Append an alias to the returned credential-bearing URL:
639    
640     mcp-fs --connect http://127.0.0.1:31740/TOKEN/files /home/alice/project
641    
642     The filesystem server initiates the TCP connection but remains the MCP server.
643     The multibroker authenticates the same token used for HTTP, registers the
644     alias and discovers the tools. A configured or connected alias cannot be
645     replaced. After disconnecting, the server retries once per second for sixty
646     attempts. Pending calls fail and are never replayed. Remote registration does
647     not grant the multibroker spawned-child shutdown authority.
648    
649     The hello is a raw JSON line, followed by ordinary MCP JSONL on the same socket;
650     the HTTP-shaped URL is an address and credential, not an HTTP request.
651     The bundled connector supports plain C<http://> endpoints. An HTTP listener is
652     already active by default when the upstream connection is HTTP.
653 root 1.5
654     =head2 Add an HTTP child
655    
656 root 1.20 A broker can mix spawned stdio servers and existing HTTP endpoints,
657     including independently implemented third-party servers:
658 root 1.5
659     mcp-multibroker --stdio \
660     code 'stdio:mcp-fs --name code /home/alice/src/project' \
661     remote https://example.org/mcp/ --bearer TOKEN
662    
663     C<--bearer> immediately after the HTTP pair belongs to that child.
664     C<--token> before all pairs configures the multibroker's own HTTP listener.
665     They authenticate different connections.
666    
667     To avoid putting a child's bearer token in the startup command, add:
668    
669     [client remote]
670     bearer = TOKEN
671     timeout = 300
672    
673     to the private global configuration, and omit C<--bearer> from the command.
674     The prefix C<remote> selects these client defaults. The command-line URL
675     still chooses the endpoint. Use the actual credential accepted by that
676     server, not the literal placeholder C<TOKEN>.
677    
678     A token already present in a child's URL needs no separate bearer option.
679     The bundled servers use static URL-safe tokens; they do not validate
680     OAuth access tokens or implement HTTP Basic authentication.
681     Use TLS or an appropriate tunnel when credentials cross untrusted networks.
682    
683     The multibroker does not put every child inside the mcp-fs sandbox.
684     Each process or remote service has its own authority and enforcement.
685    
686     =head2 Add a live Vim editor
687    
688     Install the Vim plugin using L<mcp-vim/VIM PLUGIN INSTALLATION>. It is
689     included in the source distribution but is not installed by Perl's
690     C<make install>.
691    
692 root 1.19 Without a multibroker, configure the MCP client to launch:
693    
694     mcp-vim --stdio --name editor
695    
696     Even in stdio mode, mcp-vim listens separately for editor connections.
697     If using a multibroker, start its child eagerly so Vim can connect
698     before the first MCP tool call:
699 root 1.5
700     mcp-multibroker --stdio \
701     code 'stdio:mcp-fs --name code /home/alice/src/project' \
702     vim 'stdio:mcp-vim --name editor' --eager
703    
704 root 1.19 In another terminal, obtain the editor broker's URL prefix:
705 root 1.5
706     mcp-vim --name editor --print-url
707    
708     Append the desired target name in Vim:
709    
710     :Mcp http://HOST:PORT/TOKEN/my-editor
711    
712     Use the actual printed prefix in place of C<http://HOST:PORT/TOKEN/>.
713 root 1.19 Ask the LLM to call C<targets>, then C<state> before reading or editing
714     buffers (C<vim.targets> and C<vim.state> through the multibroker).
715     These tools see live, possibly unsaved buffers. Edits require a current
716     changedtick and do not save files to disk.
717 root 1.5
718 root 1.13 To pass arguments directly, use C<PREFIX --- PROGRAM ARG... --->:
719    
720     mcp-multibroker --stdio \
721     vim --- mcp-vim --name editor --bind :: --- --eager \
722     code --- mcp-fs --name code '/home/alice/project with spaces' ---
723    
724     Only the invoking shell processes quoting. The broker passes all arguments
725     between the delimiters unchanged, including empty arguments and child options.
726     Use C<stdio:COMMAND> for shell syntax or a literal C<---> child argument.
727     An empty command or missing closing delimiter is an error.
728    
729     C<--eager> belongs immediately after its stdio URL or closing C<--->.
730 root 1.5 An eager connection failure is logged; the broker does not continuously
731     restart the child. Later tool use can try connecting again.
732    
733     =head2 Ask the client's human a question
734    
735 root 1.19 To let the assistant ask you questions, configure its MCP client to launch:
736    
737     mcp-ask-user --stdio
738    
739     Or add the question server to a multibroker:
740 root 1.5
741     mcp-multibroker --stdio \
742     code 'stdio:mcp-fs --name code /home/alice/src/project' \
743     questions 'stdio:mcp-ask-user'
744    
745 root 1.19 The LLM can call C<ask-user> (C<questions.ask-user> through the multibroker)
746     with a question, up to three suggested answers and room for free text.
747     For example, tell it to use that tool if choosing among several possible
748     tasks needs your input. For several fields or other value types,
749     C<ask-form> (C<questions.ask-form> through the multibroker) accepts
750 root 1.10 C<message> and C<requestedSchema> directly and returns the standard
751     elicitation response. Both tools use the same configured presentation mode.
752 root 1.5 Decline and cancel are distinct results; neither supplies an answer.
753    
754 root 1.7 By default the multibroker displays questions locally, using YAD or a terminal.
755     Add C<--ask mcp> before the broker entries to use the client's native forms,
756     or C<--ask auto> to select by advertised capability. This also works with
757     C<mcp-ask-user> started separately: give that server C<--ask mcp> so it
758     delegates presentation to its connecting multibroker.
759    
760     C<anyevent-mcp-form-elicitation> is the standalone form renderer. It reads standard MCP
761     form parameters as UTF-8 JSON on stdin and writes an accept/decline/cancel
762     response as JSON on stdout. C<PERL_ANYEVENT_MCP_ELICITATION_HELPER> selects
763     a replacement executable. See L<anyevent-mcp-form-elicitation> for supported fields
764     and L<mcp-ask-user> for question arguments and result fields.
765 root 1.5
766 root 1.19 =head1 CONNECTED BROWSER PAGES
767    
768     C<mcp-webbrowser> is the browser-page counterpart to C<mcp-vim>. It exposes
769     only tabs explicitly allowed by the browser user. Configure your MCP client
770     to launch:
771    
772     mcp-webbrowser --stdio
773    
774     The broker keeps its own HTTP/WebSocket listener active even in stdio mode;
775     the userscript connects to that listener, not to MCP's stdio stream.
776     In a separate terminal, obtain its URL:
777    
778     mcp-webbrowser --print-url
779    
780     Use the same instance name and configuration as the broker. Keep this
781     credential-bearing URL private.
782     Install the companion userscript from
783     C<webbrowser/mcp-webbrowser.user.js> in the source distribution or from
784     L<https://dist.schmorp.de/mcp-webbrowser/1/mcp-webbrowser.user.js>.
785     Chromium with ScriptCat has been tested. On a tab you want to expose,
786     choose B<Allow MCP access to this tab> from the userscript menu and enter
787     the printed URL when prompted. Other tabs remain unexposed.
788    
789     The broker supplies C<pages>, C<execute> and C<add-element> tools, permission
790     prompts, cancellation and execution timeouts. See
791     L<mcp-webbrowser/USERSCRIPT INSTALLATION AND USE> for setup, compatibility
792     and the current ScriptCat discarded-tab limitation.
793    
794     If the multibroker launches the browser broker, keep that child running
795     from startup so browser tabs can connect:
796    
797     mcp-multibroker --stdio browser --- mcp-webbrowser --- --eager
798    
799 root 1.5 =head1 HTTP TOKENS AND SERVER IDENTITY
800    
801     For the ordinary bundled HTTP endpoints, a client can present an accepted
802     token in either of these ways:
803    
804     POST /TOKEN/
805     POST / Authorization: Bearer TOKEN
806    
807     URL tokens are path components, not browser cookies.
808     For another configured endpoint, C</TOKEN> prefixes that endpoint path.
809     All accepted tokens authenticate the same operations; they are not separate
810     users or permission levels. Permissions still govern the tool operation.
811    
812     By default, the master secret and server name determine one stable token
813     and a port in 16384..32767. Changing a server's name changes its derived
814     credentials and default port. Changing or losing the master secret changes
815     all derived credentials. Keep an existing C<[global]> secret when editing
816     other configuration.
817    
818     To configure explicit tokens:
819    
820     [instance code]
821     tokens = first-secret,second-secret
822 root 1.1
823 root 1.5 Replace those placeholders with actual unguessable URL-safe tokens.
824     Repeated C<--token> options replace the whole configured list and the
825     derived default. The first token appears in C<--print-url>; all are accepted.
826     mcp-vim also accepts its token set for Vim and browser WebSocket connections.
827    
828     If C<--print-url> disagrees with the client's URL, compare the name,
829     command-line overrides, user and configuration environment with the running
830     process. The command resolves configuration; it does not ask the running
831     server which URL it uses. A changed file needs a server restart.
832    
833     An Origin allowlist restricts browser origins; it does not authenticate
834     clients. A CORS preflight can succeed without a token, while the MCP POST
835     still requires one. See L<AnyEvent::MCP::Server::HTTP/AUTHENTICATION> for
836     the low-level server interface.
837    
838     =head1 CLIENT EXAMPLES
839    
840     Client settings and command syntax evolve independently of this distribution.
841     These examples show the connection choices; consult the linked client
842     documentation if its interface differs. Replace illustrative paths and
843     credentials with your own.
844 root 1.1
845 root 1.5 =head2 OpenAI Codex CLI
846 root 1.1
847 root 1.5 For the first direct filesystem connection:
848 root 1.1
849 root 1.5 codex mcp add code -- \
850     mcp-fs --stdio --name code /home/alice/src/project
851 root 1.1 codex mcp list
852    
853 root 1.5 For a multibroker connection:
854    
855     codex mcp add mytools -- \
856     mcp-multibroker --stdio \
857     code 'stdio:mcp-fs --name code /home/alice/src/project'
858    
859 root 1.1 Use C</mcp> within Codex to inspect connections.
860     See L<Codex MCP documentation|https://learn.chatgpt.com/docs/extend/mcp>.
861    
862 root 1.5 =head2 Anthropic Claude Code
863 root 1.1
864 root 1.5 For the direct connection:
865 root 1.1
866 root 1.5 claude mcp add --transport stdio --scope user code -- \
867     mcp-fs --stdio --name code /home/alice/src/project
868 root 1.1 claude mcp list
869    
870 root 1.5 Replace the launched command with the multibroker command above when you
871     want several servers. Use C</mcp> for connection status. See
872 root 1.1 L<Claude Code MCP documentation|https://code.claude.com/docs/en/mcp>.
873    
874 root 1.5 =head2 Google Gemini CLI
875 root 1.1
876 root 1.5 Merge a direct server entry into C<~/.gemini/settings.json>:
877 root 1.1
878     {
879     "mcpServers": {
880 root 1.5 "code": {
881     "command": "mcp-fs",
882 root 1.1 "args": [
883 root 1.5 "--stdio", "--name", "code", "/home/alice/src/project"
884     ]
885 root 1.1 }
886     }
887     }
888    
889 root 1.5 For a combined connection, use C<mcp-multibroker> as the command and its
890     C<--stdio> and prefix/server pairs as the argument array.
891     Use C</mcp> to inspect the connection. See
892     L<Gemini CLI MCP documentation|https://geminicli.com/docs/tools/mcp-server/>.
893    
894     =head2 Hosted clients, including ChatGPT web
895    
896     A hosted client cannot spawn your local stdio command or reach your
897     machine's loopback address directly. Run the server or multibroker in HTTP
898     mode and configure a supported tunnel or reachable endpoint.
899    
900     For ChatGPT, use its custom MCP setup and, for a private server, an
901     appropriately configured Secure MCP Tunnel. Availability depends on the
902     client's plan, workspace and feature permissions. See
903     L<ChatGPT custom MCP servers|https://developers.openai.com/api/docs/guides/custom-mcp-server>
904     and L<Secure MCP Tunnel|https://developers.openai.com/blog/connect-private-mcp-servers-to-openai-products>.
905    
906     =head1 TROUBLESHOOTING
907    
908     =head2 The server does not start
909    
910     Read stderr or the client's server log. Missing Perl modules, a missing
911     workdir, unsuitable utilities or an unavailable bubblewrap executable can
912     fail startup. Confirm that the client launches the same executable and
913     arguments you intended, with the expected C<PATH> and Perl installation.
914    
915     For a local sandbox check, run from the project directory:
916    
917     mcp-fs --exec-cmd workdir-read -- ls
918 root 1.1
919 root 1.5 This runs C<ls> with the named grants and trusted baseline mounts, without
920     MCP or saved permission rules. A failure here can identify a bubblewrap
921     or runtime problem. It does not test the client connection or approval UI.
922     C<--sandbox none> disables isolation and changes worker authority; it is
923     not a fix that preserves the same permission boundary.
924 root 1.1
925 root 1.5 =head2 The client cannot connect
926    
927     For stdio, configure a command the client launches, rather than a URL.
928     A separately running stdio process is not the client's connection.
929     Do not put banners or diagnostics on stdout.
930    
931     For HTTP, leave the server running and check its address and port.
932     C<--print-url> exits without starting it. Loopback binds accept local
933     connections only; hosted or remote clients need the appropriate route or
934     tunnel. An occupied port causes a listener error, so check the server log.
935    
936     =head2 Authentication fails
937    
938     Obtain the URL with the same name, bind/token overrides and configuration
939     environment as the running process. Use the complete path, including any
940     required trailing slash. A clean URL needs an accepted bearer token.
941    
942     A multibroker child credential is not necessarily the upstream listener's
943     credential. C<--bearer> after a child pair and C<--token> before the pairs
944     configure different sides of the connection.
945    
946     If the server warns that it cannot save the master secret, another process
947     may derive a different token. Fix ownership and write access to the private
948     configuration. Do not replace an existing secret simply to add a setting.
949    
950     =head2 Connected, but there are no tools
951    
952     Inspect the server's stderr for omitted utilities. mcp-fs's C<workdirs>
953     tool reports configuration even when a utility-dependent tool is absent.
954     For a multibroker, call C<discover-brokers> to see individual connection
955     errors, then C<list-tools> to refresh definitions.
956    
957     A third-party child might require initialization or features this client
958     implementation does not support. See L<AnyEvent::MCP::Client> and its
959     transport documentation for limitations.
960    
961     =head2 There is no approval dialog
962    
963     First check whether the tool was denied by a saved rule or is waiting for
964     the client's own approval. An allowed operation needs no server prompt.
965    
966     The default helper runs on the server machine. A background service may
967     have neither a usable display nor C</dev/tty>, even though your interactive
968     shell has both. Supply the appropriate display environment, a usable helper,
969     or C<--ask auto> with a modern client supporting form elicitation.
970     C<--ask mcp> reports an error if that support is absent.
971    
972     Setting an asking mode cannot make an unsupported client display a form.
973     Check stderr and the tool error instead of assuming a missing dialog is
974     an approval.
975    
976     =head2 It asks again after I chose allow
977 root 1.1
978 root 1.5 Allow-once covers one tool invocation, including its permission retries.
979     The next invocation asks again. Use allow-always to save a rule.
980 root 1.1
981 root 1.5 Inspect the saved rule's action, workdir and grants. Listing names and
982     reading contents are different actions. A rule for one exact workdir
983     spelling will not match a differently spelled startup argument.
984     A request for extra authority, such as networking, does not match a
985     workdir-read-only allow rule. Earlier ask or deny rules take precedence.
986 root 1.1
987 root 1.5 Confirm that the prompt's permanent rule was successfully saved and that
988     you are editing the rules for the actual child name, not merely its
989     multibroker prefix.
990 root 1.1
991 root 1.5 =head2 The worker cannot see a directory or executable
992 root 1.1
993 root 1.5 The worker sees granted mounts and trusted baseline mounts, not everything
994     the server process can see. Check C<workdirs> for the selected path, mounts
995     and runtime paths. A symlink target outside those mounts is unavailable.
996 root 1.1
997 root 1.19 The ordinary sandbox runtime includes C</usr>, C</bin> and system libraries,
998     but not C</opt>. For tools or libraries under C</opt>, add this to
999     C<[program mcp-fs]> in the private global configuration:
1000    
1001     mount.opt = ro:/opt
1002    
1003     This assumes C</opt> exists. Restart mcp-fs after changing trusted mounts.
1004     If your worker Perl is C</opt/bin/perl>, you can also set
1005     C<executable.perl = /opt/bin/perl> in that program section. Supply the
1006     actual executable path: selecting it does not itself mount the
1007     executable or its dependencies inside the worker.
1008    
1009 root 1.5 A trusted mount supplies baseline access to every worker using it; a
1010     writable mount likewise supplies baseline write authority.
1011 root 1.1
1012 root 1.5 An arbitrary command might also need its user's configuration or repository
1013     credentials under HOME, or network access. Request the corresponding grants
1014     when needed; do not assume C<workdir-read> includes them.
1015 root 1.7 For example, CVS over SSH can use C<workdir-read> and C<ssh-agent>.
1016     The latter includes network access, the agent socket and C<~/.ssh/known_hosts>,
1017     without exposing private key files or the rest of HOME. The broker must
1018     inherit C<SSH_AUTH_SOCK> from your environment. User-configured helpers
1019     outside the runtime mounts need an explicit trusted mount.
1020     An explicit exec grant array replaces the default rather than adding to it.
1021 root 1.1
1022 root 1.5 =head2 My configuration change seems to be ignored
1023 root 1.1
1024 root 1.5 Check which file and section the process actually selects. Global settings
1025     use the server user's C<HOME>/C<XDG_CONFIG_HOME>. Instance names, program
1026     basenames and multibroker prefixes serve different purposes.
1027 root 1.1
1028 root 1.5 Restart after changing startup settings, mounts or utilities. Permission
1029     rules need no restart, but their order still matters. Refresh discovery
1030     after a child restart; reconnect a client that retains an old tool list.
1031     C<--print-url> reads the current configuration, which can differ from an
1032     older running process.
1033 root 1.1
1034 root 1.5 =head2 The command failed, but the MCP request succeeded
1035 root 1.1
1036 root 1.5 C<exec> reports exit status, signal or timeout as a normal tool result.
1037     A successful MCP exchange is not a successful Unix command.
1038     Conversely, a transport failure does not prove a command did nothing:
1039     it may have completed before the connection was lost. Calls are not
1040     automatically replayed after a transport failure.
1041 root 1.1
1042 root 1.11 =head1 TESTING
1043    
1044     The default test level is 0. It checks protocol behaviour, permissions,
1045     validation and ordinary process operation, including worker cancellation
1046     and reaping. Watchdogs allow slow machines time to finish; they do not
1047     make successful tests wait for the whole timeout.
1048    
1049     prove -Ilib t
1050    
1051     Set C<PERL_ANYEVENT_MCP_TESTS> to 1 to include the extended tests:
1052    
1053     PERL_ANYEVENT_MCP_TESTS=1 prove -Ilib t
1054    
1055     Level 1 adds GNU find/grep/sed/patch operations, real Vim scripting, browser
1056     transfer integration, short idle-lifetime tests, a helper descendant holding
1057     a pipe open, and tests which deliberately wait for a command timeout or
1058     cancel a form helper across several processes. Run this level before releases.
1059     Values greater than 1 currently select the same tests as level 1.
1060    
1061     Missing GNU utilities or required Vim functions cause explicit skips even
1062     at level 1. The permission and form UI tests use a YAD stand-in: neither
1063     level requires YAD, X11 or an interactive display. The filesystem tests
1064     use a bubblewrap stand-in and check arguments and worker behaviour; they
1065     do not test kernel isolation. The browser tests use simulated peers.
1066    
1067 root 1.5 =head1 WHERE TO GO NEXT
1068 root 1.1
1069 root 1.5 For available tools and server-specific options:
1070 root 1.1
1071     perldoc mcp-fs
1072     perldoc mcp-multibroker
1073 root 1.5 perldoc mcp-vim
1074     perldoc mcp-ask-user
1075 root 1.1 perldoc anyevent-mcp
1076    
1077 root 1.5 For a complete first Perl server, options, replies, permission checks and
1078     asynchronous work, see L<AnyEvent::MCP::Server::Simple/TUTORIAL>.
1079     For the module map and shared configuration reference, see L<AnyEvent::MCP>.
1080     For permission rule details, see L<AnyEvent::MCP::Server::Permissions>.
1081 root 1.1
1082     =head1 SEE ALSO
1083    
1084     L<AnyEvent::MCP>, L<AnyEvent::MCP::Server::Simple>,
1085 root 1.5 L<mcp-fs>, L<mcp-multibroker>, L<mcp-vim>, L<mcp-ask-user>,
1086     L<AnyEvent::MCP::Server::Permissions>
1087 root 1.1
1088     =cut