@centrali-io/centrali-mcp 9.5.1 → 9.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -416,3 +416,10 @@ CENTRALI_CLIENT_SECRET=... \
416
416
  CENTRALI_WORKSPACE=my-workspace \
417
417
  npx @modelcontextprotocol/inspector node dist/index.js
418
418
  ```
419
+
420
+
421
+ ### Service-account identifiers
422
+
423
+ Account-path tools use the string `clientId` returned by `create_service_account` / `list_service_accounts`, including get, update, rotate, revoke, delete, dev-token, role/group membership, and permission scan/simulate. They no longer accept numeric `serviceAccountId` inputs. Existing legacy client IDs are supported. Upgrade this package alongside IAM when deploying the client-ID route change.
424
+
425
+ The separate `generate_remediation`, `preview_remediation`, and `apply_remediation` tools retain their numeric `serviceAccountId` argument for the access API's `targetId` contract. Account responses continue to include both `id` and `clientId`.
@@ -1782,13 +1782,13 @@ function registerDescribeTools(server) {
1782
1782
  },
1783
1783
  development: {
1784
1784
  description: "Dev tokens — short-lived tokens for testing without the OAuth2 flow.",
1785
- tool: "generate_dev_token(serviceAccountId, ttlSeconds)",
1785
+ tool: "generate_dev_token(clientId, ttlSeconds)",
1786
1786
  note: "Dev tokens have limited TTL. For production, always use client_credentials flow.",
1787
1787
  },
1788
1788
  },
1789
1789
  service_account_shape: {
1790
- id: "number — auto-generated numeric ID",
1791
- clientId: "string — format: ci_<hex> — used as the client_id in OAuth2",
1790
+ id: "number — internal database key; used by remediation and role-query contracts, not service-account paths",
1791
+ clientId: "string — opaque public identifier (new accounts: sa_<hex>; legacy IDs preserved); used in all service-account paths and as client_id for token requests",
1792
1792
  clientSecret: "string — format: sk_<hex> — ONLY returned on creation and rotation",
1793
1793
  name: "string — display name",
1794
1794
  description: "string | null — optional description",
@@ -133,7 +133,7 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
133
133
  description: me.description,
134
134
  revoked: me.revoked,
135
135
  workspace: workspaceId,
136
- _hint: "Use this 'id' (numeric) with scan_service_account_permissions, simulate_service_account_permission, and generate_remediation to check or fix your own permissions.",
136
+ _hint: "Use clientId with scan_service_account_permissions and simulate_service_account_permission. Use the numeric id as serviceAccountId with generate_remediation, preview_remediation, and apply_remediation.",
137
137
  }, null, 2),
138
138
  }],
139
139
  };
@@ -168,18 +168,18 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
168
168
  };
169
169
  }
170
170
  }));
171
- (0, _register_js_1.registerTool)(server, "get_service_account", "Get details of a specific service account by its numeric ID. Returns name, clientId, description, and revocation status. Does NOT return the clientSecret (it's only shown once at creation time).", {
172
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
173
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId }) {
171
+ (0, _register_js_1.registerTool)(server, "get_service_account", "Get details of a specific service account by its clientId. Returns name, clientId, description, and revocation status. Does NOT return the clientSecret (it's only shown once at creation time).", {
172
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
173
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
174
174
  try {
175
- const result = yield getSaClient().get(`/${serviceAccountId}`);
175
+ const result = yield getSaClient().get(`/${encodeURIComponent(clientId)}`);
176
176
  return {
177
177
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
178
178
  };
179
179
  }
180
180
  catch (error) {
181
181
  return {
182
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `getting service account '${serviceAccountId}'`) }],
182
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `getting service account '${encodeURIComponent(clientId)}'`) }],
183
183
  isError: true,
184
184
  };
185
185
  }
@@ -208,61 +208,61 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
208
208
  }
209
209
  }));
210
210
  (0, _register_js_1.registerTool)(server, "update_service_account_name", "Update the display name of a service account.", {
211
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
211
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
212
212
  name: zod_1.z.string().describe("New display name"),
213
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, name }) {
213
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, name }) {
214
214
  try {
215
- const result = yield getSaClient().put(`/${serviceAccountId}/name`, { name });
215
+ const result = yield getSaClient().put(`/${encodeURIComponent(clientId)}/name`, { name });
216
216
  return {
217
217
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
218
218
  };
219
219
  }
220
220
  catch (error) {
221
221
  return {
222
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `updating service account '${serviceAccountId}' name`) }],
222
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `updating service account '${encodeURIComponent(clientId)}' name`) }],
223
223
  isError: true,
224
224
  };
225
225
  }
226
226
  }));
227
227
  (0, _register_js_1.registerTool)(server, "update_service_account_description", "Update the description of a service account.", {
228
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
228
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
229
229
  description: zod_1.z.string().nullable().describe("New description (or null to clear)"),
230
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, description }) {
230
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, description }) {
231
231
  try {
232
- const result = yield getSaClient().put(`/${serviceAccountId}/description`, { description });
232
+ const result = yield getSaClient().put(`/${encodeURIComponent(clientId)}/description`, { description });
233
233
  return {
234
234
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
235
235
  };
236
236
  }
237
237
  catch (error) {
238
238
  return {
239
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `updating service account '${serviceAccountId}' description`) }],
239
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `updating service account '${encodeURIComponent(clientId)}' description`) }],
240
240
  isError: true,
241
241
  };
242
242
  }
243
243
  }));
244
- (0, _register_js_1.registerTool)(server, "delete_service_account", "Permanently delete a service account. This is irreversible — all tokens are invalidated immediately. Note: the service account must not be revoked (revoke prevents deletion).", {
245
- clientId: zod_1.z.string().describe("The service account's clientId string (e.g., 'ci_abc123') — NOT the numeric ID"),
244
+ (0, _register_js_1.registerTool)(server, "delete_service_account", "Permanently delete a service account by clientId, including an already-revoked account. This cannot be undone.", {
245
+ clientId: zod_1.z.string().describe("The service account's clientId string (e.g., 'sa_abc123') — NOT the numeric ID"),
246
246
  }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
247
247
  try {
248
- yield getSaClient().delete(`/${clientId}`);
248
+ yield getSaClient().delete(`/${encodeURIComponent(clientId)}`);
249
249
  return {
250
- content: [{ type: "text", text: `Service account '${clientId}' deleted successfully.` }],
250
+ content: [{ type: "text", text: `Service account '${encodeURIComponent(clientId)}' deleted successfully.` }],
251
251
  };
252
252
  }
253
253
  catch (error) {
254
254
  return {
255
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `deleting service account '${clientId}'`) }],
255
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `deleting service account '${encodeURIComponent(clientId)}'`) }],
256
256
  isError: true,
257
257
  };
258
258
  }
259
259
  }));
260
260
  // ── Secret Rotation & Revocation ─────────────────────────────────
261
261
  (0, _register_js_1.registerTool)(server, "rotate_service_account_secret", "Rotate the client secret of a service account. The old secret is immediately invalidated. Returns the new clientSecret — store it securely, it's only shown once.", {
262
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
263
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId }) {
262
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
263
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
264
264
  try {
265
- const result = yield getSaClient().post(`/${serviceAccountId}/rotate`);
265
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/rotate`);
266
266
  return {
267
267
  content: [{
268
268
  type: "text",
@@ -272,34 +272,34 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
272
272
  }
273
273
  catch (error) {
274
274
  return {
275
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `rotating secret for service account '${serviceAccountId}'`) }],
275
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `rotating secret for service account '${encodeURIComponent(clientId)}'`) }],
276
276
  isError: true,
