@xns-cloud/relayer-mcp 0.7.0 → 0.9.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 +36 -4
- package/package.json +8 -2
- package/src/index.js +6 -2
- package/src/lib/environmentProbe.js +55 -0
- package/src/lib/hostAllowlist.js +57 -0
- package/src/lib/oidcAuth.js +22 -11
- package/src/tools/checkClaimStatus.js +14 -5
- package/src/tools/checkEmailVerified.js +14 -6
- package/src/tools/checkPrerequisites.js +49 -5
- package/src/tools/checkRelayerHealth.js +16 -7
- package/src/tools/configureVpd.js +13 -5
- package/src/tools/describeSettings.js +11 -3
- package/src/tools/getHostTags.js +11 -3
- package/src/tools/installRelayer.js +19 -11
- package/src/tools/manageBackups.js +28 -10
- package/src/tools/restartService.js +12 -4
- package/src/tools/setupCliCredentials.js +48 -8
- package/src/tools/startClaim.js +11 -3
- package/src/tools/startRegistration.js +68 -0
- package/src/tools/updateSettings.js +12 -4
- package/src/tools/verifyStorage.js +279 -78
- package/src/tools/registerAccount.js +0 -123
|
@@ -3,81 +3,237 @@
|
|
|
3
3
|
const { z } = require('zod');
|
|
4
4
|
const { createS3Client } = require('../lib/s3Client');
|
|
5
5
|
const { createDockerUtil } = require('../lib/dockerUtil');
|
|
6
|
+
const { createHttpClient } = require('../lib/httpClient');
|
|
7
|
+
const { createTokenManager } = require('../lib/ensureToken');
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Tool 10: verify_storage
|
|
9
|
-
* AC-20: targets the S3 gateway on port 9000 plain HTTP; reports endpoint.
|
|
10
|
-
* AC-21: verify fail → names the failing step (CreateBucket/PutObject/GetObject).
|
|
11
|
-
* W3-AC1: cleanup in finally — always removes mcp-verify-* bucket/object; failure
|
|
12
|
-
* is non-fatal (noted in response, never flips pass→fail).
|
|
13
|
-
* W3-AC2: fullaccess credential requirement stated in description and error output.
|
|
14
|
-
* W3-AC3: explicit-IP hint when endpoint was auto-detected.
|
|
15
|
-
* R6: S3 credentials must be provided (from relayer-ui IAM key-mgmt flow).
|
|
16
11
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
12
|
+
* Self-provisioning S3 round-trip verification. When called with only a
|
|
13
|
+
* muse_token, mints a throwaway IAM user with a scoped policy restricted to
|
|
14
|
+
* mcp-verify-* buckets, runs CreateBucket -> PutObject -> GetObject -> Compare,
|
|
15
|
+
* and tears everything down in finally — pass or fail.
|
|
16
|
+
*
|
|
17
|
+
* Optional access_key_id/secret_access_key skip minting entirely.
|
|
18
|
+
* The minted credential lives in memory only — zero fs usage.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Host allowlist + no-redirect policy now live in lib/hostAllowlist.js so every
|
|
22
|
+
// token-bearing tool shares one definition (MR !33).
|
|
23
|
+
const { validateHostAllowlist, NO_REDIRECT_TOKEN_CONFIG } = require('../lib/hostAllowlist');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An error whose message is authored by this tool (no caught provider text)
|
|
27
|
+
* and therefore safe to return to the MCP client verbatim.
|
|
20
28
|
*/
|
|
29
|
+
function safeError(message) {
|
|
30
|
+
return Object.assign(new Error(message), { userSafe: true });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isNotFoundResponse(msg) {
|
|
34
|
+
if (typeof msg !== 'string') return false;
|
|
35
|
+
return /not.found|does.not.exist/i.test(msg);
|
|
36
|
+
}
|
|
37
|
+
|
|
21
38
|
module.exports = function registerVerifyStorage(server, options = {}) {
|
|
22
39
|
const _createS3Client = options.createS3Client || createS3Client;
|
|
23
40
|
const docker = options.dockerUtil || createDockerUtil(options);
|
|
41
|
+
const http = options.httpClient || createHttpClient(options);
|
|
42
|
+
const tokenMgr = createTokenManager(options);
|
|
24
43
|
|
|
25
|
-
server.
|
|
44
|
+
server.registerTool(
|
|
26
45
|
'verify_storage',
|
|
27
|
-
'Verify the S3-compatible storage gateway is working by performing a round-trip test: create a test bucket, upload a small object, download it, and compare. IMPORTANT: you must supply fullaccess credentials — the admin key pair created via the Relayer UI IAM page (not a read-only or bucket-scoped key). By default targets port 9000 on the machine the Docker daemon runs on (auto-detected from the Docker context — supports remote ssh:// Docker hosts); pass endpoint to override with an explicit IP when auto-detection cannot reach the host.',
|
|
28
46
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
title: 'verify_storage',
|
|
48
|
+
description: 'Verify the S3-compatible storage gateway is working by performing a round-trip test: create a test bucket, upload a small object, download it, and compare. Provisions a temporary scoped IAM credential automatically using your OIDC session — no manual key management needed. The throwaway credential and test data are removed after the test, pass or fail. By default targets port 9000 on the machine the Docker daemon runs on (auto-detected from the Docker context); pass endpoint to override.',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
muse_token: z.string().trim().min(1).optional().describe('Optional Keycloak/Muse token override. Usually omitted — without it (and without access keys) the tool reuses the sign-in session from get_host_tags/configure_vpd, or starts a browser sign-in if there is none.'),
|
|
51
|
+
access_key_id: z.string().optional().describe('S3 access key ID — when provided with secret_access_key, skips automatic credential provisioning'),
|
|
52
|
+
secret_access_key: z.string().optional().describe('S3 secret access key — when provided with access_key_id, skips automatic credential provisioning'),
|
|
53
|
+
relayer_ui_url: z.string().trim().url().optional().default('http://localhost:8888').describe('Relayer UI base URL (default: http://localhost:8888)'),
|
|
54
|
+
endpoint: z.string().trim().url().optional().describe('S3 endpoint URL. Default: http://{docker-host}:9000. Pass an explicit IP (e.g. http://192.168.1.100:9000) when auto-detection cannot reach the host.'),
|
|
55
|
+
},
|
|
56
|
+
annotations: {
|
|
57
|
+
readOnlyHint: false,
|
|
58
|
+
destructiveHint: false,
|
|
59
|
+
openWorldHint: true,
|
|
60
|
+
},
|
|
32
61
|
},
|
|
33
|
-
async ({ access_key_id, secret_access_key, endpoint }) => {
|
|
34
|
-
const
|
|
62
|
+
async ({ muse_token, access_key_id, secret_access_key, relayer_ui_url = 'http://localhost:8888', endpoint }) => {
|
|
63
|
+
const runTs = Date.now();
|
|
64
|
+
const testBucket = `mcp-verify-${runTs}`;
|
|
35
65
|
const testKey = 'verify-test.txt';
|
|
36
|
-
const testContent = `relayer-mcp verification ${
|
|
66
|
+
const testContent = `relayer-mcp verification ${runTs}`;
|
|
37
67
|
let currentStep = 'init';
|
|
38
68
|
let endpointAutoDetected = false;
|
|
39
69
|
|
|
40
|
-
let
|
|
70
|
+
let mintedUser = null;
|
|
71
|
+
let mintedPolicyName = null;
|
|
72
|
+
let bucketCreated = false;
|
|
73
|
+
let policyCreated = false;
|
|
74
|
+
let policyAttached = false;
|
|
75
|
+
let mintConfirmed = false;
|
|
76
|
+
let bucketConfirmed = false;
|
|
77
|
+
let policyConfirmed = false;
|
|
78
|
+
let attachConfirmed = false;
|
|
79
|
+
let effectiveAK = access_key_id;
|
|
80
|
+
let effectiveSK = secret_access_key;
|
|
81
|
+
let result;
|
|
82
|
+
let isError = false;
|
|
83
|
+
|
|
84
|
+
const baseUrl = relayer_ui_url.replace(/\/+$/, '');
|
|
41
85
|
|
|
42
86
|
try {
|
|
87
|
+
const hostCheck = validateHostAllowlist(baseUrl);
|
|
88
|
+
if (!hostCheck.allowed) {
|
|
89
|
+
throw safeError(`relayer_ui_url rejected: ${hostCheck.reason}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
43
92
|
if (!endpoint) {
|
|
44
93
|
const { host } = await docker.getDockerHost();
|
|
45
94
|
endpoint = `http://${host}:9000`;
|
|
46
95
|
endpointAutoDetected = true;
|
|
47
96
|
}
|
|
97
|
+
|
|
98
|
+
const usePassthrough = effectiveAK && effectiveSK;
|
|
99
|
+
|
|
100
|
+
if (!usePassthrough) {
|
|
101
|
+
if (!muse_token) {
|
|
102
|
+
// BUG-366: reuse the OIDC session get_host_tags/configure_vpd
|
|
103
|
+
// established (shared token state), or start a browser sign-in.
|
|
104
|
+
// No tool emits the token, so requiring it as a parameter
|
|
105
|
+
// dead-ended every agent on the no-keys path.
|
|
106
|
+
//
|
|
107
|
+
// The session token is server-held — never forward it to a
|
|
108
|
+
// caller-selected origin. The fallback only targets the
|
|
109
|
+
// server-owned base, matching restart_service/manage_backups.
|
|
110
|
+
const serverOwnedBase = (options.relayerUiBase || 'http://localhost:8888').replace(/\/+$/, '');
|
|
111
|
+
if (baseUrl !== serverOwnedBase) {
|
|
112
|
+
throw safeError('The OIDC session fallback only targets the server-configured Relayer UI base (default http://localhost:8888). Pass muse_token or access_key_id/secret_access_key explicitly when targeting a custom relayer_ui_url.');
|
|
113
|
+
}
|
|
114
|
+
currentStep = 'SignIn';
|
|
115
|
+
try {
|
|
116
|
+
muse_token = await tokenMgr.ensureToken();
|
|
117
|
+
} catch (signInErr) {
|
|
118
|
+
console.error(`[verify_storage] SignIn: ${signInErr.message}`);
|
|
119
|
+
throw safeError('OIDC sign-in did not complete. Run get_host_tags first to sign in, or pass muse_token or access_key_id/secret_access_key.');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
currentStep = 'MintUser';
|
|
124
|
+
const userName = `mcp-verify-${runTs}`;
|
|
125
|
+
mintedUser = userName;
|
|
126
|
+
const { status: mintStatus, data: mintData } = await http.post(
|
|
127
|
+
`${baseUrl}/api/v1/mc/user`,
|
|
128
|
+
{ user: userName },
|
|
129
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
130
|
+
);
|
|
131
|
+
if (mintStatus !== 200) {
|
|
132
|
+
// Definitive refusal — the server answered, no user was
|
|
133
|
+
// created, so a cleanup attempt would only cry wolf.
|
|
134
|
+
// A thrown request (no response) keeps the intent flag.
|
|
135
|
+
mintedUser = null;
|
|
136
|
+
throw new Error(`Mint user failed (HTTP ${mintStatus})`);
|
|
137
|
+
}
|
|
138
|
+
effectiveAK = mintData?.access_key;
|
|
139
|
+
effectiveSK = mintData?.secret_key;
|
|
140
|
+
|
|
141
|
+
if (mintData?.success === false) {
|
|
142
|
+
mintedUser = null;
|
|
143
|
+
throw new Error('Mint user failed');
|
|
144
|
+
}
|
|
145
|
+
if (!effectiveAK || !effectiveSK) {
|
|
146
|
+
// HTTP 200 without keys is ambiguous — the user may
|
|
147
|
+
// exist, so keep the cleanup intent.
|
|
148
|
+
throw new Error('Mint user failed: response missing access_key/secret_key');
|
|
149
|
+
}
|
|
150
|
+
mintConfirmed = true;
|
|
151
|
+
|
|
152
|
+
currentStep = 'CreatePolicy';
|
|
153
|
+
mintedPolicyName = `mcp-verify-policy-${runTs}`;
|
|
154
|
+
policyCreated = true;
|
|
155
|
+
const policyDocument = JSON.stringify({
|
|
156
|
+
Version: '2012-10-17',
|
|
157
|
+
Statement: [{
|
|
158
|
+
Effect: 'Allow',
|
|
159
|
+
Action: [
|
|
160
|
+
's3:CreateBucket',
|
|
161
|
+
's3:DeleteBucket',
|
|
162
|
+
's3:ListBucket',
|
|
163
|
+
's3:PutObject',
|
|
164
|
+
's3:GetObject',
|
|
165
|
+
's3:DeleteObject',
|
|
166
|
+
],
|
|
167
|
+
Resource: [
|
|
168
|
+
'arn:aws:s3:::mcp-verify-*',
|
|
169
|
+
'arn:aws:s3:::mcp-verify-*/*',
|
|
170
|
+
],
|
|
171
|
+
}],
|
|
172
|
+
});
|
|
173
|
+
const { status: policyStatus, data: policyData } = await http.post(
|
|
174
|
+
`${baseUrl}/api/v1/mc/policy-create`,
|
|
175
|
+
{ name: mintedPolicyName, type: 'json', json: policyDocument },
|
|
176
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
177
|
+
);
|
|
178
|
+
if (policyStatus !== 200) {
|
|
179
|
+
policyCreated = false;
|
|
180
|
+
throw new Error(`Create policy failed (HTTP ${policyStatus})`);
|
|
181
|
+
}
|
|
182
|
+
if (!policyData?.success) {
|
|
183
|
+
policyCreated = false;
|
|
184
|
+
throw new Error('Create policy failed');
|
|
185
|
+
}
|
|
186
|
+
policyConfirmed = true;
|
|
187
|
+
|
|
188
|
+
currentStep = 'AttachPolicy';
|
|
189
|
+
policyAttached = true;
|
|
190
|
+
const { status: attachStatus, data: attachData } = await http.post(
|
|
191
|
+
`${baseUrl}/api/v1/mc/policy`,
|
|
192
|
+
{ name: mintedUser, policy: mintedPolicyName },
|
|
193
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
194
|
+
);
|
|
195
|
+
if (attachStatus !== 200) {
|
|
196
|
+
policyAttached = false;
|
|
197
|
+
throw new Error(`Attach policy failed (HTTP ${attachStatus})`);
|
|
198
|
+
}
|
|
199
|
+
if (attachData?.status !== 'attached') {
|
|
200
|
+
policyAttached = false;
|
|
201
|
+
throw new Error('Attach policy failed');
|
|
202
|
+
}
|
|
203
|
+
attachConfirmed = true;
|
|
204
|
+
}
|
|
205
|
+
|
|
48
206
|
const s3 = _createS3Client({
|
|
49
207
|
endpoint,
|
|
50
|
-
accessKeyId:
|
|
51
|
-
secretAccessKey:
|
|
208
|
+
accessKeyId: effectiveAK,
|
|
209
|
+
secretAccessKey: effectiveSK,
|
|
52
210
|
});
|
|
53
211
|
|
|
54
|
-
// Step 1: CreateBucket
|
|
55
212
|
currentStep = 'CreateBucket';
|
|
213
|
+
bucketCreated = true;
|
|
56
214
|
await s3.createBucket(testBucket);
|
|
215
|
+
bucketConfirmed = true;
|
|
57
216
|
|
|
58
|
-
// Step 2: PutObject
|
|
59
217
|
currentStep = 'PutObject';
|
|
60
218
|
await s3.putObject(testBucket, testKey, testContent);
|
|
61
219
|
|
|
62
|
-
// Step 3: GetObject
|
|
63
220
|
currentStep = 'GetObject';
|
|
64
221
|
const retrieved = await s3.getObject(testBucket, testKey);
|
|
65
222
|
|
|
66
|
-
// Step 4: Compare
|
|
67
223
|
currentStep = 'Compare';
|
|
68
224
|
if (retrieved !== testContent) {
|
|
69
|
-
|
|
225
|
+
result = {
|
|
70
226
|
success: false,
|
|
71
|
-
error: 'Storage verification failed at Compare: uploaded content does not match downloaded content.
|
|
227
|
+
error: 'Storage verification failed at Compare: uploaded content does not match downloaded content.',
|
|
72
228
|
endpoint,
|
|
73
229
|
failing_step: 'Compare',
|
|
74
230
|
};
|
|
231
|
+
isError = true;
|
|
75
232
|
} else {
|
|
76
233
|
const explicitIpHint = endpointAutoDetected
|
|
77
|
-
?
|
|
234
|
+
? 'If auto-detection cannot reach the host, pass an explicit endpoint (e.g. "http://<ip>:9000").'
|
|
78
235
|
: null;
|
|
79
|
-
|
|
80
|
-
verifyResult = {
|
|
236
|
+
result = {
|
|
81
237
|
success: true,
|
|
82
238
|
message: `S3 storage verification passed. Successfully created bucket, uploaded object, and verified download at ${endpoint}.`,
|
|
83
239
|
endpoint,
|
|
@@ -85,68 +241,113 @@ module.exports = function registerVerifyStorage(server, options = {}) {
|
|
|
85
241
|
...(explicitIpHint ? { note: explicitIpHint } : {}),
|
|
86
242
|
};
|
|
87
243
|
}
|
|
88
|
-
|
|
89
|
-
// Cleanup: remove test object and bucket (W3-AC1)
|
|
90
|
-
try {
|
|
91
|
-
await s3.deleteObject(testBucket, testKey);
|
|
92
|
-
await s3.deleteBucket(testBucket);
|
|
93
|
-
} catch (cleanupErr) {
|
|
94
|
-
// Non-fatal: note it but never flip the result
|
|
95
|
-
verifyResult.cleanup_warning = `Test bucket cleanup failed (${cleanupErr.message}). The bucket "${testBucket}" may remain — remove it manually via the Relayer UI.`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
content: [{
|
|
100
|
-
type: 'text',
|
|
101
|
-
text: JSON.stringify(verifyResult, null, 2),
|
|
102
|
-
}],
|
|
103
|
-
...(verifyResult.success ? {} : { isError: true }),
|
|
104
|
-
};
|
|
105
244
|
} catch (err) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
245
|
+
console.error(`[verify_storage] ${currentStep}: ${err.message}`);
|
|
246
|
+
const explicitIpHint = endpointAutoDetected
|
|
247
|
+
? ' If the endpoint cannot be reached, pass an explicit IP via the endpoint option (e.g. "http://<ip>:9000").'
|
|
248
|
+
: '';
|
|
249
|
+
// Self-authored messages (userSafe) reach the client; anything
|
|
250
|
+
// that may carry provider/response text stays in the server log.
|
|
251
|
+
const detail = err.userSafe ? ` ${err.message}` : ' See server log for detail.';
|
|
252
|
+
result = {
|
|
253
|
+
success: false,
|
|
254
|
+
error: `Storage verification failed at ${currentStep}.${detail}${explicitIpHint}`,
|
|
255
|
+
endpoint,
|
|
256
|
+
failing_step: currentStep,
|
|
257
|
+
};
|
|
258
|
+
isError = true;
|
|
259
|
+
} finally {
|
|
260
|
+
const warnings = [];
|
|
261
|
+
|
|
262
|
+
if (bucketCreated) {
|
|
110
263
|
try {
|
|
111
264
|
const s3Cleanup = _createS3Client({
|
|
112
265
|
endpoint,
|
|
113
|
-
accessKeyId:
|
|
114
|
-
secretAccessKey:
|
|
266
|
+
accessKeyId: effectiveAK,
|
|
267
|
+
secretAccessKey: effectiveSK,
|
|
115
268
|
});
|
|
116
269
|
await s3Cleanup.deleteObject(testBucket, testKey).catch(() => {});
|
|
117
270
|
await s3Cleanup.deleteBucket(testBucket);
|
|
118
|
-
} catch (
|
|
119
|
-
|
|
271
|
+
} catch (e) {
|
|
272
|
+
if (!isNotFoundResponse(e.message)) {
|
|
273
|
+
console.error(`[verify_storage] Bucket cleanup failed: ${e.message}`);
|
|
274
|
+
warnings.push('Test bucket cleanup failed (see server log)');
|
|
275
|
+
}
|
|
120
276
|
}
|
|
121
277
|
}
|
|
122
278
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
279
|
+
if (policyAttached) {
|
|
280
|
+
try {
|
|
281
|
+
const { data: detachData } = await http.post(
|
|
282
|
+
`${baseUrl}/api/v1/mc/policy-detach`,
|
|
283
|
+
{ name: mintedUser, policy: mintedPolicyName },
|
|
284
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
285
|
+
);
|
|
286
|
+
if (detachData?.status !== 'detached') {
|
|
287
|
+
const msg = detachData?.message ?? detachData?.error ?? '';
|
|
288
|
+
if (!isNotFoundResponse(msg)) {
|
|
289
|
+
console.error(`[verify_storage] Policy detach failed: ${JSON.stringify(detachData)}`);
|
|
290
|
+
warnings.push('Policy detach failed (see server log)');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch (e) {
|
|
294
|
+
console.error(`[verify_storage] Policy detach failed: ${e.message}`);
|
|
295
|
+
warnings.push('Policy detach failed (see server log)');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
127
298
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
299
|
+
if (mintedUser) {
|
|
300
|
+
try {
|
|
301
|
+
const { data: delUserData } = await http.del(
|
|
302
|
+
`${baseUrl}/api/v1/mc/user/${mintedUser}`,
|
|
303
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
304
|
+
);
|
|
305
|
+
if (delUserData?.success === false) {
|
|
306
|
+
const msg = delUserData?.message ?? delUserData?.error ?? '';
|
|
307
|
+
if (!isNotFoundResponse(msg)) {
|
|
308
|
+
console.error(`[verify_storage] User cleanup failed: ${JSON.stringify(delUserData)}`);
|
|
309
|
+
warnings.push('User cleanup failed (see server log)');
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
} catch (e) {
|
|
313
|
+
console.error(`[verify_storage] User cleanup failed: ${e.message}`);
|
|
314
|
+
warnings.push('User cleanup failed (see server log)');
|
|
315
|
+
}
|
|
316
|
+
}
|
|
131
317
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
318
|
+
if (policyCreated) {
|
|
319
|
+
try {
|
|
320
|
+
const { data: delPolicyData } = await http.del(
|
|
321
|
+
`${baseUrl}/api/v1/mc/policy/${mintedPolicyName}`,
|
|
322
|
+
{ headers: { keycloaktoken: muse_token }, ...NO_REDIRECT_TOKEN_CONFIG }
|
|
323
|
+
);
|
|
324
|
+
if (delPolicyData?.status !== 'deleted') {
|
|
325
|
+
const msg = delPolicyData?.message ?? delPolicyData?.error ?? '';
|
|
326
|
+
if (!isNotFoundResponse(msg)) {
|
|
327
|
+
console.error(`[verify_storage] Policy cleanup failed: ${JSON.stringify(delPolicyData)}`);
|
|
328
|
+
warnings.push('Policy cleanup failed (see server log)');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} catch (e) {
|
|
332
|
+
console.error(`[verify_storage] Policy cleanup failed: ${e.message}`);
|
|
333
|
+
warnings.push('Policy cleanup failed (see server log)');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
141
336
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
text: JSON.stringify(errorPayload),
|
|
146
|
-
}],
|
|
147
|
-
isError: true,
|
|
148
|
-
};
|
|
337
|
+
if (warnings.length > 0 && result) {
|
|
338
|
+
result.cleanup_warning = warnings.join('; ');
|
|
339
|
+
}
|
|
149
340
|
}
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
content: [{
|
|
344
|
+
type: 'text',
|
|
345
|
+
text: JSON.stringify(result, null, 2),
|
|
346
|
+
}],
|
|
347
|
+
...(isError ? { isError: true } : {}),
|
|
348
|
+
};
|
|
150
349
|
},
|
|
151
350
|
);
|
|
152
351
|
};
|
|
352
|
+
|
|
353
|
+
module.exports.validateHostAllowlist = validateHostAllowlist;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { z } = require('zod');
|
|
4
|
-
const { createHttpClient } = require('../lib/httpClient');
|
|
5
|
-
|
|
6
|
-
const CONSOLE_BASE_URL = 'https://console.xns.tech';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Tool 2: register_account
|
|
10
|
-
* AC-5: silent register, confirms account at {email}.
|
|
11
|
-
* AC-6: 409 → "email already has account" + next_action skip hint.
|
|
12
|
-
* AC-7: 422 → names the specific password rule.
|
|
13
|
-
* AC-8: Gate 1 dialogue names email + auth.xns.tech + auto-check.
|
|
14
|
-
*
|
|
15
|
-
* Consumes E2: POST /api/auth/register
|
|
16
|
-
* → 201 {success:true, userId, message:"Verification email sent"}
|
|
17
|
-
* → 409 {success:false, message} (already registered)
|
|
18
|
-
* → 422 {success:false, message} (validation error — password rules)
|
|
19
|
-
* → 429 {success:false, message} (rate limited)
|
|
20
|
-
*/
|
|
21
|
-
module.exports = function registerRegisterAccount(server, options = {}) {
|
|
22
|
-
const http = options.httpClient || createHttpClient(options);
|
|
23
|
-
const consoleBaseUrl = options.consoleBaseUrl || CONSOLE_BASE_URL;
|
|
24
|
-
|
|
25
|
-
server.tool(
|
|
26
|
-
'register_account',
|
|
27
|
-
'Register a new XNS account with an email and password. After registration, the user must verify their email at auth.xns.tech by clicking the link sent to their inbox. Use check_email_verified to poll for verification status. If the email already has an account, you can skip to install_relayer.',
|
|
28
|
-
{
|
|
29
|
-
email: z.string().email().describe('User email address'),
|
|
30
|
-
password: z.string().min(8).describe('Password (minimum 8 characters)'),
|
|
31
|
-
},
|
|
32
|
-
async ({ email, password }) => {
|
|
33
|
-
try {
|
|
34
|
-
const { status, data } = await http.post(
|
|
35
|
-
`${consoleBaseUrl}/api/auth/register`,
|
|
36
|
-
{ email, password },
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (status === 201) {
|
|
40
|
-
return {
|
|
41
|
-
content: [{
|
|
42
|
-
type: 'text',
|
|
43
|
-
text: JSON.stringify({
|
|
44
|
-
success: true,
|
|
45
|
-
message: `Account registered for ${email}. A verification email has been sent. The user must click the verification link at auth.xns.tech before proceeding. Use check_email_verified to poll for verification.`,
|
|
46
|
-
email,
|
|
47
|
-
userId: data.userId,
|
|
48
|
-
}),
|
|
49
|
-
}],
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (status === 409) {
|
|
54
|
-
// AC-6: carry next_action skip hint
|
|
55
|
-
return {
|
|
56
|
-
content: [{
|
|
57
|
-
type: 'text',
|
|
58
|
-
text: JSON.stringify({
|
|
59
|
-
success: false,
|
|
60
|
-
message: `Email ${email} already has an account. You can skip registration and proceed directly to install_relayer.`,
|
|
61
|
-
next_action: 'skip_to_install',
|
|
62
|
-
email,
|
|
63
|
-
}),
|
|
64
|
-
}],
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (status === 422) {
|
|
69
|
-
// AC-7: name the specific password rule
|
|
70
|
-
return {
|
|
71
|
-
content: [{
|
|
72
|
-
type: 'text',
|
|
73
|
-
text: JSON.stringify({
|
|
74
|
-
success: false,
|
|
75
|
-
message: data.message || 'Validation error — check password requirements (minimum 8 characters, at least one uppercase, one lowercase, one number).',
|
|
76
|
-
email,
|
|
77
|
-
}),
|
|
78
|
-
}],
|
|
79
|
-
isError: true,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (status === 429) {
|
|
84
|
-
return {
|
|
85
|
-
content: [{
|
|
86
|
-
type: 'text',
|
|
87
|
-
text: JSON.stringify({
|
|
88
|
-
success: false,
|
|
89
|
-
message: data.message || 'Rate limited. Please wait before retrying registration.',
|
|
90
|
-
email,
|
|
91
|
-
}),
|
|
92
|
-
}],
|
|
93
|
-
isError: true,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Unexpected status
|
|
98
|
-
return {
|
|
99
|
-
content: [{
|
|
100
|
-
type: 'text',
|
|
101
|
-
text: JSON.stringify({
|
|
102
|
-
success: false,
|
|
103
|
-
error: `Unexpected response (HTTP ${status}): ${data.message || JSON.stringify(data)}`,
|
|
104
|
-
email,
|
|
105
|
-
}),
|
|
106
|
-
}],
|
|
107
|
-
isError: true,
|
|
108
|
-
};
|
|
109
|
-
} catch (err) {
|
|
110
|
-
return {
|
|
111
|
-
content: [{
|
|
112
|
-
type: 'text',
|
|
113
|
-
text: JSON.stringify({
|
|
114
|
-
success: false,
|
|
115
|
-
error: `Registration request failed: ${err.message}`,
|
|
116
|
-
}),
|
|
117
|
-
}],
|
|
118
|
-
isError: true,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
};
|