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