277
277
  };
278
278
  }
279
279
  }));
280
280
  (0, _register_js_1.registerTool)(server, "revoke_service_account", "Revoke a service account. All existing tokens are invalidated and no new tokens can be issued. This cannot be undone.", {
281
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID to revoke"),
282
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId }) {
281
+ clientId: zod_1.z.string().describe("The service account clientId to revoke"),
282
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
283
283
  try {
284
- const result = yield getSaClient().post(`/${serviceAccountId}/revoke`);
284
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/revoke`);
285
285
  return {
286
286
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
287
287
  };
288
288
  }
289
289
  catch (error) {
290
290
  return {
291
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `revoking service account '${serviceAccountId}'`) }],
291
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `revoking service account '${encodeURIComponent(clientId)}'`) }],
292
292
  isError: true,
293
293
  };
294
294
  }
295
295
  }));
296
296
  // ── Dev Token Generation ─────────────────────────────────────────
297
297
  (0, _register_js_1.registerTool)(server, "generate_dev_token", "Generate a short-lived development token for a service account. Useful for testing and local development without the full OAuth2 client_credentials flow. The token has limited TTL.", {
298
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
298
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
299
299
  ttlSeconds: zod_1.z.number().describe("Token time-to-live in seconds (valid options depend on server config, typically 3600, 86400, 604800)"),
300
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, ttlSeconds }) {
300
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, ttlSeconds }) {
301
301
  try {
302
- const result = yield getSaClient().post(`/${serviceAccountId}/dev-token`, { ttlSeconds });
302
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/dev-token`, { ttlSeconds });
303
303
  return {
304
304
  content: [{
305
305
  type: "text",
@@ -309,43 +309,43 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
309
309
  }
310
310
  catch (error) {
311
311
  return {
312
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `generating dev token for service account '${serviceAccountId}'`) }],
312
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `generating dev token for service account '${encodeURIComponent(clientId)}'`) }],
313
313
  isError: true,
314
314
  };
315
315
  }
316
316
  }));
317
317
  // ── Permission Introspection ─────────────────────────────────────
318
318
  (0, _register_js_1.registerTool)(server, "scan_service_account_permissions", "Scan all permissions for a service account. Returns a full access matrix showing every resource and action with Allow/Deny decisions and reasons. Use this to audit what a service account can and cannot do.", {
319
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
319
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
320
320
  filter: zod_1.z.enum(["all", "allowed", "denied"]).optional().describe("Filter results: 'all' (default), 'allowed' (only granted), 'denied' (only missing)"),
321
321
  resourceCategory: zod_1.z.string().optional().describe("Filter by resource category (e.g., 'workspace')"),
322
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, filter, resourceCategory }) {
322
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, filter, resourceCategory }) {
323
323
  try {
324
324
  const params = {};
325
325
  if (filter)
326
326
  params.filter = filter;
327
327
  if (resourceCategory)
328
328
  params.resourceCategory = resourceCategory;
329
- const result = yield getSaClient().get(`/${serviceAccountId}/permissions/scan`, { params });
329
+ const result = yield getSaClient().get(`/${encodeURIComponent(clientId)}/permissions/scan`, { params });
330
330
  return {
331
331
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
332
332
  };
333
333
  }
334
334
  catch (error) {
335
335
  return {
336
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `scanning permissions for service account '${serviceAccountId}'`) }],
336
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `scanning permissions for service account '${encodeURIComponent(clientId)}'`) }],
337
337
  isError: true,
338
338
  };
339
339
  }
340
340
  }));
