ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MCP/lib/AnyEvent/MCP/Intro.pod
Revision: 1.6
Committed: Wed Oct 14 10:09:36 2026 UTC (2 weeks, 6 days ago) by root
Branch: MAIN
Changes since 1.5: +37 -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     cpan AnyEvent AnyEvent::HTTP common::sense JSON::XS
54    
55     Use the same Perl installation for dependency installation, building and
56     running the servers. A module installed for the system Perl might not be
57     available to a Perl installed under C</opt>. C<make install> needs write
58     access to the selected Perl's installation directories; use an appropriate
59     local Perl installation or run that final step with the required privileges.
60    
61     Installation puts C<mcp-fs>, C<mcp-multibroker>, C<mcp-vim>,
62     C<mcp-ask-user>, C<anyevent-mcp> and C<anyevent-mcp-askpermission> in the
63     selected executable directory. Make that directory available in the
64     environment of your MCP client, or configure absolute executable paths.
65     A desktop application need not have the same C<PATH> as your shell.
66    
67     To try an uninstalled source tree after installing its dependencies, you
68     can run a program with the source library path:
69    
70     perl -Ilib bin/mcp-fs --stdio --name code /home/alice/src/project
71    
72     Do this from the distribution directory. When configuring a client to
73     start such a command, account for the client's working directory or use
74     absolute paths to Perl, C<lib> and the script. An installed executable
75     avoids that extra setup.
76    
77     =head1 YOUR FIRST FILESYSTEM SERVER
78    
79     Start with one project and one connection. You do not need a multibroker,
80     a hand-written configuration file or saved permission rules yet.
81    
82     =head2 Choose stdio or HTTP
83    
84     Use B<stdio> when your MCP client runs on the same machine and can launch
85     a server process. Configure the client to start the following command:
86    
87     mcp-fs --stdio --name code /home/alice/src/project
88    
89     The client starts this process and uses its stdin/stdout for MCP.
90     You do not start a second copy in a terminal, and there is no listener
91     URL or HTTP token to configure. Diagnostics go to stderr.
92    
93     Clients that take a command and an argument array need these values:
94    
95     command: mcp-fs
96     arguments: --stdio, --name, code, /home/alice/src/project
97    
98     These describe separate arguments, not one shell command string.
99     Use an absolute executable path if the client cannot find C<mcp-fs>.
100     See L</CLIENT EXAMPLES> for examples of particular clients.
101    
102     Use B<HTTP> when the client connects to an already-running server, or when
103     it cannot launch a local process. Start this in a terminal on the server
104     machine and leave it running:
105    
106     mcp-fs --name code --bind :31741 /home/alice/src/project
107    
108     In another terminal, obtain the matching connection URL:
109    
110     mcp-fs --name code --bind :31741 --print-url
111    
112     The second command prints a credential-bearing URL and exits without
113     opening a listener. Configure that URL in the client. The default address
114     is IPv4 loopback, so this example is reachable from the same machine only.
115     A hosted client needs a suitable tunnel or reachable endpoint; its own
116     C<localhost> is not your computer.
117    
118     Repeat the same name and listener overrides when printing the URL.
119     Both commands must use the same user and configuration directory.
120     Port zero chooses an ephemeral port, which C<--print-url> cannot predict;
121     use an explicit port for this walkthrough.
122    
123     The HTTP server generates and saves its private master secret when needed.
124     You can initialize it explicitly with C<anyevent-mcp init>, but that
125     command is unnecessary when configuration already exists and will refuse
126     to replace it. Keep the printed URL private: possession of its token
127     authenticates a client.
128    
129     =head2 Make a useful request
130    
131     Once your client reports that the server is connected, ask the LLM:
132    
133     Show me the configured workdirs. List the top-level files in the
134     project, then read its README. Do not modify files or run commands.
135    
136     C<workdirs> returns the configured paths, sandbox grants, trusted mounts
137     and runtime paths. Listing names requests C<inspect> permission; reading
138     contents requests C<read> permission. Expect a permission prompt when
139     there is no saved rule allowing the operation.
140    
141     Choose C<Allow once> for the first operation. The worker then runs with
142     the requested sandbox grants. A denial is a tool failure that the LLM
143     should report, rather than an empty file or a disconnected server.
144    
145     For a slightly larger task, ask:
146    
147     Find TODO comments in this project and explain the three that look
148     most useful to address next. Do not modify files or run commands.
149    
150     This can use C<find>, C<grep> and C<read-lines>. You need not write MCP
151     requests yourself. If a client offers its own tool-approval prompt, that
152     is an additional client policy; it does not replace mcp-fs's permissions.
153    
154     =head2 Understand the workdir
155    
156     The directory passed at startup tells mcp-fs which workdir to expose.
157     It does not grant permission for every operation in that directory.
158     Each operation still requests its action and sandbox grants.
159    
160     With one workdir, tools can omit the C<workdir> argument. With several:
161    
162     mcp-fs --stdio --name code /home/alice/src/project /home/alice/notes
163    
164     tools select one using a zero-based index, a numeric string or an exact
165     configured/resolved path returned by C<workdirs>. Relative tool paths
166     are relative to that selection. The tool index C<0> is not a name you
167     put in permission rules.
168    
169     C<workdir-read> exposes the selected workdir read-only.
170     C<workdir-write> makes it writable and implies read access.
171     A path in another configured workdir requires all-workdirs authority;
172     a path elsewhere requires suitable home/world or shared-tmp authority.
173     A symlink cannot make an unmounted target appear inside the sandbox.
174    
175     Prefer separate, non-overlapping workdirs. Overlapping mounts have
176     unspecified access effects. See L<mcp-fs/SANDBOX GRANTS> before granting
177     access beyond the selected workdir.
178    
179 root 1.6 =head2 Inspect version-control changes
180    
181     For a Git, SVN, CVS or Mercurial working copy, ask the LLM to use
182     C<vcs-diff> and C<vcs-status>, with C<backend> set to C<git>, C<svn>, C<cvs>
183     or C<hg>. C<workdirs> reports the available clients. These tools accept
184     filenames and construct the command themselves; no shell pipeline or arbitrary
185     VCS options need to be approved.
186    
187     For example:
188    
189     Show the CVS diff for this project, limited to 200 lines.
190     Then show its status, keeping stdout lines matching "File:|Status:".
191    
192     These operations have their own permission actions. They request read access
193     to the selected workdir and home configuration; CVS also requests network
194     access automatically. Read permission for ordinary file tools does not
195     automatically authorize a VCS operation.
196    
197     For arbitrary C<exec> commands, the same output options are available:
198     C<grep> filters stdout using PCRE, C<max_lines> limits matching stdout lines,
199     and C<max_bytes> bounds returned bytes per stream. Prefer these options to a
200     shell wrapper that mixes execution and output processing. Stderr is unfiltered,
201     and exit status still describes the original command.
202    
203     Defaults return at most 2000 stdout lines and 64 KiB per stream. Raw capture
204     has a separate 1 MiB limit per stream. A true C<capture_truncated> means
205     output was omitted before filtering or collection ended on timeout, so absent
206     matches do not prove the omitted output had none. See L<mcp-fs/Command output>
207     for all result flags and limits.
208    
209 root 1.5 =head1 CONFIGURING YOUR SETUP
210    
211     There are three different things to configure: how the client connects,
212     how the server runs, and which operations the user allows. Changing one
213     does not necessarily change the other two.
214    
215     =head2 Where each setting belongs
216 root 1.1
217     =over
218    
219 root 1.5 =item Directories to expose
220    
221     Pass workdirs on the mcp-fs startup command. For a stdio server, that
222     command belongs in the client's server configuration. For an HTTP server,
223     it belongs in the command used to run the service.
224 root 1.1
225 root 1.5 =item Connection transport
226 root 1.1
227 root 1.5 The client launches a command for stdio or connects to a URL for HTTP.
228     C<--stdio> selects the former for mcp-fs and the multibroker.
229 root 1.1
230 root 1.5 =item Listener address, port and tokens
231 root 1.1
232 root 1.5 Use C<[instance NAME]> in the global configuration or command-line
233     C<--bind> and C<--token> overrides.
234 root 1.1
235 root 1.5 =item Trusted mounts and utility paths
236    
237     For mcp-fs, use C<[program NAME]> defaults and C<[instance NAME]>
238     overrides in the global configuration.
239    
240     =item Allowed operations and sandbox grants
241    
242     Use the permission rules file, normally created through approval dialogs.
243     This file is separate from the global configuration.
244    
245     =item Location of permission prompts
246    
247     Use C<--ask helper>, C<--ask auto> or C<--ask mcp>, or set
248     C<PERL_ANYEVENT_MCP_PERMISSION_ASK> in the server's environment.
249    
250     =item Combined server connections
251    
252     Put prefix/server pairs on the multibroker startup command. HTTP child
253     credentials can also use C<[client PREFIX]> in the global configuration.
254 root 1.1
255     =back
256    
257 root 1.5 =head2 One complete named configuration
258    
259     The global file is C<$XDG_CONFIG_HOME/anyevent-mcp/global.ini>, falling
260     back to C<$HOME/.config/anyevent-mcp/global.ini>. Settings are UTF-8
261     C<key = value> lines; values are unquoted. Whole-line C<#> and C<;>
262     comments are allowed. See L<AnyEvent::MCP/GLOBAL CONFIGURATION> for the
263     complete format.
264    
265     Start with the existing file, preserving its C<[global]> secret.
266     If you have no file yet, C<anyevent-mcp init> creates it privately.
267     Add the following sections:
268    
269     [program mcp-fs]
270     mount.opt = ro:/opt
271    
272     [instance code]
273     bind = 127.0.0.1:31741
274    
275     The optional C<mount.opt> line assumes C</opt> exists and contains tools
276     or libraries your workers need. Omit it if you do not need that access.
277     The ordinary sandbox runtime includes C</usr>, C</bin> and system
278     libraries, but not C</opt>. If your worker Perl is C</opt/bin/perl>, you
279     can additionally put C<executable.perl = /opt/bin/perl> in that program
280     section. Supply the actual executable path; selecting it does not itself
281     mount its files or libraries.
282    
283     Now start:
284    
285     mcp-fs --name code /home/alice/src/project
286    
287     and retrieve its URL with:
288    
289     mcp-fs --name code --print-url
290    
291     Both use C<[instance code]>. No explicit token is needed: the server
292     derives one from its name and the existing master secret.
293    
294     For this setup:
295    
296     program defaults: [program mcp-fs]
297     instance settings: [instance code]
298     selected workdir: /home/alice/src/project
299     permission file: ~/.config/anyevent-mcp/rules-fs-code.ini
300     rule-manager profile: fs-code
301    
302     The permission pathname above assumes the default configuration directory.
303     C<anyevent-mcp manage-rules fs-code> opens the graphical rule manager;
304     C<anyevent-mcp edit-rules fs-code> opens the file in your editor.
305    
306     Keep global configuration and rule files owned by the server user and
307     private, normally mode 0600. C<--config FILE> on C<anyevent-mcp init>
308     selects that command's output file; it does not make the servers use an
309     arbitrary alternate file. Use the same C<HOME>/C<XDG_CONFIG_HOME>
310     environment when running the server and its management commands.
311    
312     =head2 Names, prefixes and profiles
313    
314     C<--name code> selects instance settings, derived HTTP credentials and
315     mcp-fs's C<rules-fs-code.ini>. Without C<--name>, mcp-fs uses C<mcp-fs>,
316     giving profile C<fs-mcp-fs>. Two processes with the same name and
317     configuration share credentials and rules, even if their workdirs differ.
318    
319     A multibroker prefix, such as C<files>, only routes tools: C<grep> becomes
320     C<files.grep>. It does not rename the child server or select its rules.
321     For example:
322    
323     mcp-multibroker files \
324     'stdio:mcp-fs --name code /home/alice/src/project'
325    
326     The tools are C<files.*>, but the child still uses instance C<code>
327     and rule-manager profile C<fs-code>. The multibroker's own C<--name>
328     selects its upstream listener settings.
329 root 1.1
330 root 1.5 =head2 Configuration changes and restarts
331 root 1.1
332 root 1.5 Command-line listener options override the named global settings.
333     For mcp-fs trusted settings, an instance entry overrides the corresponding
334     program entry; an empty instance mount value suppresses the inherited mount.
335 root 1.1
336 root 1.5 Workdirs, mounts, utility paths, listener settings and tokens are read at
337     startup. Change the file or startup command, then restart the affected
338     server. The multibroker also needs restarting to change its prefix/server
339     pairs; refreshing discovery does not change those pairs.
340    
341     Permission rules are reread on permission checks, so editing them does
342     not require a restart. A client's displayed tool list can still be cached.
343     After restarting a child, refresh tool discovery or reconnect the client
344     as described in L</COMBINING SERVERS>.
345    
346     =head1 PERMISSIONS IN PRACTICE
347    
348     HTTP authentication establishes that the client may connect.
349     Permission checks decide whether a tool may perform an operation.
350     A correct token therefore does not prevent permission prompts.
351    
352     =head2 What the prompt means
353    
354     The prompt describes an action, paths or command, a reason and sandbox
355     grants. For filesystem tools, the actions are:
356    
357 root 1.6 inspect stat, list, find
358     read file-read, read-lines, grep
359     write file-write, file-patch
360     manage path-op
361     exec arbitrary command execution
362     vcs-diff working-copy differences
363     vcs-status working-copy status
364 root 1.5
365     The action and grants are independent. Allowing C<read> does not allow
366     C<write>, even if a worker grant permits both kinds of filesystem access.
367     C<exec> runs arbitrary commands; it is not a classification of supposedly
368     safe command prefixes.
369    
370     Choose allow/deny once, or always. Closing the dialog denies once.
371     An optional denial reason is returned with the error; it is not added to
372     successful tool results. An always choice opens a rule editor.
373     Filesystem allow rules can select grants and the selected workdir when
374     the authority depends on it. Deny rules can also select an exact affected
375     path. Exec offers persistent command/argv subjects.
376    
377     For exec, C<View stdin...> lets you inspect supplied input without closing
378     the approval dialog. That input is display-only: an exec allow rule does
379     not constrain future stdin. Allowing an interpreter command can therefore
380     allow a different script on its next invocation.
381    
382     A worker accessing several paths requests their combined sandbox authority
383     once. If the chosen grants are insufficient, it fails before starting.
384    
385     =head2 Save a useful read-only policy
386    
387     After trying individual operations, you might want the LLM to inspect and
388     read the project without asking each time, while keeping changes subject
389     to approval. Put these rules in C<rules-fs-code.ini>, or create equivalent
390     allow rules through the prompt:
391    
392     [rule]
393     decision=allow
394     action=inspect
395     workdir=/home/alice/src/project
396     sandbox-grants=workdir-read
397    
398     [rule]
399     decision=allow
400     action=read
401     workdir=/home/alice/src/project
402     sandbox-grants=workdir-read
403    
404     [rule]
405     decision=deny
406     action=exec
407 root 1.1
408 root 1.5 Use the exact workdir spelling passed at server startup. Absolute startup
409     paths make this easier. If creating the rules file manually, ensure it
410     belongs to the server user and is private before making another request.
411     For the default configuration directory:
412 root 1.1
413 root 1.5 chmod 600 ~/.config/anyevent-mcp/rules-fs-code.ini
414 root 1.1
415 root 1.5 Use the corresponding XDG path when configured. Without matching rules, write and manage operations
416     still ask. The final rule denies command execution outright; omit it if you
417     want execution to ask instead.
418 root 1.1
419 root 1.5 Rules run in order, stopping at the first match. An allow rule matches only
420     when its grants cover the request, including implications.
421     C<workdir-write> implies C<workdir-read>; C<network> remains independent.
422     Action and subject match exactly unless beginning with C<^>, which selects
423     a Perl regular expression. Workdir matching is always exact.
424     An explicit C<ask> rule can override later allow rules.
425    
426     These allow rules authorize sandbox access to the selected workdir.
427     They cannot confine authority to one file or a subtree inside it.
428     Filesystem operations do not offer persistent path subjects.
429     An exact C<path> matcher is available for deny rules only.
430     Trusted runtime and configured mounts remain baseline access independently
431     of these grants. See L<mcp-fs/TRUSTED CONFIGURATION>.
432    
433     =head2 Change or remove saved rules
434    
435     Use:
436    
437     anyevent-mcp manage-rules fs-code
438     anyevent-mcp edit-rules fs-code
439    
440     The first command lets you delete and reorder rules in YAD.
441     The second uses C<$VISUAL>, C<$EDITOR>, C<sensible-editor> or C<vi>.
442     An earlier deny or ask rule can explain why adding a later allow rule
443     does not change the result.
444    
445     For a custom application with another rule pathname, use:
446    
447     anyevent-mcp manage-rules-file /path/to/rules.ini
448     anyevent-mcp edit-rules-file /path/to/rules.ini
449    
450     A failed attempt to save a permanent rule is an error, not a successful
451     permanent approval. The file must remain private and owned by the server
452     user. For full syntax and programming interfaces, see
453     L<AnyEvent::MCP::Server::Permissions>.
454    
455     =head2 Choose where to ask
456    
457     The default C<helper> mode runs C<anyevent-mcp-askpermission> on the server
458     machine. It tries YAD, then C</dev/tty>, then denies if neither can be used.
459     The helper inherits the server's display environment.
460     C<PERL_ANYEVENT_MCP_PERMISSION_HELPER> selects a different executable.
461    
462     For a modern client supporting MCP form elicitation, you can instead use:
463    
464     mcp-fs --stdio --name code --ask auto /home/alice/src/project
465    
466     C<auto> uses the client's form support when advertised for that request,
467     otherwise the local helper. C<mcp> requires that support and fails when
468     unavailable. It does not silently fall back. Use client-side permission
469     approval only when that client is a trusted authority to grant access.
470    
471     To set the default for servers using the shared permission engine:
472    
473     PERL_ANYEVENT_MCP_PERMISSION_ASK=auto \
474     mcp-fs --stdio --name code /home/alice/src/project
475    
476     An explicit application C<ask> setting or C<--ask> overrides the environment.
477     For spawned stdio children, C<mcp-multibroker --ask auto> passes this
478     default to them. It cannot change the environment of an independently
479     running HTTP server.
480    
481     These settings choose where to ask; they cannot add elicitation support
482     to a client. C<mcp-ask-user> always requires client form support and has
483     no local helper fallback. A question is also different from an approval:
484     answering it does not grant a filesystem worker any authority.
485    
486     =head1 COMBINING SERVERS
487    
488     Once the first connection works, use the multibroker to give a client
489     one connection for several servers:
490    
491     mcp-multibroker --name tools --bind :31740 \
492     code 'stdio:mcp-fs --name code /home/alice/src/project' \
493     notes 'stdio:mcp-fs --name notes /home/alice/notes'
494    
495     Quote each C<stdio:> shell command as one argument.
496     The broker supplies the child's stdio environment and starts ordinary
497     children lazily, on first use. The explicit child names give them separate
498     permission profiles C<fs-code> and C<fs-notes>.
499    
500     Obtain the upstream HTTP URL with:
501    
502     mcp-multibroker --name tools --bind :31740 --print-url
503    
504     Configure this URL in place of the client's old direct connection.
505     The client can now see C<code.grep>, C<code.read-lines>, C<notes.find>
506     and other prefixed tools. It does not need a separate connection to each
507     child.
508    
509     For a client launching the multibroker locally, configure:
510    
511     mcp-multibroker --stdio --name tools \
512     code 'stdio:mcp-fs --name code /home/alice/src/project' \
513     notes 'stdio:mcp-fs --name notes /home/alice/notes'
514    
515     C<--stdio> selects the upstream connection. The child commands still use
516     C<stdio:>; that selects each downstream connection independently.
517     No upstream HTTP URL is needed in this case.
518    
519     =head2 Discover and refresh tools
520    
521     Ask the LLM:
522    
523     Call discover-brokers and list-tools, then show me which servers
524     are available and what each is for.
525    
526     C<discover-brokers> returns instructions, no instructions, or an error for
527     each configured server. C<list-tools> requests current tool definitions;
528     unreachable servers are omitted. A reachable server can still fail later.
529    
530     If the client still has an old direct tool list, C<call-tool> can invoke
531     an exact prefixed name found by C<list-tools>. Refresh the client's MCP
532     connection if it continues to hide newly available tools.
533    
534     Discovery queries the configured servers. It cannot add a server absent
535     from the broker's startup command. Changing that command requires a restart.
536    
537     =head2 Add an HTTP child
538    
539     A broker can mix spawned stdio servers and existing HTTP endpoints:
540    
541     mcp-multibroker --stdio \
542     code 'stdio:mcp-fs --name code /home/alice/src/project' \
543     remote https://example.org/mcp/ --bearer TOKEN
544    
545     C<--bearer> immediately after the HTTP pair belongs to that child.
546     C<--token> before all pairs configures the multibroker's own HTTP listener.
547     They authenticate different connections.
548    
549     To avoid putting a child's bearer token in the startup command, add:
550    
551     [client remote]
552     bearer = TOKEN
553     timeout = 300
554    
555     to the private global configuration, and omit C<--bearer> from the command.
556     The prefix C<remote> selects these client defaults. The command-line URL
557     still chooses the endpoint. Use the actual credential accepted by that
558     server, not the literal placeholder C<TOKEN>.
559    
560     A token already present in a child's URL needs no separate bearer option.
561     The bundled servers use static URL-safe tokens; they do not validate
562     OAuth access tokens or implement HTTP Basic authentication.
563     Use TLS or an appropriate tunnel when credentials cross untrusted networks.
564    
565     The multibroker does not put every child inside the mcp-fs sandbox.
566     Each process or remote service has its own authority and enforcement.
567    
568     =head2 Add a live Vim editor
569    
570     Install the Vim plugin using L<mcp-vim/VIM PLUGIN INSTALLATION>. It is
571     included in the source distribution but is not installed by Perl's
572     C<make install>.
573    
574     A spawned mcp-vim child also listens for editor connections. Start it
575     eagerly so Vim can connect before the first MCP tool call:
576    
577     mcp-multibroker --stdio \
578     code 'stdio:mcp-fs --name code /home/alice/src/project' \
579     vim 'stdio:mcp-vim --name editor' --eager
580    
581     In another terminal, obtain the editor child's URL prefix:
582    
583     mcp-vim --name editor --print-url
584    
585     Append the desired target name in Vim:
586    
587     :Mcp http://HOST:PORT/TOKEN/my-editor
588    
589     Use the actual printed prefix in place of C<http://HOST:PORT/TOKEN/>.
590     Ask the LLM to call C<vim.targets>, then C<vim.state> before reading or
591     editing buffers. These tools see live, possibly unsaved buffers.
592     Edits require a current changedtick and do not save files to disk.
593    
594     C<--eager> belongs immediately after its stdio pair.
595     An eager connection failure is logged; the broker does not continuously
596     restart the child. Later tool use can try connecting again.
597    
598     =head2 Ask the client's human a question
599    
600     For a modern client with form elicitation, add a question server:
601    
602     mcp-multibroker --stdio \
603     code 'stdio:mcp-fs --name code /home/alice/src/project' \
604     questions 'stdio:mcp-ask-user'
605    
606     The LLM can call C<questions.ask-user> with a question, up to three
607     suggested answers and room for free text. For example, tell it to use
608     that tool if choosing among several possible tasks needs your input.
609     Decline and cancel are distinct results; neither supplies an answer.
610    
611     Unlike permission prompting with C<auto>, this tool has no local-helper
612     fallback. Without modern client form support, it returns a tool error.
613     See L<mcp-ask-user> for argument limits and result fields.
614    
615     =head1 HTTP TOKENS AND SERVER IDENTITY
616    
617     For the ordinary bundled HTTP endpoints, a client can present an accepted
618     token in either of these ways:
619    
620     POST /TOKEN/
621     POST / Authorization: Bearer TOKEN
622    
623     URL tokens are path components, not browser cookies.
624     For another configured endpoint, C</TOKEN> prefixes that endpoint path.
625     All accepted tokens authenticate the same operations; they are not separate
626     users or permission levels. Permissions still govern the tool operation.
627    
628     By default, the master secret and server name determine one stable token
629     and a port in 16384..32767. Changing a server's name changes its derived
630     credentials and default port. Changing or losing the master secret changes
631     all derived credentials. Keep an existing C<[global]> secret when editing
632     other configuration.
633    
634     To configure explicit tokens:
635    
636     [instance code]
637     tokens = first-secret,second-secret
638 root 1.1
639 root 1.5 Replace those placeholders with actual unguessable URL-safe tokens.
640     Repeated C<--token> options replace the whole configured list and the
641     derived default. The first token appears in C<--print-url>; all are accepted.
642     mcp-vim also accepts its token set for Vim and browser WebSocket connections.
643    
644     If C<--print-url> disagrees with the client's URL, compare the name,
645     command-line overrides, user and configuration environment with the running
646     process. The command resolves configuration; it does not ask the running
647     server which URL it uses. A changed file needs a server restart.
648    
649     An Origin allowlist restricts browser origins; it does not authenticate
650     clients. A CORS preflight can succeed without a token, while the MCP POST
651     still requires one. See L<AnyEvent::MCP::Server::HTTP/AUTHENTICATION> for
652     the low-level server interface.
653    
654     =head1 CLIENT EXAMPLES
655    
656     Client settings and command syntax evolve independently of this distribution.
657     These examples show the connection choices; consult the linked client
658     documentation if its interface differs. Replace illustrative paths and
659     credentials with your own.
660 root 1.1
661 root 1.5 =head2 OpenAI Codex CLI
662 root 1.1
663 root 1.5 For the first direct filesystem connection:
664 root 1.1
665 root 1.5 codex mcp add code -- \
666     mcp-fs --stdio --name code /home/alice/src/project
667 root 1.1 codex mcp list
668    
669 root 1.5 For a multibroker connection:
670    
671     codex mcp add mytools -- \
672     mcp-multibroker --stdio \
673     code 'stdio:mcp-fs --name code /home/alice/src/project'
674    
675 root 1.1 Use C</mcp> within Codex to inspect connections.
676     See L<Codex MCP documentation|https://learn.chatgpt.com/docs/extend/mcp>.
677    
678 root 1.5 =head2 Anthropic Claude Code
679 root 1.1
680 root 1.5 For the direct connection:
681 root 1.1
682 root 1.5 claude mcp add --transport stdio --scope user code -- \
683     mcp-fs --stdio --name code /home/alice/src/project
684 root 1.1 claude mcp list
685    
686 root 1.5 Replace the launched command with the multibroker command above when you
687     want several servers. Use C</mcp> for connection status. See
688 root 1.1 L<Claude Code MCP documentation|https://code.claude.com/docs/en/mcp>.
689    
690 root 1.5 =head2 Google Gemini CLI
691 root 1.1
692 root 1.5 Merge a direct server entry into C<~/.gemini/settings.json>:
693 root 1.1
694     {
695     "mcpServers": {
696 root 1.5 "code": {
697     "command": "mcp-fs",
698 root 1.1 "args": [
699 root 1.5 "--stdio", "--name", "code", "/home/alice/src/project"
700     ]
701 root 1.1 }
702     }
703     }
704    
705 root 1.5 For a combined connection, use C<mcp-multibroker> as the command and its
706     C<--stdio> and prefix/server pairs as the argument array.
707     Use C</mcp> to inspect the connection. See
708     L<Gemini CLI MCP documentation|https://geminicli.com/docs/tools/mcp-server/>.
709    
710     =head2 Hosted clients, including ChatGPT web
711    
712     A hosted client cannot spawn your local stdio command or reach your
713     machine's loopback address directly. Run the server or multibroker in HTTP
714     mode and configure a supported tunnel or reachable endpoint.
715    
716     For ChatGPT, use its custom MCP setup and, for a private server, an
717     appropriately configured Secure MCP Tunnel. Availability depends on the
718     client's plan, workspace and feature permissions. See
719     L<ChatGPT custom MCP servers|https://developers.openai.com/api/docs/guides/custom-mcp-server>
720     and L<Secure MCP Tunnel|https://developers.openai.com/blog/connect-private-mcp-servers-to-openai-products>.
721    
722     =head1 TROUBLESHOOTING
723    
724     =head2 The server does not start
725    
726     Read stderr or the client's server log. Missing Perl modules, a missing
727     workdir, unsuitable utilities or an unavailable bubblewrap executable can
728     fail startup. Confirm that the client launches the same executable and
729     arguments you intended, with the expected C<PATH> and Perl installation.
730    
731     For a local sandbox check, run from the project directory:
732    
733     mcp-fs --exec-cmd workdir-read -- ls
734 root 1.1
735 root 1.5 This runs C<ls> with the named grants and trusted baseline mounts, without
736     MCP or saved permission rules. A failure here can identify a bubblewrap
737     or runtime problem. It does not test the client connection or approval UI.
738     C<--sandbox none> disables isolation and changes worker authority; it is
739     not a fix that preserves the same permission boundary.
740 root 1.1
741 root 1.5 =head2 The client cannot connect
742    
743     For stdio, configure a command the client launches, rather than a URL.
744     A separately running stdio process is not the client's connection.
745     Do not put banners or diagnostics on stdout.
746    
747     For HTTP, leave the server running and check its address and port.
748     C<--print-url> exits without starting it. Loopback binds accept local
749     connections only; hosted or remote clients need the appropriate route or
750     tunnel. An occupied port causes a listener error, so check the server log.
751    
752     =head2 Authentication fails
753    
754     Obtain the URL with the same name, bind/token overrides and configuration
755     environment as the running process. Use the complete path, including any
756     required trailing slash. A clean URL needs an accepted bearer token.
757    
758     A multibroker child credential is not necessarily the upstream listener's
759     credential. C<--bearer> after a child pair and C<--token> before the pairs
760     configure different sides of the connection.
761    
762     If the server warns that it cannot save the master secret, another process
763     may derive a different token. Fix ownership and write access to the private
764     configuration. Do not replace an existing secret simply to add a setting.
765    
766     =head2 Connected, but there are no tools
767    
768     Inspect the server's stderr for omitted utilities. mcp-fs's C<workdirs>
769     tool reports configuration even when a utility-dependent tool is absent.
770     For a multibroker, call C<discover-brokers> to see individual connection
771     errors, then C<list-tools> to refresh definitions.
772    
773     A third-party child might require initialization or features this client
774     implementation does not support. See L<AnyEvent::MCP::Client> and its
775     transport documentation for limitations.
776    
777     =head2 There is no approval dialog
778    
779     First check whether the tool was denied by a saved rule or is waiting for
780     the client's own approval. An allowed operation needs no server prompt.
781    
782     The default helper runs on the server machine. A background service may
783     have neither a usable display nor C</dev/tty>, even though your interactive
784     shell has both. Supply the appropriate display environment, a usable helper,
785     or C<--ask auto> with a modern client supporting form elicitation.
786     C<--ask mcp> reports an error if that support is absent.
787    
788     Setting an asking mode cannot make an unsupported client display a form.
789     Check stderr and the tool error instead of assuming a missing dialog is
790     an approval.
791    
792     =head2 It asks again after I chose allow
793 root 1.1
794 root 1.5 Allow-once covers one tool invocation, including its permission retries.
795     The next invocation asks again. Use allow-always to save a rule.
796 root 1.1
797 root 1.5 Inspect the saved rule's action, workdir and grants. Listing names and
798     reading contents are different actions. A rule for one exact workdir
799     spelling will not match a differently spelled startup argument.
800     A request for extra authority, such as networking, does not match a
801     workdir-read-only allow rule. Earlier ask or deny rules take precedence.
802 root 1.1
803 root 1.5 Confirm that the prompt's permanent rule was successfully saved and that
804     you are editing the rules for the actual child name, not merely its
805     multibroker prefix.
806 root 1.1
807 root 1.5 =head2 The worker cannot see a directory or executable
808 root 1.1
809 root 1.5 The worker sees granted mounts and trusted baseline mounts, not everything
810     the server process can see. Check C<workdirs> for the selected path, mounts
811     and runtime paths. A symlink target outside those mounts is unavailable.
812 root 1.1
813 root 1.5 For tools or libraries under C</opt>, add an appropriate trusted mount
814     as shown earlier and restart mcp-fs. A configured executable path alone
815     does not mount the executable or its dependencies inside the worker.
816     A trusted mount supplies baseline access to every worker using it; a
817     writable mount likewise supplies baseline write authority.
818 root 1.1
819 root 1.5 An arbitrary command might also need its user's configuration or repository
820     credentials under HOME, or network access. Request the corresponding grants
821     when needed; do not assume C<workdir-read> includes them.
822     For example, CVS access commonly needs C<workdir-read>, C<home-read> and
823     C<network>. An explicit exec grant array replaces the default rather than
824     adding to it.
825 root 1.1
826 root 1.5 =head2 My configuration change seems to be ignored
827 root 1.1
828 root 1.5 Check which file and section the process actually selects. Global settings
829     use the server user's C<HOME>/C<XDG_CONFIG_HOME>. Instance names, program
830     basenames and multibroker prefixes serve different purposes.
831 root 1.1
832 root 1.5 Restart after changing startup settings, mounts or utilities. Permission
833     rules need no restart, but their order still matters. Refresh discovery
834     after a child restart; reconnect a client that retains an old tool list.
835     C<--print-url> reads the current configuration, which can differ from an
836     older running process.
837 root 1.1
838 root 1.5 =head2 The command failed, but the MCP request succeeded
839 root 1.1
840 root 1.5 C<exec> reports exit status, signal or timeout as a normal tool result.
841     A successful MCP exchange is not a successful Unix command.
842     Conversely, a transport failure does not prove a command did nothing:
843     it may have completed before the connection was lost. Calls are not
844     automatically replayed after a transport failure.
845 root 1.1
846 root 1.5 =head1 WHERE TO GO NEXT
847 root 1.1
848 root 1.5 For available tools and server-specific options:
849 root 1.1
850     perldoc mcp-fs
851     perldoc mcp-multibroker
852 root 1.5 perldoc mcp-vim
853     perldoc mcp-ask-user
854 root 1.1 perldoc anyevent-mcp
855    
856 root 1.5 For a complete first Perl server, options, replies, permission checks and
857     asynchronous work, see L<AnyEvent::MCP::Server::Simple/TUTORIAL>.
858     For the module map and shared configuration reference, see L<AnyEvent::MCP>.
859     For permission rule details, see L<AnyEvent::MCP::Server::Permissions>.
860 root 1.1
861     =head1 SEE ALSO
862    
863     L<AnyEvent::MCP>, L<AnyEvent::MCP::Server::Simple>,
864 root 1.5 L<mcp-fs>, L<mcp-multibroker>, L<mcp-vim>, L<mcp-ask-user>,
865     L<AnyEvent::MCP::Server::Permissions>
866 root 1.1
867     =cut