AnyEvent-MCP

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    absolute paths to Perl, "lib" and the script. An installed executable
    avoids that extra setup.

PICK A SERVER
    For a local MCP client, configure it to launch the server that provides
    the tools you want:

       mcp-fs --stdio /home/alice/src/project
       mcp-vim --stdio
       mcp-webbrowser --stdio
       mcp-ask-user --stdio
       mcp-http --stdio
       mcp-imap --stdio --name personal

    "--stdio" means the MCP client launches the process. Do not start a
    separate copy in a terminal. For HTTP clients, use a running server and
    its "--print-url" instead, as explained below.

    "mcp-fs" reads, searches and changes files and runs commands in a
    sandbox. The first walkthrough below uses this server.

    "mcp-vim" reads and edits live Vim buffers. Install the companion Vim
    plugin and connect the editor to its listener; see "Add a live Vim
    editor" and "VIM PLUGIN INSTALLATION" in mcp-vim.

    "mcp-webbrowser" works with explicitly approved browser tabs. Install
    its companion userscript and connect each tab you want to expose; see
    "CONNECTED BROWSER PAGES".

    "mcp-ask-user" lets the assistant ask you questions through a local YAD
    or terminal dialog, or through the client's native form UI; see "Ask the
    client's human a question".

    "mcp-http" makes HTTP(S) requests with method- and URL-scoped
    permissions. It does not follow redirects automatically; see "Use an
    HTTP request tool".

    "mcp-imap" reads, searches and manages mailboxes. Configure the account
    interactively before starting the server; see "Read and organize mail"
    and mcp-imap for OAuth2 and account management.

    To offer several servers over one MCP connection, use "mcp-multibroker".
    It combines these servers with each other or with third-party MCP
    servers, whether started locally over stdio or reached over HTTP. Their
    tools appear under separate name prefixes; see "COMBINING SERVERS" and
    mcp-multibroker for the full command syntax.

YOUR FIRST FILESYSTEM SERVER
    Start with one project and one connection. You do not need a
    multibroker, a hand-written configuration file or saved permission rules
    yet.

  Choose stdio or HTTP
    Use stdio when your MCP client runs on the same machine and can launch a
    server process. Configure the client to start the following command:

       mcp-fs --stdio --name code /home/alice/src/project

    The client starts this process and uses its stdin/stdout for MCP. You do
    not start a second copy in a terminal, and there is no listener URL or
    HTTP token to configure. Diagnostics go to stderr.

    Clients that take a command and an argument array need these values:

       command: mcp-fs
       arguments: --stdio, --name, code, /home/alice/src/project

    These describe separate arguments, not one shell command string. Use an
    absolute executable path if the client cannot find "mcp-fs". See "CLIENT
    EXAMPLES" for examples of particular clients.

    Use HTTP when the client connects to an already-running server, or when
    it cannot launch a local process. Start this in a terminal on the server
    machine and leave it running:

       mcp-fs --name code --bind :31741 /home/alice/src/project

    In another terminal, obtain the matching connection URL:

       mcp-fs --name code --bind :31741 --print-url

    The second command prints a credential-bearing URL and exits without
    opening a listener. Configure that URL in the client. The default
    address is IPv4 loopback, so this example is reachable from the same
    machine only. A hosted client needs a suitable tunnel or reachable
    endpoint; its own "localhost" is not your computer.

    Repeat the same name and listener overrides when printing the URL. Both
    commands must use the same user and configuration directory. Port zero
    chooses an ephemeral port, which "--print-url" cannot predict; use an
    explicit port for this walkthrough.

    The HTTP server generates and saves its private master secret when
    needed. You can initialize it explicitly with "anyevent-mcp init", but
    that command is unnecessary when configuration already exists and will
    refuse to replace it. Keep the printed URL private: possession of its
    token authenticates a client.

  Make a useful request
    Once your client reports that the server is connected, ask the LLM:

       Show me the configured workdirs. List the top-level files in the
       project, then read its README if it has one. Do not modify files
       or run commands.

    "workdirs" returns the configured paths, sandbox grants, trusted mounts
    and runtime paths. Listing names requests "inspect" permission; reading
    contents requests "read" permission. Expect a permission prompt when
    there is no saved rule allowing the operation.

    Choose "Allow once" for the first operation. The worker then runs with
    the requested sandbox grants. A denial is a tool failure that the LLM
    should report, rather than an empty file or a disconnected server. See
    "Your first permission dialog" for a walkthrough.

    For a slightly larger task, ask:

       Find TODO comments in this project and explain the three that look
       most useful to address next. Do not modify files or run commands.

    This can use "find", "grep" and "read-lines". You need not write MCP