341
341
  (0, _register_js_1.registerTool)(server, "simulate_service_account_permission", "Simulate an authorization check for a service account against a specific resource and action. Returns the decision (Allow/Deny), evaluation trace, and suggestions for granting access if denied.", {
342
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
342
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
343
343
  resource: zod_1.z.string().describe("Resource identifier (e.g., 'workspace::records', 'workspace::compute-functions')"),
344
344
  resourceCategory: zod_1.z.string().describe("Resource category (e.g., 'workspace')"),
345
345
  action: zod_1.z.string().describe("Action to check (e.g., 'create', 'retrieve', 'update', 'delete', 'list', 'execute', 'manage')"),
346
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, resource, resourceCategory, action }) {
346
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, resource, resourceCategory, action }) {
347
347
  try {
348
- const result = yield getSaClient().post(`/${serviceAccountId}/permissions/simulate`, {
348
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/permissions/simulate`, {
349
349
  resource,
350
350
  resourceCategory,
351
351
  action,
@@ -356,7 +356,7 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
356
356
  }
357
357
  catch (error) {
358
358
  return {
359
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `simulating permission for service account '${serviceAccountId}'`) }],
359
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `simulating permission for service account '${encodeURIComponent(clientId)}'`) }],
360
360
  isError: true,
361
361
  };
362
362
  }
@@ -465,102 +465,102 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
465
465
  }));
466
466
  // ── Service Account ↔ Roles ──────────────────────────────────────
467
467
  (0, _register_js_1.registerTool)(server, "list_service_account_roles", "List all roles assigned to a service account.", {
468
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
469
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId }) {
468
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
469
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
470
470
  try {
471
- const result = yield getSaClient().get(`/${serviceAccountId}/roles`);
471
+ const result = yield getSaClient().get(`/${encodeURIComponent(clientId)}/roles`);
472
472
  return {
473
473
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
474
474
  };
475
475
  }
476
476
  catch (error) {
477
477
  return {
478
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `listing roles for service account '${serviceAccountId}'`) }],
478
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `listing roles for service account '${encodeURIComponent(clientId)}'`) }],
479
479
  isError: true,
480
480
  };
481
481
  }
482
482
  }));
483
483
  (0, _register_js_1.registerTool)(server, "assign_role_to_service_account", "Assign a role to a service account. The service account inherits all permissions defined in the role.", {
484
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
484
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
485
485
  roleId: zod_1.z.string().describe("The role ID (UUID) to assign"),
486
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, roleId }) {
486
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, roleId }) {
487
487
  try {
488
- const result = yield getSaClient().post(`/${serviceAccountId}/roles/${roleId}`);
488
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/roles/${roleId}`);
489
489
  return {
490
490
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
491
491
  };
492
492
  }
493
493
  catch (error) {
494
494
  return {
495
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `assigning role '${roleId}' to service account '${serviceAccountId}'`) }],
495
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `assigning role '${roleId}' to service account '${encodeURIComponent(clientId)}'`) }],
496
496
  isError: true,
497
497
  };
498
498
  }
499
499
  }));
500
500
  (0, _register_js_1.registerTool)(server, "remove_role_from_service_account", "Remove a role from a service account. The service account loses all permissions from this role.", {
501
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
501
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
502
502
  roleId: zod_1.z.string().describe("The role ID (UUID) to remove"),
503
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, roleId }) {
503
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, roleId }) {
504
504
  try {
505
- yield getSaClient().delete(`/${serviceAccountId}/roles/${roleId}`);
505
+ yield getSaClient().delete(`/${encodeURIComponent(clientId)}/roles/${roleId}`);
506
506
  return {
507
- content: [{ type: "text", text: `Role '${roleId}' removed from service account '${serviceAccountId}'.` }],
507
+ content: [{ type: "text", text: `Role '${roleId}' removed from service account '${encodeURIComponent(clientId)}'.` }],
508
508
  };
509
509
  }
510
510
  catch (error) {
511
511
  return {
512
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `removing role '${roleId}' from service account '${serviceAccountId}'`) }],
512
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `removing role '${roleId}' from service account '${encodeURIComponent(clientId)}'`) }],
513
513
  isError: true,
514
514
  };
515
515
  }
516
516
  }));
517
517
  // ── Service Account ↔ Groups ─────────────────────────────────────
518
518
  (0, _register_js_1.registerTool)(server, "list_service_account_groups", "List all groups a service account belongs to.", {
519
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
520
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId }) {
519
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
520
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId }) {
521
521
  try {
522
- const result = yield getSaClient().get(`/${serviceAccountId}/groups`);
522
+ const result = yield getSaClient().get(`/${encodeURIComponent(clientId)}/groups`);
523
523
  return {
524
524
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
525
525
  };
526
526
  }
527
527
  catch (error) {
528
528
  return {
529
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `listing groups for service account '${serviceAccountId}'`) }],
529
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `listing groups for service account '${encodeURIComponent(clientId)}'`) }],
530
530
  isError: true,
531
531
  };
532
532
  }
533
533
  }));
534
534
  (0, _register_js_1.registerTool)(server, "add_service_account_to_group", "Add a service account to a group. The service account inherits all roles assigned to the group.", {
535
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
535
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
536
536
  groupId: zod_1.z.string().describe("The group ID (UUID) to add the service account to"),
537
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, groupId }) {
537
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, groupId }) {
538
538
  try {
539
- const result = yield getSaClient().post(`/${serviceAccountId}/groups/${groupId}`);
539
+ const result = yield getSaClient().post(`/${encodeURIComponent(clientId)}/groups/${groupId}`);
540
540
  return {
541
541
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
542
542
  };
543
543
  }
544
544
  catch (error) {
545
545
  return {
546
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `adding service account '${serviceAccountId}' to group '${groupId}'`) }],
546
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `adding service account '${encodeURIComponent(clientId)}' to group '${groupId}'`) }],
547
547
  isError: true,
