@xns-cloud/relayer-mcp 0.5.2 → 0.6.1
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 +12 -4
- package/package.json +3 -2
- package/src/index.js +5 -1
- package/src/lib/allowedSettings.js +118 -0
- package/src/lib/httpClient.js +21 -0
- package/src/lib/proxyError.js +20 -0
- package/src/tools/configureVpd.js +81 -10
- package/src/tools/describeSettings.js +109 -0
- package/src/tools/getHostTags.js +41 -8
- package/src/tools/manageBackups.js +141 -0
- package/src/tools/restartService.js +85 -0
- package/src/tools/updateSettings.js +191 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @xns-cloud/relayer-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for XNS Relayer onboarding. Provides
|
|
3
|
+
MCP server for XNS Relayer onboarding and day-2 management. Provides 15 tools that let an AI agent drive the complete Relayer setup — and afterward adjust settings, manage backups, and tune the VPD — conversationally over stdio transport.
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
@@ -50,10 +50,14 @@ No separate install step required.
|
|
|
50
50
|
| 5 | `check_relayer_health` | Poll UI, S3, HostIO, and the monitoring sidecars (10s interval, 300s timeout). A missing monitoring stack reports as degraded without blocking the flow. Targets the Docker host automatically. |
|
|
51
51
|
| 6 | `start_claim` | Initiate a claim session — returns a URL for browser confirmation. |
|
|
52
52
|
| 7 | `check_claim_status` | Poll claim state (STATE_1 / STATE_2 / STATE_3). |
|
|
53
|
-
| 8 | `get_host_tags` | Retrieve available host tags for VPD configuration. |
|
|
54
|
-
| 9 | `configure_vpd` | Set data/parity host selection via CEL expressions. |
|
|
53
|
+
| 8 | `get_host_tags` | Retrieve available host tags for VPD configuration, plus the currently applied data/parity selection (read-back with an `is_default` flag). |
|
|
54
|
+
| 9 | `configure_vpd` | Set data/parity host selection via CEL expressions. `dry_run: true` previews the matched host counts without applying (requires a Relayer build with the HostIO evaluate endpoint; older builds report `preview_supported: false`). |
|
|
55
55
|
| 10 | `verify_storage` | Round-trip S3 test (create bucket, put object, get object) against the S3 gateway on port 9000. **Requires fullaccess credentials** (admin key pair from the Relayer UI IAM page — not a read-only or bucket-scoped key). Test bucket is cleaned up automatically. If auto-detection cannot reach the host, pass `endpoint` with an explicit IP (e.g. `http://192.168.1.100:9000`). |
|
|
56
56
|
| 11 | `setup_cli_credentials` | Provision S3 IAM credentials and write `~/.xns/credentials` so the XNS CLI works without further configuration. |
|
|
57
|
+
| 12 | `describe_settings` | List the adjustable settings — worker/concurrency tuning, backup schedule, cost center (CCID) — with current values, defaults, and guidance. The MCP deliberately exposes only this curated set, never the full advanced catalog. |
|
|
58
|
+
| 13 | `update_settings` | Apply a map of setting changes (whitelist-enforced). Returns `require_restart`. **Requires relayer-ui >= 3.43.3** — older servers can clobber the database password on config round-trips. |
|
|
59
|
+
| 14 | `restart_service` | Restart `hostio`, `gateway`, `s3gateway`, `database`, or all services. Disruptive; pairs with `check_relayer_health` to verify recovery. |
|
|
60
|
+
| 15 | `manage_backups` | List / start / restore / delete configuration backups. Restore is destructive and supports selective components (`db`, `conf`, `hostio`, `samba`). |
|
|
57
61
|
|
|
58
62
|
## Onboarding Flow
|
|
59
63
|
|
|
@@ -70,6 +74,10 @@ No separate install step required.
|
|
|
70
74
|
|
|
71
75
|
The operator's only required actions are: clicking one email link, completing one browser sign-in, and confirming one claim.
|
|
72
76
|
|
|
77
|
+
## Day-2 Management
|
|
78
|
+
|
|
79
|
+
After onboarding, tools 12-15 cover routine adjustments: `describe_settings` → `update_settings` → `restart_service` for tuning (workers, concurrency, backup schedule, cost center), and `manage_backups` for the backup lifecycle. All four use the same OIDC session as tools 8-9. Destructive operations (restore, restart, changing the cost center) are agent-confirmed with the operator before execution — the tool descriptions and responses carry the warnings.
|
|
80
|
+
|
|
73
81
|
## Fresh installs vs. existing deployments
|
|
74
82
|
|
|
75
83
|
`install_relayer` performs **fresh installs only** — it does not upgrade an existing deployment in place. Docker container names are unique per daemon, so any existing `xns-relayer` container (running **or stopped**, any channel — including an alpha-channel install from `releases.scpri.me`) blocks the install. Both `check_prerequisites` and `install_relayer` detect this and tell you before anything breaks.
|
|
@@ -112,7 +120,7 @@ The MCP detects this automatically (it honors `DOCKER_HOST` and the active Docke
|
|
|
112
120
|
|
|
113
121
|
## Authentication
|
|
114
122
|
|
|
115
|
-
Tools 8 and
|
|
123
|
+
Tools 8-9 and 12-15 require an OIDC token to access the Relayer API and HostIO proxy. The MCP acquires one automatically using Authorization Code + PKCE (S256) flow against the `scprime` Keycloak realm with the `relayer-native` public client. The user completes a browser sign-in; the MCP captures the code on a local `127.0.0.1` loopback listener and exchanges it for a token.
|
|
116
124
|
|
|
117
125
|
**Prerequisite:** The `relayer-native` public client must be registered on the Keycloak `scprime` realm (PKCE S256, redirect `http://127.0.0.1:*`).
|
|
118
126
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xns-cloud/relayer-mcp",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"mcpName": "tech.xns/relayer",
|
|
4
|
+
"version": "0.6.1",
|
|
5
|
+
"description": "MCP server for XNS Relayer onboarding and day-2 management — drives Relayer setup, settings, and backups conversationally over stdio, npx-ready",
|
|
5
6
|
"author": "SCP Corp",
|
|
6
7
|
"license": "Apache-2.0",
|
|
7
8
|
"homepage": "https://xns.tech",
|
package/src/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const server = new McpServer({
|
|
|
18
18
|
version: require('../package.json').version,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
// Register all
|
|
21
|
+
// Register all 15 tools
|
|
22
22
|
require('./tools/checkPrerequisites')(server);
|
|
23
23
|
require('./tools/registerAccount')(server);
|
|
24
24
|
require('./tools/checkEmailVerified')(server);
|
|
@@ -30,6 +30,10 @@ require('./tools/getHostTags')(server);
|
|
|
30
30
|
require('./tools/configureVpd')(server);
|
|
31
31
|
require('./tools/verifyStorage')(server);
|
|
32
32
|
require('./tools/setupCliCredentials')(server);
|
|
33
|
+
require('./tools/describeSettings')(server);
|
|
34
|
+
require('./tools/updateSettings')(server);
|
|
35
|
+
require('./tools/restartService')(server);
|
|
36
|
+
require('./tools/manageBackups')(server);
|
|
33
37
|
|
|
34
38
|
async function main() {
|
|
35
39
|
const transport = new StdioServerTransport();
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The curated settings whitelist shared by describe_settings and update_settings.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately a WHITELIST, not a blocklist (Ken, 2026-06-11): the Relayer
|
|
7
|
+
* exposes ~74 tunables via GET /api/v1/config, but the MCP surfaces only the
|
|
8
|
+
* operator-relevant "big ones" — worker/concurrency tuning, the backup
|
|
9
|
+
* schedule, and the cost center (CCID). Everything else (SSL, database,
|
|
10
|
+
* encryption keys, erasure geometry, inter-service wiring) is rejected so an
|
|
11
|
+
* agent can never be talked into touching it. Add keys here only with the
|
|
12
|
+
* matching group name from relayer-ui server/src/data/env_listing.json.
|
|
13
|
+
*
|
|
14
|
+
* `group` is the section of /relayer/conf/relayer_configuration.json the key
|
|
15
|
+
* lives under (relayer-ui Config.js read/write contract). `CostCenter` is the
|
|
16
|
+
* one top-level key (group: null).
|
|
17
|
+
*/
|
|
18
|
+
const ALLOWED_SETTINGS = {
|
|
19
|
+
HOSTIO_UPLOAD_WORKERS: {
|
|
20
|
+
group: 'HostIO',
|
|
21
|
+
type: 'Number',
|
|
22
|
+
note: 'Parallel upload workers. Restart of hostio required to take effect.',
|
|
23
|
+
},
|
|
24
|
+
HOSTIO_DOWNLOAD_WORKERS: {
|
|
25
|
+
group: 'HostIO',
|
|
26
|
+
type: 'Number',
|
|
27
|
+
note: 'Parallel download workers. Restart of hostio required to take effect.',
|
|
28
|
+
},
|
|
29
|
+
HOSTIO_UTILITY_OPERATIONS_WORKERS: {
|
|
30
|
+
group: 'HostIO',
|
|
31
|
+
type: 'Number',
|
|
32
|
+
note: 'Workers for background/utility operations. Restart of hostio required.',
|
|
33
|
+
},
|
|
34
|
+
HOSTIO_SIMULTANEOUS_UPLOADS: {
|
|
35
|
+
group: 'HostIO',
|
|
36
|
+
type: 'Number',
|
|
37
|
+
note: 'Upload concurrency to hosts. The server enforces a resource-aware ceiling and will reject values above it — the rejection message names the ceiling. Restart of hostio required.',
|
|
38
|
+
},
|
|
39
|
+
HOSTIO_SIMULTANEOUS_DOWNLOADS: {
|
|
40
|
+
group: 'HostIO',
|
|
41
|
+
type: 'Number',
|
|
42
|
+
note: 'Per-host download concurrency. Restart of hostio required.',
|
|
43
|
+
},
|
|
44
|
+
BACKUP_ENABLED: {
|
|
45
|
+
group: 'Backup',
|
|
46
|
+
type: 'Boolean',
|
|
47
|
+
note: 'Enable/disable the scheduled configuration backup.',
|
|
48
|
+
},
|
|
49
|
+
BACKUP_FREQUENCY: {
|
|
50
|
+
group: 'Backup',
|
|
51
|
+
type: 'Number',
|
|
52
|
+
note: 'Backup cadence in minutes.',
|
|
53
|
+
},
|
|
54
|
+
BACKUP_THRESHOLD: {
|
|
55
|
+
group: 'Backup',
|
|
56
|
+
type: 'Number',
|
|
57
|
+
note: 'Change threshold that triggers a backup.',
|
|
58
|
+
},
|
|
59
|
+
BACKUP_RETENTION: {
|
|
60
|
+
group: 'Backup',
|
|
61
|
+
type: 'Number',
|
|
62
|
+
note: 'Number of backup archives to keep.',
|
|
63
|
+
},
|
|
64
|
+
CostCenter: {
|
|
65
|
+
group: null, // top-level key in relayer_configuration.json
|
|
66
|
+
type: 'String',
|
|
67
|
+
note: 'The billing cost center (CCID). Changing it re-authenticates the Relayer against the new cost center using your OIDC session and requires a service restart. This changes who is billed — confirm with the operator before applying.',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const JS_TYPE_BY_CATALOG_TYPE = {
|
|
72
|
+
Number: 'number',
|
|
73
|
+
Boolean: 'boolean',
|
|
74
|
+
String: 'string',
|
|
75
|
+
Big: 'number',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function isAllowed(key) {
|
|
79
|
+
return Object.prototype.hasOwnProperty.call(ALLOWED_SETTINGS, key);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Validate a value's JS type against the whitelist entry's catalog type.
|
|
84
|
+
* Semantic validation (ranges, ceilings) stays server-side — the server's
|
|
85
|
+
* rejection messages pass through to the agent verbatim.
|
|
86
|
+
*/
|
|
87
|
+
function typeError(key, value) {
|
|
88
|
+
if (!isAllowed(key)) {
|
|
89
|
+
return `${key} is not an allowed setting`;
|
|
90
|
+
}
|
|
91
|
+
const expected = JS_TYPE_BY_CATALOG_TYPE[ALLOWED_SETTINGS[key].type];
|
|
92
|
+
if (expected && typeof value !== expected) {
|
|
93
|
+
return `${key} expects a ${expected}, got ${typeof value}`;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Nearest allowed-key suggestion for typo'd/hallucinated names. */
|
|
99
|
+
function suggestKey(unknownKey) {
|
|
100
|
+
const upper = String(unknownKey).toUpperCase();
|
|
101
|
+
let best = null;
|
|
102
|
+
let bestScore = 0;
|
|
103
|
+
for (const key of Object.keys(ALLOWED_SETTINGS)) {
|
|
104
|
+
const k = key.toUpperCase();
|
|
105
|
+
let score = 0;
|
|
106
|
+
// Cheap shared-bigram similarity — enough to catch transpositions/typos.
|
|
107
|
+
for (let i = 0; i < upper.length - 1; i++) {
|
|
108
|
+
if (k.includes(upper.slice(i, i + 2))) score++;
|
|
109
|
+
}
|
|
110
|
+
if (score > bestScore) {
|
|
111
|
+
bestScore = score;
|
|
112
|
+
best = key;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return bestScore >= 3 ? best : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = { ALLOWED_SETTINGS, isAllowed, typeError, suggestKey };
|
package/src/lib/httpClient.js
CHANGED
|
@@ -39,6 +39,27 @@ function createHttpClient(options = {}) {
|
|
|
39
39
|
const resp = await instance.post(url, body, config);
|
|
40
40
|
return { status: resp.status, data: resp.data };
|
|
41
41
|
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} url
|
|
45
|
+
* @param {*} body
|
|
46
|
+
* @param {object} [config]
|
|
47
|
+
* @returns {Promise<{status: number, data: *}>}
|
|
48
|
+
*/
|
|
49
|
+
async put(url, body, config = {}) {
|
|
50
|
+
const resp = await instance.put(url, body, config);
|
|
51
|
+
return { status: resp.status, data: resp.data };
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} url
|
|
56
|
+
* @param {object} [config] - axios config; pass `data` here for a body
|
|
57
|
+
* @returns {Promise<{status: number, data: *}>}
|
|
58
|
+
*/
|
|
59
|
+
async del(url, config = {}) {
|
|
60
|
+
const resp = await instance.delete(url, config);
|
|
61
|
+
return { status: resp.status, data: resp.data };
|
|
62
|
+
},
|
|
42
63
|
};
|
|
43
64
|
}
|
|
44
65
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CROSS-BOUNDARY CONTRACT — relayer-ui's HostIO proxy (server/api/v1/Proxy.js)
|
|
5
|
+
* wraps ANY upstream failure (HOSTIO down, 404 route, 4xx/5xx) as HTTP 200
|
|
6
|
+
* with body `{ success: false, state: '<axios error message>' }`. A caller that
|
|
7
|
+
* only checks the HTTP status reads those failures as success — that is exactly
|
|
8
|
+
* how relayer-mcp <=0.5.2 returned proxy error objects as "tags".
|
|
9
|
+
*
|
|
10
|
+
* @param {*} data - response body from a /api/v1/proxy/hostio/* call
|
|
11
|
+
* @returns {string|null} the failure message, or null if not a proxy failure
|
|
12
|
+
*/
|
|
13
|
+
function proxyFailure(data) {
|
|
14
|
+
if (data && typeof data === 'object' && data.success === false && typeof data.state === 'string') {
|
|
15
|
+
return data.state;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { proxyFailure };
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { z } = require('zod');
|
|
4
4
|
const { createHttpClient } = require('../lib/httpClient');
|
|
5
5
|
const { createTokenManager } = require('../lib/ensureToken');
|
|
6
|
+
const { proxyFailure } = require('../lib/proxyError');
|
|
6
7
|
|
|
7
8
|
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
8
9
|
|
|
@@ -12,8 +13,25 @@ const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
|
12
13
|
* AC-19: "use defaults" → configure_vpd("true","true") no further ask.
|
|
13
14
|
* Watch item 1: trigger OIDC re-auth on 401 — never silent failure.
|
|
14
15
|
*
|
|
15
|
-
* Consumes relayer-ui
|
|
16
|
-
*
|
|
16
|
+
* Consumes relayer-ui's HostIO proxy (server/api/v1/Proxy.js wildcard,
|
|
17
|
+
* /api/v1/proxy/hostio/* → HOSTIO /v1/hostio/<wildcard>):
|
|
18
|
+
* POST /api/v1/proxy/hostio/setexpressions { data, parity }
|
|
19
|
+
* POST /api/v1/proxy/hostio/evaluate { data, parity } (dry_run)
|
|
20
|
+
*
|
|
21
|
+
* WIRE CONTRACT — HOSTIO's SetExpressionsRequest/EvaluateRequest JSON keys are
|
|
22
|
+
* `data` and `parity` (relayer hostio/types.go), the same keys NocDashboard
|
|
23
|
+
* sends. <=0.5.2 posted {data_expression, parity_expression}: HOSTIO decoded
|
|
24
|
+
* both as "" and its fix() substituted the all-hosts default — every custom
|
|
25
|
+
* VPD selection was silently discarded while this tool reported success
|
|
26
|
+
* (verified against relayer hostselection.go fix(), 2026-06-11). The MCP
|
|
27
|
+
* param names stay data_expression/parity_expression; only the wire payload
|
|
28
|
+
* uses {data, parity}. Path double-prefix bug also fixed here — see
|
|
29
|
+
* getHostTags.js PATH CONTRACT note.
|
|
30
|
+
*
|
|
31
|
+
* dry_run routes to HOSTIO's read-only Evaluate (same compile/match path as
|
|
32
|
+
* apply — the VPD evaluation-SoT endpoint, relayer branch
|
|
33
|
+
* vpd-e1-hostio-evaluate). On Relayer builds that predate it, the proxy wraps
|
|
34
|
+
* HOSTIO's 404 as {success:false, state} → reported as preview_supported:false.
|
|
17
35
|
*/
|
|
18
36
|
module.exports = function registerConfigureVpd(server, options = {}) {
|
|
19
37
|
const http = options.httpClient || createHttpClient(options);
|
|
@@ -24,22 +42,28 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
24
42
|
|
|
25
43
|
server.tool(
|
|
26
44
|
'configure_vpd',
|
|
27
|
-
'Configure VPD (Virtual Private Datacenter) host selection for the Relayer
|
|
45
|
+
'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).',
|
|
28
46
|
{
|
|
29
47
|
data_expression: z.string().describe('CEL expression for data host selection. Use "true" for default (all hosts).'),
|
|
30
48
|
parity_expression: z.string().describe('CEL expression for parity host selection. Use "true" for default (all hosts).'),
|
|
49
|
+
dry_run: z.boolean().optional().describe('Preview how many hosts match without applying anything. Not supported on Relayer versions without the evaluate endpoint.'),
|
|
31
50
|
},
|
|
32
|
-
async ({ data_expression, parity_expression }) => {
|
|
51
|
+
async ({ data_expression, parity_expression, dry_run }) => {
|
|
33
52
|
try {
|
|
34
53
|
let token = await ensureToken();
|
|
35
54
|
|
|
55
|
+
const endpoint = dry_run
|
|
56
|
+
? `${relayerUiBase}/api/v1/proxy/hostio/evaluate`
|
|
57
|
+
: `${relayerUiBase}/api/v1/proxy/hostio/setexpressions`;
|
|
58
|
+
|
|
59
|
+
// Wire keys per HOSTIO contract — see WIRE CONTRACT note above.
|
|
36
60
|
const payload = {
|
|
37
|
-
data_expression,
|
|
38
|
-
parity_expression,
|
|
61
|
+
data: data_expression,
|
|
62
|
+
parity: parity_expression,
|
|
39
63
|
};
|
|
40
64
|
|
|
41
65
|
let { status, data } = await http.post(
|
|
42
|
-
|
|
66
|
+
endpoint,
|
|
43
67
|
payload,
|
|
44
68
|
{ headers: { keycloaktoken: token } },
|
|
45
69
|
);
|
|
@@ -48,7 +72,7 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
48
72
|
if (status === 401) {
|
|
49
73
|
token = await tokenMgr.reauth();
|
|
50
74
|
const retry = await http.post(
|
|
51
|
-
|
|
75
|
+
endpoint,
|
|
52
76
|
payload,
|
|
53
77
|
{ headers: { keycloaktoken: token } },
|
|
54
78
|
);
|
|
@@ -69,6 +93,34 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
69
93
|
};
|
|
70
94
|
}
|
|
71
95
|
|
|
96
|
+
// The proxy wraps upstream failures (HOSTIO down, missing route,
|
|
97
|
+
// compile/floor rejections) as HTTP 200 {success:false, state}.
|
|
98
|
+
const proxyErr = proxyFailure(data);
|
|
99
|
+
if (proxyErr) {
|
|
100
|
+
if (dry_run && /404/.test(proxyErr)) {
|
|
101
|
+
return {
|
|
102
|
+
content: [{
|
|
103
|
+
type: 'text',
|
|
104
|
+
text: JSON.stringify({
|
|
105
|
+
success: false,
|
|
106
|
+
preview_supported: false,
|
|
107
|
+
message: 'This Relayer version does not support VPD preview yet (no evaluate endpoint). Re-run without dry_run to apply directly, or upgrade the Relayer.',
|
|
108
|
+
}, null, 2),
|
|
109
|
+
}],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
content: [{
|
|
114
|
+
type: 'text',
|
|
115
|
+
text: JSON.stringify({
|
|
116
|
+
success: false,
|
|
117
|
+
message: `HostIO rejected the request (${proxyErr}). Common causes: invalid CEL syntax, or too few matching hosts — the Relayer requires at least 10 data and 20 parity hosts. Broaden the criteria or use defaults ("true" for both expressions).`,
|
|
118
|
+
}, null, 2),
|
|
119
|
+
}],
|
|
120
|
+
isError: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
72
124
|
// AC-18: 400 with too-few-hosts → plain re-ask naming 10/20 threshold
|
|
73
125
|
if (status === 400) {
|
|
74
126
|
const msg = typeof data === 'string' ? data : (data.message || data.error || JSON.stringify(data));
|
|
@@ -108,13 +160,32 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
108
160
|
type: 'text',
|
|
109
161
|
text: JSON.stringify({
|
|
110
162
|
success: false,
|
|
111
|
-
error: `VPD configuration failed (HTTP ${status}): ${JSON.stringify(data)}`,
|
|
163
|
+
error: `VPD ${dry_run ? 'preview' : 'configuration'} failed (HTTP ${status}): ${JSON.stringify(data)}`,
|
|
112
164
|
}),
|
|
113
165
|
}],
|
|
114
166
|
isError: true,
|
|
115
167
|
};
|
|
116
168
|
}
|
|
117
169
|
|
|
170
|
+
if (dry_run) {
|
|
171
|
+
// EvaluateResponse: {data:{matched,count}, parity:{matched,count}}.
|
|
172
|
+
// Counts only — matched key arrays can be hundreds of pubkeys.
|
|
173
|
+
return {
|
|
174
|
+
content: [{
|
|
175
|
+
type: 'text',
|
|
176
|
+
text: JSON.stringify({
|
|
177
|
+
success: true,
|
|
178
|
+
preview: true,
|
|
179
|
+
matched_data_hosts: data?.data?.count ?? null,
|
|
180
|
+
matched_parity_hosts: data?.parity?.count ?? null,
|
|
181
|
+
data_expression,
|
|
182
|
+
parity_expression,
|
|
183
|
+
message: 'Preview only — nothing was applied. Applying will be rejected if the matched counts fall below the Relayer\'s minimums. Re-run without dry_run to apply this selection.',
|
|
184
|
+
}, null, 2),
|
|
185
|
+
}],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
118
189
|
return {
|
|
119
190
|
content: [{
|
|
120
191
|
type: 'text',
|
|
@@ -132,7 +203,7 @@ module.exports = function registerConfigureVpd(server, options = {}) {
|
|
|
132
203
|
type: 'text',
|
|
133
204
|
text: JSON.stringify({
|
|
134
205
|
success: false,
|
|
135
|
-
error: `VPD configuration failed: ${err.message}`,
|
|
206
|
+
error: `VPD ${dry_run ? 'preview' : 'configuration'} failed: ${err.message}`,
|
|
136
207
|
}),
|
|
137
208
|
}],
|
|
138
209
|
isError: true,
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { createHttpClient } = require('../lib/httpClient');
|
|
4
|
+
const { createTokenManager } = require('../lib/ensureToken');
|
|
5
|
+
const { ALLOWED_SETTINGS } = require('../lib/allowedSettings');
|
|
6
|
+
|
|
7
|
+
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tool 12: describe_settings
|
|
11
|
+
* Curated runtime catalog — the MCP exposes only the whitelist in
|
|
12
|
+
* allowedSettings.js, never the full ~74-key advanced catalog (Ken,
|
|
13
|
+
* 2026-06-11). Current values + defaults come from GET /api/v1/config
|
|
14
|
+
* (relayer-ui Config.readConfig: { current, defaults, uploadTuning, ... }).
|
|
15
|
+
*/
|
|
16
|
+
module.exports = function registerDescribeSettings(server, options = {}) {
|
|
17
|
+
const http = options.httpClient || createHttpClient(options);
|
|
18
|
+
const relayerUiBase = options.relayerUiBase || RELAYER_UI_BASE;
|
|
19
|
+
|
|
20
|
+
const tokenMgr = createTokenManager(options);
|
|
21
|
+
const { ensureToken } = tokenMgr;
|
|
22
|
+
|
|
23
|
+
server.tool(
|
|
24
|
+
'describe_settings',
|
|
25
|
+
'List the adjustable Relayer settings: worker/concurrency tuning, backup schedule, and cost center (CCID). Returns current value, default, type, and guidance per setting. Use before update_settings. Requires OIDC sign-in (same session as the other tools).',
|
|
26
|
+
{
|
|
27
|
+
/* no parameters — the whitelist is small by design */
|
|
28
|
+
},
|
|
29
|
+
async () => {
|
|
30
|
+
try {
|
|
31
|
+
let token = await ensureToken();
|
|
32
|
+
|
|
33
|
+
let { status, data } = await http.get(
|
|
34
|
+
`${relayerUiBase}/api/v1/config`,
|
|
35
|
+
{ headers: { keycloaktoken: token } },
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (status === 401) {
|
|
39
|
+
token = await tokenMgr.reauth();
|
|
40
|
+
const retry = await http.get(
|
|
41
|
+
`${relayerUiBase}/api/v1/config`,
|
|
42
|
+
{ headers: { keycloaktoken: token } },
|
|
43
|
+
);
|
|
44
|
+
status = retry.status;
|
|
45
|
+
data = retry.data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (status >= 400) {
|
|
49
|
+
return {
|
|
50
|
+
content: [{
|
|
51
|
+
type: 'text',
|
|
52
|
+
text: JSON.stringify({
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Failed to read Relayer configuration (HTTP ${status}).`,
|
|
55
|
+
}),
|
|
56
|
+
}],
|
|
57
|
+
isError: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const current = data?.current || {};
|
|
62
|
+
const defaults = data?.defaults || {};
|
|
63
|
+
|
|
64
|
+
const settings = Object.entries(ALLOWED_SETTINGS).map(([name, meta]) => {
|
|
65
|
+
const currentValue = meta.group
|
|
66
|
+
? current[meta.group]?.[name]
|
|
67
|
+
: current[name];
|
|
68
|
+
const catalogEntry = meta.group ? defaults[meta.group]?.[name] : null;
|
|
69
|
+
return {
|
|
70
|
+
name,
|
|
71
|
+
group: meta.group || 'General',
|
|
72
|
+
current: currentValue,
|
|
73
|
+
default: catalogEntry ? catalogEntry.default : null,
|
|
74
|
+
type: meta.type,
|
|
75
|
+
note: meta.note,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
content: [{
|
|
81
|
+
type: 'text',
|
|
82
|
+
text: JSON.stringify({
|
|
83
|
+
success: true,
|
|
84
|
+
settings,
|
|
85
|
+
// uploadTuning: 'calculating' until a speedtest lands;
|
|
86
|
+
// 'tuned' carries the resource-aware concurrency ceiling
|
|
87
|
+
// that caps HOSTIO_SIMULTANEOUS_UPLOADS.
|
|
88
|
+
uploadTuning: data.uploadTuning ?? null,
|
|
89
|
+
message: 'These are the only settings adjustable through this MCP. Apply changes with update_settings; most need restart_service afterwards. Changing CostCenter changes who is billed — always confirm with the operator first.',
|
|
90
|
+
}, null, 2),
|
|
91
|
+
}],
|
|
92
|
+
};
|
|
93
|
+
} catch (err) {
|
|
94
|
+
return {
|
|
95
|
+
content: [{
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: JSON.stringify({
|
|
98
|
+
success: false,
|
|
99
|
+
error: `Failed to describe settings: ${err.message}`,
|
|
100
|
+
}),
|
|
101
|
+
}],
|
|
102
|
+
isError: true,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return { ensureToken, getTokenState: tokenMgr.getTokenState, setTokenState: tokenMgr.setTokenState };
|
|
109
|
+
};
|
package/src/tools/getHostTags.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { createHttpClient } = require('../lib/httpClient');
|
|
4
4
|
const { createTokenManager } = require('../lib/ensureToken');
|
|
5
|
+
const { proxyFailure } = require('../lib/proxyError');
|
|
5
6
|
|
|
6
7
|
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
7
8
|
|
|
@@ -10,8 +11,16 @@ const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
|
10
11
|
* AC-17: translate plain English → CEL; operator never sees "expression".
|
|
11
12
|
* Watch item 1: trigger OIDC re-auth on 401 — never silent failure.
|
|
12
13
|
*
|
|
13
|
-
* Consumes relayer-ui
|
|
14
|
-
*
|
|
14
|
+
* Consumes relayer-ui's HostIO proxy (server/api/v1/Proxy.js, wildcard route
|
|
15
|
+
* GET /api/v1/proxy/hostio/* → HOSTIO /v1/hostio/<wildcard>):
|
|
16
|
+
* GET /api/v1/proxy/hostio/gettags → { tags: [...] }
|
|
17
|
+
* GET /api/v1/proxy/hostio/getexpressions → { data, parity } (read-back)
|
|
18
|
+
*
|
|
19
|
+
* PATH CONTRACT — the proxy PREPENDS /v1/hostio/ to the wildcard. Passing
|
|
20
|
+
* "v1/hostio/gettags" here produced /v1/hostio/v1/hostio/gettags → HOSTIO 404,
|
|
21
|
+
* which the proxy wraps as HTTP 200 {success:false, state} (see proxyError.js).
|
|
22
|
+
* That double-prefix shipped in <=0.5.2 and broke both VPD tools — verified
|
|
23
|
+
* live against HOSTIO 2026-06-11. Fixed in 0.6.0; do not "restore" the prefix.
|
|
15
24
|
*/
|
|
16
25
|
module.exports = function registerGetHostTags(server, options = {}) {
|
|
17
26
|
const http = options.httpClient || createHttpClient(options);
|
|
@@ -22,7 +31,7 @@ module.exports = function registerGetHostTags(server, options = {}) {
|
|
|
22
31
|
|
|
23
32
|
server.tool(
|
|
24
33
|
'get_host_tags',
|
|
25
|
-
'Get the
|
|
34
|
+
'Get the available host tags for VPD (Virtual Private Datacenter) configuration, plus the currently applied VPD host selection. Translate tags into plain-language options for the operator — never show raw CEL expressions. Requires OIDC sign-in on first use (the user will be prompted to sign in via browser).',
|
|
26
35
|
{
|
|
27
36
|
/* no parameters */
|
|
28
37
|
},
|
|
@@ -31,7 +40,7 @@ module.exports = function registerGetHostTags(server, options = {}) {
|
|
|
31
40
|
let token = await ensureToken();
|
|
32
41
|
|
|
33
42
|
let { status, data } = await http.get(
|
|
34
|
-
`${relayerUiBase}/api/v1/proxy/hostio/
|
|
43
|
+
`${relayerUiBase}/api/v1/proxy/hostio/gettags`,
|
|
35
44
|
{ headers: { keycloaktoken: token } },
|
|
36
45
|
);
|
|
37
46
|
|
|
@@ -39,7 +48,7 @@ module.exports = function registerGetHostTags(server, options = {}) {
|
|
|
39
48
|
if (status === 401) {
|
|
40
49
|
token = await tokenMgr.reauth();
|
|
41
50
|
const retry = await http.get(
|
|
42
|
-
`${relayerUiBase}/api/v1/proxy/hostio/
|
|
51
|
+
`${relayerUiBase}/api/v1/proxy/hostio/gettags`,
|
|
43
52
|
{ headers: { keycloaktoken: token } },
|
|
44
53
|
);
|
|
45
54
|
status = retry.status;
|
|
@@ -59,13 +68,14 @@ module.exports = function registerGetHostTags(server, options = {}) {
|
|
|
59
68
|
};
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
|
|
71
|
+
const proxyErr = proxyFailure(data);
|
|
72
|
+
if (status >= 400 || proxyErr) {
|
|
63
73
|
return {
|
|
64
74
|
content: [{
|
|
65
75
|
type: 'text',
|
|
66
76
|
text: JSON.stringify({
|
|
67
77
|
success: false,
|
|
68
|
-
error: `Failed to retrieve host tags (HTTP ${status}): ${JSON.stringify(data)}`,
|
|
78
|
+
error: `Failed to retrieve host tags${proxyErr ? ` (HostIO proxy: ${proxyErr})` : ` (HTTP ${status}): ${JSON.stringify(data)}`}`,
|
|
69
79
|
}),
|
|
70
80
|
}],
|
|
71
81
|
isError: true,
|
|
@@ -74,13 +84,36 @@ module.exports = function registerGetHostTags(server, options = {}) {
|
|
|
74
84
|
|
|
75
85
|
const tags = data.tags || data || [];
|
|
76
86
|
|
|
87
|
+
// Read-back of the applied expressions — degraded, never fatal:
|
|
88
|
+
// tags alone are still useful when HOSTIO read-back hiccups.
|
|
89
|
+
let current = null;
|
|
90
|
+
try {
|
|
91
|
+
const exprResp = await http.get(
|
|
92
|
+
`${relayerUiBase}/api/v1/proxy/hostio/getexpressions`,
|
|
93
|
+
{ headers: { keycloaktoken: token } },
|
|
94
|
+
);
|
|
95
|
+
if (exprResp.status < 400 && !proxyFailure(exprResp.data)
|
|
96
|
+
&& typeof exprResp.data?.data === 'string'
|
|
97
|
+
&& typeof exprResp.data?.parity === 'string') {
|
|
98
|
+
current = {
|
|
99
|
+
data_expression: exprResp.data.data,
|
|
100
|
+
parity_expression: exprResp.data.parity,
|
|
101
|
+
// "true" is HOSTIO's all-hosts default (hostselection fix()).
|
|
102
|
+
is_default: exprResp.data.data === 'true' && exprResp.data.parity === 'true',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
} catch (exprErr) {
|
|
106
|
+
current = null;
|
|
107
|
+
}
|
|
108
|
+
|
|
77
109
|
return {
|
|
78
110
|
content: [{
|
|
79
111
|
type: 'text',
|
|
80
112
|
text: JSON.stringify({
|
|
81
113
|
success: true,
|
|
82
114
|
tags,
|
|
83
|
-
|
|
115
|
+
current,
|
|
116
|
+
message: 'Host tags retrieved. Present these as plain-language options to the operator (e.g., "US-based hosts", "European hosts"). Never show raw tag names or CEL expressions directly. "current" is the VPD selection applied right now (is_default true = all hosts). Use configure_vpd to change it.',
|
|
84
117
|
}, null, 2),
|
|
85
118
|
}],
|
|
86
119
|
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { z } = require('zod');
|
|
4
|
+
const { createHttpClient } = require('../lib/httpClient');
|
|
5
|
+
const { createTokenManager } = require('../lib/ensureToken');
|
|
6
|
+
|
|
7
|
+
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
8
|
+
|
|
9
|
+
// Selective-restore component keys accepted by relayer-ui Backup.restore
|
|
10
|
+
// (server/api/v1/Backup.js shouldRestore switch). Omitting components
|
|
11
|
+
// restores everything in the archive.
|
|
12
|
+
const COMPONENTS = ['db', 'conf', 'hostio', 'samba'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Tool 15: manage_backups
|
|
16
|
+
* One verb, four actions over relayer-ui's backup API:
|
|
17
|
+
* list -> GET /api/v1/backup/list
|
|
18
|
+
* start -> PUT /api/v1/backup/start (server runs a disk preflight)
|
|
19
|
+
* restore -> PUT /api/v1/backup/restore { file, components? }
|
|
20
|
+
* delete -> DELETE /api/v1/backup/remove { file }
|
|
21
|
+
* Single tool by design — backups are a small closed verb set and each extra
|
|
22
|
+
* tool definition is per-turn context weight for every agent session.
|
|
23
|
+
*/
|
|
24
|
+
module.exports = function registerManageBackups(server, options = {}) {
|
|
25
|
+
const http = options.httpClient || createHttpClient(options);
|
|
26
|
+
const relayerUiBase = options.relayerUiBase || RELAYER_UI_BASE;
|
|
27
|
+
|
|
28
|
+
const tokenMgr = createTokenManager(options);
|
|
29
|
+
const { ensureToken } = tokenMgr;
|
|
30
|
+
|
|
31
|
+
server.tool(
|
|
32
|
+
'manage_backups',
|
|
33
|
+
'Manage Relayer configuration backups: list archives, start a backup, restore from an archive, or delete one. Restore OVERWRITES current state and restarts services — always confirm with the operator and state which archive and components first. Backups must be enabled (BACKUP_ENABLED) for list/start.',
|
|
34
|
+
{
|
|
35
|
+
action: z.enum(['list', 'start', 'restore', 'delete'])
|
|
36
|
+
.describe('Backup operation to perform.'),
|
|
37
|
+
file: z.string().optional()
|
|
38
|
+
.describe('Archive file name from list (e.g. "1718000000000.zip"). Required for restore and delete.'),
|
|
39
|
+
components: z.array(z.enum(COMPONENTS)).optional()
|
|
40
|
+
.describe('Restore only these components (db, conf, hostio, samba). Omit to restore everything.'),
|
|
41
|
+
},
|
|
42
|
+
async ({ action, file, components }) => {
|
|
43
|
+
try {
|
|
44
|
+
if ((action === 'restore' || action === 'delete') && !file) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{
|
|
47
|
+
type: 'text',
|
|
48
|
+
text: JSON.stringify({
|
|
49
|
+
success: false,
|
|
50
|
+
error: `Action "${action}" requires a file name. Call manage_backups with action "list" to see available archives.`,
|
|
51
|
+
}),
|
|
52
|
+
}],
|
|
53
|
+
isError: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let token = await ensureToken();
|
|
58
|
+
|
|
59
|
+
const send = async (tok) => {
|
|
60
|
+
const headers = { keycloaktoken: tok };
|
|
61
|
+
switch (action) {
|
|
62
|
+
case 'list':
|
|
63
|
+
return http.get(`${relayerUiBase}/api/v1/backup/list`, { headers });
|
|
64
|
+
case 'start':
|
|
65
|
+
return http.put(`${relayerUiBase}/api/v1/backup/start`, {}, { headers });
|
|
66
|
+
case 'restore':
|
|
67
|
+
return http.put(
|
|
68
|
+
`${relayerUiBase}/api/v1/backup/restore`,
|
|
69
|
+
components && components.length > 0 ? { file, components } : { file },
|
|
70
|
+
{ headers },
|
|
71
|
+
);
|
|
72
|
+
case 'delete':
|
|
73
|
+
default:
|
|
74
|
+
return http.del(`${relayerUiBase}/api/v1/backup/remove`, { headers, data: { file } });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let { status, data } = await send(token);
|
|
79
|
+
if (status === 401) {
|
|
80
|
+
token = await tokenMgr.reauth();
|
|
81
|
+
({ status, data } = await send(token));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (status >= 400 || data?.success === false) {
|
|
85
|
+
const detail = data?.message || data?.error || `HTTP ${status}`;
|
|
86
|
+
return {
|
|
87
|
+
content: [{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: JSON.stringify({
|
|
90
|
+
success: false,
|
|
91
|
+
action,
|
|
92
|
+
// Backups-disabled is a state, not a fault — route the
|
|
93
|
+
// agent to the fix instead of a dead end.
|
|
94
|
+
error: data?.disabled
|
|
95
|
+
? 'Backups are disabled. Enable them with update_settings {"BACKUP_ENABLED": true} first.'
|
|
96
|
+
: `Backup ${action} failed: ${detail}`,
|
|
97
|
+
}, null, 2),
|
|
98
|
+
}],
|
|
99
|
+
isError: true,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const result = { success: true, action };
|
|
104
|
+
if (action === 'list') {
|
|
105
|
+
result.files = (data?.files || []).map((f) => ({
|
|
106
|
+
name: f.name,
|
|
107
|
+
size: f.stats?.size,
|
|
108
|
+
created: f.stats?.mtime || f.stats?.ctime,
|
|
109
|
+
}));
|
|
110
|
+
result.message = result.files.length
|
|
111
|
+
? 'Backup archives listed. Use the name field for restore/delete.'
|
|
112
|
+
: 'No backup archives found yet. Use action "start" to create one.';
|
|
113
|
+
} else if (action === 'start') {
|
|
114
|
+
result.message = 'Backup started. It appears in the list when finished.';
|
|
115
|
+
} else if (action === 'restore') {
|
|
116
|
+
result.message = 'Restore initiated — services restart as part of the restore. Verify recovery with check_relayer_health.';
|
|
117
|
+
} else {
|
|
118
|
+
result.file = file;
|
|
119
|
+
result.message = 'Backup archive deleted.';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
124
|
+
};
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return {
|
|
127
|
+
content: [{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: JSON.stringify({
|
|
130
|
+
success: false,
|
|
131
|
+
error: `Backup ${action} failed: ${err.message}`,
|
|
132
|
+
}),
|
|
133
|
+
}],
|
|
134
|
+
isError: true,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return { ensureToken, getTokenState: tokenMgr.getTokenState, setTokenState: tokenMgr.setTokenState };
|
|
141
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { z } = require('zod');
|
|
4
|
+
const { createHttpClient } = require('../lib/httpClient');
|
|
5
|
+
const { createTokenManager } = require('../lib/ensureToken');
|
|
6
|
+
|
|
7
|
+
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
8
|
+
|
|
9
|
+
// Service names accepted by relayer-ui System.js #start/#stop switch
|
|
10
|
+
// (server/api/v1/System.js) — anything else falls through to "all".
|
|
11
|
+
const SERVICES = ['hostio', 'gateway', 's3gateway', 'database', 'all'];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tool 14: restart_service
|
|
15
|
+
* Consumes relayer-ui: GET /api/v1/system/restart[/:service].
|
|
16
|
+
* Standalone by design (not a flag on update_settings): restarting drops
|
|
17
|
+
* in-flight S3 traffic, so it must be a separately confirmable step.
|
|
18
|
+
*/
|
|
19
|
+
module.exports = function registerRestartService(server, options = {}) {
|
|
20
|
+
const http = options.httpClient || createHttpClient(options);
|
|
21
|
+
const relayerUiBase = options.relayerUiBase || RELAYER_UI_BASE;
|
|
22
|
+
|
|
23
|
+
const tokenMgr = createTokenManager(options);
|
|
24
|
+
const { ensureToken } = tokenMgr;
|
|
25
|
+
|
|
26
|
+
server.tool(
|
|
27
|
+
'restart_service',
|
|
28
|
+
'Restart a Relayer service (hostio, gateway, s3gateway, database) or all services. Disruptive: in-flight S3 requests will fail during the restart — confirm with the operator before calling. Verify recovery afterwards with check_relayer_health.',
|
|
29
|
+
{
|
|
30
|
+
service: z.enum(SERVICES).optional()
|
|
31
|
+
.describe('Service to restart. Defaults to "all".'),
|
|
32
|
+
},
|
|
33
|
+
async ({ service }) => {
|
|
34
|
+
try {
|
|
35
|
+
const target = service && service !== 'all' ? `/${service}` : '';
|
|
36
|
+
const url = `${relayerUiBase}/api/v1/system/restart${target}`;
|
|
37
|
+
|
|
38
|
+
let token = await ensureToken();
|
|
39
|
+
|
|
40
|
+
let { status, data } = await http.get(url, { headers: { keycloaktoken: token } });
|
|
41
|
+
if (status === 401) {
|
|
42
|
+
token = await tokenMgr.reauth();
|
|
43
|
+
({ status, data } = await http.get(url, { headers: { keycloaktoken: token } }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (status >= 400) {
|
|
47
|
+
return {
|
|
48
|
+
content: [{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: JSON.stringify({
|
|
51
|
+
success: false,
|
|
52
|
+
error: `Restart request failed (HTTP ${status}): ${JSON.stringify(data)}`,
|
|
53
|
+
}),
|
|
54
|
+
}],
|
|
55
|
+
isError: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
content: [{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: JSON.stringify({
|
|
63
|
+
success: true,
|
|
64
|
+
service: data?.service || service || 'all',
|
|
65
|
+
message: 'Restart initiated. Services take a moment to come back — verify recovery with check_relayer_health before continuing.',
|
|
66
|
+
}, null, 2),
|
|
67
|
+
}],
|
|
68
|
+
};
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return {
|
|
71
|
+
content: [{
|
|
72
|
+
type: 'text',
|
|
73
|
+
text: JSON.stringify({
|
|
74
|
+
success: false,
|
|
75
|
+
error: `Failed to restart service: ${err.message}`,
|
|
76
|
+
}),
|
|
77
|
+
}],
|
|
78
|
+
isError: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return { ensureToken, getTokenState: tokenMgr.getTokenState, setTokenState: tokenMgr.setTokenState };
|
|
85
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { z } = require('zod');
|
|
4
|
+
const { createHttpClient } = require('../lib/httpClient');
|
|
5
|
+
const { createTokenManager } = require('../lib/ensureToken');
|
|
6
|
+
const { ALLOWED_SETTINGS, isAllowed, typeError, suggestKey } = require('../lib/allowedSettings');
|
|
7
|
+
|
|
8
|
+
const RELAYER_UI_BASE = 'http://localhost:8888';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tool 13: update_settings
|
|
12
|
+
* Whitelist-enforced read-merge-write against relayer-ui's config API:
|
|
13
|
+
* GET /api/v1/config -> merge accepted keys into `current` -> PUT { config, database }.
|
|
14
|
+
*
|
|
15
|
+
* CROSS-BOUNDARY CONTRACT — the PUT persists the FULL config file (there is no
|
|
16
|
+
* server-side patch), and `database` must round-trip from the GET. The GET
|
|
17
|
+
* redacts database.password to '[REDACTED]'; relayer-ui >= 3.43.3 restores the
|
|
18
|
+
* real password server-side (dbPasswordGuard.js). Against older relayer-ui
|
|
19
|
+
* versions this tool could clobber the DB password — the README pins the
|
|
20
|
+
* minimum version.
|
|
21
|
+
*
|
|
22
|
+
* Semantic validation stays server-side (e.g. the resource-aware upload
|
|
23
|
+
* ceiling rejects oversized HOSTIO_SIMULTANEOUS_UPLOADS); those rejection
|
|
24
|
+
* messages pass through verbatim.
|
|
25
|
+
*/
|
|
26
|
+
module.exports = function registerUpdateSettings(server, options = {}) {
|
|
27
|
+
const http = options.httpClient || createHttpClient(options);
|
|
28
|
+
const relayerUiBase = options.relayerUiBase || RELAYER_UI_BASE;
|
|
29
|
+
|
|
30
|
+
const tokenMgr = createTokenManager(options);
|
|
31
|
+
const { ensureToken } = tokenMgr;
|
|
32
|
+
|
|
33
|
+
server.tool(
|
|
34
|
+
'update_settings',
|
|
35
|
+
'Update adjustable Relayer settings (see describe_settings for the allowed set). Pass a map of setting name to new value, e.g. {"HOSTIO_UPLOAD_WORKERS": 20}. Returns require_restart — if true, follow up with restart_service after confirming with the operator. Changing CostCenter re-bills to a different cost center; always confirm first.',
|
|
36
|
+
{
|
|
37
|
+
settings: z.record(z.union([z.string(), z.number(), z.boolean()]))
|
|
38
|
+
.describe('Map of setting name to new value. Only whitelisted settings are accepted; unknown or protected keys are rejected with the allowed list.'),
|
|
39
|
+
},
|
|
40
|
+
async ({ settings }) => {
|
|
41
|
+
try {
|
|
42
|
+
const accepted = {};
|
|
43
|
+
const rejected = [];
|
|
44
|
+
for (const [key, value] of Object.entries(settings || {})) {
|
|
45
|
+
if (!isAllowed(key)) {
|
|
46
|
+
const suggestion = suggestKey(key);
|
|
47
|
+
rejected.push({
|
|
48
|
+
key,
|
|
49
|
+
reason: `not an adjustable setting${suggestion ? ` — did you mean ${suggestion}?` : ''}`,
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const typeProblem = typeError(key, value);
|
|
54
|
+
if (typeProblem) {
|
|
55
|
+
rejected.push({ key, reason: typeProblem });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
accepted[key] = value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Object.keys(accepted).length === 0) {
|
|
62
|
+
return {
|
|
63
|
+
content: [{
|
|
64
|
+
type: 'text',
|
|
65
|
+
text: JSON.stringify({
|
|
66
|
+
success: false,
|
|
67
|
+
rejected,
|
|
68
|
+
allowed_settings: Object.keys(ALLOWED_SETTINGS),
|
|
69
|
+
message: 'No valid settings to apply. Only the listed settings are adjustable through this MCP.',
|
|
70
|
+
}, null, 2),
|
|
71
|
+
}],
|
|
72
|
+
isError: true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let token = await ensureToken();
|
|
77
|
+
|
|
78
|
+
const readOnce = (tok) => http.get(
|
|
79
|
+
`${relayerUiBase}/api/v1/config`,
|
|
80
|
+
{ headers: { keycloaktoken: tok } },
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
let { status, data } = await readOnce(token);
|
|
84
|
+
if (status === 401) {
|
|
85
|
+
token = await tokenMgr.reauth();
|
|
86
|
+
({ status, data } = await readOnce(token));
|
|
87
|
+
}
|
|
88
|
+
if (status >= 400) {
|
|
89
|
+
return {
|
|
90
|
+
content: [{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: JSON.stringify({
|
|
93
|
+
success: false,
|
|
94
|
+
error: `Failed to read current configuration before update (HTTP ${status}). Nothing was changed.`,
|
|
95
|
+
}),
|
|
96
|
+
}],
|
|
97
|
+
isError: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The PUT persists the full config file AND requires the
|
|
102
|
+
// database section — refuse to write from a malformed read
|
|
103
|
+
// rather than risk persisting a gutted config.
|
|
104
|
+
if (!data || typeof data !== 'object' || !data.current || !data.database) {
|
|
105
|
+
return {
|
|
106
|
+
content: [{
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: JSON.stringify({
|
|
109
|
+
success: false,
|
|
110
|
+
error: 'Unexpected configuration response from the Relayer (missing current config or database section). Nothing was changed.',
|
|
111
|
+
}),
|
|
112
|
+
}],
|
|
113
|
+
isError: true,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Merge accepted keys into a copy of the live config. Group
|
|
118
|
+
// placement comes from the whitelist (matches the sections of
|
|
119
|
+
// relayer_configuration.json); CostCenter is top-level.
|
|
120
|
+
const config = JSON.parse(JSON.stringify(data.current));
|
|
121
|
+
for (const [key, value] of Object.entries(accepted)) {
|
|
122
|
+
const group = ALLOWED_SETTINGS[key].group;
|
|
123
|
+
if (group) {
|
|
124
|
+
config[group] = config[group] || {};
|
|
125
|
+
config[group][key] = value;
|
|
126
|
+
} else {
|
|
127
|
+
config[key] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const putResp = await http.put(
|
|
132
|
+
`${relayerUiBase}/api/v1/config`,
|
|
133
|
+
{ config, database: data.database },
|
|
134
|
+
{ headers: { keycloaktoken: token } },
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if (putResp.status >= 400 || putResp.data?.success === false) {
|
|
138
|
+
return {
|
|
139
|
+
content: [{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
success: false,
|
|
143
|
+
rejected,
|
|
144
|
+
// Server-side rejections (e.g. the upload-concurrency
|
|
145
|
+
// ceiling) carry an actionable message — surface it.
|
|
146
|
+
error: putResp.data?.message || `Configuration update failed (HTTP ${putResp.status}).`,
|
|
147
|
+
}, null, 2),
|
|
148
|
+
}],
|
|
149
|
+
isError: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const requireRestart = putResp.data?.requireRestart === true
|
|
154
|
+
|| Object.keys(accepted).some((k) => /restart/i.test(ALLOWED_SETTINGS[k].note));
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
content: [{
|
|
158
|
+
type: 'text',
|
|
159
|
+
text: JSON.stringify({
|
|
160
|
+
success: true,
|
|
161
|
+
applied: accepted,
|
|
162
|
+
rejected,
|
|
163
|
+
require_restart: requireRestart,
|
|
164
|
+
message: requireRestart
|
|
165
|
+
? 'Settings saved. They take effect after a service restart — confirm with the operator, then call restart_service.'
|
|
166
|
+
: 'Settings saved.',
|
|
167
|
+
}, null, 2),
|
|
168
|
+
}],
|
|
169
|
+
};
|
|
170
|
+
} catch (err) {
|
|
171
|
+
// err.message is surfaced DELIBERATELY (looks like R3 leakage,
|
|
172
|
+
// isn't): this is a stdio MCP in the operator's local trust
|
|
173
|
+
// domain, there is no server-side log a user would read, and
|
|
174
|
+
// the raw signal (ECONNREFUSED, timeout) is what lets the
|
|
175
|
+
// agent self-correct. Same contract as the 11 original tools.
|
|
176
|
+
return {
|
|
177
|
+
content: [{
|
|
178
|
+
type: 'text',
|
|
179
|
+
text: JSON.stringify({
|
|
180
|
+
success: false,
|
|
181
|
+
error: `Failed to update settings: ${err.message}`,
|
|
182
|
+
}),
|
|
183
|
+
}],
|
|
184
|
+
isError: true,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return { ensureToken, getTokenState: tokenMgr.getTokenState, setTokenState: tokenMgr.setTokenState };
|
|
191
|
+
};
|