README  view on Meta::CPAN

    environment; do not put a real key in a script, command line or example.
    Associate the tunnel with the ChatGPT workspace where you want to use
    it.

    For stdio, put the server startup command in a small executable wrapper,
    for example "/home/alice/bin/my-mcp":

       #!/bin/sh
       exec mcp-multibroker --stdio \
          code --- mcp-fs --name code /home/alice/src/project --- \
          questions --- mcp-ask-user ---

    With a tunnel installation providing "tunnel-client-runtime", run:

       tunnel-client-runtime run \
          --log.format=struct-text \
          --log.level=warn \
          --control-plane.tunnel-id=tunnel_... \
          --mcp.connection-max-ttl=120s \
          --mcp.command=/home/alice/bin/my-mcp

    The tunnel starts the wrapper as its stdio MCP server. Do not start a
    separate copy yourself. Make the wrapper executable and ensure its
    programs and Perl modules are on the tunnel process's "PATH".

    For HTTP, instead start the server or multibroker separately:

       mcp-multibroker --name tools --bind 127.0.0.1:16586 \
          code 'stdio:mcp-fs --name code /home/alice/src/project'

    Obtain the matching credential-bearing URL:

       mcp-multibroker --name tools --bind 127.0.0.1:16586 --print-url

    Then point the tunnel runtime at that URL, rather than a command:

       tunnel-client-runtime run \
          --log.format=struct-text \
          --log.level=warn \
          --control-plane.tunnel-id=tunnel_... \
          --mcp.connection-max-ttl=120s \
          --mcp.server-url=http://127.0.0.1:16586/TOKEN/

    Replace "TOKEN" with the actual URL path printed above, and keep it
    private. In this mode, the multibroker must remain running separately;
    the tunnel only connects to it. Both modes require the tunnel runtime to
    remain active while the hosted client uses the server. Use one of
    "--mcp.command" and "--mcp.server-url", not both.

    In ChatGPT, add a custom MCP server using a Tunnel connection and select
    the tunnel ID. Creation and visibility depend on the Platform and
    ChatGPT workspace permissions. The tunnel client's CLI and supported
    configuration forms can vary between releases; the examples above use
    the direct runtime CLI rather than its optional profile setup. See
    Secure MCP Tunnel
    <https://developers.openai.com/api/docs/guides/secure-mcp-tunnels> for
    obtaining a tunnel, runtime, credentials and connecting it to ChatGPT.