548
548
  };
549
549
  }
550
550
  }));
551
551
  (0, _register_js_1.registerTool)(server, "remove_service_account_from_group", "Remove a service account from a group. The service account loses all permissions inherited through this group.", {
552
- serviceAccountId: zod_1.z.number().describe("The service account numeric ID"),
552
+ clientId: zod_1.z.string().describe("The service account clientId (not its numeric database id)"),
553
553
  groupId: zod_1.z.string().describe("The group ID (UUID) to remove the service account from"),
554
- }, (_a) => __awaiter(this, [_a], void 0, function* ({ serviceAccountId, groupId }) {
554
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ clientId, groupId }) {
555
555
  try {
556
- yield getSaClient().delete(`/${serviceAccountId}/groups/${groupId}`);
556
+ yield getSaClient().delete(`/${encodeURIComponent(clientId)}/groups/${groupId}`);
557
557
  return {
558
- content: [{ type: "text", text: `Service account '${serviceAccountId}' removed from group '${groupId}'.` }],
558
+ content: [{ type: "text", text: `Service account '${encodeURIComponent(clientId)}' removed from group '${groupId}'.` }],
559
559
  };
560
560
  }
561
561
  catch (error) {
562
562
  return {
563
- content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `removing service account '${serviceAccountId}' from group '${groupId}'`) }],
563
+ content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `removing service account '${encodeURIComponent(clientId)}' from group '${groupId}'`) }],
564
564
  isError: true,
565
565
  };
566
566
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centrali-io/centrali-mcp",
3
- "version": "9.5.1",
3
+ "version": "9.5.2",
4
4
  "description": "Centrali MCP Server - AI assistant integration for Centrali workspaces",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -25,7 +25,7 @@
25
25
  "author": "Blueinit",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "@centrali-io/centrali-sdk": "^9.5.1",
28
+ "@centrali-io/centrali-sdk": "^9.5.2",
29
29
  "@modelcontextprotocol/sdk": "^1.28.0"
30
30
  },
31
31
  "devDependencies": {
@@ -1975,13 +1975,13 @@ export function registerDescribeTools(server: McpServer) {
1975
1975
  },
1976
1976
  development: {
1977
1977
  description: "Dev tokens — short-lived tokens for testing without the OAuth2 flow.",
1978
- tool: "generate_dev_token(serviceAccountId, ttlSeconds)",
1978
+ tool: "generate_dev_token(clientId, ttlSeconds)",
1979
1979
  note: "Dev tokens have limited TTL. For production, always use client_credentials flow.",
1980
1980
  },
1981
1981
  },
1982
1982
  service_account_shape: {
1983
- id: "number — auto-generated numeric ID",
1984
- clientId: "string — format: ci_<hex> — used as the client_id in OAuth2",
1983
+ id: "number — internal database key; used by remediation and role-query contracts, not service-account paths",
1984
+ clientId: "string — opaque public identifier (new accounts: sa_<hex>; legacy IDs preserved); used in all service-account paths and as client_id for token requests",
1985
1985
  clientSecret: "string — format: sk_<hex> — ONLY returned on creation and rotation",
1986
1986
  name: "string — display name",
1987
1987
  description: "string | null — optional description",
@@ -147,7 +147,7 @@ export function registerServiceAccountTools(
147
147
  description: me.description,
148
148
  revoked: me.revoked,
149
149
  workspace: workspaceId,
150
- _hint: "Use this 'id' (numeric) with scan_service_account_permissions, simulate_service_account_permission, and generate_remediation to check or fix your own permissions.",
150
+ _hint: "Use clientId with scan_service_account_permissions and simulate_service_account_permission. Use the numeric id as serviceAccountId with generate_remediation, preview_remediation, and apply_remediation.",
151
151
  }, null, 2),
152
152
  }],
153
153
  };
