@centrali-io/centrali-mcp 9.5.2 → 9.7.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 +48 -1
- package/dist/index.js +2 -0
- package/dist/tools/describe.js +2 -2
- package/dist/tools/files.d.ts +3 -0
- package/dist/tools/files.js +73 -0
- package/dist/tools/insights.js +14 -0
- package/dist/tools/service-accounts.js +4 -4
- package/package.json +3 -2
- package/src/index.ts +2 -0
- package/src/tools/describe.ts +2 -2
- package/src/tools/files.ts +72 -0
- package/src/tools/insights.ts +19 -0
- package/src/tools/service-accounts.ts +4 -4
- package/tests/describeCapabilities.test.cjs +5 -2
- package/tests/files.test.cjs +143 -0
- package/tests/serviceAccountsRouting.test.cjs +20 -0
- package/tests/triggerHealth.test.cjs +37 -0
package/README.md
CHANGED
|
@@ -4,7 +4,47 @@ MCP (Model Context Protocol) server for the Centrali platform. Lets AI assistant
|
|
|
4
4
|
|
|
5
5
|
> **Full documentation:** [docs.centrali.io](https://docs.centrali.io) — SDK guide, API reference, compute functions, orchestrations, and more.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## File uploads
|
|
8
|
+
|
|
9
|
+
Both hosted and stdio servers provide `upload_file`. It uploads a standalone Storage
|
|
10
|
+
file through the existing SDK and Storage API, using the authenticated workspace
|
|
11
|
+
and its existing folder permissions. Node.js 22 or newer is required for stdio.
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"filename": "hello.txt",
|
|
16
|
+
"contentType": "text/plain",
|
|
17
|
+
"contentEncoding": "utf8",
|
|
18
|
+
"content": "Hello from MCP"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For binary files use `contentEncoding: "base64"` with canonical padded base64
|
|
23
|
+
(no data URL prefix or whitespace). The decoded limit is **256 KiB**, including
|
|
24
|
+
UTF-8 byte length for text. Empty files are supported. The serialized `content`
|
|
25
|
+
JSON string also has a **768 KiB** limit so JSON escaping leaves room within the
|
|
26
|
+
hosted server's 1 MB request limit. For heavily escaped text (such as control
|
|
27
|
+
characters), encode the exact UTF-8 bytes as base64 instead.
|
|
28
|
+
`location` defaults to `/root/shared`; custom folders
|
|
29
|
+
must already exist. Files are private unless `isPublic: true` is explicitly set.
|
|
30
|
+
Public uploads allow only PNG, JPEG, GIF, WebP, plain text, JSON, MPEG/OGG/WAV
|
|
31
|
+
audio, and MP4/WebM video MIME types. HTML, SVG, XML and other active document
|
|
32
|
+
types cannot be made public through this tool because Storage serves the
|
|
33
|
+
supplied MIME type inline on the API origin. Private uploads retain support
|
|
34
|
+
for arbitrary MIME types. The SDK prefixes stored filenames with the workspace
|
|
35
|
+
and a timestamp.
|
|
36
|
+
|
|
37
|
+
The result contains `renderId`, `sizeBytes`, `contentType`, `isPublic`, `renderUrl`
|
|
38
|
+
and `downloadUrl`. Private URLs still require normal authentication. Attach the
|
|
39
|
+
returned render ID using a separate record update; an attachment failure leaves
|
|
40
|
+
the uploaded file in Storage. Repeating an upload can create another file.
|
|
41
|
+
|
|
42
|
+
The tool accepts content supplied by the client. It cannot read local paths,
|
|
43
|
+
fetch source URLs, or access chat attachments/generated images hidden by the
|
|
44
|
+
host. Never reconstruct image bytes through model transcription. Files larger
|
|
45
|
+
than 256 KiB must use the existing SDK/HTTP multipart upload API.
|
|
46
|
+
|
|
47
|
+
## Connection options
|
|
8
48
|
|
|
9
49
|
### Option 1: Hosted MCP Server (recommended)
|
|
10
50
|
|
|
@@ -423,3 +463,10 @@ npx @modelcontextprotocol/inspector node dist/index.js
|
|
|
423
463
|
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
464
|
|
|
425
465
|
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`.
|
|
466
|
+
|
|
467
|
+
## Development tests
|
|
468
|
+
|
|
469
|
+
`npm test` builds the sibling SDK first when running in the monorepo, then builds
|
|
470
|
+
MCP and runs its tests. The health regression uses the real SDK normalization,
|
|
471
|
+
so its runtime distribution must exist even on a fresh checkout. Outside the
|
|
472
|
+
monorepo, tests use the installed SDK distribution instead.
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const auth_providers_js_1 = require("./tools/auth-providers.js");
|
|
|
26
26
|
const service_accounts_js_1 = require("./tools/service-accounts.js");
|
|
27
27
|
const webhook_subscriptions_js_1 = require("./tools/webhook-subscriptions.js");
|
|
28
28
|
const events_js_1 = require("./tools/events.js");
|
|
29
|
+
const files_js_1 = require("./tools/files.js");
|
|
29
30
|
const structures_js_2 = require("./resources/structures.js");
|
|
30
31
|
function getRequiredEnv(name) {
|
|
31
32
|
const value = process.env[name];
|
|
@@ -85,6 +86,7 @@ function main() {
|
|
|
85
86
|
(0, webhook_subscriptions_js_1.registerWebhookSubscriptionTools)(server, sdk);
|
|
86
87
|
(0, events_js_1.registerEventTools)(server, sdk, baseUrl, workspaceId);
|
|
87
88
|
(0, describe_js_1.registerDescribeTools)(server);
|
|
89
|
+
(0, files_js_1.registerFileTools)(server, sdk);
|
|
88
90
|
// Register resources
|
|
89
91
|
(0, structures_js_2.registerCollectionResources)(server, sdk);
|
|
90
92
|
(0, structures_js_2.registerStructureResources)(server, sdk);
|
package/dist/tools/describe.js
CHANGED
|
@@ -285,7 +285,7 @@ function registerDescribeTools(server) {
|
|
|
285
285
|
"Function runs (execution history)": { sdk: true, mcp: true, console: true },
|
|
286
286
|
"Outbound webhooks": { sdk: true, mcp: true, console: true, note: "SDK namespace (client.webhookSubscriptions) and MCP tools wrap the REST surface including delivery replay" },
|
|
287
287
|
"Service accounts & IAM": { sdk: false, mcp: true, console: true, note: "MCP tools for full SA lifecycle, roles, groups, and permission introspection" },
|
|
288
|
-
"File uploads": { sdk: true, mcp:
|
|
288
|
+
"File uploads": { sdk: true, mcp: true, console: true, note: "upload_file accepts up to 256 KiB decoded and 768 KiB serialized content; public uploads require a passive MIME type. Larger files use client.uploadFile()." },
|
|
289
289
|
},
|
|
290
290
|
},
|
|
291
291
|
sdk_integration: {
|
|
@@ -302,7 +302,7 @@ function registerDescribeTools(server) {
|
|
|
302
302
|
note: "workspaceId is the workspace slug (e.g., 'acme'), not a UUID. See https://docs.centrali.io/guides/centrali-sdk for the full guide.",
|
|
303
303
|
},
|
|
304
304
|
file_storage: {
|
|
305
|
-
description: "Centrali has built-in file storage (Azure Blob). Use the SDK
|
|
305
|
+
description: "Centrali has built-in file storage (Azure Blob). Use upload_file via MCP for files up to 256 KiB decoded (base64 or utf8), or the SDK for larger uploads. MCP uploads return renderId and render/download URLs, default to private, and use existing workspace folder permissions. Record attachment is a separate update. Private URLs require normal authentication. The MCP tool cannot access host attachments or local paths directly.",
|
|
306
306
|
folder_system: {
|
|
307
307
|
description: "Files live in folders. Every workspace starts with system folders: /root, /root/shared, /root/users, /root/_data_directory. You MUST create a folder before uploading to it — uploading to a non-existent folder will fail.",
|
|
308
308
|
system_folders: {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerFileTools = registerFileTools;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const _register_js_1 = require("./_register.js");
|
|
15
|
+
const MAX_FILE_BYTES = 256 * 1024;
|
|
16
|
+
const MAX_CONTENT_CHARS = 4 * Math.ceil(MAX_FILE_BYTES / 3);
|
|
17
|
+
const MAX_CONTENT_JSON_BYTES = 768 * 1024;
|
|
18
|
+
// Storage renders the supplied MIME type inline on the API origin.
|
|
19
|
+
// Keep active documents (HTML, SVG, XML, etc.) out of public MCP uploads.
|
|
20
|
+
const PUBLIC_CONTENT_TYPES = new Set([
|
|
21
|
+
"image/png", "image/jpeg", "image/gif", "image/webp",
|
|
22
|
+
"text/plain", "application/json",
|
|
23
|
+
"audio/mpeg", "audio/ogg", "audio/wav", "video/mp4", "video/webm",
|
|
24
|
+
]);
|
|
25
|
+
const uploadSchema = zod_1.z.object({
|
|
26
|
+
filename: zod_1.z.string().min(1).max(255)
|
|
27
|
+
.refine(value => !/[\\/\x00-\x1f\x7f]/.test(value) && value !== "." && value !== "..", "Use a filename without path separators or control characters"),
|
|
28
|
+
contentType: zod_1.z.string().max(127)
|
|
29
|
+
.regex(/^[a-zA-Z0-9!#$&^_.+-]+\/[a-zA-Z0-9!#$&^_.+-]+$/, "Expected a MIME type such as image/png"),
|
|
30
|
+
contentEncoding: zod_1.z.enum(["base64", "utf8"]),
|
|
31
|
+
content: zod_1.z.string().max(MAX_CONTENT_CHARS)
|
|
32
|
+
.refine(value => Buffer.byteLength(JSON.stringify(value), "utf8") <= MAX_CONTENT_JSON_BYTES, "Serialized content exceeds 768 KiB; use base64 for heavily escaped text")
|
|
33
|
+
.describe("Exact file content, including empty content. Maximum 256 KiB decoded and 768 KiB as a JSON string; use base64 for heavily escaped UTF-8 text."),
|
|
34
|
+
location: zod_1.z.string().min(1).max(1024).optional()
|
|
35
|
+
.describe("Existing destination folder; defaults to /root/shared. Does not create folders."),
|
|
36
|
+
isPublic: zod_1.z.boolean().default(false)
|
|
37
|
+
.describe("Explicitly opt into unauthenticated public access. Only PNG, JPEG, GIF, WebP, plain text, JSON, MPEG/OGG/WAV audio and MP4/WebM video are allowed publicly. Defaults to private."),
|
|
38
|
+
});
|
|
39
|
+
function registerFileTools(server, sdk) {
|
|
40
|
+
(0, _register_js_1.registerTool)(server, "upload_file", "Upload a standalone file or image into the authenticated workspace's Storage (maximum 256 KiB decoded). Supply exact bytes as canonical padded base64, or text as utf8; never reconstruct binary bytes from an image description. Requires files/create permission on the destination folder. Private by default. Returns renderId and render/download URLs; private URLs require normal authentication. Use renderId in a separate record update to attach the file. This tool cannot access host attachments, local paths, or source URLs. Repeating an upload can create another file; it is not idempotent.", uploadSchema.shape, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
try {
|
|
42
|
+
const input = uploadSchema.parse(args);
|
|
43
|
+
if (input.isPublic && !PUBLIC_CONTENT_TYPES.has(input.contentType.toLowerCase())) {
|
|
44
|
+
throw new Error("Public uploads require a supported passive MIME type; HTML, SVG and other active documents must remain private");
|
|
45
|
+
}
|
|
46
|
+
const bytes = Buffer.from(input.content, input.contentEncoding === "base64" ? "base64" : "utf8");
|
|
47
|
+
if (bytes.length > MAX_FILE_BYTES) {
|
|
48
|
+
throw new Error("File exceeds the 256 KiB decoded upload limit");
|
|
49
|
+
}
|
|
50
|
+
if (input.contentEncoding === "base64" && bytes.toString("base64") !== input.content) {
|
|
51
|
+
throw new Error("content must be canonical padded base64");
|
|
52
|
+
}
|
|
53
|
+
const file = new File([new Uint8Array(bytes)], input.filename, { type: input.contentType });
|
|
54
|
+
const result = yield sdk.uploadFile(file, input.location, input.isPublic);
|
|
55
|
+
const renderId = result.data;
|
|
56
|
+
return { content: [{ type: "text", text: JSON.stringify({
|
|
57
|
+
renderId,
|
|
58
|
+
sizeBytes: bytes.length,
|
|
59
|
+
contentType: input.contentType,
|
|
60
|
+
isPublic: input.isPublic,
|
|
61
|
+
renderUrl: sdk.getFileRenderUrl(renderId),
|
|
62
|
+
downloadUrl: sdk.getFileDownloadUrl(renderId),
|
|
63
|
+
}, null, 2) }] };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// Zod errors include rejected input values. Never echo file content.
|
|
67
|
+
const message = error instanceof zod_1.z.ZodError
|
|
68
|
+
? "Invalid upload_file arguments; check filename, MIME type, encoding and content size"
|
|
69
|
+
: (0, _register_js_1.formatError)(error, "uploading file");
|
|
70
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
package/dist/tools/insights.js
CHANGED
|
@@ -13,6 +13,20 @@ exports.registerInsightTools = registerInsightTools;
|
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
14
|
const _register_js_1 = require("./_register.js");
|
|
15
15
|
function registerInsightTools(server, sdk) {
|
|
16
|
+
(0, _register_js_1.registerTool)(server, "get_trigger_health", "Inspect HTTP request acceptance separately from execution success. Returns durable receivedCount, acceptedCount, rejectedCount, rejectionReasonBreakdown, requestAcceptanceRate (null without arrivals), and executionSuccessRate. Completed decisions are buffered and rolled up about every five minutes. Storage interruptions may lose or duplicate observations; rates are approximate. In-flight requests are not counted. Counts begin at tracking rollout; older traffic is unavailable. Omit triggerId for workspace health including unattributed requests to unknown paths. Non-HTTP triggers have execution health only.", {
|
|
17
|
+
triggerId: zod_1.z.string().uuid().optional().describe("Trigger UUID; omit to list workspace health"),
|
|
18
|
+
period: zod_1.z.union([zod_1.z.literal(7), zod_1.z.literal(30)]).optional().describe("Days of health history, default 30"),
|
|
19
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ triggerId, period }) {
|
|
20
|
+
try {
|
|
21
|
+
const result = triggerId
|
|
22
|
+
? yield sdk.triggers.healthTrend(triggerId, period)
|
|
23
|
+
: yield sdk.triggers.health(period);
|
|
24
|
+
return { content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }] };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return { content: [{ type: "text", text: (0, _register_js_1.formatError)(error, "getting trigger health") }], isError: true };
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
16
30
|
(0, _register_js_1.registerTool)(server, "list_insights", "List anomaly insights detected by Centrali's AI analysis. Insights flag unusual patterns in your data such as spikes, drops, or outliers.", {
|
|
17
31
|
recordSlug: zod_1.z
|
|
18
32
|
.string()
|
|
@@ -588,7 +588,7 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
|
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
590
|
}));
|
|
591
|
-
(0, _register_js_1.registerTool)(server, "get_role", "Get
|
|
591
|
+
(0, _register_js_1.registerTool)(server, "get_role", "Get a role's name and description. Roles are labels; permissions bind resources and actions to policies that can match role names.", {
|
|
592
592
|
roleId: zod_1.z.string().describe("The role ID (UUID)"),
|
|
593
593
|
}, (_a) => __awaiter(this, [_a], void 0, function* ({ roleId }) {
|
|
594
594
|
try {
|
|
@@ -604,7 +604,7 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
|
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
606
|
}));
|
|
607
|
-
(0, _register_js_1.registerTool)(server, "create_role", "Create a new role. Roles are named labels assigned to users and service accounts. They do NOT contain
|
|
607
|
+
(0, _register_js_1.registerTool)(server, "create_role", "Create a new role. Roles are named labels assigned to users and service accounts. They do NOT contain permission IDs. To grant narrow access, assign the role to the service account, create_policy with an in_list condition on the roles attribute matching the role name, then create_permission binding that policyId to a resourceId and only the required actions (e.g. files + ['create']). Role names are immutable after creation.", {
|
|
608
608
|
name: zod_1.z.string().describe("Role name (e.g., 'Data Reader', 'Compute Admin'). Cannot be changed after creation."),
|
|
609
609
|
description: zod_1.z.string().optional().describe("Optional description of the role's purpose"),
|
|
610
610
|
}, (_a) => __awaiter(this, [_a], void 0, function* ({ name, description }) {
|
|
@@ -888,8 +888,8 @@ function registerServiceAccountTools(server, sdk, centraliUrl, workspaceId, curr
|
|
|
888
888
|
return { content: [{ type: "text", text: (0, _register_js_1.formatError)(error, `getting policy '${policyId}'`) }], isError: true };
|
|
889
889
|
}
|
|
890
890
|
}));
|
|
891
|
-
(0, _register_js_1.registerTool)(server, "create_policy", "Create
|
|
892
|
-
policy: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).describe("
|
|
891
|
+
(0, _register_js_1.registerTool)(server, "create_policy", "Create a policy with name and specification. A policy matches identity attributes; create_permission binds its policyId to a resourceId and actions. For a role, use {\"name\":\"upload-only\",\"specification\":{\"rules\":[{\"rule_id\":\"allow-upload-role\",\"effect\":\"Allow\",\"conditions\":[{\"function\":\"in_list\",\"attribute\":\"roles\",\"value\":\"file_uploaders\"}]}],\"default\":{\"rule_id\":\"default-deny\",\"effect\":\"Deny\"}}}. Match the role NAME, not its UUID. A policy alone grants no access.", {
|
|
892
|
+
policy: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).describe("Required: {name: string, specification: {rules: [{rule_id: string, effect: 'Allow'|'Deny', conditions: [{function: string, attribute: string, value?: any}]}], default: {rule_id: string, effect: 'Allow'|'Deny'}}}. Optional: description. Use distinct rule IDs. Resources and actions belong in create_permission, not here."),
|
|
893
893
|
}, (_a) => __awaiter(this, [_a], void 0, function* ({ policy }) {
|
|
894
894
|
try {
|
|
895
895
|
const result = yield getPoliciesClient().post("/", policy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centrali-io/centrali-mcp",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.7.0",
|
|
4
4
|
"description": "Centrali MCP Server - AI assistant integration for Centrali workspaces",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"url": "git+https://github.com/blueinit/centrali-mcp.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
+
"pretest": "node -e \"const fs=require('node:fs');const cp=require('node:child_process');if(fs.existsSync('../centrali-sdk/tsup.config.ts'))cp.execFileSync('npm',['run','build'],{cwd:'../centrali-sdk',stdio:'inherit'});\"",
|
|
15
16
|
"build": "tsc --project tsconfig.json",
|
|
16
17
|
"test": "npm run build && node --test 'tests/**/*.test.cjs'",
|
|
17
18
|
"prepublishOnly": "npm run build"
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"author": "Blueinit",
|
|
26
27
|
"license": "ISC",
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@centrali-io/centrali-sdk": "^9.
|
|
29
|
+
"@centrali-io/centrali-sdk": "^9.7.0",
|
|
29
30
|
"@modelcontextprotocol/sdk": "^1.28.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { registerAuthProviderTools } from "./tools/auth-providers.js";
|
|
|
16
16
|
import { registerServiceAccountTools } from "./tools/service-accounts.js";
|
|
17
17
|
import { registerWebhookSubscriptionTools } from "./tools/webhook-subscriptions.js";
|
|
18
18
|
import { registerEventTools } from "./tools/events.js";
|
|
19
|
+
import { registerFileTools } from "./tools/files.js";
|
|
19
20
|
import { registerStructureResources, registerCollectionResources } from "./resources/structures.js";
|
|
20
21
|
|
|
21
22
|
function getRequiredEnv(name: string): string {
|
|
@@ -82,6 +83,7 @@ async function main() {
|
|
|
82
83
|
registerWebhookSubscriptionTools(server, sdk);
|
|
83
84
|
registerEventTools(server, sdk, baseUrl, workspaceId);
|
|
84
85
|
registerDescribeTools(server);
|
|
86
|
+
registerFileTools(server, sdk);
|
|
85
87
|
|
|
86
88
|
// Register resources
|
|
87
89
|
registerCollectionResources(server, sdk);
|
package/src/tools/describe.ts
CHANGED
|
@@ -294,7 +294,7 @@ export function registerDescribeTools(server: McpServer) {
|
|
|
294
294
|
"Function runs (execution history)": { sdk: true, mcp: true, console: true },
|
|
295
295
|
"Outbound webhooks": { sdk: true, mcp: true, console: true, note: "SDK namespace (client.webhookSubscriptions) and MCP tools wrap the REST surface including delivery replay" },
|
|
296
296
|
"Service accounts & IAM": { sdk: false, mcp: true, console: true, note: "MCP tools for full SA lifecycle, roles, groups, and permission introspection" },
|
|
297
|
-
"File uploads": { sdk: true, mcp:
|
|
297
|
+
"File uploads": { sdk: true, mcp: true, console: true, note: "upload_file accepts up to 256 KiB decoded and 768 KiB serialized content; public uploads require a passive MIME type. Larger files use client.uploadFile()." },
|
|
298
298
|
},
|
|
299
299
|
},
|
|
300
300
|
sdk_integration: {
|
|
@@ -311,7 +311,7 @@ export function registerDescribeTools(server: McpServer) {
|
|
|
311
311
|
note: "workspaceId is the workspace slug (e.g., 'acme'), not a UUID. See https://docs.centrali.io/guides/centrali-sdk for the full guide.",
|
|
312
312
|
},
|
|
313
313
|
file_storage: {
|
|
314
|
-
description: "Centrali has built-in file storage (Azure Blob). Use the SDK
|
|
314
|
+
description: "Centrali has built-in file storage (Azure Blob). Use upload_file via MCP for files up to 256 KiB decoded (base64 or utf8), or the SDK for larger uploads. MCP uploads return renderId and render/download URLs, default to private, and use existing workspace folder permissions. Record attachment is a separate update. Private URLs require normal authentication. The MCP tool cannot access host attachments or local paths directly.",
|
|
315
315
|
folder_system: {
|
|
316
316
|
description: "Files live in folders. Every workspace starts with system folders: /root, /root/shared, /root/users, /root/_data_directory. You MUST create a folder before uploading to it — uploading to a non-existent folder will fail.",
|
|
317
317
|
system_folders: {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CentraliSDK } from "@centrali-io/centrali-sdk";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { registerTool, formatError } from "./_register.js";
|
|
5
|
+
|
|
6
|
+
const MAX_FILE_BYTES = 256 * 1024;
|
|
7
|
+
const MAX_CONTENT_CHARS = 4 * Math.ceil(MAX_FILE_BYTES / 3);
|
|
8
|
+
const MAX_CONTENT_JSON_BYTES = 768 * 1024;
|
|
9
|
+
// Storage renders the supplied MIME type inline on the API origin.
|
|
10
|
+
// Keep active documents (HTML, SVG, XML, etc.) out of public MCP uploads.
|
|
11
|
+
const PUBLIC_CONTENT_TYPES = new Set([
|
|
12
|
+
"image/png", "image/jpeg", "image/gif", "image/webp",
|
|
13
|
+
"text/plain", "application/json",
|
|
14
|
+
"audio/mpeg", "audio/ogg", "audio/wav", "video/mp4", "video/webm",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const uploadSchema = z.object({
|
|
18
|
+
filename: z.string().min(1).max(255)
|
|
19
|
+
.refine(value => !/[\\/\x00-\x1f\x7f]/.test(value) && value !== "." && value !== "..",
|
|
20
|
+
"Use a filename without path separators or control characters"),
|
|
21
|
+
contentType: z.string().max(127)
|
|
22
|
+
.regex(/^[a-zA-Z0-9!#$&^_.+-]+\/[a-zA-Z0-9!#$&^_.+-]+$/, "Expected a MIME type such as image/png"),
|
|
23
|
+
contentEncoding: z.enum(["base64", "utf8"]),
|
|
24
|
+
content: z.string().max(MAX_CONTENT_CHARS)
|
|
25
|
+
.refine(value => Buffer.byteLength(JSON.stringify(value), "utf8") <= MAX_CONTENT_JSON_BYTES,
|
|
26
|
+
"Serialized content exceeds 768 KiB; use base64 for heavily escaped text")
|
|
27
|
+
.describe("Exact file content, including empty content. Maximum 256 KiB decoded and 768 KiB as a JSON string; use base64 for heavily escaped UTF-8 text."),
|
|
28
|
+
location: z.string().min(1).max(1024).optional()
|
|
29
|
+
.describe("Existing destination folder; defaults to /root/shared. Does not create folders."),
|
|
30
|
+
isPublic: z.boolean().default(false)
|
|
31
|
+
.describe("Explicitly opt into unauthenticated public access. Only PNG, JPEG, GIF, WebP, plain text, JSON, MPEG/OGG/WAV audio and MP4/WebM video are allowed publicly. Defaults to private."),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export function registerFileTools(server: McpServer, sdk: CentraliSDK) {
|
|
35
|
+
registerTool<z.infer<typeof uploadSchema>>(server,
|
|
36
|
+
"upload_file",
|
|
37
|
+
"Upload a standalone file or image into the authenticated workspace's Storage (maximum 256 KiB decoded). Supply exact bytes as canonical padded base64, or text as utf8; never reconstruct binary bytes from an image description. Requires files/create permission on the destination folder. Private by default. Returns renderId and render/download URLs; private URLs require normal authentication. Use renderId in a separate record update to attach the file. This tool cannot access host attachments, local paths, or source URLs. Repeating an upload can create another file; it is not idempotent.",
|
|
38
|
+
uploadSchema.shape,
|
|
39
|
+
async (args) => {
|
|
40
|
+
try {
|
|
41
|
+
const input = uploadSchema.parse(args);
|
|
42
|
+
if (input.isPublic && !PUBLIC_CONTENT_TYPES.has(input.contentType.toLowerCase())) {
|
|
43
|
+
throw new Error("Public uploads require a supported passive MIME type; HTML, SVG and other active documents must remain private");
|
|
44
|
+
}
|
|
45
|
+
const bytes = Buffer.from(input.content, input.contentEncoding === "base64" ? "base64" : "utf8");
|
|
46
|
+
if (bytes.length > MAX_FILE_BYTES) {
|
|
47
|
+
throw new Error("File exceeds the 256 KiB decoded upload limit");
|
|
48
|
+
}
|
|
49
|
+
if (input.contentEncoding === "base64" && bytes.toString("base64") !== input.content) {
|
|
50
|
+
throw new Error("content must be canonical padded base64");
|
|
51
|
+
}
|
|
52
|
+
const file = new File([new Uint8Array(bytes)], input.filename, { type: input.contentType });
|
|
53
|
+
const result = await sdk.uploadFile(file, input.location, input.isPublic);
|
|
54
|
+
const renderId = result.data;
|
|
55
|
+
return { content: [{ type: "text", text: JSON.stringify({
|
|
56
|
+
renderId,
|
|
57
|
+
sizeBytes: bytes.length,
|
|
58
|
+
contentType: input.contentType,
|
|
59
|
+
isPublic: input.isPublic,
|
|
60
|
+
renderUrl: sdk.getFileRenderUrl(renderId),
|
|
61
|
+
downloadUrl: sdk.getFileDownloadUrl(renderId),
|
|
62
|
+
}, null, 2) }] };
|
|
63
|
+
} catch (error: unknown) {
|
|
64
|
+
// Zod errors include rejected input values. Never echo file content.
|
|
65
|
+
const message = error instanceof z.ZodError
|
|
66
|
+
? "Invalid upload_file arguments; check filename, MIME type, encoding and content size"
|
|
67
|
+
: formatError(error, "uploading file");
|
|
68
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
package/src/tools/insights.ts
CHANGED
|
@@ -7,6 +7,25 @@ type InsightStatus = "active" | "acknowledged" | "dismissed";
|
|
|
7
7
|
type InsightSeverity = "info" | "warning" | "critical";
|
|
8
8
|
|
|
9
9
|
export function registerInsightTools(server: McpServer, sdk: CentraliSDK) {
|
|
10
|
+
registerTool<{ triggerId?: string; period?: 7 | 30 }>(
|
|
11
|
+
server,
|
|
12
|
+
"get_trigger_health",
|
|
13
|
+
"Inspect HTTP request acceptance separately from execution success. Returns durable receivedCount, acceptedCount, rejectedCount, rejectionReasonBreakdown, requestAcceptanceRate (null without arrivals), and executionSuccessRate. Completed decisions are buffered and rolled up about every five minutes. Storage interruptions may lose or duplicate observations; rates are approximate. In-flight requests are not counted. Counts begin at tracking rollout; older traffic is unavailable. Omit triggerId for workspace health including unattributed requests to unknown paths. Non-HTTP triggers have execution health only.",
|
|
14
|
+
{
|
|
15
|
+
triggerId: z.string().uuid().optional().describe("Trigger UUID; omit to list workspace health"),
|
|
16
|
+
period: z.union([z.literal(7), z.literal(30)]).optional().describe("Days of health history, default 30"),
|
|
17
|
+
},
|
|
18
|
+
async ({ triggerId, period }) => {
|
|
19
|
+
try {
|
|
20
|
+
const result = triggerId
|
|
21
|
+
? await sdk.triggers.healthTrend(triggerId, period)
|
|
22
|
+
: await sdk.triggers.health(period);
|
|
23
|
+
return { content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }] };
|
|
24
|
+
} catch (error: unknown) {
|
|
25
|
+
return { content: [{ type: "text", text: formatError(error, "getting trigger health") }], isError: true };
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
);
|
|
10
29
|
registerTool<{
|
|
11
30
|
recordSlug?: string;
|
|
12
31
|
status?: InsightStatus;
|
|
@@ -734,7 +734,7 @@ export function registerServiceAccountTools(
|
|
|
734
734
|
|
|
735
735
|
registerTool<any>(server,
|
|
736
736
|
"get_role",
|
|
737
|
-
"Get
|
|
737
|
+
"Get a role's name and description. Roles are labels; permissions bind resources and actions to policies that can match role names.",
|
|
738
738
|
{
|
|
739
739
|
roleId: z.string().describe("The role ID (UUID)"),
|
|
740
740
|
},
|
|
@@ -755,7 +755,7 @@ export function registerServiceAccountTools(
|
|
|
755
755
|
|
|
756
756
|
registerTool<any>(server,
|
|
757
757
|
"create_role",
|
|
758
|
-
"Create a new role. Roles are named labels assigned to users and service accounts. They do NOT contain
|
|
758
|
+
"Create a new role. Roles are named labels assigned to users and service accounts. They do NOT contain permission IDs. To grant narrow access, assign the role to the service account, create_policy with an in_list condition on the roles attribute matching the role name, then create_permission binding that policyId to a resourceId and only the required actions (e.g. files + ['create']). Role names are immutable after creation.",
|
|
759
759
|
{
|
|
760
760
|
name: z.string().describe("Role name (e.g., 'Data Reader', 'Compute Admin'). Cannot be changed after creation."),
|
|
761
761
|
description: z.string().optional().describe("Optional description of the role's purpose"),
|
|
@@ -1114,9 +1114,9 @@ export function registerServiceAccountTools(
|
|
|
1114
1114
|
|
|
1115
1115
|
registerTool<any>(server,
|
|
1116
1116
|
"create_policy",
|
|
1117
|
-
"Create
|
|
1117
|
+
"Create a policy with name and specification. A policy matches identity attributes; create_permission binds its policyId to a resourceId and actions. For a role, use {\"name\":\"upload-only\",\"specification\":{\"rules\":[{\"rule_id\":\"allow-upload-role\",\"effect\":\"Allow\",\"conditions\":[{\"function\":\"in_list\",\"attribute\":\"roles\",\"value\":\"file_uploaders\"}]}],\"default\":{\"rule_id\":\"default-deny\",\"effect\":\"Deny\"}}}. Match the role NAME, not its UUID. A policy alone grants no access.",
|
|
1118
1118
|
{
|
|
1119
|
-
policy: z.record(z.string(), z.any()).describe("
|
|
1119
|
+
policy: z.record(z.string(), z.any()).describe("Required: {name: string, specification: {rules: [{rule_id: string, effect: 'Allow'|'Deny', conditions: [{function: string, attribute: string, value?: any}]}], default: {rule_id: string, effect: 'Allow'|'Deny'}}}. Optional: description. Use distinct rule IDs. Resources and actions belong in create_permission, not here."),
|
|
1120
1120
|
},
|
|
1121
1121
|
async ({ policy }) => {
|
|
1122
1122
|
try {
|
|
@@ -12,8 +12,11 @@ test("master description distinguishes retired services, interface coverage and
|
|
|
12
12
|
assert.match(features["Search"].note, /PostgreSQL/);
|
|
13
13
|
assert.match(features["Search"].note, /Meilisearch.*retired/);
|
|
14
14
|
assert.equal(features["File uploads"].console, true);
|
|
15
|
-
assert.equal(features["File uploads"].mcp,
|
|
16
|
-
assert.match(features["File uploads"].note, /
|
|
15
|
+
assert.equal(features["File uploads"].mcp, true);
|
|
16
|
+
assert.match(features["File uploads"].note, /upload_file/);
|
|
17
|
+
assert.match(features["File uploads"].note, /256 KiB decoded/);
|
|
18
|
+
assert.match(features["File uploads"].note, /768 KiB serialized/);
|
|
19
|
+
assert.match(features["File uploads"].note, /passive MIME type/);
|
|
17
20
|
assert.match(features["Realtime subscriptions (SSE)"].note, /REST SSE/);
|
|
18
21
|
assert.match(description.availability_notes.retired, /Pages.*retired/);
|
|
19
22
|
assert.match(description.availability_notes.provider_presets, /do not provision/);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const test = require("node:test");
|
|
2
|
+
const assert = require("node:assert/strict");
|
|
3
|
+
const http = require("node:http");
|
|
4
|
+
const { CentraliSDK } = require("@centrali-io/centrali-sdk");
|
|
5
|
+
const { registerFileTools } = require("../dist/tools/files.js");
|
|
6
|
+
|
|
7
|
+
const base = { filename: "image.png", contentType: "image/png", contentEncoding: "base64", content: "AAEC/w==" };
|
|
8
|
+
|
|
9
|
+
function setup(sdk) {
|
|
10
|
+
let handler;
|
|
11
|
+
registerFileTools({ tool: (_name, _description, _schema, fn) => { handler = fn; } }, sdk);
|
|
12
|
+
return handler;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test("uploads exact binary bytes privately and returns file handles without content", async () => {
|
|
16
|
+
let uploaded;
|
|
17
|
+
const handler = setup({
|
|
18
|
+
uploadFile: async (file, location, isPublic) => {
|
|
19
|
+
uploaded = { file, location, isPublic };
|
|
20
|
+
return { data: "render-id" };
|
|
21
|
+
},
|
|
22
|
+
getFileRenderUrl: id => `https://example.test/render/${id}`,
|
|
23
|
+
getFileDownloadUrl: id => `https://example.test/download/${id}`,
|
|
24
|
+
});
|
|
25
|
+
const result = await handler(base);
|
|
26
|
+
assert.equal(result.isError, undefined);
|
|
27
|
+
assert.deepEqual(Buffer.from(await uploaded.file.arrayBuffer()), Buffer.from([0, 1, 2, 255]));
|
|
28
|
+
assert.equal(uploaded.file.name, "image.png");
|
|
29
|
+
assert.equal(uploaded.file.type, "image/png");
|
|
30
|
+
assert.equal(uploaded.location, undefined);
|
|
31
|
+
assert.equal(uploaded.isPublic, false);
|
|
32
|
+
assert.deepEqual(JSON.parse(result.content[0].text), {
|
|
33
|
+
renderId: "render-id", sizeBytes: 4, contentType: "image/png", isPublic: false,
|
|
34
|
+
renderUrl: "https://example.test/render/render-id", downloadUrl: "https://example.test/download/render-id",
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("rejects malformed, noncanonical and oversized content before calling Storage", async () => {
|
|
39
|
+
const handler = setup({ uploadFile: async () => { assert.fail("must not upload invalid input"); } });
|
|
40
|
+
for (const changes of [
|
|
41
|
+
{ content: "%%%!" }, { content: "Zg" }, { content: "Zh==" },
|
|
42
|
+
{ content: "data:image/png;base64,AAEC/w==" }, { content: "AAEC/w==\n" },
|
|
43
|
+
{ filename: "../image.png" }, { filename: "a\\b" },
|
|
44
|
+
{ contentType: "image/png\r\nX-Test: x" }, { contentEncoding: "hex" },
|
|
45
|
+
{ content: Buffer.alloc(256 * 1024 + 1).toString("base64") },
|
|
46
|
+
{ contentEncoding: "utf8", content: "é".repeat(128 * 1024 + 1) },
|
|
47
|
+
]) {
|
|
48
|
+
const result = await handler({ ...base, ...changes });
|
|
49
|
+
assert.equal(result.isError, true, JSON.stringify(Object.keys(changes)));
|
|
50
|
+
assert.ok(result.content[0].text.length < 300, "errors must not echo file bytes");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("public uploads reject active and unlisted MIME types before reaching Storage", async () => {
|
|
55
|
+
const handler = setup({ uploadFile: async () => { assert.fail("must not upload public active content"); } });
|
|
56
|
+
for (const contentType of ["text/html", "TEXT/HTML", "image/svg+xml", "application/xhtml+xml", "application/xml", "application/pdf", "application/octet-stream"]) {
|
|
57
|
+
const result = await handler({ ...base, contentType, isPublic: true });
|
|
58
|
+
assert.equal(result.isError, true, contentType);
|
|
59
|
+
assert.match(result.content[0].text, /passive MIME type/);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("private active documents and empty files preserve their exact content", async () => {
|
|
64
|
+
const calls = [];
|
|
65
|
+
const handler = setup({
|
|
66
|
+
uploadFile: async (file, _location, isPublic) => {
|
|
67
|
+
calls.push({ bytes: Buffer.from(await file.arrayBuffer()), isPublic, type: file.type });
|
|
68
|
+
return { data: "id" };
|
|
69
|
+
},
|
|
70
|
+
getFileRenderUrl: () => "render", getFileDownloadUrl: () => "download",
|
|
71
|
+
});
|
|
72
|
+
for (const contentEncoding of ["base64", "utf8"]) {
|
|
73
|
+
const result = await handler({ ...base, contentEncoding, content: "" });
|
|
74
|
+
assert.equal(result.isError, undefined);
|
|
75
|
+
assert.equal(JSON.parse(result.content[0].text).sizeBytes, 0);
|
|
76
|
+
}
|
|
77
|
+
assert.equal((await handler({ ...base, contentType: "text/html", contentEncoding: "utf8", content: "<p>hello</p>" })).isError, undefined);
|
|
78
|
+
assert.deepEqual(calls.map(call => call.isPublic), [false, false, false]);
|
|
79
|
+
assert.equal(calls[2].bytes.toString(), "<p>hello</p>");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("JSON escaping is bounded while base64 still supports 256 KiB of control bytes", async () => {
|
|
83
|
+
let calls = 0;
|
|
84
|
+
const handler = setup({
|
|
85
|
+
uploadFile: async () => { calls++; return { data: "id" }; },
|
|
86
|
+
getFileRenderUrl: () => "render", getFileDownloadUrl: () => "download",
|
|
87
|
+
});
|
|
88
|
+
const content = "\u0000".repeat(256 * 1024);
|
|
89
|
+
assert.equal((await handler({ ...base, contentEncoding: "utf8", content })).isError, true);
|
|
90
|
+
assert.equal(calls, 0);
|
|
91
|
+
const accepted = { ...base, contentEncoding: "utf8", content: "\u0000".repeat(120 * 1024) };
|
|
92
|
+
assert.ok(Buffer.byteLength(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "upload_file", arguments: accepted } })) < 1024 * 1024);
|
|
93
|
+
assert.equal((await handler(accepted)).isError, undefined);
|
|
94
|
+
assert.equal((await handler({ ...base, content: Buffer.from(content).toString("base64") })).isError, undefined);
|
|
95
|
+
assert.equal(calls, 2);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("accepts the exact decoded size limit", async () => {
|
|
99
|
+
const handler = setup({
|
|
100
|
+
uploadFile: async file => { assert.equal(file.size, 256 * 1024); return { data: "id" }; },
|
|
101
|
+
getFileRenderUrl: () => "render", getFileDownloadUrl: () => "download",
|
|
102
|
+
});
|
|
103
|
+
assert.equal((await handler({ ...base, content: Buffer.alloc(256 * 1024).toString("base64") })).isError, undefined);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("reports Storage authorization and folder failures as tool errors", async () => {
|
|
107
|
+
for (const status of [403, 404, 409, 500]) {
|
|
108
|
+
const handler = setup({ uploadFile: async () => { throw { status, message: "Upload refused" }; } });
|
|
109
|
+
const result = await handler(base);
|
|
110
|
+
assert.equal(result.isError, true);
|
|
111
|
+
assert.match(result.content[0].text, new RegExp(String(status)));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("real SDK sends authenticated workspace multipart, UTF-8, folder and explicit visibility", async t => {
|
|
116
|
+
let captured;
|
|
117
|
+
const server = http.createServer(async (req, res) => {
|
|
118
|
+
const chunks = [];
|
|
119
|
+
for await (const chunk of req) chunks.push(chunk);
|
|
120
|
+
captured = { url: req.url, headers: req.headers, body: Buffer.concat(chunks).toString("utf8") };
|
|
121
|
+
res.setHeader("Content-Type", "application/json");
|
|
122
|
+
res.end(JSON.stringify("render-id"));
|
|
123
|
+
});
|
|
124
|
+
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
|
125
|
+
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
126
|
+
const baseUrl = `http://127.0.0.1:${server.address().port}`;
|
|
127
|
+
const sdk = new CentraliSDK({ baseUrl, workspaceId: "authenticated-workspace", axiosConfig: { baseURL: baseUrl } });
|
|
128
|
+
sdk.setToken("test-token");
|
|
129
|
+
const result = await setup(sdk)({
|
|
130
|
+
...base, filename: "note.txt", contentType: "text/plain", contentEncoding: "utf8",
|
|
131
|
+
content: "Hello 🌍", location: "/root/shared/notes", isPublic: true,
|
|
132
|
+
workspaceId: "attacker-workspace",
|
|
133
|
+
});
|
|
134
|
+
assert.equal(result.isError, undefined, result.content[0].text);
|
|
135
|
+
assert.match(captured.url, /authenticated-workspace/);
|
|
136
|
+
assert.ok(!captured.url.includes("attacker-workspace"));
|
|
137
|
+
assert.equal(captured.headers.authorization, "Bearer test-token");
|
|
138
|
+
assert.match(captured.headers["content-type"], /multipart\/form-data; boundary=/);
|
|
139
|
+
assert.match(captured.body, /filename="note.txt"/);
|
|
140
|
+
assert.match(captured.body, /Hello 🌍/);
|
|
141
|
+
assert.match(captured.body, /name="location"\r\n\r\n\/root\/shared\/notes/);
|
|
142
|
+
assert.match(captured.body, /name="isPublic"\r\n\r\ntrue/);
|
|
143
|
+
});
|
|
@@ -92,3 +92,23 @@ test('delete description permits already-revoked accounts', () => {
|
|
|
92
92
|
assert.doesNotMatch(description, /must not be revoked|revoke prevents deletion/);
|
|
93
93
|
} finally { restore(); }
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
test('policy guidance supplies the IAM specification format and keeps actions in permissions', async () => {
|
|
97
|
+
const { calls, tools, restore } = setup();
|
|
98
|
+
try {
|
|
99
|
+
const tool = tools.get('create_policy');
|
|
100
|
+
// Execute the exact example advertised to agents, rather than inventing a second fixture.
|
|
101
|
+
const example = tool.description.match(/use (\{.*\})\. Match/)[1];
|
|
102
|
+
const policy = JSON.parse(example);
|
|
103
|
+
assert.equal(policy.specification.rules[0].effect, 'Allow');
|
|
104
|
+
assert.equal(policy.specification.rules[0].conditions[0].attribute, 'roles');
|
|
105
|
+
assert.equal(policy.specification.rules[0].conditions[0].value, 'file_uploaders');
|
|
106
|
+
assert.equal(policy.specification.default.effect, 'Deny');
|
|
107
|
+
assert.match(tool.schema.policy.description, /specification/);
|
|
108
|
+
assert.doesNotMatch(tool.schema.policy.description, /principals/);
|
|
109
|
+
assert.match(tools.get('create_role').description, /create_permission.*required actions/);
|
|
110
|
+
await tool.handler({ policy });
|
|
111
|
+
assert.equal(calls[0].method, 'post');
|
|
112
|
+
assert.equal(calls[0].body, policy);
|
|
113
|
+
} finally { restore(); }
|
|
114
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { registerInsightTools } = require('../dist/tools/insights.js');
|
|
4
|
+
|
|
5
|
+
test('trigger health tool exposes independent metrics and routes workspace / trigger reads', async () => {
|
|
6
|
+
const tools = new Map();
|
|
7
|
+
const calls = [];
|
|
8
|
+
const metrics = { receivedCount: 12, rejectedCount: 12, requestAcceptanceRate: 0, executionSuccessRate: 1 };
|
|
9
|
+
registerInsightTools({ tool: (name, description, schema, handler) => tools.set(name, { description, schema, handler }) }, {
|
|
10
|
+
triggers: {
|
|
11
|
+
health: async (...args) => { calls.push(['list', ...args]); return { data: metrics }; },
|
|
12
|
+
healthTrend: async (...args) => { calls.push(['trend', ...args]); return { data: metrics }; },
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const tool = tools.get('get_trigger_health');
|
|
16
|
+
assert.match(tool.description, /executionSuccessRate/);
|
|
17
|
+
assert.equal(tool.schema.period.safeParse(14).success, false);
|
|
18
|
+
assert.equal(tool.schema.triggerId.safeParse('bad-id').success, false);
|
|
19
|
+
assert.deepEqual(JSON.parse((await tool.handler({ period: 7 })).content[0].text), metrics);
|
|
20
|
+
await tool.handler({ triggerId: 'trigger-1', period: 30 });
|
|
21
|
+
assert.deepEqual(calls, [['list', 7], ['trend', 'trigger-1', 30]]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('real SDK controller envelopes keep workspace metadata and trend summary in MCP output', async () => {
|
|
25
|
+
const { CentraliSDK } = require('@centrali-io/centrali-sdk');
|
|
26
|
+
const tools = new Map();
|
|
27
|
+
const summary = { executionSuccessRate: 1, requestAcceptanceRate: 0, rejectedCount: 12 };
|
|
28
|
+
const list = { data: [{ triggerId: 't', ...summary }], meta: { unattributedRequests: { rejectedCount: 3 } } };
|
|
29
|
+
const trend = { trigger: { id: 't' }, data: [{ date: '2026-10-27', ...summary }], summary };
|
|
30
|
+
const sdk = new CentraliSDK({ baseUrl: 'https://example.com', workspaceId: 'acme', token: 'test', axiosConfig: {
|
|
31
|
+
adapter: async config => ({ data: config.url.endsWith('/trend') ? trend : list, status: 200, statusText: 'OK', headers: {}, config }),
|
|
32
|
+
} });
|
|
33
|
+
registerInsightTools({ tool: (name, description, schema, handler) => tools.set(name, handler) }, sdk);
|
|
34
|
+
const handle = tools.get('get_trigger_health');
|
|
35
|
+
assert.deepEqual(JSON.parse((await handle({ period: 7 })).content[0].text), list);
|
|
36
|
+
assert.deepEqual(JSON.parse((await handle({ triggerId: 't', period: 7 })).content[0].text).summary, summary);
|
|
37
|
+
});
|