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