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