ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-MCP/README
Revision: 1.4
Committed: Wed Oct 21 16:24:15 2026 UTC (13 days, 4 hours ago) by root
Branch: MAIN
Changes since 1.3: +23 -5 lines
Log Message:
*** empty log message ***

File Contents

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