ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-MCP/lib/AnyEvent/MCP/Intro.pod
Revision: 1.7
Committed: Wed Oct 14 13:36:51 2026 UTC (2 weeks, 4 days ago) by root
Branch: MAIN
Changes since 1.6: +27 -11 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 root 1.7 The multibroker can handle form elicitation locally for both stdio and HTTP
482     children. C<--ask helper> selects local dialogs even if the upstream client
483     advertises native forms; C<--ask mcp> forwards forms upstream, and C<auto>
484     uses native forms when advertised. If a client claims support but silently
485     declines questions, use C<helper>. A decline never causes a fallback prompt.
486    
487     Standalone C<mcp-ask-user> also supports these modes and defaults to the
488     local helper. A question is different from an approval: answering it does
489     not grant a filesystem worker any authority.
490 root 1.5
491     =head1 COMBINING SERVERS
492    
493     Once the first connection works, use the multibroker to give a client
494     one connection for several servers:
495    
496     mcp-multibroker --name tools --bind :31740 \
497     code 'stdio:mcp-fs --name code /home/alice/src/project' \
498     notes 'stdio:mcp-fs --name notes /home/alice/notes'
499    
500     Quote each C<stdio:> shell command as one argument.
501     The broker supplies the child's stdio environment and starts ordinary
502     children lazily, on first use. The explicit child names give them separate
503     permission profiles C<fs-code> and C<fs-notes>.
504    
505     Obtain the upstream HTTP URL with:
506    
507     mcp-multibroker --name tools --bind :31740 --print-url
508    
509     Configure this URL in place of the client's old direct connection.
510     The client can now see C<code.grep>, C<code.read-lines>, C<notes.find>
511     and other prefixed tools. It does not need a separate connection to each
512     child.
513    
514     For a client launching the multibroker locally, configure:
515    
516     mcp-multibroker --stdio --name tools \
517     code 'stdio:mcp-fs --name code /home/alice/src/project' \
518     notes 'stdio:mcp-fs --name notes /home/alice/notes'
519    
520     C<--stdio> selects the upstream connection. The child commands still use
521     C<stdio:>; that selects each downstream connection independently.
522     No upstream HTTP URL is needed in this case.
523    
524     =head2 Discover and refresh tools
525    
526     Ask the LLM:
527    
528     Call discover-brokers and list-tools, then show me which servers
529     are available and what each is for.
530    
531     C<discover-brokers> returns instructions, no instructions, or an error for
532     each configured server. C<list-tools> requests current tool definitions;
533     unreachable servers are omitted. A reachable server can still fail later.
534    
535     If the client still has an old direct tool list, C<call-tool> can invoke
536     an exact prefixed name found by C<list-tools>. Refresh the client's MCP
537     connection if it continues to hide newly available tools.
538    
539     Discovery queries the configured servers. It cannot add a server absent
540     from the broker's startup command. Changing that command requires a restart.
541    
542     =head2 Add an HTTP child
543    
544     A broker can mix spawned stdio servers and existing HTTP endpoints:
545    
546     mcp-multibroker --stdio \
547     code 'stdio:mcp-fs --name code /home/alice/src/project' \
548     remote https://example.org/mcp/ --bearer TOKEN
549    
550     C<--bearer> immediately after the HTTP pair belongs to that child.
551     C<--token> before all pairs configures the multibroker's own HTTP listener.
552     They authenticate different connections.
553    
554     To avoid putting a child's bearer token in the startup command, add:
555    
556     [client remote]
557     bearer = TOKEN
558     timeout = 300
559    
560     to the private global configuration, and omit C<--bearer> from the command.
561     The prefix C<remote> selects these client defaults. The command-line URL
562     still chooses the endpoint. Use the actual credential accepted by that
563     server, not the literal placeholder C<TOKEN>.
564    
565     A token already present in a child's URL needs no separate bearer option.
566     The bundled servers use static URL-safe tokens; they do not validate
567     OAuth access tokens or implement HTTP Basic authentication.
568     Use TLS or an appropriate tunnel when credentials cross untrusted networks.
569    
570     The multibroker does not put every child inside the mcp-fs sandbox.
571     Each process or remote service has its own authority and enforcement.
572    
573     =head2 Add a live Vim editor
574    
575     Install the Vim plugin using L<mcp-vim/VIM PLUGIN INSTALLATION>. It is
576     included in the source distribution but is not installed by Perl's
577     C<make install>.
578    
579     A spawned mcp-vim child also listens for editor connections. Start it
580     eagerly so Vim can connect before the first MCP tool call:
581    
582     mcp-multibroker --stdio \
583     code 'stdio:mcp-fs --name code /home/alice/src/project' \
584     vim 'stdio:mcp-vim --name editor' --eager
585    
586     In another terminal, obtain the editor child's URL prefix:
587    
588     mcp-vim --name editor --print-url
589    
590     Append the desired target name in Vim:
591    
592     :Mcp http://HOST:PORT/TOKEN/my-editor
593    
594     Use the actual printed prefix in place of C<http://HOST:PORT/TOKEN/>.
595     Ask the LLM to call C<vim.targets>, then C<vim.state> before reading or
596     editing buffers. These tools see live, possibly unsaved buffers.
597     Edits require a current changedtick and do not save files to disk.
598    
599     C<--eager> belongs immediately after its stdio pair.
600     An eager connection failure is logged; the broker does not continuously
601     restart the child. Later tool use can try connecting again.
602    
603     =head2 Ask the client's human a question
604    
605 root 1.7 To let the assistant ask you questions, add a question server:
606 root 1.5
607     mcp-multibroker --stdio \
608     code 'stdio:mcp-fs --name code /home/alice/src/project' \
609     questions 'stdio:mcp-ask-user'
610    
611     The LLM can call C<questions.ask-user> with a question, up to three
612     suggested answers and room for free text. For example, tell it to use
613     that tool if choosing among several possible tasks needs your input.
614     Decline and cancel are distinct results; neither supplies an answer.
615    
616 root 1.7 By default the multibroker displays questions locally, using YAD or a terminal.
617     Add C<--ask mcp> before the broker entries to use the client's native forms,
618     or C<--ask auto> to select by advertised capability. This also works with
619     C<mcp-ask-user> started separately: give that server C<--ask mcp> so it
620     delegates presentation to its connecting multibroker.
621    
622     C<anyevent-mcp-form-elicitation> is the standalone form renderer. It reads standard MCP
623     form parameters as UTF-8 JSON on stdin and writes an accept/decline/cancel
624     response as JSON on stdout. C<PERL_ANYEVENT_MCP_ELICITATION_HELPER> selects
625     a replacement executable. See L<anyevent-mcp-form-elicitation> for supported fields
626     and L<mcp-ask-user> for question arguments and result fields.
627 root 1.5
628     =head1 HTTP TOKENS AND SERVER IDENTITY
629    
630     For the ordinary bundled HTTP endpoints, a client can present an accepted
631     token in either of these ways:
632    
633     POST /TOKEN/
634     POST / Authorization: Bearer TOKEN
635    
636     URL tokens are path components, not browser cookies.
637     For another configured endpoint, C</TOKEN> prefixes that endpoint path.
638     All accepted tokens authenticate the same operations; they are not separate
639     users or permission levels. Permissions still govern the tool operation.
640    
641     By default, the master secret and server name determine one stable token
642     and a port in 16384..32767. Changing a server's name changes its derived
643     credentials and default port. Changing or losing the master secret changes
644     all derived credentials. Keep an existing C<[global]> secret when editing
645     other configuration.
646    
647     To configure explicit tokens:
648    
649     [instance code]
650     tokens = first-secret,second-secret
651 root 1.1
652 root 1.5 Replace those placeholders with actual unguessable URL-safe tokens.
653     Repeated C<--token> options replace the whole configured list and the
654     derived default. The first token appears in C<--print-url>; all are accepted.
655     mcp-vim also accepts its token set for Vim and browser WebSocket connections.
656    
657     If C<--print-url> disagrees with the client's URL, compare the name,
658     command-line overrides, user and configuration environment with the running
659     process. The command resolves configuration; it does not ask the running
660     server which URL it uses. A changed file needs a server restart.
661    
662     An Origin allowlist restricts browser origins; it does not authenticate
663     clients. A CORS preflight can succeed without a token, while the MCP POST
664     still requires one. See L<AnyEvent::MCP::Server::HTTP/AUTHENTICATION> for
665     the low-level server interface.
666    
667     =head1 CLIENT EXAMPLES
668    
669     Client settings and command syntax evolve independently of this distribution.
670     These examples show the connection choices; consult the linked client
671     documentation if its interface differs. Replace illustrative paths and
672     credentials with your own.
673 root 1.1
674 root 1.5 =head2 OpenAI Codex CLI
675 root 1.1
676 root 1.5 For the first direct filesystem connection:
677 root 1.1
678 root 1.5 codex mcp add code -- \
679     mcp-fs --stdio --name code /home/alice/src/project
680 root 1.1 codex mcp list
681    
682 root 1.5 For a multibroker connection:
683    
684     codex mcp add mytools -- \
685     mcp-multibroker --stdio \
686     code 'stdio:mcp-fs --name code /home/alice/src/project'
687    
688 root 1.1 Use C</mcp> within Codex to inspect connections.
689     See L<Codex MCP documentation|https://learn.chatgpt.com/docs/extend/mcp>.
690    
691 root 1.5 =head2 Anthropic Claude Code
692 root 1.1
693 root 1.5 For the direct connection:
694 root 1.1
695 root 1.5 claude mcp add --transport stdio --scope user code -- \
696     mcp-fs --stdio --name code /home/alice/src/project
697 root 1.1 claude mcp list
698    
699 root 1.5 Replace the launched command with the multibroker command above when you
700     want several servers. Use C</mcp> for connection status. See
701 root 1.1 L<Claude Code MCP documentation|https://code.claude.com/docs/en/mcp>.
702    
703 root 1.5 =head2 Google Gemini CLI
704 root 1.1
705 root 1.5 Merge a direct server entry into C<~/.gemini/settings.json>:
706 root 1.1
707     {
708     "mcpServers": {
709 root 1.5 "code": {
710     "command": "mcp-fs",
711 root 1.1 "args": [
712 root 1.5 "--stdio", "--name", "code", "/home/alice/src/project"
713     ]
714 root 1.1 }
715     }
716     }
717    
718 root 1.5 For a combined connection, use C<mcp-multibroker> as the command and its
719     C<--stdio> and prefix/server pairs as the argument array.
720     Use C</mcp> to inspect the connection. See
721     L<Gemini CLI MCP documentation|https://geminicli.com/docs/tools/mcp-server/>.
722    
723     =head2 Hosted clients, including ChatGPT web
724    
725     A hosted client cannot spawn your local stdio command or reach your
726     machine's loopback address directly. Run the server or multibroker in HTTP
727     mode and configure a supported tunnel or reachable endpoint.
728    
729     For ChatGPT, use its custom MCP setup and, for a private server, an
730     appropriately configured Secure MCP Tunnel. Availability depends on the
731     client's plan, workspace and feature permissions. See
732     L<ChatGPT custom MCP servers|https://developers.openai.com/api/docs/guides/custom-mcp-server>
733     and L<Secure MCP Tunnel|https://developers.openai.com/blog/connect-private-mcp-servers-to-openai-products>.
734    
735     =head1 TROUBLESHOOTING
736    
737     =head2 The server does not start
738    
739     Read stderr or the client's server log. Missing Perl modules, a missing
740     workdir, unsuitable utilities or an unavailable bubblewrap executable can
741     fail startup. Confirm that the client launches the same executable and
742     arguments you intended, with the expected C<PATH> and Perl installation.
743    
744     For a local sandbox check, run from the project directory:
745    
746     mcp-fs --exec-cmd workdir-read -- ls
747 root 1.1
748 root 1.5 This runs C<ls> with the named grants and trusted baseline mounts, without
749     MCP or saved permission rules. A failure here can identify a bubblewrap
750     or runtime problem. It does not test the client connection or approval UI.
751     C<--sandbox none> disables isolation and changes worker authority; it is
752     not a fix that preserves the same permission boundary.
753 root 1.1
754 root 1.5 =head2 The client cannot connect
755    
756     For stdio, configure a command the client launches, rather than a URL.
757     A separately running stdio process is not the client's connection.
758     Do not put banners or diagnostics on stdout.
759    
760     For HTTP, leave the server running and check its address and port.
761     C<--print-url> exits without starting it. Loopback binds accept local
762     connections only; hosted or remote clients need the appropriate route or
763     tunnel. An occupied port causes a listener error, so check the server log.
764    
765     =head2 Authentication fails
766    
767     Obtain the URL with the same name, bind/token overrides and configuration
768     environment as the running process. Use the complete path, including any
769     required trailing slash. A clean URL needs an accepted bearer token.
770    
771     A multibroker child credential is not necessarily the upstream listener's
772     credential. C<--bearer> after a child pair and C<--token> before the pairs
773     configure different sides of the connection.
774    
775     If the server warns that it cannot save the master secret, another process
776     may derive a different token. Fix ownership and write access to the private
777     configuration. Do not replace an existing secret simply to add a setting.
778    
779     =head2 Connected, but there are no tools
780    
781     Inspect the server's stderr for omitted utilities. mcp-fs's C<workdirs>
782     tool reports configuration even when a utility-dependent tool is absent.
783     For a multibroker, call C<discover-brokers> to see individual connection
784     errors, then C<list-tools> to refresh definitions.
785    
786     A third-party child might require initialization or features this client
787     implementation does not support. See L<AnyEvent::MCP::Client> and its
788     transport documentation for limitations.
789    
790     =head2 There is no approval dialog
791    
792     First check whether the tool was denied by a saved rule or is waiting for
793     the client's own approval. An allowed operation needs no server prompt.
794    
795     The default helper runs on the server machine. A background service may
796     have neither a usable display nor C</dev/tty>, even though your interactive
797     shell has both. Supply the appropriate display environment, a usable helper,
798     or C<--ask auto> with a modern client supporting form elicitation.
799     C<--ask mcp> reports an error if that support is absent.
800    
801     Setting an asking mode cannot make an unsupported client display a form.
802     Check stderr and the tool error instead of assuming a missing dialog is
803     an approval.
804    
805     =head2 It asks again after I chose allow
806 root 1.1
807 root 1.5 Allow-once covers one tool invocation, including its permission retries.
808     The next invocation asks again. Use allow-always to save a rule.
809 root 1.1
810 root 1.5 Inspect the saved rule's action, workdir and grants. Listing names and
811     reading contents are different actions. A rule for one exact workdir
812     spelling will not match a differently spelled startup argument.
813     A request for extra authority, such as networking, does not match a
814     workdir-read-only allow rule. Earlier ask or deny rules take precedence.
815 root 1.1
816 root 1.5 Confirm that the prompt's permanent rule was successfully saved and that
817     you are editing the rules for the actual child name, not merely its
818     multibroker prefix.
819 root 1.1
820 root 1.5 =head2 The worker cannot see a directory or executable
821 root 1.1
822 root 1.5 The worker sees granted mounts and trusted baseline mounts, not everything
823     the server process can see. Check C<workdirs> for the selected path, mounts
824     and runtime paths. A symlink target outside those mounts is unavailable.
825 root 1.1
826 root 1.5 For tools or libraries under C</opt>, add an appropriate trusted mount
827     as shown earlier and restart mcp-fs. A configured executable path alone
828     does not mount the executable or its dependencies inside the worker.
829     A trusted mount supplies baseline access to every worker using it; a
830     writable mount likewise supplies baseline write authority.
831 root 1.1
832 root 1.5 An arbitrary command might also need its user's configuration or repository
833     credentials under HOME, or network access. Request the corresponding grants
834     when needed; do not assume C<workdir-read> includes them.
835 root 1.7 For example, CVS over SSH can use C<workdir-read> and C<ssh-agent>.
836     The latter includes network access, the agent socket and C<~/.ssh/known_hosts>,
837     without exposing private key files or the rest of HOME. The broker must
838     inherit C<SSH_AUTH_SOCK> from your environment. User-configured helpers
839     outside the runtime mounts need an explicit trusted mount.
840     An explicit exec grant array replaces the default rather than adding to it.
841 root 1.1
842 root 1.5 =head2 My configuration change seems to be ignored
843 root 1.1
844 root 1.5 Check which file and section the process actually selects. Global settings
845     use the server user's C<HOME>/C<XDG_CONFIG_HOME>. Instance names, program
846     basenames and multibroker prefixes serve different purposes.
847 root 1.1
848 root 1.5 Restart after changing startup settings, mounts or utilities. Permission
849     rules need no restart, but their order still matters. Refresh discovery
850     after a child restart; reconnect a client that retains an old tool list.
851     C<--print-url> reads the current configuration, which can differ from an
852     older running process.
853 root 1.1
854 root 1.5 =head2 The command failed, but the MCP request succeeded
855 root 1.1
856 root 1.5 C<exec> reports exit status, signal or timeout as a normal tool result.
857     A successful MCP exchange is not a successful Unix command.
858     Conversely, a transport failure does not prove a command did nothing:
859     it may have completed before the connection was lost. Calls are not
860     automatically replayed after a transport failure.
861 root 1.1
862 root 1.5 =head1 WHERE TO GO NEXT
863 root 1.1
864 root 1.5 For available tools and server-specific options:
865 root 1.1
866     perldoc mcp-fs
867     perldoc mcp-multibroker
868 root 1.5 perldoc mcp-vim
869     perldoc mcp-ask-user
870 root 1.1 perldoc anyevent-mcp
871    
872 root 1.5 For a complete first Perl server, options, replies, permission checks and
873     asynchronous work, see L<AnyEvent::MCP::Server::Simple/TUTORIAL>.
874     For the module map and shared configuration reference, see L<AnyEvent::MCP>.
875     For permission rule details, see L<AnyEvent::MCP::Server::Permissions>.
876 root 1.1
877     =head1 SEE ALSO
878    
879     L<AnyEvent::MCP>, L<AnyEvent::MCP::Server::Simple>,
880 root 1.5 L<mcp-fs>, L<mcp-multibroker>, L<mcp-vim>, L<mcp-ask-user>,
881     L<AnyEvent::MCP::Server::Permissions>
882 root 1.1
883     =cut