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