@apex-inc/mcp-server 0.64.1 → 0.66.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/dist/letter-blocks.d.ts +15 -3
- package/dist/letter-blocks.d.ts.map +1 -1
- package/dist/letter-blocks.js +28 -1
- package/dist/letter-blocks.js.map +1 -1
- package/dist/setup-catchup-tools.d.ts +130 -4
- package/dist/setup-catchup-tools.d.ts.map +1 -1
- package/dist/setup-catchup-tools.js +205 -14
- package/dist/setup-catchup-tools.js.map +1 -1
- package/dist/tool-groups.d.ts.map +1 -1
- package/dist/tool-groups.js +12 -1
- package/dist/tool-groups.js.map +1 -1
- package/dist/tool-shared.d.ts +23 -2
- package/dist/tool-shared.d.ts.map +1 -1
- package/dist/tool-shared.js +36 -2
- package/dist/tool-shared.js.map +1 -1
- package/dist/tools/context.d.ts +33 -5
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +48 -6
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/experiments.d.ts +26 -18
- package/dist/tools/experiments.d.ts.map +1 -1
- package/dist/tools/experiments.js +107 -19
- package/dist/tools/experiments.js.map +1 -1
- package/dist/tools/letters.d.ts +214 -29
- package/dist/tools/letters.d.ts.map +1 -1
- package/dist/tools/letters.js +325 -26
- package/dist/tools/letters.js.map +1 -1
- package/dist/tools/measurement.d.ts +68 -7
- package/dist/tools/measurement.d.ts.map +1 -1
- package/dist/tools/measurement.js +149 -41
- package/dist/tools/measurement.js.map +1 -1
- package/dist/tools/people.d.ts +99 -0
- package/dist/tools/people.d.ts.map +1 -0
- package/dist/tools/people.js +245 -0
- package/dist/tools/people.js.map +1 -0
- package/dist/tools.d.ts +588 -63
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +2 -0
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/skills/apex-communications/SKILL.md +4 -3
- package/skills/apex-experimentation/SKILL.md +12 -0
- package/skills/apex-integration-cookbook/SKILL.md +1 -1
- package/skills/apex-setup/SKILL.md +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { apiGet, apiPost, apiPatch, apiPut,
|
|
2
|
+
import { apiGet, apiPost, apiPatch, apiPut, postServerEvents, SERVER_KEY_NEEDED_MESSAGE, } from "../api-client.js";
|
|
3
3
|
import { getPersonLabel, lowerPerson } from "../person-label.js";
|
|
4
4
|
import { MCP_SERVER_VERSION } from "../version.js";
|
|
5
|
-
import { APEX, appUrl, errMsg, MCP_AGENT_VISITOR_ID, windowQuery, } from "../tool-shared.js";
|
|
5
|
+
import { APEX, appUrl, errMsg, MCP_AGENT_VISITOR_ID, resolveActiveWorkspace, windowQuery, } from "../tool-shared.js";
|
|
6
6
|
function text(t, isError = false) {
|
|
7
7
|
return { content: [{ type: "text", text: t }], ...(isError ? { isError: true } : {}) };
|
|
8
8
|
}
|
|
@@ -43,16 +43,30 @@ const keyEventCategorySchema = z
|
|
|
43
43
|
.describe("What kind of step it is; sets its place in the funnel.");
|
|
44
44
|
function keyEventLine(k, i) {
|
|
45
45
|
const tags = [
|
|
46
|
-
k.
|
|
46
|
+
k.archivedAt ? `archived ${k.archivedAt.slice(0, 10)}` : null,
|
|
47
|
+
k.isCurrentGoal && !k.archivedAt ? "main goal" : null,
|
|
47
48
|
k.entityScope === "account" ? "counts companies" : null,
|
|
48
49
|
k.definitionVersion > 1 ? `v${k.definitionVersion}` : null,
|
|
49
50
|
].filter(Boolean);
|
|
50
|
-
|
|
51
|
+
const head = ` ${i + 1}. ${k.name} [${k.id}]${tags.length ? ` (${tags.join(", ")})` : ""}: ${k.counts}`;
|
|
52
|
+
return k.nameWarning ? `${head}\n ⚠ ${k.nameWarning}` : head;
|
|
51
53
|
}
|
|
54
|
+
const KEY_EVENT_USE_KIND = {
|
|
55
|
+
journey: "Adaptive Journey",
|
|
56
|
+
segment: "Segment",
|
|
57
|
+
test: "Test",
|
|
58
|
+
campaign: "Campaign",
|
|
59
|
+
target: "Target",
|
|
60
|
+
};
|
|
52
61
|
function keyEventUseLine(u) {
|
|
53
|
-
const kind = u.kind
|
|
62
|
+
const kind = KEY_EVENT_USE_KIND[u.kind] ?? "Used by";
|
|
54
63
|
return ` • ${kind} "${u.name}" [${u.id}]${u.status ? ` (${u.status})` : ""}: ${u.role}. ${appUrl(u.href)}`;
|
|
55
64
|
}
|
|
65
|
+
function keyEventFindingLine(f) {
|
|
66
|
+
const sign = f.metricDelta > 0 ? "+" : "";
|
|
67
|
+
const version = f.keyEvent?.version ? ` on v${f.keyEvent.version}` : "";
|
|
68
|
+
return ` Finding ${f.evaluatedAt.slice(0, 10)}: test ${f.experimentId} ${f.classification}${version}, ${sign}${f.metricDelta}% (${f.statisticalSignificance}% sure)`;
|
|
69
|
+
}
|
|
56
70
|
/** How sure Apex is, in the same words the dashboard uses. */
|
|
57
71
|
function sureWords(confidence) {
|
|
58
72
|
if (confidence >= 0.95)
|
|
@@ -66,11 +80,13 @@ function keyEventSuggestionLines(s, nameOf) {
|
|
|
66
80
|
const ids = s.keyEventIds ?? [];
|
|
67
81
|
const what = s.kind === "merge_key_events"
|
|
68
82
|
? `Merge ${ids.slice(1).map(named).join(", ")} into ${ids[0] ? named(ids[0]) : s.name}: they count the same thing`
|
|
69
|
-
: s.kind === "
|
|
70
|
-
? `
|
|
71
|
-
: s.
|
|
72
|
-
? `
|
|
73
|
-
:
|
|
83
|
+
: s.kind === "restore_key_event"
|
|
84
|
+
? `Bring back archived key event "${s.name}"${ids[0] ? ` [${ids[0]}]` : ""}: ${s.events.join(", ")} arrived again`
|
|
85
|
+
: s.kind === "extend_key_event"
|
|
86
|
+
? `Add ${s.events.join(", ")} to ${ids[0] ? named(ids[0]) : s.name}`
|
|
87
|
+
: s.events.length > 1
|
|
88
|
+
? `Make "${s.name}" a key event, reached by ${s.events.join(", ")}`
|
|
89
|
+
: `Make "${s.name}" a key event, reached by ${s.events[0]}`;
|
|
74
90
|
return [
|
|
75
91
|
` ${what}`,
|
|
76
92
|
` suggestion_id ${s.id}. ${sureWords(s.confidence)} (${Math.round(s.confidence * 100)}%).`,
|
|
@@ -271,7 +287,8 @@ export const measurementTools = {
|
|
|
271
287
|
const q = days && days !== "all" ? `?days=${days}` : "?days=all";
|
|
272
288
|
const res = await apiGet(`/api/growth/reality${q}`);
|
|
273
289
|
const goals = res.data?.goals ?? [];
|
|
274
|
-
|
|
290
|
+
const unmeasured = res.data?.unmeasuredKeyEvents ?? [];
|
|
291
|
+
if (goals.length === 0 && unmeasured.length === 0) {
|
|
275
292
|
return {
|
|
276
293
|
content: [
|
|
277
294
|
{
|
|
@@ -283,8 +300,14 @@ export const measurementTools = {
|
|
|
283
300
|
}
|
|
284
301
|
const pctFmt = (v) => v == null ? "—" : `${v > 0 ? "+" : ""}${(v * 100).toFixed(1)}%`;
|
|
285
302
|
const lines = goals.map((g) => {
|
|
303
|
+
const totalConversions = (g.counts?.exposedConversions ?? 0) + (g.counts?.holdoutConversions ?? 0);
|
|
304
|
+
if (totalConversions === 0) {
|
|
305
|
+
const evLabel = g.eventName ? `${g.eventName} ` : "";
|
|
306
|
+
const totalSubjects = (g.counts?.exposedSubjects ?? 0) + (g.counts?.holdoutSubjects ?? 0);
|
|
307
|
+
return ` • ${g.goalName}: NO EVENTS YET (0 ${evLabel}conversions across ${totalSubjects.toLocaleString()} holdout-tracked people since ${g.collectingSince || "—"} — check get_wiring_status or list_data_sources)`;
|
|
308
|
+
}
|
|
286
309
|
if (!g.isDecisive) {
|
|
287
|
-
return ` • ${g.goalName}: COLLECTING (directional ${pctFmt(g.lift)}, since ${g.collectingSince || "—"})`;
|
|
310
|
+
return ` • ${g.goalName}: COLLECTING (directional ${pctFmt(g.lift)}, ${totalConversions.toLocaleString()} conversions since ${g.collectingSince || "—"})`;
|
|
288
311
|
}
|
|
289
312
|
const ci = g.liftCI
|
|
290
313
|
? ` [${pctFmt(g.liftCI.lower)}, ${pctFmt(g.liftCI.upper)}]`
|
|
@@ -294,6 +317,12 @@ export const measurementTools = {
|
|
|
294
317
|
: "";
|
|
295
318
|
return ` • ${g.goalName}: ${pctFmt(g.lift)} vs holdout${ci} — DECISIVE${rev}`;
|
|
296
319
|
});
|
|
320
|
+
if (unmeasured.length > 0) {
|
|
321
|
+
for (const u of unmeasured) {
|
|
322
|
+
const evLabel = u.eventName ? ` (${u.eventName})` : "";
|
|
323
|
+
lines.push(` • ${u.name}${evLabel}: NO EVENTS YET (no holdout-tracked traffic since this key event was added — forward-only)`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
297
326
|
return {
|
|
298
327
|
content: [
|
|
299
328
|
{
|
|
@@ -524,17 +553,20 @@ export const measurementTools = {
|
|
|
524
553
|
},
|
|
525
554
|
},
|
|
526
555
|
list_key_events: {
|
|
527
|
-
description: `${APEX} — The workspace's key events (the actions that matter to the business: Lead captured, Qualified, Revenue realized) in funnel order: which events reach each one, its version, whether it counts people or companies, and which one is the main one. These are the columns get_efforts shows; pass the ids to get_efforts key_event_ids or set_campaign_steps. Make one with create_key_event.`,
|
|
528
|
-
schema: z.object({
|
|
529
|
-
|
|
530
|
-
|
|
556
|
+
description: `${APEX} — The workspace's key events (the actions that matter to the business: Lead captured, Qualified, Revenue realized) in funnel order: which events reach each one, its version, whether it counts people or companies, and which one is the main one. Pass include_archived: true to include archived key events too (needed to find an id for restore_key_event). These are the columns get_efforts shows; pass the ids to get_efforts key_event_ids or set_campaign_steps. Make one with create_key_event.`,
|
|
557
|
+
schema: z.object({
|
|
558
|
+
includeArchived: z.boolean().optional().describe("Include archived key events too (default false)."),
|
|
559
|
+
}),
|
|
560
|
+
handler: async (args = {}) => {
|
|
561
|
+
const q = args.includeArchived ? "?include_archived=1" : "";
|
|
562
|
+
const res = await apiGet(`/api/key-events${q}`);
|
|
531
563
|
const keyEvents = res.data?.keyEvents ?? [];
|
|
532
564
|
if (keyEvents.length === 0) {
|
|
533
565
|
return {
|
|
534
566
|
content: [
|
|
535
567
|
{
|
|
536
568
|
type: "text",
|
|
537
|
-
text: `${APEX} No key events yet. Make one with create_key_event (for example Lead captured, reached by application_submitted or audit_booked), or on ${appUrl("/dashboard/
|
|
569
|
+
text: `${APEX} No key events yet. Make one with create_key_event (for example Lead captured, reached by application_submitted or audit_booked), or on ${appUrl("/dashboard/key-events")}.`,
|
|
538
570
|
},
|
|
539
571
|
],
|
|
540
572
|
};
|
|
@@ -544,7 +576,7 @@ export const measurementTools = {
|
|
|
544
576
|
},
|
|
545
577
|
},
|
|
546
578
|
get_key_event: {
|
|
547
|
-
description: `${APEX} — One key event: the events that reach it and their conditions, every earlier version,
|
|
579
|
+
description: `${APEX} — One key event: the events that reach it and their conditions, every earlier version, the ad platform conversions linked to it, and the finished tests that were judged on it (so results that counted the same outcome line up). Id from list_key_events.`,
|
|
548
580
|
schema: z.object({ keyEventId: z.string().min(1).describe("From list_key_events.") }),
|
|
549
581
|
handler: async ({ keyEventId }) => {
|
|
550
582
|
try {
|
|
@@ -558,6 +590,15 @@ export const measurementTools = {
|
|
|
558
590
|
}
|
|
559
591
|
for (const l of res.data?.links ?? [])
|
|
560
592
|
lines.push(` Linked: ${l.integration ?? "platform"} ${l.platformActionName ?? ""}`.trimEnd());
|
|
593
|
+
// Finished tests judged on it, so results that counted the same outcome line up.
|
|
594
|
+
try {
|
|
595
|
+
const findings = await apiGet(`/api/outcomes?key_event_id=${encodeURIComponent(keyEventId)}`);
|
|
596
|
+
for (const f of (Array.isArray(findings) ? findings : []).slice(0, 10))
|
|
597
|
+
lines.push(keyEventFindingLine(f));
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
/* the key event itself is the answer; findings are extra */
|
|
601
|
+
}
|
|
561
602
|
return text(lines.join("\n"));
|
|
562
603
|
}
|
|
563
604
|
catch (err) {
|
|
@@ -574,6 +615,7 @@ export const measurementTools = {
|
|
|
574
615
|
entityScope: z.enum(["person", "account"]).optional().describe("person (default) or account (a company reaches it when its first person does)."),
|
|
575
616
|
description: z.string().max(1000).optional(),
|
|
576
617
|
template: z.string().max(100).optional().describe("The template it follows, e.g. lead_captured."),
|
|
618
|
+
position: z.number().int().min(0).max(999).optional().describe("Optional explicit funnel rank (0 = earliest step). Omit to use automatic funnel order."),
|
|
577
619
|
}),
|
|
578
620
|
handler: async (args) => {
|
|
579
621
|
try {
|
|
@@ -584,6 +626,7 @@ export const measurementTools = {
|
|
|
584
626
|
...(args.entityScope ? { entity_scope: args.entityScope } : {}),
|
|
585
627
|
...(args.description ? { description: args.description } : {}),
|
|
586
628
|
...(args.template ? { template: args.template } : {}),
|
|
629
|
+
...(typeof args.position === "number" ? { position: args.position } : {}),
|
|
587
630
|
});
|
|
588
631
|
const k = res.data?.keyEvent;
|
|
589
632
|
return text(k ? `${APEX} Made key event:\n${keyEventLine(k, 0)}\nApex is now checking people's history for it.` : `${APEX} Made key event.`);
|
|
@@ -594,7 +637,7 @@ export const measurementTools = {
|
|
|
594
637
|
},
|
|
595
638
|
},
|
|
596
639
|
update_key_event: {
|
|
597
|
-
description: `${APEX} — Change a key event. Renaming keeps its version. Changing its events, their conditions or entity_scope makes a new version: people already counted keep the version they reached, and running tests keep the one they started with. is_current_goal true makes it the main one Attribution
|
|
640
|
+
description: `${APEX} — Change a key event. Renaming or changing position keeps its version. Changing its events, their conditions or entity_scope makes a new version: people already counted keep the version they reached, and running tests keep the one they started with. is_current_goal true makes it the workspace's main goal: the one key event Home, Attribution and Channels count when no other is picked. A workspace has one, so it takes the place of the last. Tests, journeys and segments name their own key event and ignore it. Workspace admin.`,
|
|
598
641
|
schema: z.object({
|
|
599
642
|
keyEventId: z.string().min(1).describe("From list_key_events."),
|
|
600
643
|
name: z.string().min(1).max(200).optional(),
|
|
@@ -602,7 +645,8 @@ export const measurementTools = {
|
|
|
602
645
|
category: keyEventCategorySchema.optional(),
|
|
603
646
|
entityScope: z.enum(["person", "account"]).optional(),
|
|
604
647
|
description: z.string().max(1000).optional(),
|
|
605
|
-
|
|
648
|
+
position: z.number().int().min(0).max(999).nullable().optional().describe("Explicit funnel rank (0 = earliest), or null to reset to automatic order."),
|
|
649
|
+
isCurrentGoal: z.literal(true).optional().describe("Make it the workspace's main goal, in place of the one before."),
|
|
606
650
|
}),
|
|
607
651
|
handler: async (args) => {
|
|
608
652
|
try {
|
|
@@ -612,6 +656,7 @@ export const measurementTools = {
|
|
|
612
656
|
...(args.category ? { category: args.category } : {}),
|
|
613
657
|
...(args.entityScope ? { entity_scope: args.entityScope } : {}),
|
|
614
658
|
...(args.description !== undefined ? { description: args.description } : {}),
|
|
659
|
+
...(args.position !== undefined ? { position: args.position } : {}),
|
|
615
660
|
...(args.isCurrentGoal ? { is_current_goal: true } : {}),
|
|
616
661
|
});
|
|
617
662
|
const k = res.data?.keyEvent;
|
|
@@ -622,13 +667,51 @@ export const measurementTools = {
|
|
|
622
667
|
}
|
|
623
668
|
},
|
|
624
669
|
},
|
|
625
|
-
|
|
626
|
-
description: `${APEX} —
|
|
670
|
+
reorder_key_events: {
|
|
671
|
+
description: `${APEX} — Set the workspace's funnel order for its active key events (earliest step first). Pass key_event_ids in the exact sequence customers move through your product; any active key event omitted from the list stays after the ones you named. Workspace admin.`,
|
|
672
|
+
schema: z.object({
|
|
673
|
+
keyEventIds: z.array(z.string().min(1)).min(1).max(200).describe("Active key event IDs in funnel order, earliest step first."),
|
|
674
|
+
}),
|
|
675
|
+
handler: async ({ keyEventIds }) => {
|
|
676
|
+
try {
|
|
677
|
+
const res = await apiPost("/api/key-events/reorder", {
|
|
678
|
+
key_event_ids: keyEventIds,
|
|
679
|
+
});
|
|
680
|
+
const keyEvents = res.data?.keyEvents ?? [];
|
|
681
|
+
const lines = [`${APEX} Updated key event funnel order`, `${"═".repeat(40)}`, ...keyEvents.map(keyEventLine)];
|
|
682
|
+
return text(lines.join("\n"));
|
|
683
|
+
}
|
|
684
|
+
catch (err) {
|
|
685
|
+
return text(`${APEX} ${errMsg(err)}`, true);
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
archive_key_event: {
|
|
690
|
+
description: `${APEX} — Archive a key event nothing active uses. It stops counting new people and leaves every picker, while keeping its version history, who reached it, and old reports intact. Bring it back anytime with restore_key_event. Apex refuses while an active journey, an active segment, a campaign, a target, a test that is not finished, or an ad platform send uses it, and the reply says which: take it out of each one first (get_key_event_usage lists them). Do not work around a refusal; tell the user what uses it. Finished tests and archived segments do not stand in the way. Prefer update_key_event when the meaning changed. Workspace admin.`,
|
|
627
691
|
schema: z.object({ keyEventId: z.string().min(1).describe("From list_key_events.") }),
|
|
628
692
|
handler: async ({ keyEventId }) => {
|
|
629
693
|
try {
|
|
630
|
-
await
|
|
631
|
-
|
|
694
|
+
const res = await apiPost(`/api/key-events/${encodeURIComponent(keyEventId)}/archive`, {});
|
|
695
|
+
const k = res.data?.keyEvent;
|
|
696
|
+
return text(k
|
|
697
|
+
? `${APEX} Archived "${k.name}" [${k.id}]. It stopped counting new people and left every picker; its history and versions are kept. Bring it back anytime with restore_key_event.`
|
|
698
|
+
: `${APEX} Archived ${keyEventId}. Bring it back anytime with restore_key_event.`);
|
|
699
|
+
}
|
|
700
|
+
catch (err) {
|
|
701
|
+
return text(`${APEX} ${errMsg(err)}`, true);
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
restore_key_event: {
|
|
706
|
+
description: `${APEX} — Bring an archived key event back. It returns to every picker, starts counting new people again, and scans history for events heard while it was archived. Use list_key_events with include_archived: true to find archived ids. Workspace admin.`,
|
|
707
|
+
schema: z.object({ keyEventId: z.string().min(1).describe("From list_key_events with include_archived: true.") }),
|
|
708
|
+
handler: async ({ keyEventId }) => {
|
|
709
|
+
try {
|
|
710
|
+
const res = await apiPost(`/api/key-events/${encodeURIComponent(keyEventId)}/restore`, {});
|
|
711
|
+
const k = res.data?.keyEvent;
|
|
712
|
+
return text(k
|
|
713
|
+
? `${APEX} Brought back:\n${keyEventLine(k, 0)}\nApex is now checking history for events heard while it was archived.`
|
|
714
|
+
: `${APEX} Brought ${keyEventId} back.`);
|
|
632
715
|
}
|
|
633
716
|
catch (err) {
|
|
634
717
|
return text(`${APEX} ${errMsg(err)}`, true);
|
|
@@ -675,14 +758,14 @@ export const measurementTools = {
|
|
|
675
758
|
},
|
|
676
759
|
},
|
|
677
760
|
get_key_event_usage: {
|
|
678
|
-
description: `${APEX} — Where a key event is used: the Adaptive Journeys, segments and
|
|
761
|
+
description: `${APEX} — Where a key event is used: the Adaptive Journeys, active segments, tests, campaigns and targets that name it, and what each does with it (goal, starts when reached, guardrail, judged on it). Read it before update_key_event, archive_key_event or accepting a merge. Id from list_key_events.`,
|
|
679
762
|
schema: z.object({ keyEventId: z.string().min(1).describe("From list_key_events.") }),
|
|
680
763
|
handler: async ({ keyEventId }) => {
|
|
681
764
|
try {
|
|
682
765
|
const res = await apiGet(`/api/key-events/${encodeURIComponent(keyEventId)}/usage`);
|
|
683
766
|
const usage = res.data?.usage ?? [];
|
|
684
767
|
if (usage.length === 0)
|
|
685
|
-
return text(`${APEX} Nothing uses ${keyEventId} yet. No journey, segment or
|
|
768
|
+
return text(`${APEX} Nothing uses ${keyEventId} yet. No journey, segment, test, campaign or target names it.`);
|
|
686
769
|
const lines = [`${APEX} Used in ${usage.length} place${usage.length === 1 ? "" : "s"}`, ...usage.map(keyEventUseLine)];
|
|
687
770
|
return text(lines.join("\n"));
|
|
688
771
|
}
|
|
@@ -692,7 +775,7 @@ export const measurementTools = {
|
|
|
692
775
|
},
|
|
693
776
|
},
|
|
694
777
|
suggest_key_events: {
|
|
695
|
-
description: `${APEX} — What Apex suggests about key events, from the events it hears: events that mean the same moment and should count as one key event, events to add to a key event the workspace has, and two key events that count the same thing. Each comes with why and how sure Apex is. Apex only lists what it is sure enough about, so an empty answer is normal for a new workspace. Show the owner the suggestion and the why, then accept_key_event_suggestion or dismiss_key_event_suggestion on their answer. Never accept on your own.`,
|
|
778
|
+
description: `${APEX} — What Apex suggests about key events, from the events it hears: events that mean the same moment and should count as one key event, a single event that is a standard moment (order_placed is a purchase) with no key event for it yet, events to add to a key event the workspace has, and two key events that count the same thing. Each comes with why and how sure Apex is. Apex only lists what it is sure enough about, so an empty answer is normal for a new workspace. Show the owner the suggestion and the why, then accept_key_event_suggestion or dismiss_key_event_suggestion on their answer. Never accept on your own.`,
|
|
696
779
|
schema: z.object({}),
|
|
697
780
|
handler: async () => {
|
|
698
781
|
try {
|
|
@@ -719,15 +802,20 @@ export const measurementTools = {
|
|
|
719
802
|
},
|
|
720
803
|
},
|
|
721
804
|
accept_key_event_suggestion: {
|
|
722
|
-
description: `${APEX} — Take one suggestion from suggest_key_events, after the owner said yes: makes the key event, adds the events to the one they have, or merges the two. A merge deletes nothing; the key event merged away keeps counting for anything that names it. name calls it something else. events keeps only some of the suggested events; the ones left out are remembered as not belonging. Workspace admin.`,
|
|
805
|
+
description: `${APEX} — Take one suggestion from suggest_key_events, after the owner said yes: makes the key event, adds the events to the one they have, or merges the two. A merge deletes nothing; the key event merged away keeps counting for anything that names it. name calls it something else. events keeps only some of the suggested events; the ones left out are remembered as not belonging. For a merge, keep_key_event_id picks which key event keeps its name; leave it out and the first one the suggestion names is kept (the one in use, then the one the owner named, then a funnel step). Workspace admin.`,
|
|
723
806
|
schema: z.object({
|
|
724
807
|
suggestionId: z.string().min(1).describe("From suggest_key_events."),
|
|
725
808
|
name: z.string().min(1).max(120).optional().describe("Call the key event something else."),
|
|
726
809
|
events: z.array(z.string().min(1)).min(1).max(20).optional().describe("Keep only these of the suggested events."),
|
|
810
|
+
keepKeyEventId: z.string().min(1).optional().describe("For a merge: the id of the key event that keeps its name. One of the ids the suggestion names."),
|
|
727
811
|
}),
|
|
728
812
|
handler: async (args) => {
|
|
729
813
|
try {
|
|
730
|
-
const res = await apiPost(`/api/key-events/suggestions/${encodeURIComponent(args.suggestionId)}/accept`, {
|
|
814
|
+
const res = await apiPost(`/api/key-events/suggestions/${encodeURIComponent(args.suggestionId)}/accept`, {
|
|
815
|
+
...(args.name ? { name: args.name } : {}),
|
|
816
|
+
...(args.events ? { events: args.events } : {}),
|
|
817
|
+
...(args.keepKeyEventId ? { keep_key_event_id: args.keepKeyEventId } : {}),
|
|
818
|
+
});
|
|
731
819
|
const k = res.data?.keyEvent;
|
|
732
820
|
if (!k)
|
|
733
821
|
return text(`${APEX} Accepted.`);
|
|
@@ -1488,7 +1576,7 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1488
1576
|
},
|
|
1489
1577
|
},
|
|
1490
1578
|
define_event: {
|
|
1491
|
-
description: `${APEX} — Define a governed custom event in the workspace's Schema (the customer-extensible registry). Promotes one of the merchant's own events to a first-class, typed, versioned definition that behaves like a canonical Apex Spec event (selectable as a journey trigger/goal, resolvable as comm tokens, validated at ingest). Names must be snake_case and CANNOT shadow a canonical Apex Spec event — call get_event_spec first and reuse the canonical event when one fits. Propose the schema from the merchant's observed payloads (get_schema) and codebase, then confirm with them before defining.`,
|
|
1579
|
+
description: `${APEX} — Define a governed custom event in the workspace's Schema (the customer-extensible registry). Promotes one of the merchant's own events to a first-class, typed, versioned definition that behaves like a canonical Apex Spec event (selectable as a journey trigger/goal, resolvable as comm tokens, validated at ingest). Name it the way Apex Spec events are named: the thing, then a past-tense verb (report_exported, never export_report). Names must be snake_case and CANNOT shadow a canonical Apex Spec event — call get_event_spec first and reuse the canonical event when one fits. Propose the schema from the merchant's observed payloads (get_schema) and codebase, then confirm with them before defining.`,
|
|
1492
1580
|
schema: z.object({
|
|
1493
1581
|
name: z.string().describe("snake_case event name, not already in the Apex Spec"),
|
|
1494
1582
|
description: z.string().describe("One sentence: when this event fires"),
|
|
@@ -1630,7 +1718,10 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1630
1718
|
.describe("Include archived sources. Defaults to false."),
|
|
1631
1719
|
}),
|
|
1632
1720
|
handler: async ({ includeArchived }) => {
|
|
1633
|
-
const proj =
|
|
1721
|
+
const proj = await resolveActiveWorkspace();
|
|
1722
|
+
if (!proj) {
|
|
1723
|
+
return text("No active workspace. Use switch_workspace first (or set APEX_WORKSPACE_KEY).", true);
|
|
1724
|
+
}
|
|
1634
1725
|
const qs = includeArchived ? "?includeArchived=true" : "";
|
|
1635
1726
|
const json = await apiGet(`/api/workspaces/${proj}/data-sources${qs}`);
|
|
1636
1727
|
const sources = json.data ?? [];
|
|
@@ -1650,7 +1741,10 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1650
1741
|
name: z.string().describe("Display name, e.g. 'Marketing site' or 'Backend API'."),
|
|
1651
1742
|
}),
|
|
1652
1743
|
handler: async ({ kind, name }) => {
|
|
1653
|
-
const proj =
|
|
1744
|
+
const proj = await resolveActiveWorkspace();
|
|
1745
|
+
if (!proj) {
|
|
1746
|
+
return text("No active workspace. Use switch_workspace first (or set APEX_WORKSPACE_KEY).", true);
|
|
1747
|
+
}
|
|
1654
1748
|
const json = await apiPost(`/api/workspaces/${proj}/data-sources`, { kind, name });
|
|
1655
1749
|
const s = json.data;
|
|
1656
1750
|
return { content: [{ type: "text", text: `✓ Created data source **${s.name}** (${s.kind}) — ${s.status} · \`${s.id}\`` }] };
|
|
@@ -1662,7 +1756,10 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1662
1756
|
id: z.string().describe("The data source id (ds_...)."),
|
|
1663
1757
|
}),
|
|
1664
1758
|
handler: async ({ id }) => {
|
|
1665
|
-
const proj =
|
|
1759
|
+
const proj = await resolveActiveWorkspace();
|
|
1760
|
+
if (!proj) {
|
|
1761
|
+
return text("No active workspace. Use switch_workspace first (or set APEX_WORKSPACE_KEY).", true);
|
|
1762
|
+
}
|
|
1666
1763
|
const json = await apiGet(`/api/workspaces/${proj}/data-sources/${encodeURIComponent(id)}/health`);
|
|
1667
1764
|
const h = json.data;
|
|
1668
1765
|
return { content: [{ type: "text", text: `# ${h.kind} source ${h.id}\n\n- status: **${h.status}**\n- first seen: ${h.firstSeenAt ?? "never"}\n- last seen: ${h.lastSeenAt ?? "never"}` }] };
|
|
@@ -1728,7 +1825,7 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1728
1825
|
description: `${APEX} — Live wiring verification for the active workspace: which canonical events have been received (tier: waiting → detected → verified), which identify traits (first_name, email, …) are arriving, per-data-source status, and which journey/communication templates are Ready to run. Call this AFTER instrumenting tracking code to verify your own work — iterate until each wired event reports "detected". Presence-only: never returns end-user values.`,
|
|
1729
1826
|
schema: z.object({}),
|
|
1730
1827
|
handler: async () => {
|
|
1731
|
-
const workspaceKey =
|
|
1828
|
+
const workspaceKey = await resolveActiveWorkspace();
|
|
1732
1829
|
if (!workspaceKey) {
|
|
1733
1830
|
return {
|
|
1734
1831
|
content: [{ type: "text", text: "No active workspace. Use switch_workspace first (or set APEX_WORKSPACE_KEY)." }],
|
|
@@ -1742,9 +1839,16 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1742
1839
|
const sourceLines = d.sources.map((s) => `- ${s.name} (${s.kind}): ${s.status}${s.lastSeenAt ? ` — last event ${s.lastSeenAt}` : ""}`);
|
|
1743
1840
|
const readyTemplates = d.templates.filter((t) => t.ready);
|
|
1744
1841
|
const blockedTemplates = d.templates.filter((t) => !t.ready);
|
|
1842
|
+
// Always list every journey template (so setup-referenced templates like
|
|
1843
|
+
// `mobile-install-nudge` are never pushed off by communication templates),
|
|
1844
|
+
// while capping non-journey blocked templates at 10.
|
|
1845
|
+
const blockedJourneys = blockedTemplates.filter((t) => t.templateKind === "journey");
|
|
1846
|
+
const blockedOther = blockedTemplates
|
|
1847
|
+
.filter((t) => t.templateKind !== "journey")
|
|
1848
|
+
.slice(0, 10);
|
|
1745
1849
|
const templateLines = [
|
|
1746
|
-
...readyTemplates.map((t) => `- ✅ ${t.title} (${t.templateKind}, id: ${t.templateId}) — Ready to run${t.templateKind === "journey" ? ` → create_journey_from_template({
|
|
1747
|
-
...
|
|
1850
|
+
...readyTemplates.map((t) => `- ✅ ${t.title} (${t.templateKind}, id: ${t.templateId}) — Ready to run${t.templateKind === "journey" ? ` → create_journey_from_template({ template_id: "${t.templateId}" })` : ""}`),
|
|
1851
|
+
...[...blockedJourneys, ...blockedOther].map((t) => `- ⏳ ${t.title} (${t.templateKind}, id: ${t.templateId}) — needs ${[...t.missingEvents, ...t.missingTraits].join(", ") || "?"}`),
|
|
1748
1852
|
];
|
|
1749
1853
|
const milestones = [
|
|
1750
1854
|
d.milestones.firstEventAt ? `First event: ${d.milestones.firstEventAt}` : "First event: not yet",
|
|
@@ -1788,10 +1892,14 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1788
1892
|
}))
|
|
1789
1893
|
.min(1)
|
|
1790
1894
|
.describe("Every instrumentation opportunity found in the scan — both already-wired events (wired: true) and the gaps you propose to wire."),
|
|
1791
|
-
summary: z
|
|
1895
|
+
summary: z
|
|
1896
|
+
.string()
|
|
1897
|
+
.max(500)
|
|
1898
|
+
.optional()
|
|
1899
|
+
.describe("One-paragraph scan summary for the merchant (max 500 characters) — include what you're deliberately NOT wiring and why."),
|
|
1792
1900
|
}),
|
|
1793
1901
|
handler: async (args) => {
|
|
1794
|
-
const workspaceKey =
|
|
1902
|
+
const workspaceKey = await resolveActiveWorkspace();
|
|
1795
1903
|
if (!workspaceKey) {
|
|
1796
1904
|
return {
|
|
1797
1905
|
content: [{ type: "text", text: "No active workspace. Use switch_workspace first (or set APEX_WORKSPACE_KEY)." }],
|
|
@@ -1823,7 +1931,7 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1823
1931
|
visitorId: z.string().optional().describe("Visitor id (default a test id)"),
|
|
1824
1932
|
}),
|
|
1825
1933
|
handler: async (args) => {
|
|
1826
|
-
const workspaceKey =
|
|
1934
|
+
const workspaceKey = await resolveActiveWorkspace();
|
|
1827
1935
|
if (!workspaceKey) {
|
|
1828
1936
|
return { content: [{ type: "text", text: "No active workspace. Run /apex-login or set APEX_WORKSPACE_KEY." }] };
|
|
1829
1937
|
}
|
|
@@ -1920,7 +2028,7 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1920
2028
|
},
|
|
1921
2029
|
},
|
|
1922
2030
|
list_conversions: {
|
|
1923
|
-
description: `${APEX} — List the workspace's Conversions (owned-event definitions of valued actions, e.g. "Purchase", "Signup"). Call this when the user asks what conversions are defined. The
|
|
2031
|
+
description: `${APEX} — List the workspace's Conversions (owned-event definitions of valued actions, e.g. "Purchase", "Signup"). Call this when the user asks what conversions are defined. The one marked primary is the workspace's main goal (the dashboard calls it Main goal), the one Attribution leads with; it does not pick the funnel stages and it is not the experiment default. Experiments name their own metric; the funnel follows the workspace conversion model.`,
|
|
1924
2032
|
schema: z.object({}),
|
|
1925
2033
|
handler: async () => {
|
|
1926
2034
|
const conversions = await apiGet("/api/conversion-goals");
|
|
@@ -1999,7 +2107,7 @@ Events fired through this tool carry a stable synthetic visitorId (mcp-agent-*,
|
|
|
1999
2107
|
},
|
|
2000
2108
|
},
|
|
2001
2109
|
set_primary_conversion: {
|
|
2002
|
-
description: `${APEX} — Make a Conversion the workspace's
|
|
2110
|
+
description: `${APEX} — Make a Conversion the workspace's main goal (the dashboard calls it Main goal; it was the primary conversion before). Same as update_key_event with is_current_goal true. Attribution, get_efforts and next moves lead with it, and it replaces any goal picked before. It does not set experiment defaults or the funnel stages; experiments name their own metric. Pass the conversion id from list_conversions.`,
|
|
2003
2111
|
schema: z.object({
|
|
2004
2112
|
conversionId: z.string().describe("The conversion id to promote (from list_conversions)."),
|
|
2005
2113
|
}),
|