@sentientui/mcp 0.19.0 → 0.21.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/AGENTS.md +60 -27
- package/README.md +45 -28
- package/dist/{chunk-HT23NB6F.js → chunk-K7JN3LOH.js} +481 -49
- package/dist/index.cjs +486 -49
- package/dist/index.js +6 -1
- package/dist/lib.cjs +531 -49
- package/dist/lib.d.cts +29 -2
- package/dist/lib.d.ts +29 -2
- package/dist/lib.js +49 -1
- package/package.json +3 -2
package/dist/lib.cjs
CHANGED
|
@@ -41,6 +41,8 @@ __export(lib_exports, {
|
|
|
41
41
|
ApiClient: () => ApiClient,
|
|
42
42
|
ApiError: () => ApiError,
|
|
43
43
|
PUBLIC_UI_RESOURCE_URIS: () => PUBLIC_UI_RESOURCE_URIS,
|
|
44
|
+
TOOL_CATALOG: () => TOOL_CATALOG,
|
|
45
|
+
TOOL_NAMES: () => TOOL_NAMES,
|
|
44
46
|
createMcpServer: () => createMcpServer
|
|
45
47
|
});
|
|
46
48
|
module.exports = __toCommonJS(lib_exports);
|
|
@@ -56,9 +58,10 @@ var import_zod = require("zod");
|
|
|
56
58
|
|
|
57
59
|
// src/api-client.ts
|
|
58
60
|
var ApiError = class extends Error {
|
|
59
|
-
constructor(status, message) {
|
|
61
|
+
constructor(status, message, detail) {
|
|
60
62
|
super(message);
|
|
61
63
|
this.status = status;
|
|
64
|
+
this.detail = detail;
|
|
62
65
|
this.name = "ApiError";
|
|
63
66
|
}
|
|
64
67
|
};
|
|
@@ -75,8 +78,14 @@ var ApiClient = class {
|
|
|
75
78
|
async post(path, body) {
|
|
76
79
|
return this.request("POST", path, body);
|
|
77
80
|
}
|
|
81
|
+
async patch(path, body) {
|
|
82
|
+
return this.request("PATCH", path, body);
|
|
83
|
+
}
|
|
84
|
+
async delete(path, body) {
|
|
85
|
+
return this.request("DELETE", path, body);
|
|
86
|
+
}
|
|
78
87
|
async request(method, path, body, isRetry = false) {
|
|
79
|
-
var _a, _b;
|
|
88
|
+
var _a, _b, _c;
|
|
80
89
|
const res = await fetch(`${this.baseUrl}/v1/mgmt${path}`, {
|
|
81
90
|
method,
|
|
82
91
|
headers: __spreadValues({
|
|
@@ -93,7 +102,9 @@ var ApiClient = class {
|
|
|
93
102
|
return this.request(method, path, body, true);
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
|
-
|
|
105
|
+
const code = String((_b = (_a = errBody.error) != null ? _a : errBody.message) != null ? _b : res.statusText);
|
|
106
|
+
const human = (_c = errBody.message) != null ? _c : errBody.reason;
|
|
107
|
+
throw new ApiError(res.status, code, typeof human === "string" && human !== code ? human : void 0);
|
|
97
108
|
}
|
|
98
109
|
};
|
|
99
110
|
|
|
@@ -165,7 +176,7 @@ function localDate(iso, timeZone) {
|
|
|
165
176
|
}
|
|
166
177
|
function apiErrorGuidance(err, extra) {
|
|
167
178
|
if (extra && Object.prototype.hasOwnProperty.call(extra, err.message)) {
|
|
168
|
-
return extra[err.message];
|
|
179
|
+
return extra[err.message] + detailSuffix(err);
|
|
169
180
|
}
|
|
170
181
|
switch (err.message) {
|
|
171
182
|
case "insufficient_scope":
|
|
@@ -174,6 +185,15 @@ function apiErrorGuidance(err, extra) {
|
|
|
174
185
|
return "Demo mode is read-only. Create a SentientUI account and sign in (or use a project server key) to make changes.";
|
|
175
186
|
case "insufficient_role":
|
|
176
187
|
return "Your account role does not permit this action \u2014 it needs the account owner or an admin.";
|
|
188
|
+
// The mgmt write routes answer a viewer with `role_required` (and origins
|
|
189
|
+
// with `not_authorized`), not `insufficient_role` — so every role refusal
|
|
190
|
+
// fell through to the generic 403 "check your key has access" advice and
|
|
191
|
+
// sent the agent re-authenticating for a permission it already had wrong.
|
|
192
|
+
case "role_required":
|
|
193
|
+
case "not_authorized":
|
|
194
|
+
return `Your role on this project cannot make this change \u2014 it needs an editor or admin.${detailSuffix(err)}`;
|
|
195
|
+
case "ai_unavailable":
|
|
196
|
+
return "AI generation is unavailable on the SentientUI server right now (no model is configured). Nothing was queued \u2014 retry later.";
|
|
177
197
|
default:
|
|
178
198
|
break;
|
|
179
199
|
}
|
|
@@ -205,10 +225,25 @@ function apiErrorGuidance(err, extra) {
|
|
|
205
225
|
return `This feature requires a higher plan (${err.message}). Upgrade your SentientUI plan, then try again.`;
|
|
206
226
|
}
|
|
207
227
|
if (err.status === 403) {
|
|
208
|
-
return `Access denied (${err.message}). Check that your key or login has access to this project
|
|
228
|
+
return `Access denied (${err.message}). Check that your key or login has access to this project.${detailSuffix(err)}`;
|
|
229
|
+
}
|
|
230
|
+
if (err.status === 404) {
|
|
231
|
+
return `Not found (${err.message}). The project, component, variant, goal or cell does not exist, or this credential cannot see it (an sk_ server key sees only its own project). Re-read the ids with list_projects, list_components, list_goals or get_cell_matrix and retry with an exact id.` + detailSuffix(err);
|
|
232
|
+
}
|
|
233
|
+
if (err.status === 400) {
|
|
234
|
+
return `The API rejected the arguments (${err.message}).${detailSuffix(err)} Correct the input and retry \u2014 repeating the same call will fail the same way.`;
|
|
235
|
+
}
|
|
236
|
+
if (err.status === 409) {
|
|
237
|
+
return `Conflict (${err.message}): the target's current state does not allow this.${detailSuffix(err)} Read its current state first, then retry the step that makes this valid.`;
|
|
238
|
+
}
|
|
239
|
+
if (err.status === 502 || err.status === 503 || err.status === 504) {
|
|
240
|
+
return `SentientUI is temporarily unavailable (${err.status} ${err.message}). Nothing changed \u2014 wait a moment and retry.`;
|
|
209
241
|
}
|
|
210
242
|
return null;
|
|
211
243
|
}
|
|
244
|
+
function detailSuffix(err) {
|
|
245
|
+
return err.detail ? ` Server says: ${untrusted(err.detail, 300)}` : "";
|
|
246
|
+
}
|
|
212
247
|
async function settled(p) {
|
|
213
248
|
try {
|
|
214
249
|
return { ok: true, value: await p };
|
|
@@ -321,6 +356,37 @@ function registerProjectTools(server, client) {
|
|
|
321
356
|
};
|
|
322
357
|
}, CREATE_PROJECT_GUIDANCE)
|
|
323
358
|
);
|
|
359
|
+
server.registerTool(
|
|
360
|
+
"add_origin",
|
|
361
|
+
{
|
|
362
|
+
title: "Add allowed origin",
|
|
363
|
+
description: "Allow-list a site origin (scheme + host, e.g. https://www.example.com) so the SDK's events from it are accepted. Idempotent: an origin already on the list is left as is. Removing an origin is dashboard-only. Needs an editor/admin login or the project's sk_ server key. Confirm the exact origin with the user first \u2014 an allowed origin can send events into this project.",
|
|
364
|
+
inputSchema: {
|
|
365
|
+
projectId: projectIdSchema,
|
|
366
|
+
origin: import_zod2.z.string().min(1).max(500).describe("The site origin, e.g. https://www.example.com (a pasted page URL is reduced to its origin)")
|
|
367
|
+
},
|
|
368
|
+
outputSchema: {
|
|
369
|
+
origins: import_zod2.z.array(import_zod2.z.string()).describe("The full allow-list after the change")
|
|
370
|
+
},
|
|
371
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
372
|
+
},
|
|
373
|
+
withApiErrorGuidance(async ({ projectId, origin }) => {
|
|
374
|
+
var _a;
|
|
375
|
+
const id = encodeURIComponent(projectId);
|
|
376
|
+
const res = await client.post(`/projects/${id}/origins`, { origin });
|
|
377
|
+
const origins = (_a = res.origins) != null ? _a : [];
|
|
378
|
+
return {
|
|
379
|
+
content: [{
|
|
380
|
+
type: "text",
|
|
381
|
+
text: `Allowed origins: ${origins.map((o) => untrusted(o)).join(", ") || "(none)"}. Events from these origins are accepted (other API instances pick the change up within ~30 seconds, when their key cache expires).`
|
|
382
|
+
}],
|
|
383
|
+
structuredContent: { origins }
|
|
384
|
+
};
|
|
385
|
+
}, {
|
|
386
|
+
invalid_origin: "That is not a usable origin. Pass a scheme and host, e.g. https://www.example.com.",
|
|
387
|
+
origin_required: "An origin is required, e.g. https://www.example.com."
|
|
388
|
+
})
|
|
389
|
+
);
|
|
324
390
|
server.registerTool(
|
|
325
391
|
"list_projects",
|
|
326
392
|
{
|
|
@@ -365,13 +431,16 @@ function registerProjectTools(server, client) {
|
|
|
365
431
|
"get_project_stats",
|
|
366
432
|
{
|
|
367
433
|
title: "Project health stats",
|
|
368
|
-
description: "Get health
|
|
434
|
+
description: "Get ingestion health for a project: status, events and sessions in the last 24 hours, the time of the last event, and the all-time count of calls to the SentientUI agent API (/v1/agent) \u2014 NOT MCP tool calls.",
|
|
369
435
|
inputSchema: { projectId: projectIdSchema },
|
|
370
436
|
outputSchema: {
|
|
371
437
|
status: import_zod2.z.string().describe("Overall project health status"),
|
|
372
438
|
events24h: import_zod2.z.number().describe("Events in the last 24 hours"),
|
|
373
439
|
sessions24h: import_zod2.z.number().describe("Sessions in the last 24 hours"),
|
|
374
|
-
|
|
440
|
+
// Was "Total agent (MCP/API) calls" — but the count comes from
|
|
441
|
+
// agent_events, which only the /v1/agent endpoint writes. MCP tool calls
|
|
442
|
+
// are never in it, so an agent read its own activity as missing.
|
|
443
|
+
agentCalls: import_zod2.z.number().describe("All-time calls to the /v1/agent agent API (not MCP tool calls)"),
|
|
375
444
|
lastEventAt: import_zod2.z.string().nullable().describe("ISO timestamp of the last event, or null")
|
|
376
445
|
},
|
|
377
446
|
annotations: {
|
|
@@ -388,7 +457,7 @@ function registerProjectTools(server, client) {
|
|
|
388
457
|
`Status: ${stats.status}`,
|
|
389
458
|
`Events (24h): ${stats.events24h}`,
|
|
390
459
|
`Sessions (24h): ${stats.sessions24h}`,
|
|
391
|
-
`Agent calls (
|
|
460
|
+
`Agent API calls (/v1/agent, all-time): ${stats.agentCalls}`,
|
|
392
461
|
`Last event: ${(_a = stats.lastEventAt) != null ? _a : "never"}`
|
|
393
462
|
].join("\n");
|
|
394
463
|
return {
|
|
@@ -681,6 +750,10 @@ var EVIDENCE_LABEL = {
|
|
|
681
750
|
early_signal: "Early signal (still moving \u2014 not a result)",
|
|
682
751
|
moderate_evidence: "Moderate evidence (about one call in five of this strength is wrong \u2014 not decided)",
|
|
683
752
|
strong_evidence: "Strong evidence",
|
|
753
|
+
// The mirror of moderate_evidence. Before the server had it, an arm clearly
|
|
754
|
+
// behind its baseline read "Inconclusive (… without separating)" — it HAD
|
|
755
|
+
// separated, downward.
|
|
756
|
+
likely_worse: "Likely worse than the baseline (about one call in five of this strength is wrong \u2014 not decided)",
|
|
684
757
|
inconclusive: "Inconclusive (ran a full period without separating from the baseline)"
|
|
685
758
|
};
|
|
686
759
|
var STATES = new Set(Object.keys(EVIDENCE_LABEL));
|
|
@@ -731,7 +804,9 @@ function verdictOf(state, stats, isBaseline) {
|
|
|
731
804
|
var VERDICT_TEXT = {
|
|
732
805
|
ahead: "reliably AHEAD of the baseline",
|
|
733
806
|
behind: "reliably BEHIND the baseline",
|
|
734
|
-
|
|
807
|
+
// "not RELIABLY": this is printed beside moderate_evidence and likely_worse
|
|
808
|
+
// labels too, and a bare "not separated" contradicted the label next to it.
|
|
809
|
+
unclear: "not reliably separated from the baseline",
|
|
735
810
|
no_evidence: "no evidence available from the server"
|
|
736
811
|
};
|
|
737
812
|
function rateWithN(conversions, n, unit = "sessions") {
|
|
@@ -817,7 +892,7 @@ function registerComponentTools(server, client) {
|
|
|
817
892
|
conversions: import_zod3.z.number().describe("Converting sessions in the window"),
|
|
818
893
|
currentCvr: import_zod3.z.number().nullable().describe("conversions / sessions over the window (0-1); null at 0 sessions"),
|
|
819
894
|
lowSample: import_zod3.z.boolean().describe(`True under ${MIN_EVIDENCE_SAMPLE} sessions \u2014 the rate is not interpretable on its own`),
|
|
820
|
-
evidenceState: import_zod3.z.string().nullable().describe("Reliability (all time): the server's ALL-TIME evidence state vs the baseline on direct evidence \u2014 not_enough_data | early_signal | moderate_evidence | strong_evidence | inconclusive; null for the baseline or when not provided. Not a verdict on the windowed rate"),
|
|
895
|
+
evidenceState: import_zod3.z.string().nullable().describe("Reliability (all time): the server's ALL-TIME evidence state vs the baseline on direct evidence \u2014 not_enough_data | early_signal | moderate_evidence | strong_evidence | likely_worse | inconclusive; null for the baseline or when not provided. Not a verdict on the windowed rate"),
|
|
821
896
|
probBeatsBaseline: import_zod3.z.number().nullable().describe("P(this arm > baseline), all-time, from the server; null when not provided"),
|
|
822
897
|
reliabilityVerdict: import_zod3.z.enum(["baseline", "ahead", "behind", "unclear", "no_evidence"]).describe("The all-time verdict read from evidenceState \u2014 reliability (all time), which can differ from `verdict` on the window"),
|
|
823
898
|
windowEvidenceState: import_zod3.z.string().nullable().describe("The server's evidence state on the WINDOWED session conversion rate vs the baseline; null for the baseline, when the arm was not scored in the window, or on older APIs"),
|
|
@@ -1135,7 +1210,10 @@ function registerPersonaTools(server, client) {
|
|
|
1135
1210
|
"get_persona_breakdown",
|
|
1136
1211
|
{
|
|
1137
1212
|
title: "Persona breakdown",
|
|
1138
|
-
|
|
1213
|
+
// Takes no range/from/to on purpose: the API computes it over every
|
|
1214
|
+
// retained session and has no window. Saying so stops an agent from
|
|
1215
|
+
// reading it beside a 7d get_variant_performance as the same period.
|
|
1216
|
+
description: "Get the distribution of visitor persona clusters with session counts and reliability scores, over ALL retained human sessions (not windowed \u2014 this has no range input, unlike the conversion tools)." + UNTRUSTED_FIELDS_NOTE,
|
|
1139
1217
|
inputSchema: { projectId: projectIdSchema },
|
|
1140
1218
|
_meta: uiMeta("persona-breakdown"),
|
|
1141
1219
|
outputSchema: {
|
|
@@ -1196,8 +1274,13 @@ function registerGoalTools(server, client) {
|
|
|
1196
1274
|
server.registerTool(
|
|
1197
1275
|
"get_goal_funnel",
|
|
1198
1276
|
{
|
|
1199
|
-
|
|
1200
|
-
|
|
1277
|
+
// Named get_goal_funnel for compatibility (renaming a published tool
|
|
1278
|
+
// breaks every saved prompt and host allow-list), but it is NOT a funnel:
|
|
1279
|
+
// agents asked it for step drop-off and reported per-goal rates as funnel
|
|
1280
|
+
// stages. The title and the first words of the description now say what
|
|
1281
|
+
// it is, and point to the real funnel tool.
|
|
1282
|
+
title: "Goal conversions (per goal \u2014 not a step funnel)",
|
|
1283
|
+
description: "Per-goal conversion summary \u2014 NOT a step funnel (for step-by-step drop-off use list_funnels + get_funnel_report). Gets goal hit counts and unique-session conversion rates for a window (default: last 30 calendar days), plus a per-variant breakdown. NOTE: the per-variant completionRate values are ALL-TIME (bounded only by plan retention), NOT windowed \u2014 a variant completion rate needs the full assignment history as its denominator, so it does not change when you narrow `range`, and retired components keep appearing in it. Only hits/uniqueSessions/conversionRate/revenue respect the window. Per-variant rates are descriptive, not joined to the evidence verdicts \u2014 for whether an arm is ahead, use get_variant_performance." + UNTRUSTED_FIELDS_NOTE,
|
|
1201
1284
|
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
1202
1285
|
_meta: uiMeta("goal-funnel"),
|
|
1203
1286
|
outputSchema: {
|
|
@@ -1378,6 +1461,51 @@ function registerGoalTools(server, client) {
|
|
|
1378
1461
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent };
|
|
1379
1462
|
})
|
|
1380
1463
|
);
|
|
1464
|
+
server.registerTool(
|
|
1465
|
+
"define_goal",
|
|
1466
|
+
{
|
|
1467
|
+
title: "Define a new goal",
|
|
1468
|
+
description: "Create a NEW goal (conversion signal) for a project. Create-only: it never changes an existing goal \u2014 an id that already exists, including an archived one, is refused (goal_exists); call list_goals first. It never sets or changes the PRIMARY goal (what experiments optimize): the goal is created as 'secondary' (default) or 'guardrail'; choosing the primary stays a dashboard decision. A guardrail goal can pause variants that hurt it \u2014 say so when proposing one. Event types: url_reached (needs urlPattern, e.g. /thank-you), click / form_submit (need a locator, usually easier to pick in the dashboard on-site editor, or fire from code with client.goal('<goalId>') instead), scroll_depth (needs threshold in (0, 1]). Needs an editor/admin login or the project's sk_ server key. Confirm the goal id, event and pattern with the user before calling.",
|
|
1469
|
+
inputSchema: {
|
|
1470
|
+
projectId: projectIdSchema,
|
|
1471
|
+
goalId: import_zod6.z.string().min(1).max(128).refine((s) => !s.startsWith("funnel:"), "'funnel:' is reserved for funnel bindings").describe("Stable id code will reference, e.g. 'signup' or 'checkout-complete'. Must not exist yet."),
|
|
1472
|
+
event: import_zod6.z.enum(["url_reached", "click", "form_submit", "scroll_depth"]).describe("What counts as a conversion"),
|
|
1473
|
+
urlPattern: import_zod6.z.string().min(1).max(512).optional().describe("url_reached only: the path pattern, e.g. '/thank-you' or '/orders/*'"),
|
|
1474
|
+
locator: import_zod6.z.record(import_zod6.z.unknown()).optional().describe('click / form_submit only: the element locator (e.g. { "id": "signup-button" })'),
|
|
1475
|
+
threshold: import_zod6.z.number().gt(0).max(1).optional().describe("scroll_depth only: how far down the page counts, in (0, 1]"),
|
|
1476
|
+
displayName: import_zod6.z.string().min(1).max(128).optional().describe("Human-readable name shown in the dashboard"),
|
|
1477
|
+
role: import_zod6.z.enum(["secondary", "guardrail"]).optional().describe("secondary (default) is tracked and reported; guardrail can also pause variants that hurt it. Never 'primary'."),
|
|
1478
|
+
defaultValue: import_zod6.z.number().positive().max(1e9).optional().describe("Fixed worth of one conversion in the project currency (revenue goals)")
|
|
1479
|
+
},
|
|
1480
|
+
outputSchema: {
|
|
1481
|
+
goalId: import_zod6.z.string(),
|
|
1482
|
+
role: import_zod6.z.enum(["secondary", "guardrail"]).describe("Never primary \u2014 this tool cannot change the primary goal")
|
|
1483
|
+
},
|
|
1484
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
1485
|
+
},
|
|
1486
|
+
withApiErrorGuidance(async ({ projectId, goalId, event, urlPattern, locator, threshold, displayName, role, defaultValue }) => {
|
|
1487
|
+
var _a, _b, _c;
|
|
1488
|
+
const id = encodeURIComponent(projectId);
|
|
1489
|
+
const res = await client.post(`/projects/${id}/goal-definitions`, __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1490
|
+
goalId,
|
|
1491
|
+
event
|
|
1492
|
+
}, urlPattern !== void 0 ? { urlPattern } : {}), locator !== void 0 ? { locator } : {}), threshold !== void 0 ? { threshold } : {}), displayName !== void 0 ? { displayName } : {}), role !== void 0 ? { role } : {}), defaultValue !== void 0 ? { defaultValue } : {}));
|
|
1493
|
+
const structuredContent = { goalId: (_a = res.goalId) != null ? _a : goalId, role: (_c = (_b = res.role) != null ? _b : role) != null ? _c : "secondary" };
|
|
1494
|
+
return {
|
|
1495
|
+
content: [{
|
|
1496
|
+
type: "text",
|
|
1497
|
+
text: `Created goal ${untrusted(structuredContent.goalId)} (${structuredContent.role}, ${event}). It is active now. The primary goal was not changed \u2014 if this should be what experiments optimize, the owner can make it primary in the dashboard. Reference the goalId verbatim from code (client.goal('<goalId>')) if the event is not tracked automatically.`
|
|
1498
|
+
}],
|
|
1499
|
+
structuredContent
|
|
1500
|
+
};
|
|
1501
|
+
}, {
|
|
1502
|
+
goal_exists: "A goal with this id already exists (it may be archived). define_goal never changes an existing goal \u2014 pick a new id (see list_goals), or edit that goal in the dashboard.",
|
|
1503
|
+
primary_not_allowed: "define_goal never sets the primary goal. Create it as secondary; the owner can make it primary in the dashboard.",
|
|
1504
|
+
invalid_goal_id: "That goal id is not allowed: use 1-128 characters, and not the reserved 'funnel:' prefix.",
|
|
1505
|
+
invalid_goal: "The goal definition is incomplete for its event type: url_reached needs urlPattern, click/form_submit need a locator, scroll_depth needs threshold.",
|
|
1506
|
+
"Not Found": "This SentientUI API does not support creating goals from MCP yet (it predates create-only goals). Define the goal in the dashboard instead."
|
|
1507
|
+
})
|
|
1508
|
+
);
|
|
1381
1509
|
}
|
|
1382
1510
|
|
|
1383
1511
|
// src/tools/funnels.ts
|
|
@@ -1587,7 +1715,9 @@ function registerLayoutTools(server, client) {
|
|
|
1587
1715
|
"get_layout_stats",
|
|
1588
1716
|
{
|
|
1589
1717
|
title: "Layout stats",
|
|
1590
|
-
|
|
1718
|
+
// No window by design: these are the bandit's cumulative pulls and reward,
|
|
1719
|
+
// the state serving reads — not a report over a period.
|
|
1720
|
+
description: "Get per-persona section layout rankings with bandit pulls and average reward \u2014 the cumulative learning state serving uses (not windowed; there is no range input). avgReward is a reward signal, not a conversion rate." + UNTRUSTED_FIELDS_NOTE,
|
|
1591
1721
|
inputSchema: { projectId: projectIdSchema },
|
|
1592
1722
|
_meta: uiMeta("layout-stats"),
|
|
1593
1723
|
outputSchema: {
|
|
@@ -1639,7 +1769,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1639
1769
|
"create_variant",
|
|
1640
1770
|
{
|
|
1641
1771
|
title: "Create managed variant",
|
|
1642
|
-
description: "Create a NO-CODE managed text variant for a component (content stored in SentientUI, rendered by <AdaptiveText>). Use this ONLY for text-only variants the user wants without a code change. For variants that will live in the codebase (full components \u2014 copy, markup, styling), use get_variant_brief and write the variant in code instead; those auto-register on deploy and do not need create_variant.
|
|
1772
|
+
description: "Create a NO-CODE managed text variant for a component (content stored in SentientUI, rendered by <AdaptiveText>). Use this ONLY for text-only variants the user wants without a code change. For variants that will live in the codebase (full components \u2014 copy, markup, styling), use get_variant_brief and write the variant in code instead; those auto-register on deploy and do not need create_variant. Works on every plan with an editor/admin login or the project's sk_ server key (anonymous demo tokens are read-only). The variant is created as a DRAFT \u2014 it serves no traffic until activated with update_variant (status 'active'). Confirm the text with the user before calling.",
|
|
1643
1773
|
inputSchema: {
|
|
1644
1774
|
projectId: projectIdSchema,
|
|
1645
1775
|
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID to add a variant to"),
|
|
@@ -1673,7 +1803,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1673
1803
|
return {
|
|
1674
1804
|
content: [{
|
|
1675
1805
|
type: "text",
|
|
1676
|
-
text: `Managed text variant created: ${result.variantId} ("${result.displayName}") for component ${componentId}${contentNote}. It is
|
|
1806
|
+
text: `Managed text variant created: ${result.variantId} ("${result.displayName}") for component ${componentId}${contentNote}. It is a draft and serves no traffic yet \u2014 after the user confirms, activate it with update_variant (status 'active'), or delete it with delete_variant_draft. Reminder: this is a no-code managed variant; for code-native variants, edit the code instead (see get_variant_brief).`
|
|
1677
1807
|
}],
|
|
1678
1808
|
structuredContent: {
|
|
1679
1809
|
variantId: result.variantId,
|
|
@@ -1689,20 +1819,24 @@ function registerVariantWriteTools(server, client) {
|
|
|
1689
1819
|
"pause_variant",
|
|
1690
1820
|
{
|
|
1691
1821
|
title: "Pause variant",
|
|
1692
|
-
description: "Pause a variant
|
|
1822
|
+
description: "Pause a variant: no new traffic is assigned to it until it is resumed. This changes what live visitors see, so CONFIRM with the user before calling. Undo with resume_variant.",
|
|
1693
1823
|
inputSchema: {
|
|
1694
1824
|
projectId: projectIdSchema,
|
|
1695
|
-
componentId: import_zod10.z.string().describe("The component ID"),
|
|
1696
|
-
variantId: import_zod10.z.string().describe("The variant ID to pause")
|
|
1825
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1826
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The variant ID to pause")
|
|
1697
1827
|
},
|
|
1698
1828
|
outputSchema: {
|
|
1699
1829
|
variantId: import_zod10.z.string(),
|
|
1700
1830
|
componentId: import_zod10.z.string(),
|
|
1701
1831
|
paused: import_zod10.z.literal(true).describe("The variant is now paused")
|
|
1702
1832
|
},
|
|
1833
|
+
// destructiveHint was false, so hosts that gate destructive tools behind a
|
|
1834
|
+
// confirmation ran this without asking — yet it pulls a live arm out of
|
|
1835
|
+
// serving for every visitor. It is reversible (resume_variant), but the
|
|
1836
|
+
// hint is about the change to the environment, not about undo.
|
|
1703
1837
|
annotations: {
|
|
1704
1838
|
readOnlyHint: false,
|
|
1705
|
-
destructiveHint:
|
|
1839
|
+
destructiveHint: true,
|
|
1706
1840
|
idempotentHint: true,
|
|
1707
1841
|
openWorldHint: false
|
|
1708
1842
|
}
|
|
@@ -1713,17 +1847,194 @@ function registerVariantWriteTools(server, client) {
|
|
|
1713
1847
|
return {
|
|
1714
1848
|
content: [{
|
|
1715
1849
|
type: "text",
|
|
1716
|
-
text: `Variant ${variantId} in component ${componentId}
|
|
1850
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is paused. No new traffic will be assigned to it. Undo with resume_variant.`
|
|
1717
1851
|
}],
|
|
1718
1852
|
structuredContent: { variantId, componentId, paused: true }
|
|
1719
1853
|
};
|
|
1720
1854
|
})
|
|
1721
1855
|
);
|
|
1856
|
+
server.registerTool(
|
|
1857
|
+
"resume_variant",
|
|
1858
|
+
{
|
|
1859
|
+
title: "Resume variant",
|
|
1860
|
+
description: "Resume a paused variant so it is assigned traffic again \u2014 works for a manual pause (pause_variant) and for a guardrail auto-pause (see list_guardrail_events). Resuming a guardrail-paused arm puts a variant the guardrail judged harmful back in front of visitors, so CONFIRM with the user first.",
|
|
1861
|
+
inputSchema: {
|
|
1862
|
+
projectId: projectIdSchema,
|
|
1863
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1864
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The paused variant ID to resume")
|
|
1865
|
+
},
|
|
1866
|
+
outputSchema: {
|
|
1867
|
+
variantId: import_zod10.z.string(),
|
|
1868
|
+
componentId: import_zod10.z.string(),
|
|
1869
|
+
paused: import_zod10.z.literal(false).describe("The variant is no longer paused")
|
|
1870
|
+
},
|
|
1871
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1872
|
+
},
|
|
1873
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1874
|
+
const id = encodeURIComponent(projectId);
|
|
1875
|
+
await client.post(`/projects/${id}/guardrails/${encodeURIComponent(componentId)}/unpause`, {
|
|
1876
|
+
variantIds: [variantId]
|
|
1877
|
+
});
|
|
1878
|
+
return {
|
|
1879
|
+
content: [{
|
|
1880
|
+
type: "text",
|
|
1881
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is resumed and will be assigned traffic again.`
|
|
1882
|
+
}],
|
|
1883
|
+
structuredContent: { variantId, componentId, paused: false }
|
|
1884
|
+
};
|
|
1885
|
+
})
|
|
1886
|
+
);
|
|
1887
|
+
server.registerTool(
|
|
1888
|
+
"update_variant",
|
|
1889
|
+
{
|
|
1890
|
+
title: "Update managed variant",
|
|
1891
|
+
description: "Edit a NO-CODE managed variant (one created with create_variant or in the dashboard): its display name, its text, or its status \u2014 'active' starts serving it to visitors, 'draft' takes it back out of rotation. Code-native variants cannot be edited here (change the code). Overwriting text or activating changes what live visitors see, so CONFIRM with the user first. Omit a field to leave it unchanged.",
|
|
1892
|
+
inputSchema: {
|
|
1893
|
+
projectId: projectIdSchema,
|
|
1894
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1895
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The managed variant ID (dm_\u2026)"),
|
|
1896
|
+
displayName: import_zod10.z.string().min(1).max(200).optional().describe("New display name"),
|
|
1897
|
+
content: import_zod10.z.string().max(1e4).optional().describe("New text content (replaces the old text)"),
|
|
1898
|
+
status: import_zod10.z.enum(["draft", "active"]).optional().describe("'active' serves it; 'draft' stops serving it")
|
|
1899
|
+
},
|
|
1900
|
+
outputSchema: {
|
|
1901
|
+
variantId: import_zod10.z.string(),
|
|
1902
|
+
componentId: import_zod10.z.string(),
|
|
1903
|
+
changed: import_zod10.z.array(import_zod10.z.string()).describe("Fields that were sent for update"),
|
|
1904
|
+
status: import_zod10.z.enum(["draft", "active"]).nullable().describe("The new status, or null when unchanged")
|
|
1905
|
+
},
|
|
1906
|
+
// Destructive: the previous text is overwritten, not versioned.
|
|
1907
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1908
|
+
},
|
|
1909
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId, displayName, content, status }) => {
|
|
1910
|
+
const changed = [
|
|
1911
|
+
...displayName !== void 0 ? ["displayName"] : [],
|
|
1912
|
+
...content !== void 0 ? ["content"] : [],
|
|
1913
|
+
...status !== void 0 ? ["status"] : []
|
|
1914
|
+
];
|
|
1915
|
+
if (changed.length === 0) {
|
|
1916
|
+
return {
|
|
1917
|
+
content: [{ type: "text", text: "Nothing to update \u2014 pass displayName, content and/or status." }],
|
|
1918
|
+
isError: true
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
const id = encodeURIComponent(projectId);
|
|
1922
|
+
await client.patch(`/projects/${id}/variants`, { componentId, variantId, displayName, content, status });
|
|
1923
|
+
const statusNote = status === "active" ? " It is now ACTIVE and will be assigned traffic." : status === "draft" ? " It is now a draft and no longer serves traffic." : "";
|
|
1924
|
+
return {
|
|
1925
|
+
content: [{
|
|
1926
|
+
type: "text",
|
|
1927
|
+
text: `Managed variant ${untrusted(variantId)} in component ${untrusted(componentId)} updated (${changed.join(", ")}).${statusNote}`
|
|
1928
|
+
}],
|
|
1929
|
+
structuredContent: { variantId, componentId, changed, status: status != null ? status : null }
|
|
1930
|
+
};
|
|
1931
|
+
}, {
|
|
1932
|
+
// PATCH matches managed variants only, so a code-native id answers a
|
|
1933
|
+
// bare not_found that read as "that variant does not exist".
|
|
1934
|
+
not_found: "No MANAGED variant with that id exists in this component. Code-native variants (declared in <Adaptive variants>) are edited in the code, not here \u2014 check ids with list_components (a wrong projectId answers the same way)."
|
|
1935
|
+
})
|
|
1936
|
+
);
|
|
1937
|
+
server.registerTool(
|
|
1938
|
+
"delete_variant_draft",
|
|
1939
|
+
{
|
|
1940
|
+
title: "Delete draft variant",
|
|
1941
|
+
description: "Permanently delete a managed variant that is still a DRAFT (never activated). Active variants cannot be deleted \u2014 pause or retire them instead. CONFIRM with the user first: this cannot be undone.",
|
|
1942
|
+
inputSchema: {
|
|
1943
|
+
projectId: projectIdSchema,
|
|
1944
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1945
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The draft managed variant ID (dm_\u2026)")
|
|
1946
|
+
},
|
|
1947
|
+
outputSchema: {
|
|
1948
|
+
variantId: import_zod10.z.string(),
|
|
1949
|
+
componentId: import_zod10.z.string(),
|
|
1950
|
+
deleted: import_zod10.z.literal(true)
|
|
1951
|
+
},
|
|
1952
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1953
|
+
},
|
|
1954
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1955
|
+
const id = encodeURIComponent(projectId);
|
|
1956
|
+
await client.delete(`/projects/${id}/variants`, { componentId, variantId });
|
|
1957
|
+
return {
|
|
1958
|
+
content: [{
|
|
1959
|
+
type: "text",
|
|
1960
|
+
text: `Draft variant ${untrusted(variantId)} in component ${untrusted(componentId)} was deleted.`
|
|
1961
|
+
}],
|
|
1962
|
+
structuredContent: { variantId, componentId, deleted: true }
|
|
1963
|
+
};
|
|
1964
|
+
}, {
|
|
1965
|
+
// The API's DELETE matches managed drafts only, so an active or
|
|
1966
|
+
// code-native variant answers a bare not_found — say why.
|
|
1967
|
+
not_found: "No managed DRAFT variant with that id exists in this component. Active and code-native variants cannot be deleted \u2014 use pause_variant or retire_variant instead (check ids with list_components; a wrong projectId answers the same way)."
|
|
1968
|
+
})
|
|
1969
|
+
);
|
|
1970
|
+
server.registerTool(
|
|
1971
|
+
"retire_variant",
|
|
1972
|
+
{
|
|
1973
|
+
title: "Retire variant",
|
|
1974
|
+
description: "Retire (archive) an ACTIVE variant: it stops serving and moves to the archived list. Works for code-native variants that were removed from the code and linger. A promoted (pinned) variant must be unpromoted in the dashboard first. CONFIRM with the user first; undo with restore_variant.",
|
|
1975
|
+
inputSchema: {
|
|
1976
|
+
projectId: projectIdSchema,
|
|
1977
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1978
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The active variant ID to retire")
|
|
1979
|
+
},
|
|
1980
|
+
outputSchema: {
|
|
1981
|
+
variantId: import_zod10.z.string(),
|
|
1982
|
+
componentId: import_zod10.z.string(),
|
|
1983
|
+
status: import_zod10.z.literal("retired")
|
|
1984
|
+
},
|
|
1985
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1986
|
+
},
|
|
1987
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1988
|
+
const id = encodeURIComponent(projectId);
|
|
1989
|
+
await client.post(`/projects/${id}/variants/retire`, { componentId, variantId });
|
|
1990
|
+
return {
|
|
1991
|
+
content: [{
|
|
1992
|
+
type: "text",
|
|
1993
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is retired and no longer serves. Undo with restore_variant.`
|
|
1994
|
+
}],
|
|
1995
|
+
structuredContent: { variantId, componentId, status: "retired" }
|
|
1996
|
+
};
|
|
1997
|
+
}, {
|
|
1998
|
+
variant_promoted: "This variant is promoted (pinned as the winner), so it cannot be retired. Unpromote it in the dashboard first, then retry.",
|
|
1999
|
+
not_found: "No ACTIVE variant with that id exists in this component (it may already be retired, or still a draft), or the projectId is wrong. Check ids with list_components."
|
|
2000
|
+
})
|
|
2001
|
+
);
|
|
2002
|
+
server.registerTool(
|
|
2003
|
+
"restore_variant",
|
|
2004
|
+
{
|
|
2005
|
+
title: "Restore variant",
|
|
2006
|
+
description: "Bring a RETIRED variant back to active so it serves again. For a managed draft that was never activated use update_variant (status 'active') instead. Restoring does not clear a pause \u2014 use resume_variant for that. CONFIRM with the user first.",
|
|
2007
|
+
inputSchema: {
|
|
2008
|
+
projectId: projectIdSchema,
|
|
2009
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
2010
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The retired variant ID to restore")
|
|
2011
|
+
},
|
|
2012
|
+
outputSchema: {
|
|
2013
|
+
variantId: import_zod10.z.string(),
|
|
2014
|
+
componentId: import_zod10.z.string(),
|
|
2015
|
+
status: import_zod10.z.literal("active")
|
|
2016
|
+
},
|
|
2017
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
2018
|
+
},
|
|
2019
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
2020
|
+
const id = encodeURIComponent(projectId);
|
|
2021
|
+
await client.post(`/projects/${id}/variants/restore`, { componentId, variantId });
|
|
2022
|
+
return {
|
|
2023
|
+
content: [{
|
|
2024
|
+
type: "text",
|
|
2025
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is active again. If it was also paused, call resume_variant.`
|
|
2026
|
+
}],
|
|
2027
|
+
structuredContent: { variantId, componentId, status: "active" }
|
|
2028
|
+
};
|
|
2029
|
+
})
|
|
2030
|
+
);
|
|
1722
2031
|
server.registerTool(
|
|
1723
2032
|
"refresh_insights",
|
|
1724
2033
|
{
|
|
1725
2034
|
title: "Refresh insights",
|
|
1726
|
-
|
|
2035
|
+
// The plan and role gates were undocumented, so agents on Free called it
|
|
2036
|
+
// and got a bare 403 they could not explain to the user.
|
|
2037
|
+
description: "Trigger fresh AI insight generation for a project (a paid model call). Needs the Starter plan or higher and an editor/admin role (anonymous demo tokens are read-only); advisor recommendations additionally need Growth or higher. Returns immediately; call get_insights in ~15 seconds to see results.",
|
|
1727
2038
|
inputSchema: { projectId: projectIdSchema },
|
|
1728
2039
|
outputSchema: {
|
|
1729
2040
|
projectId: import_zod10.z.string(),
|
|
@@ -1775,11 +2086,21 @@ var BEST_PRACTICE_PRIORS = {
|
|
|
1775
2086
|
"Make the CTA specific and benefit-led.",
|
|
1776
2087
|
"Add a single strong proof point; remove competing distractions."
|
|
1777
2088
|
],
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2089
|
+
// Keys must be the project context types the API accepts (projects.ts
|
|
2090
|
+
// VALID_CONTEXT_TYPES: saas | ecommerce | marketing | landing | internal).
|
|
2091
|
+
// A `marketplace` key sat here that no project could ever have, while
|
|
2092
|
+
// marketing and internal projects silently fell through to the generic list.
|
|
2093
|
+
marketing: [
|
|
2094
|
+
'Make the page answer "what is this and why should I care" in the first screen.',
|
|
2095
|
+
"Give each section one job and one next step; cut competing CTAs.",
|
|
2096
|
+
"Put the strongest proof (named customers, a hard number) near the primary CTA.",
|
|
2097
|
+
"Match the copy to where the visitor came from (campaign, search intent)."
|
|
2098
|
+
],
|
|
2099
|
+
internal: [
|
|
2100
|
+
"Optimize for task completion, not persuasion: make the next step obvious.",
|
|
2101
|
+
"Reduce steps and fields; prefill what the system already knows.",
|
|
2102
|
+
"Use plain, specific labels over marketing copy.",
|
|
2103
|
+
"Make errors and empty states say exactly what to do next."
|
|
1783
2104
|
]
|
|
1784
2105
|
};
|
|
1785
2106
|
var GENERIC_PRIORS = [
|
|
@@ -1812,7 +2133,10 @@ function guidanceFor(dataState, contextType, arms) {
|
|
|
1812
2133
|
}
|
|
1813
2134
|
case "directional": {
|
|
1814
2135
|
const inconclusive = arms.some((a) => a.state === "inconclusive");
|
|
1815
|
-
|
|
2136
|
+
const likelyWorse = arms.filter((a) => !a.isBaseline && a.state === "likely_worse").map((a) => untrusted(a.variantId));
|
|
2137
|
+
return 'No comparison on this component is decided. Early, moderate and likely-worse signals are hypotheses, not results (each is wrong about one time in five), so do not target an arm as "under-" or "out-performing". ' + (likelyWorse.length ? `Probably behind the baseline (not decided): ${likelyWorse.join(", ")} \u2014 do not build on ${likelyWorse.length === 1 ? "it" : "them"}. ` : "") + // "did not separate" is not "do not differ": the old wording asserted
|
|
2138
|
+
// an equality the evidence never measured.
|
|
2139
|
+
(inconclusive ? "At least one arm ran a full period without separating from the baseline \u2014 any difference between the existing versions is too small to detect, so make a clearly different change rather than a tweak. " : "") + "Lean on the best-practice priors below and make one focused change.";
|
|
1816
2140
|
}
|
|
1817
2141
|
case "collecting":
|
|
1818
2142
|
if (!arms.some((a) => !a.isBaseline)) {
|
|
@@ -2310,12 +2634,12 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2310
2634
|
"get_agent_traffic",
|
|
2311
2635
|
{
|
|
2312
2636
|
title: "Agent traffic",
|
|
2313
|
-
description: "Which AI agents and crawlers are reading this site: totals by type (passive crawlers, agentic browsers, agent API calls), engine breakdown, and the paths they fetch most. Defaults to the last 30 days; pass from/to
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
},
|
|
2637
|
+
description: "Which AI agents and crawlers are reading this site: totals by type (passive crawlers, agentic browsers, agent API calls), engine breakdown, and the paths they fetch most. Defaults to the last 30 calendar days; pass range (7d/30d/90d/all) or from/to (YYYY-MM-DD) like every other windowed tool (agent logs are retained 30 days on Free/Starter, 90 on Growth+). Agent traffic is tracked separately and never counted in conversion rate." + UNTRUSTED_FIELDS_NOTE,
|
|
2638
|
+
// This tool alone took ad-hoc ISO from/to with no range token and echoed
|
|
2639
|
+
// no window, while every other windowed tool used rangeInputSchema — so
|
|
2640
|
+
// agents passed range:'7d' here, it was silently dropped, and 30 days of
|
|
2641
|
+
// traffic was reported as a week. The endpoint uses the shared resolver.
|
|
2642
|
+
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
2319
2643
|
outputSchema: {
|
|
2320
2644
|
totals: import_zod14.z.object({ crawler: import_zod14.z.number(), api: import_zod14.z.number(), browser: import_zod14.z.number() }),
|
|
2321
2645
|
engines: import_zod14.z.array(
|
|
@@ -2329,20 +2653,18 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2329
2653
|
})
|
|
2330
2654
|
),
|
|
2331
2655
|
intents: import_zod14.z.object({ user: import_zod14.z.number(), search: import_zod14.z.number(), training: import_zod14.z.number(), other: import_zod14.z.number() }).describe("Crawler fetches by purpose: user = an assistant answering a real person live"),
|
|
2332
|
-
topPaths: import_zod14.z.array(import_zod14.z.object({ path: import_zod14.z.string(), count: import_zod14.z.number(), engines: import_zod14.z.number() }))
|
|
2656
|
+
topPaths: import_zod14.z.array(import_zod14.z.object({ path: import_zod14.z.string(), count: import_zod14.z.number(), engines: import_zod14.z.number() })),
|
|
2657
|
+
window: windowOutputSchema
|
|
2333
2658
|
},
|
|
2334
2659
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2335
2660
|
},
|
|
2336
|
-
withApiErrorGuidance(async ({ projectId, from, to }) => {
|
|
2661
|
+
withApiErrorGuidance(async ({ projectId, range, from, to }) => {
|
|
2337
2662
|
const id = encodeURIComponent(projectId);
|
|
2338
|
-
const qs = new URLSearchParams();
|
|
2339
|
-
if (from) qs.set("from", from);
|
|
2340
|
-
if (to) qs.set("to", to);
|
|
2341
|
-
const query = qs.toString();
|
|
2342
2663
|
const s = await client.get(
|
|
2343
|
-
`/projects/${id}/agent-activity/summary${
|
|
2664
|
+
`/projects/${id}/agent-activity/summary${rangeQuery({ range, from, to })}`
|
|
2344
2665
|
);
|
|
2345
|
-
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths };
|
|
2666
|
+
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths, window: s.window };
|
|
2667
|
+
const win = windowLine(s.window);
|
|
2346
2668
|
const total = s.totals.crawler + s.totals.api + s.totals.browser;
|
|
2347
2669
|
if (total === 0) {
|
|
2348
2670
|
return {
|
|
@@ -2354,6 +2676,7 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2354
2676
|
};
|
|
2355
2677
|
}
|
|
2356
2678
|
const lines = [
|
|
2679
|
+
...win ? [win] : [],
|
|
2357
2680
|
`Agent traffic: ${s.totals.crawler} crawler fetches, ${s.totals.api} agent API calls, ${s.totals.browser} agentic browser sessions.`,
|
|
2358
2681
|
`Live user fetches: ${s.intents.user} \xB7 Search index: ${s.intents.search} \xB7 Training: ${s.intents.training}${s.intents.other ? ` \xB7 Other: ${s.intents.other}` : ""} (a "live user fetch" = an AI assistant reading your site to answer a real person).`,
|
|
2359
2682
|
"",
|
|
@@ -2444,7 +2767,7 @@ var personaOutput = import_zod15.z.object({
|
|
|
2444
2767
|
var cellOutput = import_zod15.z.object({
|
|
2445
2768
|
slotId: import_zod15.z.string(),
|
|
2446
2769
|
persona: import_zod15.z.string(),
|
|
2447
|
-
status: import_zod15.z.string().describe("pending | generating | live | error | rejected"),
|
|
2770
|
+
status: import_zod15.z.string().describe("pending | generating | review (waiting for approval) | live | error | rejected"),
|
|
2448
2771
|
requestedBy: import_zod15.z.string(),
|
|
2449
2772
|
armId: import_zod15.z.string().nullable(),
|
|
2450
2773
|
rationale: import_zod15.z.string().nullable(),
|
|
@@ -2484,6 +2807,10 @@ function registerCellTools(server, client) {
|
|
|
2484
2807
|
personas: import_zod15.z.array(personaOutput),
|
|
2485
2808
|
cells: import_zod15.z.array(cellOutput),
|
|
2486
2809
|
autoFill: import_zod15.z.boolean(),
|
|
2810
|
+
// The API has always sent this; without it in the schema zod stripped
|
|
2811
|
+
// it, and generate_cell had no way to know a version would wait for a
|
|
2812
|
+
// human instead of publishing.
|
|
2813
|
+
reviewMode: import_zod15.z.boolean().optional().describe("True when generated versions wait for approval (review_cell) instead of publishing automatically"),
|
|
2487
2814
|
// Nullable: a project with no persona set at all reports null, not a
|
|
2488
2815
|
// string. That is the NORMAL state since the default vocabulary was
|
|
2489
2816
|
// emptied, so a non-nullable schema failed output validation on most
|
|
@@ -2500,7 +2827,7 @@ function registerCellTools(server, client) {
|
|
|
2500
2827
|
const byCell = new Map(data.cells.map((c) => [`${c.slotId}::${c.persona}`, c]));
|
|
2501
2828
|
const lines = [
|
|
2502
2829
|
`Slots: ${data.slots.map((s) => `${untrusted(s.displayName)}${s.live === false ? " [draft]" : ""}`).join(", ") || "(none published)"}`,
|
|
2503
|
-
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 persona source: ${(_a = data.personaSource) != null ? _a : 'none (one "everyone" row)'}`
|
|
2830
|
+
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 review before publishing: ${data.reviewMode ? "ON (approve with review_cell)" : "off"} \xB7 persona source: ${(_a = data.personaSource) != null ? _a : 'none (one "everyone" row)'}`
|
|
2504
2831
|
];
|
|
2505
2832
|
for (const p of data.personas) {
|
|
2506
2833
|
const states = data.slots.map((s) => {
|
|
@@ -2585,7 +2912,12 @@ function registerCellTools(server, client) {
|
|
|
2585
2912
|
"generate_cell",
|
|
2586
2913
|
{
|
|
2587
2914
|
title: "Generate a cell version",
|
|
2588
|
-
|
|
2915
|
+
// The old copy promised "goes live, usually under a minute" — but with
|
|
2916
|
+
// review mode on the worker parks the version for a human (status
|
|
2917
|
+
// 'review') and nothing serves until someone approves it, and the queue
|
|
2918
|
+
// can defer a cell (retry backoff, the plan's monthly generation cap). An
|
|
2919
|
+
// agent relayed "it's live" for versions no visitor would ever see.
|
|
2920
|
+
description: "Queue AI generation of a version for one (persona, slot) cell; the worker writes it asynchronously, brand-locked. If the project has review mode on, the finished version WAITS for approval (list_cell_reviews / review_cell) and serves nobody until approved; otherwise it publishes automatically as a named option the optimizer explores. Also regenerates or retries a failed cell. Generation volume is capped per plan (Free included). Check get_cell_matrix for progress. Confirm with the user before calling \u2014 each generation is a model call against the plan quota.",
|
|
2589
2921
|
inputSchema: {
|
|
2590
2922
|
projectId: projectIdSchema,
|
|
2591
2923
|
slotId: import_zod15.z.string().min(1).max(128).describe("The slot id (a matrix column)"),
|
|
@@ -2594,28 +2926,130 @@ function registerCellTools(server, client) {
|
|
|
2594
2926
|
outputSchema: {
|
|
2595
2927
|
slotId: import_zod15.z.string(),
|
|
2596
2928
|
persona: import_zod15.z.string(),
|
|
2597
|
-
status: import_zod15.z.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress")
|
|
2929
|
+
status: import_zod15.z.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress"),
|
|
2930
|
+
reviewMode: import_zod15.z.boolean().nullable().describe("True: the version will wait for review_cell approval. False: it publishes automatically. Null: could not be read.")
|
|
2598
2931
|
},
|
|
2599
2932
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
2600
2933
|
},
|
|
2601
2934
|
withApiErrorGuidance(async ({ projectId, slotId, persona }) => {
|
|
2602
2935
|
const id = encodeURIComponent(projectId);
|
|
2603
2936
|
await client.post(`/projects/${id}/cells/generate`, { slotId, persona });
|
|
2937
|
+
const matrix = await settled(client.get(`/projects/${id}/cells`));
|
|
2938
|
+
const reviewMode = matrix.ok && typeof matrix.value.reviewMode === "boolean" ? matrix.value.reviewMode : null;
|
|
2939
|
+
const next = reviewMode === true ? "Review mode is ON: when it is written it will WAIT for approval and serve nobody until then \u2014 list it with list_cell_reviews and approve or reject it with review_cell (after the user decides)." : reviewMode === false ? "Review mode is off: once written it publishes automatically and the optimizer starts exploring it." : 'Could not read whether review mode is on \u2014 check get_cell_matrix: status "review" means it is waiting for approval (review_cell), "live" means it is serving.';
|
|
2604
2940
|
return {
|
|
2605
2941
|
content: [
|
|
2606
2942
|
{
|
|
2607
2943
|
type: "text",
|
|
2608
|
-
text: `
|
|
2944
|
+
text: `Queued a version of ${untrusted(slotId, 64)} for ${untrusted(persona, 64)}. It is written asynchronously (the queue may defer it \u2014 retries back off, and the plan caps generations). ${next} Track it with get_cell_matrix or get_cell_detail.`
|
|
2609
2945
|
}
|
|
2610
2946
|
],
|
|
2611
|
-
structuredContent: { slotId, persona, status: "pending" }
|
|
2947
|
+
structuredContent: { slotId, persona, status: "pending", reviewMode }
|
|
2948
|
+
};
|
|
2949
|
+
})
|
|
2950
|
+
);
|
|
2951
|
+
server.registerTool(
|
|
2952
|
+
"list_cell_reviews",
|
|
2953
|
+
{
|
|
2954
|
+
title: "Versions waiting for review",
|
|
2955
|
+
description: "Generated versions waiting for approval (review mode): which slot and visitor type, the proposed text or layout, and why it was written. Approve or reject each with review_cell after the user decides." + UNTRUSTED_FIELDS_NOTE,
|
|
2956
|
+
inputSchema: { projectId: projectIdSchema },
|
|
2957
|
+
outputSchema: {
|
|
2958
|
+
reviews: import_zod15.z.array(
|
|
2959
|
+
import_zod15.z.object({
|
|
2960
|
+
slotId: import_zod15.z.string(),
|
|
2961
|
+
slotName: import_zod15.z.string(),
|
|
2962
|
+
persona: import_zod15.z.string(),
|
|
2963
|
+
personaDisplay: import_zod15.z.string(),
|
|
2964
|
+
content: import_zod15.z.string().nullable().describe("Proposed text, when the version is text (null for a block/layout version)"),
|
|
2965
|
+
rationale: import_zod15.z.string().nullable(),
|
|
2966
|
+
refinedFrom: import_zod15.z.string().nullable().describe("Live version this one would replace; that version keeps serving until approval"),
|
|
2967
|
+
updatedAt: import_zod15.z.string()
|
|
2968
|
+
})
|
|
2969
|
+
)
|
|
2970
|
+
},
|
|
2971
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2972
|
+
},
|
|
2973
|
+
withApiErrorGuidance(async ({ projectId }) => {
|
|
2974
|
+
var _a;
|
|
2975
|
+
const id = encodeURIComponent(projectId);
|
|
2976
|
+
const data = await client.get(`/projects/${id}/cell-reviews`);
|
|
2977
|
+
const reviews = ((_a = data.reviews) != null ? _a : []).map((r) => {
|
|
2978
|
+
var _a2, _b, _c;
|
|
2979
|
+
return {
|
|
2980
|
+
slotId: r.slotId,
|
|
2981
|
+
slotName: r.slotName,
|
|
2982
|
+
persona: r.persona,
|
|
2983
|
+
personaDisplay: r.personaDisplay,
|
|
2984
|
+
content: typeof ((_a2 = r.pendingArm) == null ? void 0 : _a2.content) === "string" ? r.pendingArm.content : null,
|
|
2985
|
+
rationale: (_b = r.rationale) != null ? _b : null,
|
|
2986
|
+
refinedFrom: (_c = r.refinedFrom) != null ? _c : null,
|
|
2987
|
+
updatedAt: String(r.updatedAt)
|
|
2988
|
+
};
|
|
2989
|
+
});
|
|
2990
|
+
if (reviews.length === 0) {
|
|
2991
|
+
return {
|
|
2992
|
+
content: [{ type: "text", text: "No generated versions are waiting for review." }],
|
|
2993
|
+
structuredContent: { reviews }
|
|
2994
|
+
};
|
|
2995
|
+
}
|
|
2996
|
+
const lines = reviews.map(
|
|
2997
|
+
(r) => [
|
|
2998
|
+
`- ${untrusted(r.slotName, 60)} (slotId ${untrusted(r.slotId, 64)}) for ${untrusted(r.personaDisplay, 60)} (persona ${untrusted(r.persona, 64)})`,
|
|
2999
|
+
r.content !== null ? ` Proposed text: ${untrusted(r.content, 300)}` : " Proposed: a designed block/layout (preview it in the dashboard)",
|
|
3000
|
+
r.rationale ? ` Why: ${untrusted(r.rationale, 300)}` : null,
|
|
3001
|
+
r.refinedFrom ? ` Would replace ${untrusted(r.refinedFrom, 64)}, which keeps serving until approval.` : null
|
|
3002
|
+
].filter((l) => l !== null).join("\n")
|
|
3003
|
+
);
|
|
3004
|
+
lines.push("", "Approve or reject each with review_cell (slotId + persona) once the user has decided.");
|
|
3005
|
+
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent: { reviews } };
|
|
3006
|
+
})
|
|
3007
|
+
);
|
|
3008
|
+
server.registerTool(
|
|
3009
|
+
"review_cell",
|
|
3010
|
+
{
|
|
3011
|
+
title: "Approve or reject a generated version",
|
|
3012
|
+
description: "Approve or reject ONE generated version waiting for review (see list_cell_reviews). 'approve' publishes it to live visitors of that type; 'reject' discards it (a rejected refinement leaves the current live version in place). This is the human decision review mode exists for \u2014 only call it with the user's explicit go-ahead.",
|
|
3013
|
+
inputSchema: {
|
|
3014
|
+
projectId: projectIdSchema,
|
|
3015
|
+
slotId: import_zod15.z.string().min(1).max(128).describe("The slot id of the version under review"),
|
|
3016
|
+
persona: import_zod15.z.string().min(1).max(64).describe("The persona key of the version under review"),
|
|
3017
|
+
action: import_zod15.z.enum(["approve", "reject"]),
|
|
3018
|
+
feedback: import_zod15.z.string().max(2e3).optional().describe("Optional reviewer note, stored with a rejection")
|
|
3019
|
+
},
|
|
3020
|
+
outputSchema: {
|
|
3021
|
+
slotId: import_zod15.z.string(),
|
|
3022
|
+
persona: import_zod15.z.string(),
|
|
3023
|
+
action: import_zod15.z.enum(["approve", "reject"]),
|
|
3024
|
+
status: import_zod15.z.string().describe("live (approved, or a rejected refinement whose incumbent keeps serving) | rejected"),
|
|
3025
|
+
armId: import_zod15.z.string().nullable().describe("The published option id, on approval")
|
|
3026
|
+
},
|
|
3027
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
3028
|
+
},
|
|
3029
|
+
withApiErrorGuidance(async ({ projectId, slotId, persona, action, feedback }) => {
|
|
3030
|
+
var _a, _b;
|
|
3031
|
+
const id = encodeURIComponent(projectId);
|
|
3032
|
+
const res = await client.post(`/projects/${id}/cells/review`, {
|
|
3033
|
+
slotId,
|
|
3034
|
+
persona,
|
|
3035
|
+
action,
|
|
3036
|
+
feedback
|
|
3037
|
+
});
|
|
3038
|
+
const status = (_a = res.status) != null ? _a : action === "approve" ? "live" : "rejected";
|
|
3039
|
+
const text = action === "approve" ? `Approved: the version for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} is now live${res.armId ? ` as option ${untrusted(res.armId, 64)}` : ""}.` : status === "live" ? `Rejected: the proposed refinement for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} was discarded; the current live version keeps serving.` : `Rejected: the version for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} was discarded; that visitor type keeps seeing the original.`;
|
|
3040
|
+
return {
|
|
3041
|
+
content: [{ type: "text", text }],
|
|
3042
|
+
structuredContent: { slotId, persona, action, status, armId: (_b = res.armId) != null ? _b : null }
|
|
2612
3043
|
};
|
|
3044
|
+
}, {
|
|
3045
|
+
not_found: "No version is waiting for review in that cell (it may already have been approved or rejected). Check list_cell_reviews.",
|
|
3046
|
+
publish_failed: "Approval could not publish this version (the slot may be full of options, or its configuration changed). It stays in review \u2014 check the reason in get_cell_detail or the dashboard, then retry."
|
|
2613
3047
|
})
|
|
2614
3048
|
);
|
|
2615
3049
|
}
|
|
2616
3050
|
|
|
2617
3051
|
// src/server.ts
|
|
2618
|
-
var PKG_VERSION = true ? "0.
|
|
3052
|
+
var PKG_VERSION = true ? "0.21.0" : "0.0.0-dev";
|
|
2619
3053
|
function createMcpServer(client) {
|
|
2620
3054
|
const server = new import_mcp.McpServer(
|
|
2621
3055
|
{
|
|
@@ -2653,10 +3087,58 @@ function createMcpServer(client) {
|
|
|
2653
3087
|
registerCellTools(server, client);
|
|
2654
3088
|
return server;
|
|
2655
3089
|
}
|
|
3090
|
+
|
|
3091
|
+
// src/tool-catalog.ts
|
|
3092
|
+
var TOOL_CATALOG = [
|
|
3093
|
+
// Projects
|
|
3094
|
+
{ name: "list_projects", access: "read", summary: "List the projects this credential can see (an sk_ key sees only its own project)" },
|
|
3095
|
+
{ name: "create_project", access: "write", summary: "Create a project and return its pk_ public key (account login only \u2014 not an sk_ key or demo token)" },
|
|
3096
|
+
{ name: "get_project_stats", access: "read", summary: "Ingestion health: status, 24h events and sessions, and /v1/agent API calls" },
|
|
3097
|
+
{ name: "add_origin", access: "write", summary: "Allow-list a site origin so the SDK's events from it are accepted" },
|
|
3098
|
+
// Components and variants
|
|
3099
|
+
{ name: "list_components", access: "read", summary: "Adaptive components with variant counts and impressions" },
|
|
3100
|
+
{ name: "get_variant_performance", access: "read", summary: "Per-(component, variant) rates with their n and the server's evidence verdict vs the baseline" },
|
|
3101
|
+
{ name: "get_variant_brief", access: "read", summary: "Evidence-driven brief for writing a new code-native variant" },
|
|
3102
|
+
{ name: "get_test_brief", access: "read", summary: "Ready-to-paste test code that forces one of a component's real variants" },
|
|
3103
|
+
{ name: "create_variant", access: "write", summary: "Create a no-code managed text variant as a draft" },
|
|
3104
|
+
{ name: "update_variant", access: "write", summary: "Edit a managed variant's name or text, or activate a draft (status active) / move it back to draft" },
|
|
3105
|
+
{ name: "delete_variant_draft", access: "write", summary: "Delete a managed variant that is still a draft" },
|
|
3106
|
+
{ name: "pause_variant", access: "write", summary: "Pause a variant so no new traffic is assigned to it (undo with resume_variant)" },
|
|
3107
|
+
{ name: "resume_variant", access: "write", summary: "Resume a paused variant \u2014 manual or guardrail pause" },
|
|
3108
|
+
{ name: "retire_variant", access: "write", summary: "Retire (archive) an active variant (undo with restore_variant)" },
|
|
3109
|
+
{ name: "restore_variant", access: "write", summary: "Bring a retired variant back to active" },
|
|
3110
|
+
// Goals, funnels, guardrails
|
|
3111
|
+
{ name: "get_goal_funnel", access: "read", summary: "Per-goal conversion summary (windowed) with descriptive all-time per-variant rates \u2014 not a step funnel (see get_funnel_report)" },
|
|
3112
|
+
{ name: "list_goals", access: "read", summary: "Defined goals (id, role, event, status), including ones with no conversions yet" },
|
|
3113
|
+
{ name: "define_goal", access: "write", summary: "Create a new goal \u2014 never overwrites an existing goal and never changes the primary goal" },
|
|
3114
|
+
{ name: "list_funnels", access: "read", summary: "Defined multi-step funnels" },
|
|
3115
|
+
{ name: "get_funnel_report", access: "read", summary: "Step-by-step funnel drop-off" },
|
|
3116
|
+
{ name: "list_guardrail_events", access: "read", summary: "Every variant currently paused by a guardrail (optionally only pauses from the last N days)" },
|
|
3117
|
+
// Audience and layout
|
|
3118
|
+
{ name: "get_persona_breakdown", access: "read", summary: "Visitor clusters with session counts and reliability (all retained sessions)" },
|
|
3119
|
+
{ name: "get_layout_stats", access: "read", summary: "Per-persona section order with bandit pulls and reward (cumulative state)" },
|
|
3120
|
+
// Insights
|
|
3121
|
+
{ name: "get_insights", access: "read", summary: "Ranked measured findings with their sample, plus AI narrations marked unmeasured" },
|
|
3122
|
+
{ name: "refresh_insights", access: "write", summary: "Regenerate AI insights (Starter+ and an editor/admin role; a paid model call)" },
|
|
3123
|
+
// Generated versions (persona x slot cells)
|
|
3124
|
+
{ name: "get_cell_matrix", access: "read", summary: 'The "Who sees what" matrix of generated versions per visitor type and region' },
|
|
3125
|
+
{ name: "get_cell_detail", access: "read", summary: "One cell's generated version, why it was written, and how it performs" },
|
|
3126
|
+
{ name: "generate_cell", access: "write", summary: "Queue AI generation for one cell \u2014 publishes automatically, or waits for approval when review mode is on" },
|
|
3127
|
+
{ name: "list_cell_reviews", access: "read", summary: "Generated versions waiting for approval (review mode)" },
|
|
3128
|
+
{ name: "review_cell", access: "write", summary: "Approve (publish) or reject one generated version waiting for review" },
|
|
3129
|
+
// Agent traffic
|
|
3130
|
+
{ name: "get_agent_traffic", access: "read", summary: "Which AI crawlers, agentic browsers and agent API callers read the site (windowed)" },
|
|
3131
|
+
{ name: "get_agent_legibility", access: "read", summary: "Whether the pages agents read are machine-legible, with fixes" },
|
|
3132
|
+
// Setup
|
|
3133
|
+
{ name: "get_integration_guide", access: "read", summary: "SDK setup guide (static \u2014 same for every project)" }
|
|
3134
|
+
];
|
|
3135
|
+
var TOOL_NAMES = TOOL_CATALOG.map((t) => t.name);
|
|
2656
3136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2657
3137
|
0 && (module.exports = {
|
|
2658
3138
|
ApiClient,
|
|
2659
3139
|
ApiError,
|
|
2660
3140
|
PUBLIC_UI_RESOURCE_URIS,
|
|
3141
|
+
TOOL_CATALOG,
|
|
3142
|
+
TOOL_NAMES,
|
|
2661
3143
|
createMcpServer
|
|
2662
3144
|
});
|