@xns-cloud/relayer-mcp 0.11.1 → 0.13.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/PRIVACY.md +14 -8
- package/README.md +66 -19
- package/manifest.json +5 -6
- package/package.json +3 -5
- package/src/index.js +4 -2
- package/src/lib/dockerUtil.js +121 -2
- package/src/lib/nodeVersion.js +3 -3
- package/src/lib/serverInstructions.js +11 -0
- package/src/tools/checkClaimStatus.js +1 -1
- package/src/tools/checkEmailVerified.js +1 -1
- package/src/tools/checkPrerequisites.js +349 -40
- package/src/tools/checkRelayerHealth.js +64 -10
- package/src/tools/configureVpd.js +1 -1
- package/src/tools/describeSettings.js +2 -6
- package/src/tools/getHostTags.js +1 -1
- package/src/tools/installRelayer.js +276 -59
- package/src/tools/manageBackups.js +1 -1
- package/src/tools/restartService.js +1 -1
- package/src/tools/setupCliCredentials.js +1 -1
- package/src/tools/startClaim.js +1 -1
- package/src/tools/startRegistration.js +1 -1
- package/src/tools/updateSettings.js +1 -1
- package/src/tools/verifyStorage.js +1 -1
- package/src/templates/docker-compose.yml +0 -86
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const net = require('net');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
4
6
|
const { createHttpClient } = require('../lib/httpClient');
|
|
5
|
-
const { createDockerUtil, redactEndpoint } = require('../lib/dockerUtil');
|
|
7
|
+
const { createDockerUtil, redactEndpoint, classifyDockerFailure } = require('../lib/dockerUtil');
|
|
6
8
|
const { environmentProbe: defaultEnvironmentProbe } = require('../lib/environmentProbe');
|
|
7
9
|
|
|
10
|
+
// The one-command install (installs Docker, the compose plugin and the Relayer).
|
|
11
|
+
const INSTALL_COMMAND = 'curl -fsSL https://releases.xns.tech/relayer/install.sh | sh';
|
|
12
|
+
|
|
13
|
+
// The container the install script and install_relayer start.
|
|
14
|
+
const RELAYER_CONTAINER = 'xns-relayer';
|
|
15
|
+
|
|
16
|
+
// The Compose project the install script and install_relayer start the stack
|
|
17
|
+
// under, and the two monitoring containers the release compose names outright
|
|
18
|
+
// (container_name). A container with one of these names that belongs to some
|
|
19
|
+
// other project makes `docker compose up` fail with a name conflict.
|
|
20
|
+
const RELAYER_PROJECT = 'xns-relayer';
|
|
21
|
+
const FIXED_CONTAINER_NAMES = ['prometheus', 'alertmanager'];
|
|
22
|
+
|
|
23
|
+
// install_relayer's default install_path; the install script uses the same dir.
|
|
24
|
+
const DEFAULT_INSTALL_DIR = '/opt/xns-relayer';
|
|
25
|
+
|
|
26
|
+
// 10 GB in decimal bytes: fails at 10*10^9 - 1, passes at 10*10^9.
|
|
27
|
+
const MIN_FREE_BYTES = 10 * 10 ** 9;
|
|
28
|
+
const BYTES_PER_GB = 10 ** 9;
|
|
29
|
+
|
|
30
|
+
const GROUP_NOTE = 'the Docker socket refuses this user until the docker group applies (see docker_group)';
|
|
31
|
+
|
|
8
32
|
/**
|
|
9
33
|
* Tool 1: check_prerequisites
|
|
10
34
|
* Reports docker, ports, disk, and connectivity in plain English.
|
|
@@ -29,17 +53,193 @@ function checkPort(port) {
|
|
|
29
53
|
});
|
|
30
54
|
}
|
|
31
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Free space as "9.99 GB", rounded DOWN so a figure just under the threshold
|
|
58
|
+
* never prints as "10.00 GB".
|
|
59
|
+
*/
|
|
60
|
+
function formatGb(bytes) {
|
|
61
|
+
return `${(Math.floor(bytes / (BYTES_PER_GB / 100)) / 100).toFixed(2)} GB`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* statfs the nearest existing ancestor of `target` (the install dir usually
|
|
66
|
+
* does not exist before the install). Only ENOENT walks up; any other error
|
|
67
|
+
* propagates so the caller reports the leg as unreadable, never as passed.
|
|
68
|
+
*
|
|
69
|
+
* @returns {Promise<{path: string, freeBytes: number}>}
|
|
70
|
+
*/
|
|
71
|
+
async function freeBytesAt(statfs, target) {
|
|
72
|
+
let current = path.resolve(target);
|
|
73
|
+
for (;;) {
|
|
74
|
+
try {
|
|
75
|
+
const stats = await statfs(current);
|
|
76
|
+
return { path: current, freeBytes: Number(stats.bavail) * Number(stats.bsize) };
|
|
77
|
+
} catch (err) {
|
|
78
|
+
const parent = path.dirname(current);
|
|
79
|
+
if (err?.code !== 'ENOENT' || parent === current) throw err;
|
|
80
|
+
current = parent;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* True when /etc/group's docker line lists the user. An unreadable file reads
|
|
87
|
+
* as "not listed", which names the add-group command (safe either way).
|
|
88
|
+
*/
|
|
89
|
+
async function isInDockerGroup(readFile, username) {
|
|
90
|
+
try {
|
|
91
|
+
const groupFile = await readFile('/etc/group', 'utf8');
|
|
92
|
+
const line = String(groupFile).split('\n').find((l) => l.startsWith('docker:'));
|
|
93
|
+
if (!line) return false;
|
|
94
|
+
const members = (line.split(':')[3] || '').split(',').map((m) => m.trim());
|
|
95
|
+
return members.includes(username);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.error(`[check_prerequisites] could not read /etc/group: ${err.message}`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
32
102
|
module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
33
103
|
const docker = options.dockerUtil || createDockerUtil(options);
|
|
34
104
|
const http = options.httpClient || createHttpClient(options);
|
|
35
105
|
const _checkPort = options.checkPort || checkPort;
|
|
36
106
|
const _environmentProbe = options.environmentProbe || defaultEnvironmentProbe;
|
|
107
|
+
const _statfs = options.statfs || require('fs').promises.statfs;
|
|
108
|
+
const _readFile = options.fs?.readFile || require('fs').promises.readFile;
|
|
109
|
+
const _userInfo = options.userInfo || os.userInfo;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* install_relayer is fresh-install only; an existing xns-relayer container
|
|
113
|
+
* (running or stopped, any channel) would fail it with a name conflict.
|
|
114
|
+
* A RUNNING one (e.g. the one the install script started) is ready to use,
|
|
115
|
+
* so its remediation never says to stop or remove it.
|
|
116
|
+
*/
|
|
117
|
+
async function checkExistingInstall(dockerState) {
|
|
118
|
+
if (dockerState === 'denied') {
|
|
119
|
+
return { name: 'existing_install', passed: true, skipped: true, detail: `Existing-install check skipped — ${GROUP_NOTE}.` };
|
|
120
|
+
}
|
|
121
|
+
let existing;
|
|
122
|
+
try {
|
|
123
|
+
existing = await docker.findContainer(RELAYER_CONTAINER);
|
|
124
|
+
} catch {
|
|
125
|
+
return { name: 'existing_install', passed: true, detail: 'Existing-install check skipped (Docker not reachable)' };
|
|
126
|
+
}
|
|
127
|
+
if (!existing) {
|
|
128
|
+
return { name: 'existing_install', passed: true, detail: 'No existing xns-relayer container — ready for a fresh install' };
|
|
129
|
+
}
|
|
130
|
+
const detail = `An existing 'xns-relayer' container was found (status: ${existing.status}; image: ${existing.image}).`;
|
|
131
|
+
if (existing.running) {
|
|
132
|
+
return {
|
|
133
|
+
name: 'existing_install',
|
|
134
|
+
passed: true,
|
|
135
|
+
warning: true,
|
|
136
|
+
detail,
|
|
137
|
+
remediation: 'This Relayer is already installed and running, and install_relayer performs fresh installs only, so skip install_relayer and continue onboarding with check_relayer_health against it.',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
name: 'existing_install',
|
|
142
|
+
passed: true,
|
|
143
|
+
warning: true,
|
|
144
|
+
detail,
|
|
145
|
+
remediation: 'install_relayer performs fresh installs only. To replace the existing deployment: docker stop xns-relayer && docker rm xns-relayer (data directory is preserved), then install. To keep it, skip install_relayer and continue onboarding against the existing deployment.',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The remote Docker host a failed `docker info` was aimed at, or null when
|
|
151
|
+
* the daemon is local or the host cannot be resolved.
|
|
152
|
+
*/
|
|
153
|
+
async function remoteHostOf() {
|
|
154
|
+
try {
|
|
155
|
+
const raw = await docker.getDockerHost();
|
|
156
|
+
const host = typeof raw?.host === 'string' ? raw.host.trim() : '';
|
|
157
|
+
if (!raw?.remote || host === '' || host === 'localhost') return null;
|
|
158
|
+
return { remote: true, host, endpoint: redactEndpoint(raw.endpoint) };
|
|
159
|
+
} catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Containers named prometheus/alertmanager that are not this Relayer's. */
|
|
165
|
+
async function checkFixedNames(dockerState, dockerHost) {
|
|
166
|
+
const name = 'fixed_container_names';
|
|
167
|
+
if (dockerState !== 'ok' || dockerHost.remote) {
|
|
168
|
+
return { name, passed: true, skipped: true, detail: 'Container-name check skipped — Docker is not readable on this machine.' };
|
|
169
|
+
}
|
|
170
|
+
const foreign = [];
|
|
171
|
+
for (const containerName of FIXED_CONTAINER_NAMES) {
|
|
172
|
+
const project = await docker.containerProject(containerName);
|
|
173
|
+
if (project !== null && project !== RELAYER_PROJECT) foreign.push(containerName);
|
|
174
|
+
}
|
|
175
|
+
if (foreign.length === 0) {
|
|
176
|
+
return { name, passed: true, detail: 'No other container is named prometheus or alertmanager' };
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
name,
|
|
180
|
+
passed: false,
|
|
181
|
+
detail: `A container named ${foreign.join(' and ')} already exists and is not part of the Relayer; the Relayer needs those names`,
|
|
182
|
+
remediation: `Rename it (docker rename ${foreign[0]} ${foreign[0]}-old) or remove it, then re-run check_prerequisites.`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** One filesystem leg of the disk check. */
|
|
187
|
+
async function diskLeg(which, target) {
|
|
188
|
+
try {
|
|
189
|
+
const { path: fsPath, freeBytes } = await freeBytesAt(_statfs, target);
|
|
190
|
+
return { which, path: fsPath, free_bytes: freeBytes, passed: freeBytes >= MIN_FREE_BYTES };
|
|
191
|
+
} catch (err) {
|
|
192
|
+
console.error(`[check_prerequisites] statfs ${target} failed: ${err.message}`);
|
|
193
|
+
return { which, path: target, passed: true, skipped: true, detail: `Free space on the ${which} could not be read` };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The Docker root leg: only for a local daemon whose `docker info` answered. */
|
|
198
|
+
async function dockerRootLeg(dockerState, dockerHost) {
|
|
199
|
+
const which = 'Docker root';
|
|
200
|
+
if (dockerHost.remote) {
|
|
201
|
+
return { which, passed: true, skipped: true, detail: `Docker root check skipped — the Docker daemon runs on ${dockerHost.host}, so its disk must be checked there` };
|
|
202
|
+
}
|
|
203
|
+
if (dockerState !== 'ok') {
|
|
204
|
+
return { which, passed: true, skipped: true, detail: 'Docker root check skipped — docker info is not readable' };
|
|
205
|
+
}
|
|
206
|
+
let rootDir = '';
|
|
207
|
+
try {
|
|
208
|
+
const { stdout } = await docker.docker(['info', '--format', '{{.DockerRootDir}}']);
|
|
209
|
+
rootDir = String(stdout).trim();
|
|
210
|
+
} catch (err) {
|
|
211
|
+
console.error(`[check_prerequisites] docker info DockerRootDir failed: ${err.message}`);
|
|
212
|
+
}
|
|
213
|
+
if (!path.isAbsolute(rootDir)) {
|
|
214
|
+
return { which, passed: true, skipped: true, detail: 'Docker root check skipped — docker info gave no Docker root directory' };
|
|
215
|
+
}
|
|
216
|
+
return diskLeg(which, rootDir);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function checkDisk(dockerState, dockerHost) {
|
|
220
|
+
const filesystems = [
|
|
221
|
+
await dockerRootLeg(dockerState, dockerHost),
|
|
222
|
+
await diskLeg('install dir', DEFAULT_INSTALL_DIR),
|
|
223
|
+
];
|
|
224
|
+
const short = filesystems.filter((f) => !f.passed);
|
|
225
|
+
if (short.length === 0) {
|
|
226
|
+
return { name: 'disk', passed: true, detail: 'At least 10 GB is free on the Docker root and the install dir', filesystems };
|
|
227
|
+
}
|
|
228
|
+
const where = short.map((f) => `${formatGb(f.free_bytes)} free on the ${f.which} (${f.path})`).join(' and ');
|
|
229
|
+
return {
|
|
230
|
+
name: 'disk',
|
|
231
|
+
passed: false,
|
|
232
|
+
detail: `Not enough disk space: ${where}; the Relayer needs at least 10 GB free on each`,
|
|
233
|
+
remediation: `Free up space until at least 10 GB is free on ${short.map((f) => `${f.path} (${f.which})`).join(' and ')}, then re-run check_prerequisites. Check with: df -h ${short.map((f) => f.path).join(' ')}`,
|
|
234
|
+
filesystems,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
37
237
|
|
|
38
238
|
server.registerTool(
|
|
39
239
|
'check_prerequisites',
|
|
40
240
|
{
|
|
41
|
-
title: '
|
|
42
|
-
description: 'Check system prerequisites for XNS Relayer installation: Docker
|
|
241
|
+
title: 'Check prerequisites',
|
|
242
|
+
description: 'Check system prerequisites for XNS Relayer installation: Docker installed and its daemon running (local or remote via DOCKER_HOST / ssh:// context), the Docker compose plugin, docker group access for this user, required ports (8888, 9000, 9443; a port held by the running xns-relayer container passes), no container from another project named prometheus or alertmanager, an existing xns-relayer installation, at least 10 GB free on the Docker root and the install directory, 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
243
|
inputSchema: {
|
|
44
244
|
/* no parameters */
|
|
45
245
|
},
|
|
@@ -58,6 +258,9 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
58
258
|
// on another machine and the local checks below must adapt.
|
|
59
259
|
const DEFAULT_DOCKER_HOST = { remote: false, host: 'localhost', endpoint: null };
|
|
60
260
|
let dockerHost = DEFAULT_DOCKER_HOST;
|
|
261
|
+
// 'ok' | 'missing' (no docker CLI) | 'stopped' (daemon unreachable) |
|
|
262
|
+
// 'denied' (socket refuses this user: the daemon runs).
|
|
263
|
+
let dockerState = 'ok';
|
|
61
264
|
try {
|
|
62
265
|
await docker.docker(['info', '--format', '{{.ServerVersion}}']);
|
|
63
266
|
const raw = await docker.getDockerHost();
|
|
@@ -79,13 +282,109 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
79
282
|
: 'Docker is running',
|
|
80
283
|
});
|
|
81
284
|
} catch (err) {
|
|
285
|
+
// Missing is decided by the spawn code, never by message text:
|
|
286
|
+
// a daemon error can say "no such file or directory" too.
|
|
287
|
+
const remote = err?.code === 'ENOENT' ? null : await remoteHostOf();
|
|
288
|
+
if (err?.code === 'ENOENT') {
|
|
289
|
+
dockerState = 'missing';
|
|
290
|
+
allPassed = false;
|
|
291
|
+
checks.push({
|
|
292
|
+
name: 'docker',
|
|
293
|
+
passed: false,
|
|
294
|
+
detail: 'Docker is not installed on this machine',
|
|
295
|
+
remediation: `Run the one-command install, which installs Docker, the compose plugin and the Relayer: ${INSTALL_COMMAND} (Ubuntu 24.04 or Debian 12). To install on a different persistent machine, run this MCP on that machine (a Docker host with Node.js 24) rather than pointing at it remotely.`,
|
|
296
|
+
});
|
|
297
|
+
} else if (remote) {
|
|
298
|
+
// DECISION: a failing `docker info` against an ssh:// or tcp://
|
|
299
|
+
// DOCKER_HOST is a problem with that host, not with this user's
|
|
300
|
+
// docker group, and the daemon-stopped command would be run on
|
|
301
|
+
// the wrong machine. Name the host; the remote checks that
|
|
302
|
+
// follow (install_file_location, ports skipped) then apply.
|
|
303
|
+
dockerState = 'stopped';
|
|
304
|
+
dockerHost = remote;
|
|
305
|
+
allPassed = false;
|
|
306
|
+
checks.push({
|
|
307
|
+
name: 'docker',
|
|
308
|
+
passed: false,
|
|
309
|
+
detail: `The Docker daemon on ${remote.host} (via ${remote.endpoint}) could not be reached`,
|
|
310
|
+
remediation: `Check the connection and that Docker is running on ${remote.host}, and that your user there can use it (docker group on ${remote.host}, not on this machine). Or unset DOCKER_HOST / switch to the default Docker context to use this machine.`,
|
|
311
|
+
});
|
|
312
|
+
} else if (classifyDockerFailure(err)?.key === 'permission_denied') {
|
|
313
|
+
// The daemon answered and refused this user: Docker is fine,
|
|
314
|
+
// the docker_group check below carries the one failure.
|
|
315
|
+
dockerState = 'denied';
|
|
316
|
+
checks.push({
|
|
317
|
+
name: 'docker',
|
|
318
|
+
passed: true,
|
|
319
|
+
detail: 'Docker is installed and its daemon is running, but the Docker socket refuses this user',
|
|
320
|
+
});
|
|
321
|
+
} else {
|
|
322
|
+
dockerState = 'stopped';
|
|
323
|
+
allPassed = false;
|
|
324
|
+
checks.push({
|
|
325
|
+
name: 'docker',
|
|
326
|
+
passed: false,
|
|
327
|
+
detail: 'Docker is installed, but the Docker daemon is not running',
|
|
328
|
+
remediation: 'Start the Docker daemon: sudo systemctl start docker',
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 1a. Compose plugin. `docker compose version` needs no daemon, so it
|
|
334
|
+
// runs when the daemon is down or the socket refuses; only a missing
|
|
335
|
+
// docker CLI skips it (Docker-missing is then the one failure).
|
|
336
|
+
if (dockerState === 'missing') {
|
|
337
|
+
checks.push({ name: 'docker_compose', passed: true, skipped: true, detail: 'Compose plugin check skipped — Docker is not installed (the one-command install adds both)' });
|
|
338
|
+
} else {
|
|
339
|
+
try {
|
|
340
|
+
await docker.docker(['compose', 'version']);
|
|
341
|
+
checks.push({ name: 'docker_compose', passed: true, detail: 'The Docker compose plugin is installed' });
|
|
342
|
+
} catch {
|
|
343
|
+
allPassed = false;
|
|
344
|
+
checks.push({
|
|
345
|
+
name: 'docker_compose',
|
|
346
|
+
passed: false,
|
|
347
|
+
detail: 'The Docker compose plugin is missing',
|
|
348
|
+
remediation: "Install it from Docker's apt repository: sudo apt-get install docker-compose-plugin",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// 1b. docker group. Decided by `docker info` itself: only a denied
|
|
354
|
+
// socket is a group problem (root and rootless Docker answer without
|
|
355
|
+
// the group). /etc/group then tells "not added" from "added, but this
|
|
356
|
+
// session predates it".
|
|
357
|
+
if (dockerState === 'denied') {
|
|
82
358
|
allPassed = false;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
359
|
+
// os.userInfo() throws when the UID has no passwd entry (arbitrary-UID
|
|
360
|
+
// containers); fall back to $USER rather than failing the whole tool.
|
|
361
|
+
// With no name at all, '$USER' goes into the command as written:
|
|
362
|
+
// the user's own shell expands it.
|
|
363
|
+
let username = process.env.USER || '$USER';
|
|
364
|
+
try {
|
|
365
|
+
username = _userInfo().username || username;
|
|
366
|
+
} catch (err) {
|
|
367
|
+
console.error(`[check_prerequisites] userInfo failed: ${err.message}`);
|
|
368
|
+
}
|
|
369
|
+
if (await isInDockerGroup(_readFile, username)) {
|
|
370
|
+
checks.push({
|
|
371
|
+
name: 'docker_group',
|
|
372
|
+
passed: false,
|
|
373
|
+
detail: `${username} is in the docker group, but this session started before the group was added, so the Docker socket still refuses it`,
|
|
374
|
+
remediation: 'Your session predates the group change: log out and back in (or reboot), then re-run check_prerequisites. Nothing needs reinstalling.',
|
|
375
|
+
});
|
|
376
|
+
} else {
|
|
377
|
+
checks.push({
|
|
378
|
+
name: 'docker_group',
|
|
379
|
+
passed: false,
|
|
380
|
+
detail: `${username} is not in the docker group, so the Docker socket refuses it`,
|
|
381
|
+
remediation: `Add yourself to the docker group: sudo usermod -aG docker ${username} — then log out and back in and re-run check_prerequisites.`,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
} else if (dockerState === 'ok') {
|
|
385
|
+
checks.push({ name: 'docker_group', passed: true, detail: 'This user can reach the Docker daemon' });
|
|
386
|
+
} else {
|
|
387
|
+
checks.push({ name: 'docker_group', passed: true, skipped: true, detail: 'Docker group check skipped — the Docker daemon is not reachable' });
|
|
89
388
|
}
|
|
90
389
|
|
|
91
390
|
// 1b. install_relayer refuses when the daemon is on another machine
|
|
@@ -97,7 +396,7 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
97
396
|
name: 'install_file_location',
|
|
98
397
|
passed: false,
|
|
99
398
|
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
|
|
399
|
+
remediation: `Run the MCP on ${dockerHost.host} (install Node.js 24 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.`,
|
|
101
400
|
});
|
|
102
401
|
}
|
|
103
402
|
|
|
@@ -108,8 +407,31 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
108
407
|
const requiredPorts = [
|
|
109
408
|
{ port: 8888, name: 'port_8888', service: 'the Relayer UI', inUseRemediation: 'Port 8888 is required for the Relayer UI. Stop the service using this port, or install with a different port via install_relayer ui_port.' },
|
|
110
409
|
{ port: 9000, name: 'port_9000', service: 'the S3 gateway', inUseRemediation: 'Port 9000 is required for the S3 gateway. Stop the service using this port (common conflict: another S3-compatible service), or install with a different port via install_relayer s3_port.' },
|
|
410
|
+
// The release compose publishes the S3 HTTPS port too. install_relayer
|
|
411
|
+
// has no parameter for it, so the only fix is to free it.
|
|
412
|
+
{ port: 9443, name: 'port_9443', service: 'the S3 HTTPS port', inUseRemediation: 'Port 9443 is required for the S3 HTTPS port. Stop the service using this port; install_relayer ui_port and s3_port do not move it.' },
|
|
111
413
|
];
|
|
414
|
+
// The install script leaves its own xns-relayer holding 8888/9000.
|
|
415
|
+
// Those ports are "in use" by the Relayer itself: a pass, not a
|
|
416
|
+
// conflict. Looked up once, only when a bind-probe finds a port held.
|
|
417
|
+
let ownPorts = null;
|
|
418
|
+
const relayerHostPorts = async () => {
|
|
419
|
+
if (ownPorts) return ownPorts;
|
|
420
|
+
ownPorts = [];
|
|
421
|
+
const container = await docker.findContainer(RELAYER_CONTAINER);
|
|
422
|
+
if (container?.running) {
|
|
423
|
+
// containerHostPorts answers [] on any docker failure.
|
|
424
|
+
ownPorts = await docker.containerHostPorts(RELAYER_CONTAINER);
|
|
425
|
+
}
|
|
426
|
+
return ownPorts;
|
|
427
|
+
};
|
|
112
428
|
for (const { port, name, inUseRemediation } of requiredPorts) {
|
|
429
|
+
if (dockerState === 'denied') {
|
|
430
|
+
// Who holds the port cannot be read through a refused socket,
|
|
431
|
+
// and right after the install script it is our own Relayer.
|
|
432
|
+
checks.push({ name, passed: true, skipped: true, detail: `Port ${port} check skipped — ${GROUP_NOTE}.` });
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
113
435
|
if (dockerHost.remote) {
|
|
114
436
|
checks.push({
|
|
115
437
|
name,
|
|
@@ -123,6 +445,8 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
123
445
|
const available = await _checkPort(port);
|
|
124
446
|
if (available) {
|
|
125
447
|
checks.push({ name, passed: true, detail: `Port ${port} is available` });
|
|
448
|
+
} else if (dockerState === 'ok' && (await relayerHostPorts()).includes(port)) {
|
|
449
|
+
checks.push({ name, passed: true, detail: `Port ${port} is in use by the running ${RELAYER_CONTAINER} container (this Relayer), which is expected` });
|
|
126
450
|
} else {
|
|
127
451
|
allPassed = false;
|
|
128
452
|
checks.push({ name, passed: false, detail: `Port ${port} is already in use`, remediation: inUseRemediation });
|
|
@@ -133,25 +457,14 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
133
457
|
}
|
|
134
458
|
}
|
|
135
459
|
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
passed: true,
|
|
145
|
-
warning: true,
|
|
146
|
-
detail: `An existing 'xns-relayer' container was found (status: ${existing.status}; image: ${existing.image}).`,
|
|
147
|
-
remediation: 'install_relayer performs fresh installs only. To replace the existing deployment: docker stop xns-relayer && docker rm xns-relayer (data directory is preserved), then install. To keep it, skip install_relayer and continue onboarding against the running deployment.',
|
|
148
|
-
});
|
|
149
|
-
} else {
|
|
150
|
-
checks.push({ name: 'existing_install', passed: true, detail: 'No existing xns-relayer container — ready for a fresh install' });
|
|
151
|
-
}
|
|
152
|
-
} catch {
|
|
153
|
-
checks.push({ name: 'existing_install', passed: true, detail: 'Existing-install check skipped (Docker not reachable)' });
|
|
154
|
-
}
|
|
460
|
+
// 3a. The release compose fixes the names prometheus and alertmanager.
|
|
461
|
+
// A container of that name from another Compose project stops the install.
|
|
462
|
+
const fixedNames = await checkFixedNames(dockerState, dockerHost);
|
|
463
|
+
if (!fixedNames.passed) allPassed = false;
|
|
464
|
+
checks.push(fixedNames);
|
|
465
|
+
|
|
466
|
+
// 3b. Existing installation — warn early, here.
|
|
467
|
+
checks.push(await checkExistingInstall(dockerState));
|
|
155
468
|
|
|
156
469
|
// 3c. Ephemeral environment — finding, never a failure.
|
|
157
470
|
try {
|
|
@@ -176,23 +489,19 @@ module.exports = function registerCheckPrerequisites(server, options = {}) {
|
|
|
176
489
|
checks.push({ name: 'ephemeral_environment', passed: true, detail: 'Ephemeral-environment check skipped (probe error)' });
|
|
177
490
|
}
|
|
178
491
|
|
|
179
|
-
// 4. Disk space
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} catch {
|
|
185
|
-
// If docker system df fails but docker info succeeded, still note it
|
|
186
|
-
checks.push({ name: 'disk', passed: true, detail: 'Disk check skipped (Docker storage stats unavailable)' });
|
|
187
|
-
}
|
|
492
|
+
// 4. Disk space: at least 10 GB free on BOTH the Docker root (images
|
|
493
|
+
// land there; often its own volume) and the install dir's filesystem.
|
|
494
|
+
const diskCheck = await checkDisk(dockerState, dockerHost);
|
|
495
|
+
if (!diskCheck.passed) allPassed = false;
|
|
496
|
+
checks.push(diskCheck);
|
|
188
497
|
|
|
189
498
|
// 5-6. Network connectivity
|
|
190
499
|
const connectivityChecks = [
|
|
191
500
|
{ url: 'https://console.xns.tech/health', name: 'connectivity_console', host: 'console.xns.tech' },
|
|
192
501
|
{ url: 'https://auth.xns.tech/auth/realms/scprime/.well-known/openid-configuration', name: 'connectivity_auth', host: 'auth.xns.tech' },
|
|
193
|
-
// The registry install_relayer pulls from (
|
|
502
|
+
// The registry install_relayer pulls from (release channel, anonymous).
|
|
194
503
|
// /v2/ is the registry version probe — 200 without credentials.
|
|
195
|
-
{ url: 'https://releases.
|
|
504
|
+
{ url: 'https://releases.xns.tech/v2/', name: 'connectivity_registry', host: 'releases.xns.tech' },
|
|
196
505
|
];
|
|
197
506
|
for (const { url, name, host } of connectivityChecks) {
|
|
198
507
|
try {
|
|
@@ -11,6 +11,9 @@ const POLL_TIMEOUT_MS = 300000; // 300s (AC-13, QA-1)
|
|
|
11
11
|
// Loopback aliases — all classify as "local", not a remote Docker host.
|
|
12
12
|
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
13
13
|
|
|
14
|
+
// The container install_relayer creates.
|
|
15
|
+
const RELAYER_CONTAINER = 'xns-relayer';
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Normalize a user-supplied or detected host for URL composition: trim, strip
|
|
16
19
|
* ANY accidental scheme prefix (http://, tcp://, ssh://…), bracket bare IPv6.
|
|
@@ -34,6 +37,21 @@ function normalizeHost(value) {
|
|
|
34
37
|
return hostname.includes(':') && !hostname.startsWith('[') ? `[${hostname}]` : hostname;
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Whether two normalized hosts name the same machine (all loopback names match,
|
|
42
|
+
* case ignored).
|
|
43
|
+
*
|
|
44
|
+
* @param {string} a
|
|
45
|
+
* @param {string} b
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
function sameMachine(a, b) {
|
|
49
|
+
// Host names are case-insensitive: 'Docker-Box.lan' and 'docker-box.lan' are one machine.
|
|
50
|
+
const x = a.toLowerCase();
|
|
51
|
+
const y = b.toLowerCase();
|
|
52
|
+
return x === y || (LOCAL_HOSTS.has(x) && LOCAL_HOSTS.has(y));
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
/**
|
|
38
56
|
* Tool 5: check_relayer_health
|
|
39
57
|
* AC-13: report healthy only when ui+s3+hostio healthy; name unhealthy component; 300s timeout.
|
|
@@ -54,8 +72,8 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
54
72
|
server.registerTool(
|
|
55
73
|
'check_relayer_health',
|
|
56
74
|
{
|
|
57
|
-
title: '
|
|
58
|
-
description: 'Check the health of all Relayer services: UI (port 8888), S3 gateway (port 9000), HostIO, and the monitoring sidecars (Prometheus + Grafana containers). Polls every 10 seconds for up to 300 seconds. Reports each component status individually and names any unhealthy component; a missing monitoring stack reports as degraded (dashboards empty) without blocking the install flow. Targets the machine the Docker daemon runs on (auto-detected from the Docker context — supports remote ssh:// Docker hosts); pass host to override. Note: HostIO health status is unknown until OIDC authentication is completed.',
|
|
75
|
+
title: 'Check Relayer health',
|
|
76
|
+
description: 'Check the health of all Relayer services: UI (port 8888), S3 gateway (port 9000), HostIO, and the monitoring sidecars (Prometheus + Grafana containers). Polls every 10 seconds for up to 300 seconds. Reports each component status individually and names any unhealthy component; a missing monitoring stack reports as degraded (dashboards empty) without blocking the install flow. Targets the machine the Docker daemon runs on (auto-detected from the Docker context — supports remote ssh:// Docker hosts); pass host to override. Until the owner claims the Relayer and signs in to its web UI it reports awaiting_claim: the S3 gateway and HostIO start only then, so a fresh install is ready for start_claim once the UI answers. Note: HostIO health status is unknown until OIDC authentication is completed.',
|
|
59
77
|
inputSchema: {
|
|
60
78
|
poll: z.boolean().optional().default(true).describe('If true (default), poll until healthy or timeout. If false, check once.'),
|
|
61
79
|
host: z.string().trim().min(1).optional().describe('Hostname/IP where the Relayer containers run. Default: auto-detected from the Docker context (localhost, or the remote host for ssh:// / tcp:// contexts).'),
|
|
@@ -76,6 +94,17 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
76
94
|
// Resolve where the containers actually run — once per call.
|
|
77
95
|
const dockerHost = host ? { host, remote: !LOCAL_HOSTS.has(normalizeHost(host)) } : await docker.getDockerHost();
|
|
78
96
|
const target = normalizeHost(dockerHost.host);
|
|
97
|
+
|
|
98
|
+
// The token check runs through the Docker CLI, so it only speaks
|
|
99
|
+
// for `target` when the CLI points at that machine. Resolved once,
|
|
100
|
+
// and only when a check needs it.
|
|
101
|
+
let dockerReachesTarget;
|
|
102
|
+
const tokenCheckApplies = async () => {
|
|
103
|
+
if (dockerReachesTarget === undefined) {
|
|
104
|
+
dockerReachesTarget = !host || sameMachine(target, normalizeHost((await docker.getDockerHost()).host));
|
|
105
|
+
}
|
|
106
|
+
return dockerReachesTarget;
|
|
107
|
+
};
|
|
79
108
|
const uiBase = `http://${target}:${uiPort}`;
|
|
80
109
|
const s3Base = `http://${target}:${s3Port}`;
|
|
81
110
|
|
|
@@ -98,6 +127,21 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
98
127
|
components.s3 = { healthy: false, status: null };
|
|
99
128
|
}
|
|
100
129
|
|
|
130
|
+
// Until the owner claims the Relayer and signs in, it has no
|
|
131
|
+
// Muse token and keeps the S3 gateway (and HostIO) stopped,
|
|
132
|
+
// so S3 down on such a box is the expected state.
|
|
133
|
+
const awaitingClaim = components.ui.healthy === true
|
|
134
|
+
&& components.s3.healthy !== true
|
|
135
|
+
&& await tokenCheckApplies()
|
|
136
|
+
&& await docker.hasMuseToken(RELAYER_CONTAINER) === false;
|
|
137
|
+
if (awaitingClaim) {
|
|
138
|
+
components.s3 = {
|
|
139
|
+
healthy: null,
|
|
140
|
+
status: components.s3.status,
|
|
141
|
+
note: 'Not started yet: the S3 gateway starts once the owner claims the Relayer (start_claim) and signs in to its web UI.',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
101
145
|
// HostIO — requires auth. Report null (unknown) not false (down).
|
|
102
146
|
// TP-31: hostio = null before auth
|
|
103
147
|
try {
|
|
@@ -131,18 +175,24 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
131
175
|
}),
|
|
132
176
|
};
|
|
133
177
|
|
|
134
|
-
// Healthy if UI and S3 are up
|
|
135
|
-
|
|
136
|
-
const
|
|
178
|
+
// Healthy if UI and S3 are up, or the UI is up and the Relayer
|
|
179
|
+
// awaits its claim. HostIO null (unknown) does NOT block.
|
|
180
|
+
const coreHealthy = components.ui.healthy === true
|
|
181
|
+
&& (components.s3.healthy === true || awaitingClaim);
|
|
182
|
+
// A Relayer awaiting its claim is ready, not all healthy: S3 is not up yet.
|
|
183
|
+
const allKnownHealthy = components.ui.healthy === true
|
|
184
|
+
&& components.s3.healthy === true
|
|
185
|
+
&& components.hostio.healthy === true;
|
|
137
186
|
|
|
138
187
|
const unhealthy = [];
|
|
139
188
|
if (!components.ui.healthy) unhealthy.push(`UI (${target}:${uiPort})`);
|
|
140
|
-
if (
|
|
189
|
+
if (components.s3.healthy !== true && !awaitingClaim) unhealthy.push(`S3 gateway (${target}:${s3Port})`);
|
|
141
190
|
|
|
142
191
|
return {
|
|
143
192
|
components,
|
|
144
193
|
healthy: coreHealthy,
|
|
145
194
|
all_healthy: allKnownHealthy,
|
|
195
|
+
awaiting_claim: awaitingClaim || undefined,
|
|
146
196
|
// JSON.stringify drops undefined — degraded only appears when true.
|
|
147
197
|
degraded: monitoringHealthy ? undefined : true,
|
|
148
198
|
unhealthy: unhealthy.length > 0 ? unhealthy : undefined,
|
|
@@ -157,10 +207,16 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
157
207
|
? ' DEGRADED: monitoring stack (Prometheus/Grafana) is not running — Monitoring dashboards will be empty.'
|
|
158
208
|
: '');
|
|
159
209
|
|
|
210
|
+
const healthyMessage = (r) => (r.awaiting_claim
|
|
211
|
+
? `The Relayer is installed and its web UI is up. Its S3 gateway and HostIO start once the owner claims it and signs in: if it is not claimed yet, proceed to start_claim; if the claim is done, have the owner sign in at ${uiBase}.`
|
|
212
|
+
: r.all_healthy
|
|
213
|
+
? 'All Relayer services are healthy (UI, S3, HostIO).'
|
|
214
|
+
: 'Relayer core services (UI + S3) are healthy. HostIO status is pending authentication.') + degradedSuffix(r);
|
|
215
|
+
|
|
160
216
|
if (!poll) {
|
|
161
217
|
const result = await checkOnce();
|
|
162
218
|
const message = result.healthy
|
|
163
|
-
?
|
|
219
|
+
? healthyMessage(result)
|
|
164
220
|
: `Relayer is not yet healthy. Unhealthy: ${result.unhealthy.join(', ')}.`;
|
|
165
221
|
|
|
166
222
|
return {
|
|
@@ -198,9 +254,7 @@ module.exports = function registerCheckRelayerHealth(server, options = {}) {
|
|
|
198
254
|
};
|
|
199
255
|
}
|
|
200
256
|
|
|
201
|
-
const message = (result
|
|
202
|
-
? 'All Relayer services are healthy (UI, S3, HostIO). Ready for claim.'
|
|
203
|
-
: 'Relayer core services (UI + S3) are healthy. HostIO status pending authentication. Proceed to start_claim.') + degradedSuffix(result);
|
|
257
|
+
const message = healthyMessage(result);
|
|
204
258
|
|
|
205
259
|
return {
|
|
206
260
|
content: [{
|
|
@@ -43,7 +43,7 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
43
43
|
server.registerTool(
|
|
44
44
|
'configure_vpd',
|
|
45
45
|
{
|
|
46
|
-
title: '
|
|
46
|
+
title: 'Configure host selection (VPD)',
|
|
47
47
|
description: 'Configure VPD (Virtual Private Datacenter) host selection for the Relayer, or preview it with dry_run. Use defaults ("true" for both expressions) or a CEL expression filtering hosts by tags. The Relayer requires a minimum of 10 data hosts and 20 parity hosts — if too few match, broaden the criteria. Requires OIDC sign-in (same session as get_host_tags).',
|
|
48
48
|
inputSchema: {
|
|
49
49
|
data_expression: z.string().describe('CEL expression for data host selection. Use "true" for default (all hosts).'),
|