TROUBLESHOOTING
  The server does not start
    Read stderr or the client's server log. Missing Perl modules, a missing
    workdir, unsuitable utilities or an unavailable bubblewrap executable
    can fail startup. Confirm that the client launches the same executable
    and arguments you intended, with the expected "PATH" and Perl
    installation.

    For a local sandbox check, run from the project directory:

       mcp-fs --exec-cmd workdir-read -- ls

    This runs "ls" with the named grants and trusted baseline mounts,
    without MCP or saved permission rules. A failure here can identify a
    bubblewrap or runtime problem. It does not test the client connection or
    approval UI. "--sandbox none" disables isolation and changes worker
    authority; it is not a fix that preserves the same permission boundary.

  The client cannot connect
    For stdio, configure a command the client launches, rather than a URL. A
    separately running stdio process is not the client's connection. Do not
    put banners or diagnostics on stdout.

    For HTTP, leave the server running and check its address and port.
    "--print-url" exits without starting it. Loopback binds accept local
    connections only; hosted or remote clients need the appropriate route or
    tunnel. An occupied port causes a listener error, so check the server
    log.

    For reverse "--connect" servers, check the connecting process's log as
    well as the multibroker. "https://" requires a certificate trusted by
    the connecting process and a hostname matching the URL. A TLS error
    stops that reverse server immediately; it does not retry with plaintext.
    TCP connection refusal is retried for up to sixty attempts.

  Authentication fails
    Obtain the URL with the same name, bind/token overrides and
    configuration environment as the running process. Use the complete path;
    the final slash is optional for endpoints whose configured path ends in
    one. A clean URL needs an accepted bearer token.

    A multibroker child credential is not necessarily the upstream
    listener's credential. "--bearer" after a child pair and "--token"
    before the pairs configure different sides of the connection.

    For IMAP OAuth2, obtaining an access token does not by itself prove that
    IMAP authentication will work. Check the authorized browser account,
    requested IMAP scope and saved "user" name. Copy the complete redirected
    address-bar URL after authorization, even when the browser displays an
    unreachable loopback page.

    If the server warns that it cannot save the master secret, another
    process may derive a different token. Check write access to the global
    configuration. Do not replace an existing secret simply to add a
    setting.

  Connected, but there are no tools
    Inspect the server's stderr for omitted utilities. mcp-fs's "workdirs"
    tool reports configuration even when a utility-dependent tool is absent.
    For a multibroker, call "discover-brokers" to see individual connection
    errors, then "list-tools" to refresh definitions.

    A third-party child might require initialization or features this client
    implementation does not support. See AnyEvent::MCP::Client and its
    transport documentation for limitations.

  There is no approval dialog
    First check whether the tool was denied by a saved rule or is waiting
    for the client's own approval. An allowed operation needs no server
    prompt.

    The default helper runs on the server machine. A background service may
    have neither a usable display nor "/dev/tty", even though your
    interactive shell has both. Supply the appropriate display environment,
    a usable helper, or "--ask auto" with a modern client supporting form
    elicitation. "--ask mcp" reports an error if that support is absent.

    Setting an asking mode cannot make an unsupported client display a form.
    Check stderr and the tool error instead of assuming a missing dialog is
    an approval.

  It asks again after I chose allow
    Allow-once covers one tool invocation, including its permission retries.
    The next invocation asks again. Use allow-always to save a rule.

    Inspect the saved rule's action, workdir and grants. Listing names and
    reading contents are different actions. A rule for one exact workdir
    spelling will not match a differently spelled startup argument. A
    request for extra authority, such as networking, does not match a
    workdir-read-only allow rule. Earlier ask or deny rules take precedence.

    Confirm that the prompt's permanent rule was successfully saved and that
    you are editing the rules for the actual child name, not merely its
    multibroker prefix.

  The worker cannot see a directory or executable
    The worker sees granted mounts and trusted baseline mounts, not
    everything the server process can see. Check "workdirs" for the selected
    path, mounts and runtime paths. A symlink target outside those mounts is
    unavailable.

    The ordinary sandbox runtime includes "/usr", "/bin" and system
    libraries, but not "/opt". For tools or libraries under "/opt", add this
    to "[program mcp-fs]" in the private global configuration:

       mount.opt = ro:/opt

    This assumes "/opt" exists. Restart mcp-fs after changing trusted
    mounts. If your worker Perl is "/opt/bin/perl", you can also set
    "executable.perl = /opt/bin/perl" in that program section. Supply the
    actual executable path: selecting it does not itself mount the
    executable or its dependencies inside the worker.

    A trusted mount supplies baseline access to every worker using it; a
    writable mount likewise supplies baseline write authority.

    An arbitrary command might also need its user's configuration or
    repository credentials under HOME, or network access. Request the
    corresponding grants when needed; do not assume "workdir-read" includes
    them. For example, CVS over SSH can use "workdir-read" and "ssh-agent".
    The latter includes network access, the agent socket and
    "~/.ssh/known_hosts", without exposing private key files or the rest of
    HOME. The broker must inherit "SSH_AUTH_SOCK" from your environment.
    User-configured helpers outside the runtime mounts need an explicit
    trusted mount. An explicit exec grant array replaces the default rather
    than adding to it.

  My configuration change seems to be ignored
    Check which file and section the process actually selects. Global
    settings use the server user's "HOME"/"XDG_CONFIG_HOME". Instance names,
    program basenames and multibroker prefixes serve different purposes.

    Restart after changing startup settings, mounts or utilities. Permission
    rules need no restart, but their order still matters. Refresh discovery
    after a child restart; reconnect a client that retains an old tool list.
    "--print-url" reads the current configuration, which can differ from an
    older running process.

  The command failed, but the MCP request succeeded



( run in 0.772 second using v1.01-cache-2.11-cpan-60884a8df76 )