@apex-inc/mcp-server 0.66.0 → 0.68.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/api-client.d.ts +2 -0
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +11 -0
- package/dist/api-client.js.map +1 -1
- package/dist/tool-groups.d.ts.map +1 -1
- package/dist/tool-groups.js +3 -0
- package/dist/tool-groups.js.map +1 -1
- package/dist/tools/ad-platforms.d.ts +24 -16
- package/dist/tools/ad-platforms.d.ts.map +1 -1
- package/dist/tools/ad-platforms.js +54 -11
- package/dist/tools/ad-platforms.js.map +1 -1
- package/dist/tools/apex-campaigns.d.ts +2 -2
- package/dist/tools/context.d.ts +15 -3
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +66 -29
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/measurement.d.ts +88 -2
- package/dist/tools/measurement.d.ts.map +1 -1
- package/dist/tools/measurement.js +158 -4
- package/dist/tools/measurement.js.map +1 -1
- package/dist/tools/partners.d.ts +27 -4
- package/dist/tools/partners.d.ts.map +1 -1
- package/dist/tools/partners.js +74 -6
- package/dist/tools/partners.js.map +1 -1
- package/dist/tools.d.ts +155 -27
- package/dist/tools.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/apex-integration-cookbook/SKILL.md +25 -0
|
@@ -21,6 +21,10 @@ const keyEventSourceSchema = z.object({
|
|
|
21
21
|
selector: z.string().optional().describe('For form_submit: one form, as "#id". Omit for any form.'),
|
|
22
22
|
target_url: z.string().optional().describe("For form_submit: the page the form is on. Omit for any page."),
|
|
23
23
|
where: z.array(keyEventConditionSchema).max(10).optional().describe("Conditions on the event's data, all must hold."),
|
|
24
|
+
revenue_stream: z
|
|
25
|
+
.enum(["dedupe_with_billing", "additive"])
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('Only on Revenue key events (purchase/subscribe): "dedupe_with_billing" (default, billing stays primary) or "additive" (separate money stream not in Stripe/Shopify/QuickBooks, e.g. offline deals).'),
|
|
24
28
|
});
|
|
25
29
|
const keyEventCategorySchema = z
|
|
26
30
|
.enum([
|
|
@@ -41,6 +45,17 @@ const keyEventCategorySchema = z
|
|
|
41
45
|
"other",
|
|
42
46
|
])
|
|
43
47
|
.describe("What kind of step it is; sets its place in the funnel.");
|
|
48
|
+
async function revenueOverlapNoteFor(category) {
|
|
49
|
+
if (category !== "purchase" && category !== "subscribe")
|
|
50
|
+
return null;
|
|
51
|
+
try {
|
|
52
|
+
const res = await apiGet("/api/revenue/sources");
|
|
53
|
+
return res.data?.overlapWarning ?? null;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
44
59
|
function keyEventLine(k, i) {
|
|
45
60
|
const tags = [
|
|
46
61
|
k.archivedAt ? `archived ${k.archivedAt.slice(0, 10)}` : null,
|
|
@@ -629,7 +644,11 @@ export const measurementTools = {
|
|
|
629
644
|
...(typeof args.position === "number" ? { position: args.position } : {}),
|
|
630
645
|
});
|
|
631
646
|
const k = res.data?.keyEvent;
|
|
632
|
-
|
|
647
|
+
const note = await revenueOverlapNoteFor(k?.category ?? args.category);
|
|
648
|
+
const body = k
|
|
649
|
+
? `${APEX} Made key event:\n${keyEventLine(k, 0)}\nApex is now checking people's history for it.`
|
|
650
|
+
: `${APEX} Made key event.`;
|
|
651
|
+
return text(note ? `${body}\n\nNote: ${note}` : body);
|
|
633
652
|
}
|
|
634
653
|
catch (err) {
|
|
635
654
|
return text(`${APEX} ${errMsg(err)}`, true);
|
|
@@ -660,7 +679,91 @@ export const measurementTools = {
|
|
|
660
679
|
...(args.isCurrentGoal ? { is_current_goal: true } : {}),
|
|
661
680
|
});
|
|
662
681
|
const k = res.data?.keyEvent;
|
|
663
|
-
|
|
682
|
+
const note = await revenueOverlapNoteFor(k?.category ?? args.category);
|
|
683
|
+
const body = k ? `${APEX} Saved:\n${keyEventLine(k, 0)}` : `${APEX} Saved.`;
|
|
684
|
+
return text(note ? `${body}\n\nNote: ${note}` : body);
|
|
685
|
+
}
|
|
686
|
+
catch (err) {
|
|
687
|
+
return text(`${APEX} ${errMsg(err)}`, true);
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
get_revenue_sources: {
|
|
692
|
+
description: `${APEX} — Where this workspace's revenue comes from: connected billing and CRM tools (Stripe, Shopify, QuickBooks, HubSpot), which source currently counts as primary, the active Revenue key event and whether each tracked event dedupes with billing or counts as a separate money stream, plus any suspected duplicate revenue waiting for review.`,
|
|
693
|
+
schema: z.object({}),
|
|
694
|
+
handler: async () => {
|
|
695
|
+
try {
|
|
696
|
+
const res = await apiGet("/api/revenue/sources");
|
|
697
|
+
const d = res.data;
|
|
698
|
+
if (!d)
|
|
699
|
+
return text(`${APEX} Couldn't load revenue sources.`, true);
|
|
700
|
+
const lines = [
|
|
701
|
+
`${APEX} Revenue sources`,
|
|
702
|
+
`${"═".repeat(40)}`,
|
|
703
|
+
`Counting now: ${d.countingNow ?? (d.needsReferee ? "none (pick one with set_revenue_source_of_truth)" : "none yet")}${d.revenueSourceOfTruth ? " (picked)" : d.isProvisional ? " (automatic until you pick)" : ""}`,
|
|
704
|
+
];
|
|
705
|
+
if (d.connectedIntegrations.length > 0) {
|
|
706
|
+
lines.push("Connected billing/CRM:", ...d.connectedIntegrations.map((c) => ` • ${c.label}: ${c.isCounting ? "counting" : c.isLive ? "live (not primary)" : "connected"}`));
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
lines.push("Connected billing/CRM: none");
|
|
710
|
+
}
|
|
711
|
+
if (d.revenueKeyEvent) {
|
|
712
|
+
lines.push(`Revenue key event: ${d.revenueKeyEvent.name} [${d.revenueKeyEvent.id}] (${d.revenueKeyEvent.category})`);
|
|
713
|
+
for (const s of d.revenueKeyEvent.sources) {
|
|
714
|
+
lines.push(` • ${s.eventName ?? s.type}: ${s.revenueStream === "additive" ? "separate money stream (adds alongside billing)" : "same sales (dedupe with billing)"}`);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
lines.push("Revenue key event: none set (built-in purchases count by default)");
|
|
719
|
+
}
|
|
720
|
+
if (d.suspectedDuplicateCount > 0) {
|
|
721
|
+
lines.push(`Suspected duplicates: $${d.suspectedDuplicateUsd.toFixed(2)} across ${d.suspectedDuplicateCount} ${d.suspectedDuplicateCount === 1 ? "sale" : "sales"}. Review on ${appUrl("/dashboard/settings/attribution")}.`);
|
|
722
|
+
}
|
|
723
|
+
if (d.overlapWarning)
|
|
724
|
+
lines.push("", `Note: ${d.overlapWarning}`);
|
|
725
|
+
return text(lines.join("\n"));
|
|
726
|
+
}
|
|
727
|
+
catch (err) {
|
|
728
|
+
return text(`${APEX} ${errMsg(err)}`, true);
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
},
|
|
732
|
+
set_revenue_source_of_truth: {
|
|
733
|
+
description: `${APEX} — Pick which single revenue source counts as the workspace's primary source of truth (stripe, shopify, quickbooks, hubspot, server, sdk, manual). Call first with confirm omitted/false to preview how historical revenue would change, then call again with confirm: true to apply the restatement. Workspace admin.`,
|
|
734
|
+
schema: z.object({
|
|
735
|
+
sourceOfTruth: z
|
|
736
|
+
.enum(["stripe", "shopify", "quickbooks", "hubspot", "server", "sdk", "manual"])
|
|
737
|
+
.describe("The source that should count as primary revenue."),
|
|
738
|
+
confirm: z
|
|
739
|
+
.boolean()
|
|
740
|
+
.optional()
|
|
741
|
+
.describe("Omit or false to preview the restatement impact without writing; true to apply it."),
|
|
742
|
+
}),
|
|
743
|
+
handler: async (args) => {
|
|
744
|
+
try {
|
|
745
|
+
if (!args.confirm) {
|
|
746
|
+
const res = await apiPost("/api/revenue/referee", {
|
|
747
|
+
sourceOfTruth: args.sourceOfTruth,
|
|
748
|
+
previewOnly: true,
|
|
749
|
+
});
|
|
750
|
+
const p = res.data?.preview;
|
|
751
|
+
if (!p)
|
|
752
|
+
return text(`${APEX} Preview unavailable.`, true);
|
|
753
|
+
return text([
|
|
754
|
+
`${APEX} Preview: switch revenue source of truth to ${args.sourceOfTruth}`,
|
|
755
|
+
`${"═".repeat(40)}`,
|
|
756
|
+
`Before: $${p.beforeUsd.toFixed(2)} → After: $${p.afterUsd.toFixed(2)} (change: ${p.deltaUsd >= 0 ? "+" : ""}$${p.deltaUsd.toFixed(2)})`,
|
|
757
|
+
`Events reflagged: ${p.eventsReflagged}, people recalculated: ${p.affectedLeads}`,
|
|
758
|
+
`Nothing changed yet. Call set_revenue_source_of_truth again with source_of_truth: "${args.sourceOfTruth}" and confirm: true to apply.`,
|
|
759
|
+
].join("\n"));
|
|
760
|
+
}
|
|
761
|
+
const res = await apiPost("/api/revenue/referee", {
|
|
762
|
+
sourceOfTruth: args.sourceOfTruth,
|
|
763
|
+
acknowledgeRestatement: true,
|
|
764
|
+
});
|
|
765
|
+
const d = res.data;
|
|
766
|
+
return text(`${APEX} Revenue source of truth is now ${d?.sourceOfTruth ?? args.sourceOfTruth} (${d?.eventsReflagged ?? 0} events updated, ${d?.affectedLeads ?? 0} people recalculated).`);
|
|
664
767
|
}
|
|
665
768
|
catch (err) {
|
|
666
769
|
return text(`${APEX} ${errMsg(err)}`, true);
|
|
@@ -758,14 +861,14 @@ export const measurementTools = {
|
|
|
758
861
|
},
|
|
759
862
|
},
|
|
760
863
|
get_key_event_usage: {
|
|
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.`,
|
|
864
|
+
description: `${APEX} — Where a key event is used: the Adaptive Journeys, active segments, tests, campaigns, partner programs paying on it, and targets that name it, and what each does with it (goal, starts when reached, guardrail, judged on it, pays partners). Read it before update_key_event, archive_key_event or accepting a merge. Id from list_key_events.`,
|
|
762
865
|
schema: z.object({ keyEventId: z.string().min(1).describe("From list_key_events.") }),
|
|
763
866
|
handler: async ({ keyEventId }) => {
|
|
764
867
|
try {
|
|
765
868
|
const res = await apiGet(`/api/key-events/${encodeURIComponent(keyEventId)}/usage`);
|
|
766
869
|
const usage = res.data?.usage ?? [];
|
|
767
870
|
if (usage.length === 0)
|
|
768
|
-
return text(`${APEX} Nothing uses ${keyEventId} yet. No journey, segment, test, campaign or target names it.`);
|
|
871
|
+
return text(`${APEX} Nothing uses ${keyEventId} yet. No journey, segment, test, campaign, partner program or target names it.`);
|
|
769
872
|
const lines = [`${APEX} Used in ${usage.length} place${usage.length === 1 ? "" : "s"}`, ...usage.map(keyEventUseLine)];
|
|
770
873
|
return text(lines.join("\n"));
|
|
771
874
|
}
|
|
@@ -774,6 +877,57 @@ export const measurementTools = {
|
|
|
774
877
|
}
|
|
775
878
|
},
|
|
776
879
|
},
|
|
880
|
+
get_key_event_timing: {
|
|
881
|
+
description: `${APEX} — How long it takes people or companies to go from one key event to another (e.g. Trial started to Paid, or Qualified to Revenue), overall and broken down by campaign. Omit to_key_event_id to measure time to the workspace's primary revenue key event (or purchases by default). Ids come from list_key_events.`,
|
|
882
|
+
schema: z.object({
|
|
883
|
+
fromKeyEventId: z.string().min(1).describe("Starting key event id from list_key_events."),
|
|
884
|
+
toKeyEventId: z
|
|
885
|
+
.string()
|
|
886
|
+
.min(1)
|
|
887
|
+
.optional()
|
|
888
|
+
.describe("Ending key event id from list_key_events. Omit to measure time to the workspace's primary revenue key event (or purchases)."),
|
|
889
|
+
scope: z.enum(["person", "account"]).optional().describe("Count per person or per company (defaults to the starting key event's scope)."),
|
|
890
|
+
campaignId: z.string().min(1).optional().describe("Filter to a single Apex campaign id."),
|
|
891
|
+
start: z.string().optional().describe("Only count people/companies who reached the starting key event on or after this ISO date."),
|
|
892
|
+
end: z.string().optional().describe("Only count people/companies who reached the starting key event on or before this ISO date."),
|
|
893
|
+
}),
|
|
894
|
+
handler: async (args) => {
|
|
895
|
+
try {
|
|
896
|
+
const params = new URLSearchParams({ from_key_event_id: args.fromKeyEventId });
|
|
897
|
+
if (args.toKeyEventId)
|
|
898
|
+
params.set("to_key_event_id", args.toKeyEventId);
|
|
899
|
+
if (args.scope)
|
|
900
|
+
params.set("scope", args.scope);
|
|
901
|
+
if (args.campaignId)
|
|
902
|
+
params.set("campaign_id", args.campaignId);
|
|
903
|
+
if (args.start)
|
|
904
|
+
params.set("start", args.start);
|
|
905
|
+
if (args.end)
|
|
906
|
+
params.set("end", args.end);
|
|
907
|
+
const res = await apiGet(`/api/key-events/timing?${params.toString()}`);
|
|
908
|
+
const d = res.data;
|
|
909
|
+
if (!d)
|
|
910
|
+
return text(`${APEX} Couldn't read key event timing.`, true);
|
|
911
|
+
const unit = d.scope === "account" ? "companies" : "people";
|
|
912
|
+
const fmtDur = (hours, days) => hours === null ? "—" : days !== null && days >= 2 ? `${days}d` : `${hours}h`;
|
|
913
|
+
const pct = (r) => `${Math.round(r * 1000) / 10}%`;
|
|
914
|
+
const lines = [
|
|
915
|
+
`${APEX} ${d.from.name} → ${d.to.name} (${unit})`,
|
|
916
|
+
`Overall: ${d.overall.reachedTo}/${d.overall.reachedFrom} (${pct(d.overall.conversionRate)}) · median ${fmtDur(d.overall.medianHours, d.overall.medianDays)}`,
|
|
917
|
+
];
|
|
918
|
+
if (d.byCampaign.length > 0) {
|
|
919
|
+
lines.push("", "By campaign:");
|
|
920
|
+
for (const row of d.byCampaign) {
|
|
921
|
+
lines.push(` • ${row.campaignName}: ${row.reachedTo}/${row.reachedFrom} (${pct(row.conversionRate)}) · median ${fmtDur(row.medianHours, row.medianDays)}`);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return text(lines.join("\n"));
|
|
925
|
+
}
|
|
926
|
+
catch (err) {
|
|
927
|
+
return text(`${APEX} ${errMsg(err)}`, true);
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
},
|
|
777
931
|
suggest_key_events: {
|
|
778
932
|
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.`,
|
|
779
933
|
schema: z.object({}),
|