@@ -189,19 +189,19 @@ export function registerServiceAccountTools(
189
189
 
190
190
  registerTool<any>(server,
191
191
  "get_service_account",
192
- "Get details of a specific service account by its numeric ID. Returns name, clientId, description, and revocation status. Does NOT return the clientSecret (it's only shown once at creation time).",
192
+ "Get details of a specific service account by its clientId. Returns name, clientId, description, and revocation status. Does NOT return the clientSecret (it's only shown once at creation time).",
193
193
  {
194
- serviceAccountId: z.number().describe("The service account numeric ID"),
194
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
195
195
  },
196
- async ({ serviceAccountId }) => {
196
+ async ({ clientId }) => {
197
197
  try {
198
- const result = await getSaClient().get(`/${serviceAccountId}`);
198
+ const result = await getSaClient().get(`/${encodeURIComponent(clientId)}`);
199
199
  return {
200
200
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
201
201
  };
202
202
  } catch (error: unknown) {
203
203
  return {
204
- content: [{ type: "text", text: formatError(error, `getting service account '${serviceAccountId}'`) }],
204
+ content: [{ type: "text", text: formatError(error, `getting service account '${encodeURIComponent(clientId)}'`) }],
205
205
  isError: true,
206
206
  };
207
207
  }
@@ -246,18 +246,18 @@ export function registerServiceAccountTools(
246
246
  "update_service_account_name",
247
247
  "Update the display name of a service account.",
248
248
  {
249
- serviceAccountId: z.number().describe("The service account numeric ID"),
249
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
250
250
  name: z.string().describe("New display name"),
251
251
  },
252
- async ({ serviceAccountId, name }) => {
252
+ async ({ clientId, name }) => {
253
253
  try {
254
- const result = await getSaClient().put(`/${serviceAccountId}/name`, { name });
254
+ const result = await getSaClient().put(`/${encodeURIComponent(clientId)}/name`, { name });
255
255
  return {
256
256
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
257
257
  };
258
258
  } catch (error: unknown) {
259
259
  return {
260
- content: [{ type: "text", text: formatError(error, `updating service account '${serviceAccountId}' name`) }],
260
+ content: [{ type: "text", text: formatError(error, `updating service account '${encodeURIComponent(clientId)}' name`) }],
261
261
  isError: true,
262
262
  };
263
263
  }
@@ -268,18 +268,18 @@ export function registerServiceAccountTools(
268
268
  "update_service_account_description",
269
269
  "Update the description of a service account.",
270
270
  {
271
- serviceAccountId: z.number().describe("The service account numeric ID"),
271
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
272
272
  description: z.string().nullable().describe("New description (or null to clear)"),
273
273
  },
274
- async ({ serviceAccountId, description }) => {
274
+ async ({ clientId, description }) => {
275
275
  try {
276
- const result = await getSaClient().put(`/${serviceAccountId}/description`, { description });
276
+ const result = await getSaClient().put(`/${encodeURIComponent(clientId)}/description`, { description });
277
277
  return {
278
278
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
279
279
  };
280
280
  } catch (error: unknown) {
281
281
  return {
282
- content: [{ type: "text", text: formatError(error, `updating service account '${serviceAccountId}' description`) }],
282
+ content: [{ type: "text", text: formatError(error, `updating service account '${encodeURIComponent(clientId)}' description`) }],
283
283
  isError: true,
284
284
  };
285
285
  }
@@ -288,19 +288,19 @@ export function registerServiceAccountTools(
288
288
 
289
289
  registerTool<any>(server,
290
290
  "delete_service_account",
291
- "Permanently delete a service account. This is irreversible — all tokens are invalidated immediately. Note: the service account must not be revoked (revoke prevents deletion).",
291
+ "Permanently delete a service account by clientId, including an already-revoked account. This cannot be undone.",
292
292
  {
293
- clientId: z.string().describe("The service account's clientId string (e.g., 'ci_abc123') — NOT the numeric ID"),
293
+ clientId: z.string().describe("The service account's clientId string (e.g., 'sa_abc123') — NOT the numeric ID"),
294
294
  },
295
295
  async ({ clientId }) => {
296
296
  try {
297
- await getSaClient().delete(`/${clientId}`);
297
+ await getSaClient().delete(`/${encodeURIComponent(clientId)}`);
298
298
  return {
299
- content: [{ type: "text", text: `Service account '${clientId}' deleted successfully.` }],
299
+ content: [{ type: "text", text: `Service account '${encodeURIComponent(clientId)}' deleted successfully.` }],
300
300
  };
301
301
  } catch (error: unknown) {
302
302
  return {
303
- content: [{ type: "text", text: formatError(error, `deleting service account '${clientId}'`) }],
303
+ content: [{ type: "text", text: formatError(error, `deleting service account '${encodeURIComponent(clientId)}'`) }],
304
304
  isError: true,
305
305
  };
306
306
  }
@@ -313,11 +313,11 @@ export function registerServiceAccountTools(
313
313
  "rotate_service_account_secret",
314
314
  "Rotate the client secret of a service account. The old secret is immediately invalidated. Returns the new clientSecret — store it securely, it's only shown once.",
315
315
  {
316
- serviceAccountId: z.number().describe("The service account numeric ID"),
316
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
317
317
  },
318
- async ({ serviceAccountId }) => {
318
+ async ({ clientId }) => {
319
319
  try {
320
- const result = await getSaClient().post(`/${serviceAccountId}/rotate`);
320
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/rotate`);
321
321
  return {
322
322
  content: [{
323
323
  type: "text",
@@ -333,7 +333,7 @@ export function registerServiceAccountTools(
333
333
  };
334
334
  } catch (error: unknown) {
335
335
  return {
336
- content: [{ type: "text", text: formatError(error, `rotating secret for service account '${serviceAccountId}'`) }],
336
+ content: [{ type: "text", text: formatError(error, `rotating secret for service account '${encodeURIComponent(clientId)}'`) }],
337
337
  isError: true,
338
338
  };
339
339
  }
@@ -344,17 +344,17 @@ export function registerServiceAccountTools(
344
344
  "revoke_service_account",
345
345
  "Revoke a service account. All existing tokens are invalidated and no new tokens can be issued. This cannot be undone.",
346
346
  {
347
- serviceAccountId: z.number().describe("The service account numeric ID to revoke"),
347
+ clientId: z.string().describe("The service account clientId to revoke"),
348
348
  },
349
- async ({ serviceAccountId }) => {
349
+ async ({ clientId }) => {
350
350
  try {
351
- const result = await getSaClient().post(`/${serviceAccountId}/revoke`);
351
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/revoke`);
352
352
  return {
353
353
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
354
354
  };
355
355
  } catch (error: unknown) {
356
356
  return {
357
- content: [{ type: "text", text: formatError(error, `revoking service account '${serviceAccountId}'`) }],
357
+ content: [{ type: "text", text: formatError(error, `revoking service account '${encodeURIComponent(clientId)}'`) }],
358
358
  isError: true,
359
359
  };
360
360
  }
@@ -367,12 +367,12 @@ export function registerServiceAccountTools(
367
367
  "generate_dev_token",
368
368
  "Generate a short-lived development token for a service account. Useful for testing and local development without the full OAuth2 client_credentials flow. The token has limited TTL.",
369
369
  {
370
- serviceAccountId: z.number().describe("The service account numeric ID"),
370
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
371
371
  ttlSeconds: z.number().describe("Token time-to-live in seconds (valid options depend on server config, typically 3600, 86400, 604800)"),
372
372
  },
373
- async ({ serviceAccountId, ttlSeconds }) => {
373
+ async ({ clientId, ttlSeconds }) => {
374
374
  try {
375
- const result = await getSaClient().post(`/${serviceAccountId}/dev-token`, { ttlSeconds });
375
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/dev-token`, { ttlSeconds });
376
376
  return {
377
377
  content: [{
378
378
  type: "text",
@@ -388,7 +388,7 @@ export function registerServiceAccountTools(
388
388
  };
389
389
  } catch (error: unknown) {
390
390
  return {
391
- content: [{ type: "text", text: formatError(error, `generating dev token for service account '${serviceAccountId}'`) }],
391
+ content: [{ type: "text", text: formatError(error, `generating dev token for service account '${encodeURIComponent(clientId)}'`) }],
392
392
  isError: true,
393
393
  };
394
394
  }
@@ -401,22 +401,22 @@ export function registerServiceAccountTools(
401
401
  "scan_service_account_permissions",
402
402
  "Scan all permissions for a service account. Returns a full access matrix showing every resource and action with Allow/Deny decisions and reasons. Use this to audit what a service account can and cannot do.",
403
403
  {
404
- serviceAccountId: z.number().describe("The service account numeric ID"),
404
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
405
405
  filter: z.enum(["all", "allowed", "denied"]).optional().describe("Filter results: 'all' (default), 'allowed' (only granted), 'denied' (only missing)"),
406
406
  resourceCategory: z.string().optional().describe("Filter by resource category (e.g., 'workspace')"),
407
407
  },
408
- async ({ serviceAccountId, filter, resourceCategory }) => {
408
+ async ({ clientId, filter, resourceCategory }) => {
409
409
  try {
410
410
  const params: Record<string, any> = {};
411
411
  if (filter) params.filter = filter;
412
412
  if (resourceCategory) params.resourceCategory = resourceCategory;
413
- const result = await getSaClient().get(`/${serviceAccountId}/permissions/scan`, { params });
413
+ const result = await getSaClient().get(`/${encodeURIComponent(clientId)}/permissions/scan`, { params });
414
414
  return {
415
415
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
416
416
  };
417
417
  } catch (error: unknown) {
418
418
  return {
419
- content: [{ type: "text", text: formatError(error, `scanning permissions for service account '${serviceAccountId}'`) }],
419
+ content: [{ type: "text", text: formatError(error, `scanning permissions for service account '${encodeURIComponent(clientId)}'`) }],
420
420
  isError: true,
421
421
  };
422
422
  }
@@ -427,14 +427,14 @@ export function registerServiceAccountTools(
427
427
  "simulate_service_account_permission",
428
428
  "Simulate an authorization check for a service account against a specific resource and action. Returns the decision (Allow/Deny), evaluation trace, and suggestions for granting access if denied.",
429
429
  {
430
- serviceAccountId: z.number().describe("The service account numeric ID"),
430
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
431
431
  resource: z.string().describe("Resource identifier (e.g., 'workspace::records', 'workspace::compute-functions')"),
432
432
  resourceCategory: z.string().describe("Resource category (e.g., 'workspace')"),
433
433
  action: z.string().describe("Action to check (e.g., 'create', 'retrieve', 'update', 'delete', 'list', 'execute', 'manage')"),
434
434
  },
435
- async ({ serviceAccountId, resource, resourceCategory, action }) => {
435
+ async ({ clientId, resource, resourceCategory, action }) => {
436
436
  try {
437
- const result = await getSaClient().post(`/${serviceAccountId}/permissions/simulate`, {
437
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/permissions/simulate`, {
438
438
  resource,
439
439
  resourceCategory,
440
440
  action,
@@ -444,7 +444,7 @@ export function registerServiceAccountTools(
444
444
  };
445
445
  } catch (error: unknown) {
446
446
  return {
447
- content: [{ type: "text", text: formatError(error, `simulating permission for service account '${serviceAccountId}'`) }],
447
+ content: [{ type: "text", text: formatError(error, `simulating permission for service account '${encodeURIComponent(clientId)}'`) }],
448
448
  isError: true,
449
449
  };
450
450
  }
@@ -577,17 +577,17 @@ export function registerServiceAccountTools(
577
577
  "list_service_account_roles",
578
578
  "List all roles assigned to a service account.",
579
579
  {
580
- serviceAccountId: z.number().describe("The service account numeric ID"),
580
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
581
581
  },
582
- async ({ serviceAccountId }) => {
582
+ async ({ clientId }) => {
583
583
  try {
584
- const result = await getSaClient().get(`/${serviceAccountId}/roles`);
584
+ const result = await getSaClient().get(`/${encodeURIComponent(clientId)}/roles`);
585
585
  return {
586
586
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
587
587
  };
588
588
  } catch (error: unknown) {
589
589
  return {
590
- content: [{ type: "text", text: formatError(error, `listing roles for service account '${serviceAccountId}'`) }],
590
+ content: [{ type: "text", text: formatError(error, `listing roles for service account '${encodeURIComponent(clientId)}'`) }],
591
591
  isError: true,
592
592
  };
593
593
  }
@@ -598,18 +598,18 @@ export function registerServiceAccountTools(
598
598
  "assign_role_to_service_account",
599
599
  "Assign a role to a service account. The service account inherits all permissions defined in the role.",
600
600
  {
601
- serviceAccountId: z.number().describe("The service account numeric ID"),
601
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
602
602
  roleId: z.string().describe("The role ID (UUID) to assign"),
603
603
  },
604
- async ({ serviceAccountId, roleId }) => {
604
+ async ({ clientId, roleId }) => {
605
605
  try {
606
- const result = await getSaClient().post(`/${serviceAccountId}/roles/${roleId}`);
606
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/roles/${roleId}`);
607
607
  return {
608
608
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
609
609
  };
610
610
  } catch (error: unknown) {
611
611
  return {
612
- content: [{ type: "text", text: formatError(error, `assigning role '${roleId}' to service account '${serviceAccountId}'`) }],
612
+ content: [{ type: "text", text: formatError(error, `assigning role '${roleId}' to service account '${encodeURIComponent(clientId)}'`) }],
613
613
  isError: true,
614
614
  };
615
615
  }
@@ -620,18 +620,18 @@ export function registerServiceAccountTools(
620
620
  "remove_role_from_service_account",
621
621
  "Remove a role from a service account. The service account loses all permissions from this role.",
622
622
  {
623
- serviceAccountId: z.number().describe("The service account numeric ID"),
623
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
624
624
  roleId: z.string().describe("The role ID (UUID) to remove"),
625
625
  },
626
- async ({ serviceAccountId, roleId }) => {
626
+ async ({ clientId, roleId }) => {
627
627
  try {
628
- await getSaClient().delete(`/${serviceAccountId}/roles/${roleId}`);
628
+ await getSaClient().delete(`/${encodeURIComponent(clientId)}/roles/${roleId}`);
629
629
  return {
630
- content: [{ type: "text", text: `Role '${roleId}' removed from service account '${serviceAccountId}'.` }],
630
+ content: [{ type: "text", text: `Role '${roleId}' removed from service account '${encodeURIComponent(clientId)}'.` }],
631
631
  };
632
632
  } catch (error: unknown) {
633
633
  return {
634
- content: [{ type: "text", text: formatError(error, `removing role '${roleId}' from service account '${serviceAccountId}'`) }],
634
+ content: [{ type: "text", text: formatError(error, `removing role '${roleId}' from service account '${encodeURIComponent(clientId)}'`) }],
635
635
  isError: true,
636
636
  };
637
637
  }
@@ -644,17 +644,17 @@ export function registerServiceAccountTools(
644
644
  "list_service_account_groups",
645
645
  "List all groups a service account belongs to.",
646
646
  {
647
- serviceAccountId: z.number().describe("The service account numeric ID"),
647
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
648
648
  },
649
- async ({ serviceAccountId }) => {
649
+ async ({ clientId }) => {
650
650
  try {
651
- const result = await getSaClient().get(`/${serviceAccountId}/groups`);
651
+ const result = await getSaClient().get(`/${encodeURIComponent(clientId)}/groups`);
652
652
  return {
653
653
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
654
654
  };
655
655
  } catch (error: unknown) {
656
656
  return {
657
- content: [{ type: "text", text: formatError(error, `listing groups for service account '${serviceAccountId}'`) }],
657
+ content: [{ type: "text", text: formatError(error, `listing groups for service account '${encodeURIComponent(clientId)}'`) }],
658
658
  isError: true,
659
659
  };
660
660
  }
@@ -665,18 +665,18 @@ export function registerServiceAccountTools(
665
665
  "add_service_account_to_group",
666
666
  "Add a service account to a group. The service account inherits all roles assigned to the group.",
667
667
  {
668
- serviceAccountId: z.number().describe("The service account numeric ID"),
668
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
669
669
  groupId: z.string().describe("The group ID (UUID) to add the service account to"),
670
670
  },
671
- async ({ serviceAccountId, groupId }) => {
671
+ async ({ clientId, groupId }) => {
672
672
  try {
673
- const result = await getSaClient().post(`/${serviceAccountId}/groups/${groupId}`);
673
+ const result = await getSaClient().post(`/${encodeURIComponent(clientId)}/groups/${groupId}`);
674
674
  return {
675
675
  content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
676
676
  };
677
677
  } catch (error: unknown) {
678
678
  return {
679
- content: [{ type: "text", text: formatError(error, `adding service account '${serviceAccountId}' to group '${groupId}'`) }],
679
+ content: [{ type: "text", text: formatError(error, `adding service account '${encodeURIComponent(clientId)}' to group '${groupId}'`) }],
680
680
  isError: true,
681
681
  };
682
682
  }
@@ -687,18 +687,18 @@ export function registerServiceAccountTools(
687
687
  "remove_service_account_from_group",
688
688
  "Remove a service account from a group. The service account loses all permissions inherited through this group.",
689
689
  {
690
- serviceAccountId: z.number().describe("The service account numeric ID"),
690
+ clientId: z.string().describe("The service account clientId (not its numeric database id)"),
691
691
  groupId: z.string().describe("The group ID (UUID) to remove the service account from"),
692
692
  },
693
- async ({ serviceAccountId, groupId }) => {
693
+ async ({ clientId, groupId }) => {
694
694
  try {
695
- await getSaClient().delete(`/${serviceAccountId}/groups/${groupId}`);
695
+ await getSaClient().delete(`/${encodeURIComponent(clientId)}/groups/${groupId}`);
696
696
  return {
697
- content: [{ type: "text", text: `Service account '${serviceAccountId}' removed from group '${groupId}'.` }],
697
+ content: [{ type: "text", text: `Service account '${encodeURIComponent(clientId)}' removed from group '${groupId}'.` }],
698
698
  };
699
699
  } catch (error: unknown) {
700
700
  return {
701
- content: [{ type: "text", text: formatError(error, `removing service account '${serviceAccountId}' from group '${groupId}'`) }],
701
+ content: [{ type: "text", text: formatError(error, `removing service account '${encodeURIComponent(clientId)}' from group '${groupId}'`) }],
702
702
  isError: true,
703
703
  };
704
704
  }
@@ -0,0 +1,94 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const axios = require('axios');
4
+ const { registerServiceAccountTools } = require('../dist/tools/service-accounts.js');
5
+
6
+ const paths = [
7
+ ['get_service_account', 'get', ''],
8
+ ['update_service_account_name', 'put', '/name'],
9
+ ['update_service_account_description', 'put', '/description'],
10
+ ['delete_service_account', 'delete', ''],
11
+ ['rotate_service_account_secret', 'post', '/rotate'],
12
+ ['revoke_service_account', 'post', '/revoke'],
13
+ ['generate_dev_token', 'post', '/dev-token'],
14
+ ['scan_service_account_permissions', 'get', '/permissions/scan'],
15
+ ['simulate_service_account_permission', 'post', '/permissions/simulate'],
16
+ ['list_service_account_roles', 'get', '/roles'],
17
+ ['assign_role_to_service_account', 'post', '/roles/role-1'],
18
+ ['remove_role_from_service_account', 'delete', '/roles/role-1'],
19
+ ['list_service_account_groups', 'get', '/groups'],
20
+ ['add_service_account_to_group', 'post', '/groups/group-1'],
21
+ ['remove_service_account_from_group', 'delete', '/groups/group-1'],
22
+ ];
23
+ // Capture actual Axios requests without contacting IAM.
24
+ function setup(accounts = []) {
25
+ const calls = [];
26
+ const tools = new Map();
27
+ const create = axios.create;
28
+ axios.create = () => {
29
+ const client = { interceptors: { request: { use() {} }, response: { use() {} } } };
30
+ for (const method of ['get', 'post', 'put', 'delete']) {
31
+ client[method] = async (path, body) => { calls.push({ method, path, body }); return { data: method === 'get' && path === '/' ? { data: accounts } : {} }; };
32
+ }
33
+ return client;
34
+ };
35
+ registerServiceAccountTools({ tool(name, desc, schema, handler) { tools.set(name, { description: desc, schema, handler }); } }, {}, 'https://api.example.com', 'acme', { clientId: 'sa_identity' });
36
+ return { calls, tools, restore: () => { axios.create = create; } };
37
+ }
38
+ for (const [name, method, suffix] of paths) {
39
+ test(`${name}: string clientId contract and account path`, async () => {
40
+ const { calls, tools, restore } = setup();
41
+ try {
42
+ const tool = tools.get(name);
43
+ assert.ok(tool, name);
44
+ assert.equal(tool.schema.clientId.safeParse('cid_legacy').success, true);
45
+ assert.equal(tool.schema.clientId.safeParse(2403).success, false);
46
+ assert.equal(tool.schema.serviceAccountId, undefined);
47
+ const result = await tool.handler({ clientId: 'cid_legacy', roleId: 'role-1', groupId: 'group-1', name: 'Changed', description: 'Changed', ttlSeconds: 3600, resource: 'records', resourceCategory: 'workspace', action: 'retrieve' });
48
+ assert.ok(!result.isError);
49
+ assert.equal(calls[0].method, method);
50
+ assert.equal(calls[0].path, `/cid_legacy${suffix}`);
51
+ } finally { restore(); }
52
+ });
53
+ }
54
+ test('remediation retains its explicit numeric targetId contract', async () => {
55
+ const { calls, tools, restore } = setup();
56
+ try {
57
+ const tool = tools.get('generate_remediation');
58
+ assert.equal(tool.schema.serviceAccountId.safeParse(2403).success, true);
59
+ await tool.handler({ serviceAccountId: 2403, resource: 'records', resourceCategory: 'workspace', actions: ['retrieve'] });
60
+ assert.equal(calls[0].body.targetId, 2403);
61
+ } finally { restore(); }
62
+ });
63
+
64
+ // Agent-facing instructions are part of the tool contract, alongside schemas.
65
+ test('identity guidance separates clientId inspection from numeric remediation', async () => {
66
+ const { tools, restore } = setup([{ id: 2403, clientId: 'sa_identity', name: 'Identity' }]);
67
+ try {
68
+ const result = await tools.get('get_current_identity').handler({});
69
+ assert.ok(!result.isError);
70
+ const identity = JSON.parse(result.content[0].text);
71
+ assert.equal(identity.id, 2403);
72
+ assert.equal(identity.clientId, 'sa_identity');
73
+ const [inspection, remediation] = identity._hint.split('. ');
74
+ assert.match(inspection, /clientId.*scan_service_account_permissions.*simulate_service_account_permission/);
75
+ assert.doesNotMatch(inspection, /numeric/);
76
+ assert.match(remediation, /numeric id as serviceAccountId.*generate_remediation.*preview_remediation.*apply_remediation/);
77
+ } finally { restore(); }
78
+ });
79
+ test('get description advertises the clientId argument', () => {
80
+ const { tools, restore } = setup();
81
+ try {
82
+ const description = tools.get('get_service_account').description;
83
+ assert.match(description, /by its clientId/);
84
+ assert.doesNotMatch(description, /by its numeric ID/);
85
+ } finally { restore(); }
86
+ });
87
+ test('delete description permits already-revoked accounts', () => {
88
+ const { tools, restore } = setup();
89
+ try {
90
+ const description = tools.get('delete_service_account').description;
91
+ assert.match(description, /including an already-revoked account/);
92
+ assert.doesNotMatch(description, /must not be revoked|revoke prevents deletion/);
93
+ } finally { restore(); }
94
+ });