@xns-cloud/relayer-mcp 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ npx @xns-cloud/relayer-mcp@latest
15
15
  ## Requirements
16
16
 
17
17
  - **Node.js 20+** — see [Installing Node.js 20](#installing-nodejs-20) if your distro ships an older version.
18
- - **Docker Engine** — on the same machine, or on a remote host via a Docker context (see [Remote Docker hosts](#remote-docker-hosts)).
18
+ - **Docker Engine** — on the same machine that runs the MCP. `install_relayer` refuses when the Docker daemon is on another machine (see [Remote Docker hosts](#remote-docker-hosts)).
19
19
 
20
20
  ### Installing Node.js 20
21
21
 
@@ -36,74 +36,7 @@ If you start the MCP on an older Node, it exits immediately with this same guida
36
36
 
37
37
  The Relayer runs as a Docker container and persists its data in a Docker volume. If the MCP is running inside an ephemeral environment (a sandbox container, a CI runner, or a throwaway VM), any installation performed there will be lost when that environment exits. `check_prerequisites` detects this automatically and reports it as a warning with a concrete next step — it never blocks the flow.
38
38
 
39
- **If your environment is ephemeral**, install on a persistent Docker host instead. The easiest path from an ephemeral sandbox is an SSH Docker context:
40
-
41
- ```bash
42
- docker context create relayer --docker "host=ssh://user@persistent-host"
43
- docker context use relayer
44
- ```
45
-
46
- The MCP then drives the install on the persistent host through the SSH context. Alternatively, hand the install step to a human operator on the target machine and continue onboarding from `check_relayer_health` onwards.
47
-
48
- **Know the tradeoff before you take this path.** With an SSH context the containers start on the remote host and the data lives in Docker volumes there, but `install_relayer` writes `docker-compose.yml` and `.env` on the machine running the MCP — not on the Docker host. That is fine for the install and fine for your data; it is not fine for day 2. Restarting, changing ports, and upgrading from the Docker host all need a compose file that host does not have. From an ephemeral sandbox it is worse: the only copy of those files exits with the sandbox, leaving a running Relayer nobody can administer.
49
-
50
- `check_prerequisites` warns about this before anything is written, and `install_relayer` returns an `action_required` field plus a `move_files` block carrying the source machine and path, the destination machine and path, the Docker endpoint it detected, where the compose file came from, and the contents of the env file it wrote. Either run the MCP on the Docker host, or [move the install directory across](#moving-the-install-files-to-the-docker-host) as soon as the install finishes.
51
-
52
- ### Moving the install files to the Docker host
53
-
54
- The MCP does **not** generate a copy command for you. Getting one right means guessing your scp version, shell, ssh port, bastion, sudo policy and path, and a wrong command that looks right is worse than no command. Below are three worked examples covering the common shapes — take the one that matches your setup and substitute the values from `move_files`.
55
-
56
- Three things to know before you adapt any of them:
57
-
58
- - **Keep the same directory name on both machines.** Compose takes the project name from the directory it runs in, and volume names are prefixed with it. Land the files in `/srv/relayer` instead of `/opt/xns-relayer` and `docker compose` there is a *different project*: it will not see the running containers, and `docker compose up` would create a second set of empty volumes and then fail, because `container_name: xns-relayer` is pinned in the compose file and that name is already taken. You get a `409 Conflict` rather than a working Relayer, plus stray empty volumes to clean up. Use the last path segment from `move_files.destination_path`. Keeping the whole path identical is safest — a compose file that binds a relative host path resolves it against the project directory.
59
- - **Copy to the parent directory.** `scp -r /opt/xns-relayer host:/opt/xns-relayer` copies *into* an existing target, leaving the files at `/opt/xns-relayer/xns-relayer/` where `docker compose` will not find them.
60
- - **`/opt` needs root.** If your ssh user cannot write the destination, create it first — `scp` will not create a missing parent.
61
-
62
- **1 — SSH Docker context, default path.** The common case.
63
-
64
- ```bash
65
- ssh -t user@docker-box 'sudo install -d -o $USER /opt/xns-relayer'
66
- scp -r /opt/xns-relayer user@docker-box:/opt
67
- ```
68
-
69
- **2 — Non-standard ssh port, or the Docker host behind a bastion.** Note `ssh` takes `-p` for the port and `scp` takes `-P`; `-J` is the jump host.
70
-
71
- ```bash
72
- ssh -t -p 2222 user@docker-box 'sudo install -d -o $USER /opt/xns-relayer'
73
- scp -P 2222 -r /opt/xns-relayer user@docker-box:/opt
74
-
75
- # via a bastion — the prepare step needs the same -J
76
- ssh -t -J user@bastion user@docker-box 'sudo install -d -o $USER /opt/xns-relayer'
77
- scp -J user@bastion -r /opt/xns-relayer user@docker-box:/opt
78
- ```
79
-
80
- **3 — No ssh route from this machine.** A `tcp://` Docker context, a key only the Docker CLI can use, or a locked-down sandbox. There are only two small files, so recreate them on the Docker host by hand.
81
-
82
- Check `move_files.compose_source` in the response first — it tells you where your compose file came from, and the three cases need different handling:
83
-
84
- | `compose_source` | Where to get `docker-compose.yml` |
85
- |---|---|
86
- | `channel` | `curl -fsSLO <compose_url>`, using the URL from `move_files.compose_url` |
87
- | `bundled-fallback` | It came from inside the npm package on the MCP machine, not from a URL. Copy that one file across by any means you have — a clipboard paste is fine, it is a few dozen lines. |
88
- | `compose_url` | Your own custom compose, from wherever you supplied it. |
89
-
90
- Then, in a directory whose **last path segment matches** `move_files.destination_path`:
91
-
92
- ```bash
93
- # on the Docker host
94
- sudo install -d -o $USER /opt/xns-relayer
95
- cd /opt/xns-relayer
96
- # put docker-compose.yml here per the table above, then write the env file:
97
- printf 'UI_PORT=8888\nS3_PORT=9000\nBIND_ADDRESS=\n' > .env
98
- ```
99
-
100
- Use the values from `move_files.env_contents`, not the defaults above, if you installed with custom ports or a bind address. If `env_contents` is `null` the install wrote no env file (the `compose_url` path) — your compose file supplies its own values, or you export them before `docker compose up`.
101
-
102
- Verify from the Docker host afterwards — this should list the running services rather than an error about a missing configuration file, and should show the containers that are *already up*, not propose new ones:
103
-
104
- ```bash
105
- cd /opt/xns-relayer && docker compose ps
106
- ```
39
+ **If your environment is ephemeral**, run the MCP on a persistent Docker host instead (install Node.js 20 there and point your MCP client at it). Alternatively, hand the install step to a human operator on the target machine and continue onboarding from `check_relayer_health` onwards.
107
40
 
108
41
  ## Install
109
42
 
@@ -194,23 +127,11 @@ then run `install_relayer` again. To keep the existing deployment, skip `install
194
127
 
195
128
  ## Remote Docker hosts
196
129
 
197
- Claude Code doesn't have to run on the Docker machine. If you run it on a management node or jump host, point the Docker CLI at the remote server with an SSH context:
198
-
199
- ```bash
200
- docker context create relayer --docker "host=ssh://user@docker-box"
201
- docker context use relayer
202
- ```
203
-
204
- (Requires the `docker` CLI on the management node — the [static binary](https://docs.docker.com/engine/install/binaries/) is enough — and SSH key access to the Docker host.)
205
-
206
- The MCP detects this automatically (it honors `DOCKER_HOST` and the active Docker context):
130
+ `install_relayer` writes `docker-compose.yml` and `.env` on the machine running the MCP, then runs `docker compose up` against whichever daemon the Docker CLI points at. When that daemon is on another machine (`DOCKER_HOST=ssh://…` or `tcp://…`, or an SSH Docker context), it refuses before writing or starting anything, and the error names the Docker host.
207
131
 
208
- - `install_relayer` runs `docker compose` against the remote daemon.
209
- - `check_relayer_health` and `verify_storage` probe the **remote host's** ports 8888/9000 instead of localhost — make sure those are reachable from the management node.
210
- - `check_prerequisites` skips the local port-availability probes (the containers bind ports on the remote host) and reports them as skipped with instructions.
211
- - `check_prerequisites` also raises an `install_file_location` warning, and `install_relayer` returns `action_required` plus a `file_location` block naming both machines — because the install files are written on the management node while the containers run on the Docker host. See [Environment](#environment) for what to do about it.
132
+ To install, run the MCP on the Docker host (Node.js 20 there, MCP client pointed at it) and run `install_relayer` again. Or unset `DOCKER_HOST` / switch to the default Docker context to install on the machine running the MCP.
212
133
 
213
- `check_relayer_health` accepts a `host` override, and `verify_storage` an `endpoint` override, for setups the auto-detection can't see (port forwards, NAT).
134
+ `check_prerequisites` reports the same condition as a failed `install_file_location` check. Health checks still work against a remote daemon: the MCP honors `DOCKER_HOST` and the active Docker context, `check_relayer_health` and `verify_storage` probe the remote host's ports 8888/9000 instead of localhost, and `check_prerequisites` skips the local port probes. `check_relayer_health` accepts a `host` override, and `verify_storage` an `endpoint` override, for setups the auto-detection can't see (port forwards, NAT).
214
135
 
215
136
  ## Troubleshooting
216
137
 
@@ -220,8 +141,8 @@ The MCP detects this automatically (it honors `DOCKER_HOST` and the active Docke
220
141
  | `install_relayer` reports an existing `xns-relayer` container | A previous deployment (any channel) owns the container name | [Fresh installs vs. existing deployments](#fresh-installs-vs-existing-deployments) |
221
142
  | Port 8888/9000 already in use | Another service on the Docker host (another S3-compatible service squatting 9000) | Stop it, or install with custom ports: `install_relayer` `ui_port` / `s3_port` (health checks accept the same) |
222
143
  | Health checks fail but containers run on a remote Docker host | Ports 8888/9000 not reachable from the management node | Open them, or pass `host` / `endpoint` overrides |
223
- | `docker compose` on the Docker host says no configuration file found, after a successful install | The MCP ran on another machine, so the compose and env files were written there | [Moving the install files to the Docker host](#moving-the-install-files-to-the-docker-host), or reinstall with the MCP running on the Docker host |
224
- | `install_relayer` fails with "Failed to create directory … on this machine" | The install path needs root on the machine running the MCP (common on macOS/Windows workstations for paths under `/opt`) | Pass a writable `install_path`, or run the MCP on the Docker host |
144
+ | `install_relayer` fails with "The Docker daemon is on <host>, not this machine" | `DOCKER_HOST` or an SSH/TCP Docker context points at another machine, and the install files would be written here instead | Run the MCP on that host and re-run, or unset `DOCKER_HOST` / use the default Docker context ([Remote Docker hosts](#remote-docker-hosts)) |
145
+ | `install_relayer` fails with "Failed to create directory …" | The install path needs root on the machine running the MCP (common on macOS/Windows workstations for paths under `/opt`), or a regular file sits at or along it | Pass a writable `install_path`; the exact OS error is in the MCP server's stderr log |
225
146
 
226
147
  ## Authentication
227
148
 
package/manifest.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.3",
3
3
  "name": "relayer-mcp",
4
4
  "display_name": "XNS Relayer",
5
- "version": "0.10.2",
5
+ "version": "0.11.0",
6
6
  "description": "Set up and manage a self-hosted XNS Relayer — S3-compatible object storage — conversationally.",
7
7
  "long_description": "XNS Relayer is S3-compatible object storage you host yourself: $0 egress, uncapped, on hardware you control. This extension gives Claude 15 tools that walk the whole lifecycle — check prerequisites, register an XNS account, install the Relayer via Docker Compose, claim it to your account, choose which hosts store your data (VPD), verify an S3 round trip, provision CLI credentials, then handle day-2 work: settings, service restarts, and configuration backups.\n\nThe server runs locally on your machine and talks to your Relayer over loopback or your private network only — connections to public addresses are refused by design. Sign-in happens in your browser against XNS's identity service; the agent never sees your password.",
8
8
  "author": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xns-cloud/relayer-mcp",
3
3
  "mcpName": "tech.xns/relayer",
4
- "version": "0.10.2",
4
+ "version": "0.11.0",
5
5
  "description": "MCP server for XNS Relayer onboarding and day-2 management — drives Relayer setup, settings, and backups conversationally over stdio, npx-ready",
6
6
  "author": "SCP Corp",
7
7
  "license": "Apache-2.0",
@@ -1,13 +1,39 @@
1
1
  'use strict';
2
2
 
3
+ const net = require('net');
3
4
  const { execFile: nodeExecFile } = require('child_process');
4
5
 
6
+ // Every loopback spelling a Docker endpoint can carry: localhost, the whole
7
+ // 127/8 block, the 0.0.0.0 / [::] wildcards, [::1], and IPv4-mapped 127/8
8
+ // ([::ffff:127.0.0.1], which URL normalizes to [::ffff:7f00:1]).
9
+ function isLoopbackHost(name) {
10
+ if (['localhost', '0.0.0.0', '[::1]', '[::]'].includes(name)) return true;
11
+ if (net.isIPv4(name)) return name.startsWith('127.');
12
+ const mapped = /^\[::ffff:([0-9a-f]{1,4}):[0-9a-f]{1,4}\]$/.exec(name);
13
+ return Boolean(mapped) && (parseInt(mapped[1], 16) >> 8) === 127;
14
+ }
15
+
16
+ /**
17
+ * Replace the password in an endpoint URL's userinfo with ***. An ssh:// or
18
+ * tcp:// DOCKER_HOST can carry one, and tools echo the endpoint back to the
19
+ * client. The password runs to the LAST '@' before the path, query or
20
+ * fragment, as URL parsers (and Docker's own) read it, so a password
21
+ * containing '@' is fully masked and an '@' after the authority is left alone.
22
+ *
23
+ * @param {string|null|undefined} endpoint
24
+ * @returns {string|null}
25
+ */
26
+ function redactEndpoint(endpoint) {
27
+ if (typeof endpoint !== 'string') return endpoint ?? null;
28
+ return endpoint.replace(/^([a-z][a-z0-9+.-]*:\/\/[^:@/?#]*):[^/?#]*@/i, '$1:***@');
29
+ }
30
+
5
31
  /**
6
32
  * Parse a Docker endpoint URL into { remote, host }.
7
33
  *
8
34
  * unix:// and npipe:// sockets are local by definition. ssh:// and tcp://
9
35
  * point at another machine — unless the hostname is loopback. Anything
10
- * unparseable falls back to local, matching pre-context behaviour.
36
+ * unparseable falls back to local, matching pre-context behavior.
11
37
  *
12
38
  * @param {string} endpoint - e.g. 'unix:///var/run/docker.sock', 'ssh://user@host'
13
39
  * @returns {{remote: boolean, host: string}}
@@ -18,8 +44,12 @@ function parseDockerEndpoint(endpoint) {
18
44
  if (endpoint.startsWith('unix://') || endpoint.startsWith('npipe://')) return local;
19
45
  try {
20
46
  const { hostname } = new URL(endpoint);
21
- // URL.hostname keeps IPv6 brackets: 'tcp://[::1]:2375' → '[::1]'
22
- if (!hostname || ['localhost', '127.0.0.1', '[::1]'].includes(hostname)) return local;
47
+ // URL.hostname keeps IPv6 brackets ('tcp://[::1]:2375' → '[::1]') and
48
+ // does not lowercase tcp:// or ssh:// hosts, so compare lowercased.
49
+ // install_relayer refuses a remote daemon, so every loopback form —
50
+ // the whole 127/8 block, the 0.0.0.0 / [::] wildcards — must read local.
51
+ const name = hostname.toLowerCase();
52
+ if (!name || isLoopbackHost(name)) return local;
23
53
  return { remote: true, host: hostname };
24
54
  } catch {
25
55
  return local;
@@ -146,4 +176,4 @@ function createDockerUtil(options = {}) {
146
176
  return { docker, composeUp, isContainerRunning, findContainer, getDockerHost };
147
177
  }
148
178
 
149
- module.exports = { createDockerUtil, parseDockerEndpoint };
179
+ module.exports = { createDockerUtil, parseDockerEndpoint, redactEndpoint };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const net = require('net');
4
4
  const { createHttpClient } = require('../lib/httpClient');
5
- const { createDockerUtil } = require('../lib/dockerUtil');
5
+ const { createDockerUtil, redactEndpoint } = require('../lib/dockerUtil');
6
6
  const { environmentProbe: defaultEnvironmentProbe } = require('../lib/environmentProbe');
7
7
 
8
8
  /**
@@ -39,7 +39,7 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
39
39
  'check_prerequisites',
40
40
  {
41
41
  title: 'check_prerequisites',
42
- description: 'Check system prerequisites for XNS Relayer installation: Docker availability (local or remote via DOCKER_HOST / ssh:// context), required ports (8888, 9000), an existing xns-relayer installation, disk space, and network connectivity to console.xns.tech and auth.xns.tech. Also reports where install_relayer will write its files: on a remote Docker daemon the files land on this machine while the containers run on the remote host, raised as an install_file_location warning. Run this first before any other relayer tool.',
42
+ description: 'Check system prerequisites for XNS Relayer installation: Docker availability (local or remote via DOCKER_HOST / ssh:// context), required ports (8888, 9000), an existing xns-relayer installation, disk space, and network connectivity to console.xns.tech and auth.xns.tech. Also fails the check when the Docker daemon is on another machine (install_file_location), because install_relayer refuses in that case; run the MCP on the Docker host instead. Run this first before any other relayer tool.',
43
43
  inputSchema: {
44
44
  /* no parameters */
45
45
  },
@@ -69,7 +69,7 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
69
69
  dockerHost = {
70
70
  remote: isRemote,
71
71
  host: isRemote ? remoteHost : 'localhost',
72
- endpoint: raw?.endpoint ?? null,
72
+ endpoint: redactEndpoint(raw?.endpoint), // echoed in the docker check detail
73
73
  };
74
74
  checks.push({
75
75
  name: 'docker',
@@ -84,27 +84,20 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
84
84
  name: 'docker',
85
85
  passed: false,
86
86
  detail: 'Docker is not available or not running',
87
- remediation: 'Install Docker Engine (https://docs.docker.com/engine/install/) and ensure the Docker daemon is running. On Linux: sudo systemctl start docker. Remote daemon: create an SSH context — docker context create relayer --docker "host=ssh://user@host" && docker context use relayer',
87
+ remediation: 'Install Docker Engine (https://docs.docker.com/engine/install/) and ensure the Docker daemon is running. On Linux: sudo systemctl start docker. To install on a persistent machine, run this MCP on that machine (a Docker host with Node.js 20) rather than pointing at it remotely.',
88
88
  });
89
89
  }
90
90
 
91
- // 1b. WHERE the install files will land. This is the last point at
92
- // which the user can still choose to run the MCP on the Docker host
93
- // instead — install_relayer writes its docker-compose.yml and .env
94
- // with local mkdir/curl/fs while starting the containers remotely,
95
- // so on a remote daemon the deployment and the files that define it
96
- // end up on different machines. Nothing is lost (named volumes keep
97
- // the data on the Docker host), but nobody can restart, re-port, or
98
- // upgrade it from the Docker host without those files — and if this
99
- // machine is a sandbox, the only copy dies with it. Say so BEFORE a
100
- // file is written, not in the success payload afterwards.
91
+ // 1b. install_relayer refuses when the daemon is on another machine
92
+ // (it writes docker-compose.yml and .env on THIS machine). Fail here
93
+ // so a passing check is never followed by a refused install.
101
94
  if (dockerHost.remote) {
95
+ allPassed = false;
102
96
  checks.push({
103
97
  name: 'install_file_location',
104
- passed: true,
105
- warning: true,
106
- detail: `install_relayer runs on THIS machine and writes docker-compose.yml and .env here, but the Docker daemon is on ${dockerHost.host} — so the containers and the files that define them will end up on different machines. The install itself works and the data is safe (Docker named volumes on ${dockerHost.host}); what will not work is restarting, changing ports, or upgrading from ${dockerHost.host}, because that host has no compose file.`,
107
- remediation: `Preferred: run the MCP on ${dockerHost.host} itself (install Node.js 20 there and point your MCP client at it) so the files and the containers stay together. Otherwise install from here and move the install directory to ${dockerHost.host} immediately afterwards, before you need to restart or upgrade — see "Moving the install files to the Docker host" in the relayer-mcp README for worked examples. If this machine is a sandbox, CI runner, or throwaway VM, move them before the session ends: the only copy of your compose file leaves with it.`
98
+ passed: false,
99
+ detail: `The Docker daemon is on ${dockerHost.host}, not this machine. install_relayer will refuse: it writes docker-compose.yml and .env on this machine, not on ${dockerHost.host}.`,
100
+ remediation: `Run the MCP on ${dockerHost.host} (install Node.js 20 there and point your MCP client at it), then run check_prerequisites and install_relayer from there. Or unset DOCKER_HOST / switch to the default Docker context to install on this machine.`,
108
101
  });
109
102
  }
110
103
 
@@ -173,8 +166,8 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
173
166
  ? `This environment appears to be ephemeral (${probe.signals.join('; ')}), but Docker targets a remote host (${dockerHost.host}). Persistence depends on the remote Docker host.`
174
167
  : `This environment appears to be ephemeral (${probe.signals.join('; ')}). A Relayer installed here will be lost when the container exits.`,
175
168
  remediation: remoteDocker
176
- ? `The Relayer will be installed on the remote Docker host — verify that host has persistent storage. Note also that install_relayer writes docker-compose.yml and .env HERE, in this ephemeral environment, not on ${dockerHost.host}. Move them to ${dockerHost.host} straight after the install or they are gone when this environment exits, leaving a running deployment nobody can restart or upgrade.`
177
- : 'Install on a persistent Docker host instead. If you are running from a sandbox or CI, use an SSH Docker context to target a persistent machine: docker context create relayer --docker "host=ssh://user@host" && docker context use relayer',
169
+ ? `install_relayer will refuse while Docker targets ${dockerHost.host}. Run the MCP on ${dockerHost.host} (a persistent Docker host) instead of from this ephemeral environment.`
170
+ : 'Install on a persistent Docker host instead. If you are running from a sandbox or CI, run the MCP on a persistent Docker host rather than here.',
178
171
  });
179
172
  } else {
180
173
  checks.push({ name: 'ephemeral_environment', passed: true, detail: 'Environment appears persistent — install will survive restarts' });
@@ -3,7 +3,7 @@
3
3
  const { z } = require('zod');
4
4
  const path = require('path');
5
5
  const net = require('net');
6
- const { createDockerUtil } = require('../lib/dockerUtil');
6
+ const { createDockerUtil, redactEndpoint } = require('../lib/dockerUtil');
7
7
 
8
8
  const BIND_ADDRESS_HELP = 'bind_address must be empty (all interfaces), an IPv4 address (e.g. "127.0.0.1"), or a bracketed IPv6 address (e.g. "[::1]") — the Compose ports host component is an IP address, not a hostname';
9
9
 
@@ -46,29 +46,20 @@ const TEMPLATE_PATH = path.join(__dirname, '..', 'templates', 'docker-compose.ym
46
46
  // alpha channel or beta — makes `docker compose up` fail with a name conflict.
47
47
  const CONTAINER_NAME = 'xns-relayer';
48
48
 
49
- // The machine running this MCP and the machine running the Docker daemon are
50
- // routinely NOT the same one. Claude Desktop and Cursor run on a workstation;
51
- // the disks live on a server. Our own README steers ephemeral-sandbox users to
52
- // an ssh:// Docker context, and check_prerequisites' remediation text says the
53
- // same. In that configuration every file this tool writes (mkdir, curl, the
54
- // .env) lands HERE while composeUp starts the containers THERE.
55
- //
56
- // The install still works: the compose uses named volumes, so the data lives on
57
- // the Docker host and nothing is lost. What breaks is day 2 — restart, port
58
- // change, upgrade all need a compose file that is not on the machine running
59
- // the containers, and if this machine is a sandbox it takes the only copy with
60
- // it. Reporting a single install_path hides that, so the response names both
61
- // machines instead.
49
+ // The machine running this MCP and the machine running the Docker daemon can
50
+ // differ (DOCKER_HOST=ssh://..., tcp://..., or an ssh Docker context). This tool
51
+ // writes docker-compose.yml and .env on THIS machine, while compose up runs on
52
+ // the Docker host, so with a remote daemon it refuses before writing anything.
62
53
  const LOCAL_DOCKER_HOST = Object.freeze({ remote: false, host: 'localhost', endpoint: null });
63
54
 
64
55
  /**
65
56
  * Resolve which machine the Docker daemon runs on, defensively.
66
57
  *
67
- * Advisory only — this must NEVER be the reason an install fails, so a missing
68
- * helper, a throwing helper, or incomplete metadata all fall back to local.
69
- * "remote" without a nameable host is incomplete metadata, not a remote
70
- * install; checkPrerequisites applies the same rule and we must not warn about
71
- * a machine we cannot name.
58
+ * The result gates the install: a remote daemon makes install_relayer refuse.
59
+ * A detection failure (missing helper, throwing helper) or incomplete metadata
60
+ * ("remote" without a nameable host) still falls back to local and installs,
61
+ * because refusing on a machine we cannot name would block installs on a guess
62
+ * and give the user nothing to act on.
72
63
  */
73
64
  async function resolveDockerHost(docker) {
74
65
  if (!docker || typeof docker.getDockerHost !== 'function') return LOCAL_DOCKER_HOST;
@@ -85,6 +76,14 @@ async function resolveDockerHost(docker) {
85
76
  }
86
77
  }
87
78
 
79
+ // Caught error text never goes back to the MCP client (.coderabbit.yaml path
80
+ // rule): execFile and OS messages can carry paths and system detail. A failure
81
+ // this file raises is marked userSafe (same convention as verifyStorage.js) and
82
+ // its cause is logged to stderr.
83
+ function safeError(message, cause) {
84
+ return Object.assign(new Error(message, { cause }), { userSafe: true });
85
+ }
86
+
88
87
  /**
89
88
  * Tool 4: install_relayer
90
89
  * AC-12: confirms "containers starting"; no manual shell.
@@ -99,7 +98,7 @@ async function resolveDockerHost(docker) {
99
98
  * install still completes and the response says it fell back.
100
99
  *
101
100
  * `compose_url` stays as an optional override for internal/custom installs;
102
- * when given, the old download-a-URL behaviour is preserved.
101
+ * when given, the old download-a-URL behavior is preserved.
103
102
  */
104
103
  module.exports = function registerInstallRelayer(server, options = {}) {
105
104
  const docker = options.dockerUtil || createDockerUtil(options);
@@ -111,7 +110,7 @@ module.exports = function registerInstallRelayer(server, options = {}) {
111
110
  'install_relayer',
112
111
  {
113
112
  title: 'install_relayer',
114
- description: 'Install and start the XNS Relayer. By default fetches the canonical beta channel bundle — relayer + the Prometheus/Grafana monitoring stack — from releases.scpri.me (anonymous pull) and writes a .env, then runs docker compose up -d — the user does NOT need to author any file. Falls back to a bundled copy of the bundle if the fetch fails. Pass compose_url only to override with a custom compose.\n\nIMPORTANT — two machines: this tool writes docker-compose.yml and .env on the machine running the MCP, but starts the containers on whichever machine the Docker daemon is on. With DOCKER_HOST or an ssh:// Docker context those are different machines. The install works and the data is safe (Docker named volumes on the Docker host), but the deployment cannot be restarted, re-ported, or upgraded from the Docker host until those files are copied there. When it detects a remote daemon the response leads with an action_required field, file_location names both machines, and move_files carries the source and destination plus the env-file contents. This tool deliberately does NOT generate a copy command — the correct one depends on the scp version, shell, ssh port, bastion and sudo policy in use, and a wrong command that looks right is worse than none; the README section named in the response has worked examples for the common setups. Surface action_required to the user verbatim — do not summarize it away.\n\nExposure decisions on this surface:\n\n1. BINDING — bind_address controls which host network interface Docker publishes ports on. Default: empty (all interfaces — the dashboard answers from any machine on the LAN with zero configuration). Set to "127.0.0.1" for loopback-only, or a specific interface IP. The value is passed to docker compose via env as BIND_ADDRESS; it takes effect only if the compose file used for the install references BIND_ADDRESS in its port declarations. The bundled fallback compose does; the channel compose and any compose_url override are fetched remotely and may not. The prerequisite check (check_prerequisites) probes port availability by binding 0.0.0.0 regardless of this setting.\n\n2. UI TLS — ui_tls_enabled describes whether the admin UI listens on HTTPS in addition to HTTP. Default: false (off). This switch is described here for decision visibility; it is NOT wired to behavior in this version — setting it to true is accepted but has no effect until a future release ships the listener. Cost when enabled: requires a TLS certificate and key provisioned on the host.\n\n3. S3 TLS — s3_tls_enabled describes whether the S3 gateway listens on HTTPS in addition to HTTP. Default: false (off). This switch is described here for decision visibility; it is NOT wired to behavior in this version — setting it to true is accepted but has no effect until a future release ships the listener. Cost when enabled: requires a TLS certificate and key provisioned on the host; S3 clients must be configured to use the HTTPS endpoint.',
113
+ description: 'Install and start the XNS Relayer. By default fetches the canonical beta channel bundle — relayer + the Prometheus/Grafana monitoring stack — from releases.scpri.me (anonymous pull) and writes a .env, then runs docker compose up -d — the user does NOT need to author any file. Falls back to a bundled copy of the bundle if the fetch fails. Pass compose_url only to override with a custom compose.\n\nIMPORTANT — two machines: this tool writes docker-compose.yml and .env on the machine running the MCP, then starts the containers on whichever machine the Docker daemon is on. When DOCKER_HOST or an ssh:// Docker context points at a daemon on another machine, the tool refuses: it writes nothing and starts nothing, and returns an error naming the Docker host. Run the MCP on the Docker host (Node.js 20 there) and install from there.\n\nExposure decisions on this surface:\n\n1. BINDING — bind_address controls which host network interface Docker publishes ports on. Default: empty (all interfaces — the dashboard answers from any machine on the LAN with zero configuration). Set to "127.0.0.1" for loopback-only, or a specific interface IP. The value is passed to docker compose via env as BIND_ADDRESS; it takes effect only if the compose file used for the install references BIND_ADDRESS in its port declarations. The bundled fallback compose does; the channel compose and any compose_url override are fetched remotely and may not. The prerequisite check (check_prerequisites) probes port availability by binding 0.0.0.0 regardless of this setting.\n\n2. UI TLS — ui_tls_enabled describes whether the admin UI listens on HTTPS in addition to HTTP. Default: false (off). This switch is described here for decision visibility; it is NOT wired to behavior in this version — setting it to true is accepted but has no effect until a future release ships the listener. Cost when enabled: requires a TLS certificate and key provisioned on the host.\n\n3. S3 TLS — s3_tls_enabled describes whether the S3 gateway listens on HTTPS in addition to HTTP. Default: false (off). This switch is described here for decision visibility; it is NOT wired to behavior in this version — setting it to true is accepted but has no effect until a future release ships the listener. Cost when enabled: requires a TLS certificate and key provisioned on the host; S3 clients must be configured to use the HTTPS endpoint.',
115
114
  inputSchema: {
116
115
  install_path: z.string().optional().default('/opt/xns-relayer').describe('Directory to install the compose file into'),
117
116
  ui_port: z.number().int().min(1).max(65535).optional().default(8888).describe('Host port for the Relayer admin/customer UI (container 8888). Docker publishes this port on the interface chosen by bind_address.'),
@@ -136,12 +135,24 @@ module.exports = function registerInstallRelayer(server, options = {}) {
136
135
  const composePath = path.join(install_path, 'docker-compose.yml');
137
136
  const envPath = path.join(install_path, '.env');
138
137
 
139
- // Resolved before the first write so every message below — the
140
- // mkdir error included — can name the right machine.
138
+ // Gate first: before any lookup, mkdir, download or write. The
139
+ // files would land on this machine, not on the Docker host.
141
140
  const dockerHost = await resolveDockerHost(docker);
142
- const localDesc = dockerHost.remote
143
- ? `this machine (the one running the MCP, NOT the Docker host ${dockerHost.host})`
144
- : 'this machine';
141
+ if (dockerHost.remote) {
142
+ return {
143
+ content: [{
144
+ type: 'text',
145
+ text: JSON.stringify({
146
+ success: false,
147
+ error: `The Docker daemon is on ${dockerHost.host}, not this machine. install_relayer would write docker-compose.yml and .env on this machine instead of on ${dockerHost.host}, so nothing was written and nothing was started.`,
148
+ docker_host: dockerHost.host,
149
+ docker_endpoint: redactEndpoint(dockerHost.endpoint),
150
+ remediation: `Run the MCP on ${dockerHost.host} (install Node.js 20 there and point your MCP client at it), then run install_relayer again. Or, to install on this machine, unset DOCKER_HOST or switch to the default Docker context.`,
151
+ }, null, 2),
152
+ }],
153
+ isError: true,
154
+ };
155
+ }
145
156
 
146
157
  // Preflight: install_relayer is for FRESH installs only — it does
147
158
  // not upgrade an existing deployment in place. An existing
@@ -166,17 +177,14 @@ module.exports = function registerInstallRelayer(server, options = {}) {
166
177
  // Create install directory (execFile, no shell)
167
178
  await new Promise((resolve, reject) => {
168
179
  execFileFn('mkdir', ['-p', install_path], {}, (err) => {
169
- // mkdir runs HERE, not on the Docker host. On a workstation
170
- // driving a remote daemon, /opt needs root and this is the
171
- // first thing that fails — so name the machine that refused.
172
- if (err) return reject(new Error(`Failed to create directory ${install_path} on ${localDesc}: ${err.message}`));
180
+ if (err) return reject(safeError(`Failed to create directory ${install_path} — check that the path is writable on this machine and no file sits at or along it`, err));
173
181
  resolve();
174
182
  });
175
183
  });
176
184
 
177
185
  const fetchCompose = (url) => new Promise((resolve, reject) => {
178
186
  execFileFn('curl', ['-fsSL', '-o', composePath, url], { timeout: 60000 }, (err) => {
179
- if (err) return reject(new Error(`Failed to download compose file: ${err.message}`));
187
+ if (err) return reject(safeError('Failed to download compose file', err));
180
188
  resolve();
181
189
  });
182
190
  });
@@ -201,7 +209,8 @@ module.exports = function registerInstallRelayer(server, options = {}) {
201
209
  const template = await fsp.readFile(TEMPLATE_PATH, 'utf8');
202
210
  await fsp.writeFile(composePath, template);
203
211
  source = 'bundled-fallback';
204
- note = `Channel bundle fetch failed (${fetchErr.message}) — fell back to the bundled compose. Same services; re-running install later is not required.`;
212
+ console.error(`[install_relayer] channel bundle fetch failed: ${fetchErr.cause?.message ?? fetchErr.message}`);
213
+ note = 'Channel bundle fetch failed — fell back to the bundled compose. Same services; re-running install later is not required.';
205
214
  }
206
215
  envContents = `UI_PORT=${ui_port}\nS3_PORT=${s3_port}\nBIND_ADDRESS=${bindPrefix}\n`;
207
216
  await fsp.writeFile(envPath, envContents);
@@ -215,88 +224,14 @@ module.exports = function registerInstallRelayer(server, options = {}) {
215
224
  env: { ...process.env, UI_PORT: String(ui_port), S3_PORT: String(s3_port), BIND_ADDRESS: bindPrefix },
216
225
  });
217
226
 
218
- // Two machines, two statements — never one install_path that is
219
- // only true on one of them. `action_required` leads the payload
220
- // when they differ so an agent relaying this cannot bury it.
221
- const fileLocation = {
222
- same_machine: !dockerHost.remote,
223
- files_written_on: dockerHost.remote
224
- ? 'this machine — the one running the MCP, NOT the Docker host'
225
- : 'this machine (which is also the Docker host)',
226
- docker_host: dockerHost.remote ? dockerHost.host : 'localhost',
227
- docker_endpoint: dockerHost.endpoint,
228
- containers_running_on: dockerHost.remote ? dockerHost.host : 'this machine',
229
- data_stored_on: dockerHost.remote
230
- ? `${dockerHost.host} — Docker named volumes on the Docker host; no Relayer data is stored on this machine`
231
- : 'this machine — Docker named volumes',
232
- };
233
-
234
- // Deliberately no generated shell command here. Getting one right
235
- // means guessing the user's scp version, shell, ssh port, bastion,
236
- // sudo policy and path — and a wrong command that looks right is
237
- // worse than none. State the facts instead and point at the
238
- // worked examples in the README, which a person can match to
239
- // their own setup. `move_files` carries enough to rebuild the
240
- // install by hand when there is no ssh route at all — but only
241
- // `compose_source` tells the user WHICH of the three recovery
242
- // paths applies, and on the compose_url path there is no env
243
- // file to hand back because none was written.
244
- const actionRequired = dockerHost.remote
245
- ? `The Relayer is running on ${dockerHost.host}, but the files that define it are NOT. `
246
- + `${envContents ? 'docker-compose.yml and the env file were' : 'docker-compose.yml was'} written to ${install_path} on this machine; `
247
- + `${dockerHost.host} has no copy. Your data is safe — it is in Docker volumes on ${dockerHost.host}. `
248
- + `What does not work until you fix this: restarting, changing ports, or upgrading from `
249
- + `${dockerHost.host}, because "docker compose" there has no file to read. `
250
- + `Move them now, not later — if this machine is a sandbox, CI runner, or throwaway VM, before the session ends. `
251
- + `Keep the same directory name — compose takes its project name from it, so a differently-named `
252
- + `directory starts a new project that creates empty volumes and then fails on the pinned `
253
- + `xns-relayer container name. `
254
- + `See "Moving the install files to the Docker host" in the relayer-mcp README for worked examples covering `
255
- + `an ssh Docker context, a non-standard port or bastion, and a host you cannot ssh to from here. `
256
- + `Better long-term: run this MCP on ${dockerHost.host} so the files and the containers stay together.`
257
- : null;
258
-
259
227
  return {
260
228
  content: [{
261
229
  type: 'text',
262
230
  text: JSON.stringify({
263
231
  success: true,
264
- ...(actionRequired ? { action_required: actionRequired } : {}),
265
- message: dockerHost.remote
266
- ? `XNS Relayer containers are starting on ${dockerHost.host}. Read action_required before continuing — the install files were written on this machine, not on ${dockerHost.host}. Use check_relayer_health to monitor when all services are ready.`
267
- : 'XNS Relayer containers are starting. Use check_relayer_health to monitor when all services are ready.',
232
+ message: 'XNS Relayer containers are starting. Use check_relayer_health to monitor when all services are ready.',
268
233
  compose_path: composePath,
269
234
  install_path,
270
- file_location: fileLocation,
271
- ...(dockerHost.remote ? {
272
- move_files: {
273
- source_machine: 'this machine (the one running the MCP)',
274
- source_path: install_path,
275
- destination_machine: dockerHost.host,
276
- // The last path segment is load-bearing: compose derives
277
- // the project name from it and prefixes volume names with
278
- // it, so a differently-named directory on the Docker host is
279
- // a different project. It creates a second set of empty
280
- // volumes and then fails, because container_name is pinned
281
- // to xns-relayer and that name is already taken — a 409, not
282
- // a silent wrong start. Same directory name on both machines.
283
- destination_path: install_path,
284
- docker_endpoint: dockerHost.endpoint,
285
- files: envContents ? ['docker-compose.yml', '.env'] : ['docker-compose.yml'],
286
- // Which of the three recovery paths in the README applies.
287
- // 'bundled-fallback' is the one with no URL to fetch — that
288
- // compose came out of the npm package on THIS machine, so
289
- // the file itself has to travel.
290
- compose_source: source,
291
- compose_url: source === 'channel' ? channelComposeUrl
292
- : source === 'compose_url' ? compose_url
293
- : null,
294
- // null on the compose_url path: no env file is written
295
- // there, so there is nothing to hand back.
296
- env_contents: envContents,
297
- readme_section: 'Moving the install files to the Docker host',
298
- },
299
- } : {}),
300
235
  source,
301
236
  // D5/W5: state the binding at install time, out-of-band, so a
302
237
  // refused connection is explainable later. Two statements, never
@@ -331,12 +266,13 @@ module.exports = function registerInstallRelayer(server, options = {}) {
331
266
  }],
332
267
  };
333
268
  } catch (err) {
269
+ console.error(`[install_relayer] ${err.message}${err.cause ? `: ${err.cause.message}` : ''}`);
334
270
  return {
335
271
  content: [{
336
272
  type: 'text',
337
273
  text: JSON.stringify({
338
274
  success: false,
339
- error: `Relayer installation failed: ${err.message}`,
275
+ error: `Relayer installation failed: ${err.userSafe ? err.message : 'See server log for detail.'}`,
340
276
  }),
341
277
  }],
342
278
  isError: true,