@apex-inc/mcp-server 0.74.0 → 0.75.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/tool-groups.d.ts.map +1 -1
- package/dist/tool-groups.js +2 -0
- package/dist/tool-groups.js.map +1 -1
- package/dist/tools/letters.d.ts +236 -44
- package/dist/tools/letters.d.ts.map +1 -1
- package/dist/tools/letters.js +161 -37
- package/dist/tools/letters.js.map +1 -1
- package/dist/tools/measurement.d.ts +10 -10
- package/dist/tools.d.ts +250 -54
- package/dist/tools.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/tools/letters.js
CHANGED
|
@@ -35,6 +35,41 @@ function everyoneInSegmentLine(c) {
|
|
|
35
35
|
const been = c.alreadyBeenIn ? ` ${people(c.alreadyBeenIn)} already went through it in the last 90 days and won't start again.` : "";
|
|
36
36
|
return `${c.capped ? "At least " : ""}${people(c.wouldStart)} in ${c.segmentName} would start.${been}`;
|
|
37
37
|
}
|
|
38
|
+
const segmentEventWhereSchema = z
|
|
39
|
+
.array(z.object({
|
|
40
|
+
field_path: z.string().min(1).describe("Event property path (dot notation for nested keys, e.g. ft_source_group or plan.tier)."),
|
|
41
|
+
operator: z.enum(["equals", "not_equals", "in", "exists", "not_exists"]),
|
|
42
|
+
value: z
|
|
43
|
+
.union([
|
|
44
|
+
z.string(),
|
|
45
|
+
z.number(),
|
|
46
|
+
z.boolean(),
|
|
47
|
+
z.array(z.union([z.string(), z.number(), z.boolean()])),
|
|
48
|
+
])
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Value to match (omit for exists/not_exists; array for in)."),
|
|
51
|
+
}))
|
|
52
|
+
.max(10)
|
|
53
|
+
.optional()
|
|
54
|
+
.describe("Optional event-property filters (ANDed on the same event).");
|
|
55
|
+
const segmentConditionsSchema = z.object({
|
|
56
|
+
match: z.enum(["all", "any"]),
|
|
57
|
+
groups: z.array(z.object({
|
|
58
|
+
match: z.enum(["all", "any"]),
|
|
59
|
+
conditions: z.array(z.object({
|
|
60
|
+
verb: z.enum(["has", "hasnt"]).optional(),
|
|
61
|
+
event: z.string().optional(),
|
|
62
|
+
where: segmentEventWhereSchema,
|
|
63
|
+
at_least: z.number().int().min(1).optional(),
|
|
64
|
+
key_event_id: z.string().optional(),
|
|
65
|
+
scope: z.enum(["person", "account"]).optional(),
|
|
66
|
+
window_days: z.number().optional(),
|
|
67
|
+
attribute: z.string().optional(),
|
|
68
|
+
op: z.enum(["is", "is_not", "exists"]).optional(),
|
|
69
|
+
value: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
70
|
+
})),
|
|
71
|
+
})),
|
|
72
|
+
});
|
|
38
73
|
export const letterTools = {
|
|
39
74
|
recommend_communications: {
|
|
40
75
|
description: "Get recommended lifecycle communications for your vertical and conversion model. Returns a prioritized list of emails and push notifications to set up.",
|
|
@@ -1061,7 +1096,7 @@ export const letterTools = {
|
|
|
1061
1096
|
// Agent-friendly arg names (snake_case) are mapped to the REST
|
|
1062
1097
|
// routes inside each handler.,
|
|
1063
1098
|
create_journey: {
|
|
1064
|
-
description: `${APEX} — Create a blank draft journey (an unconfigured event trigger wired to an exit). Inherits the workspace's messaging guardrails attribution window by default (or pass attribution_window_days to override for this journey). Then set_journey_trigger and add_journey_step to build it, and publish_journey to launch. For e-commerce flows like cart recovery, prefer create_journey_from_template. audience_bucket defaults to production (live customers). Same email on TestFlight and the store is two people — do not create a staging copy of the journey.`,
|
|
1099
|
+
description: `${APEX} — Create a blank draft journey (an unconfigured event trigger wired to an exit). Inherits the workspace's messaging guardrails attribution window by default (or pass attribution_window_days to override for this journey). Then set_journey_trigger and add_journey_step to build it, and publish_journey to launch. If the journey is meant to close a funnel gap (e.g. Sign-up → Activation or Churned → Reactivated), prefer create_journey_from_funnel_gap so the trigger, goal, and later-stage auto-exits are wired automatically. For e-commerce flows like cart recovery, prefer create_journey_from_template. audience_bucket defaults to production (live customers). Same email on TestFlight and the store is two people — do not create a staging copy of the journey.`,
|
|
1065
1100
|
schema: z.object({
|
|
1066
1101
|
name: z.string().optional().describe("Journey name (default 'Untitled journey')."),
|
|
1067
1102
|
audience_bucket: z
|
|
@@ -1119,6 +1154,127 @@ export const letterTools = {
|
|
|
1119
1154
|
}
|
|
1120
1155
|
},
|
|
1121
1156
|
},
|
|
1157
|
+
get_journey_funnel_coverage: {
|
|
1158
|
+
description: `${APEX} — Read the workspace's funnel stages, stage-to-stage progress (default last 30 days), and which funnel gaps (e.g. Sign-up → Activation, Churned → Reactivated) have live journeys, draft journeys, or no journey yet. Call this before create_journey_from_funnel_gap to get exact from_key_event_id and to_key_event_id values.`,
|
|
1159
|
+
schema: z.object({
|
|
1160
|
+
days: z
|
|
1161
|
+
.number()
|
|
1162
|
+
.int()
|
|
1163
|
+
.min(1)
|
|
1164
|
+
.max(365)
|
|
1165
|
+
.optional()
|
|
1166
|
+
.describe("Window in days for stage-to-stage progress counts (default 30)."),
|
|
1167
|
+
}),
|
|
1168
|
+
handler: async ({ days }) => {
|
|
1169
|
+
try {
|
|
1170
|
+
const qs = days !== undefined ? `?days=${encodeURIComponent(String(days))}` : "";
|
|
1171
|
+
const res = await apiGet(`/api/journeys/funnel-coverage${qs}`);
|
|
1172
|
+
if (!tenantOk(res.metadata?.workspace_key))
|
|
1173
|
+
return tenantMismatch();
|
|
1174
|
+
const d = res.data;
|
|
1175
|
+
if (!d || d.source !== "key_events" || d.gaps.length === 0) {
|
|
1176
|
+
return {
|
|
1177
|
+
content: [
|
|
1178
|
+
{
|
|
1179
|
+
type: "text",
|
|
1180
|
+
text: `${APEX} This workspace doesn't have at least two active funnel stages in Key Events yet. Define funnel stages with create_key_event (or on /dashboard/key-events) first.`,
|
|
1181
|
+
},
|
|
1182
|
+
],
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
const stageLine = d.stages
|
|
1186
|
+
.map((s) => `${s.label} (${s.reachedWindow} in ${d.windowDays}d)`)
|
|
1187
|
+
.join(" → ");
|
|
1188
|
+
const gapLines = d.gaps.map((g) => {
|
|
1189
|
+
const status = g.coverageStatus === "live"
|
|
1190
|
+
? `LIVE (${g.journeys.map((j) => `"${j.name}" [${j.id}]`).join(", ")})`
|
|
1191
|
+
: g.coverageStatus === "draft"
|
|
1192
|
+
? `DRAFT/PAUSED (${g.journeys.map((j) => `"${j.name}" [${j.id}]`).join(", ")})`
|
|
1193
|
+
: "NO JOURNEY";
|
|
1194
|
+
const prog = g.progress.enteredWindow > 0 && g.progress.progressRateWindow !== null
|
|
1195
|
+
? `${Math.round(g.progress.progressRateWindow * 100)}% (${g.progress.progressedWindow}/${g.progress.enteredWindow}, ${g.progress.stillInGapWindow} waiting)`
|
|
1196
|
+
: `no activity in last ${d.windowDays}d`;
|
|
1197
|
+
return ` • ${g.kind === "winback" ? "[Win-back] " : ""}${g.from.label} → ${g.to.label} | ${status} | ${prog}\n from_key_event_id: "${g.from.keyEventId}", to_key_event_id: "${g.to.keyEventId}"`;
|
|
1198
|
+
});
|
|
1199
|
+
return {
|
|
1200
|
+
content: [
|
|
1201
|
+
{
|
|
1202
|
+
type: "text",
|
|
1203
|
+
text: [
|
|
1204
|
+
`${APEX} Funnel coverage (last ${d.windowDays}d): ${d.summary.liveCovered}/${d.summary.totalGaps} live, ${d.summary.draftOnly} draft, ${d.summary.uncovered} uncovered`,
|
|
1205
|
+
`Stages: ${stageLine}`,
|
|
1206
|
+
``,
|
|
1207
|
+
...gapLines,
|
|
1208
|
+
``,
|
|
1209
|
+
`To auto-wire a draft journey for any gap, call create_journey_from_funnel_gap with its from_key_event_id and to_key_event_id.`,
|
|
1210
|
+
].join("\n"),
|
|
1211
|
+
},
|
|
1212
|
+
],
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
catch (err) {
|
|
1216
|
+
return { content: [{ type: "text", text: `${APEX} ${errMsg(err)}` }], isError: true };
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
},
|
|
1220
|
+
create_journey_from_funnel_gap: {
|
|
1221
|
+
description: `${APEX} — Create a draft journey pre-wired for a workspace funnel gap (e.g. Sign-up → Activation, or Churned → Reactivated). Automatically sets the start trigger on from_key_event_id (last-day segment so past history never floods it), sets the journey goal to to_key_event_id, and wires automatic exit rules for the goal, every later funnel stage, and off-ramps. Call get_journey_funnel_coverage first to see the workspace's gaps and key event ids.`,
|
|
1222
|
+
schema: z.object({
|
|
1223
|
+
fromKeyEventId: z.string().describe("Starting funnel stage key event id (from get_journey_funnel_coverage)."),
|
|
1224
|
+
toKeyEventId: z.string().describe("Goal funnel stage key event id (from get_journey_funnel_coverage)."),
|
|
1225
|
+
name: z.string().optional().describe("Optional journey name (defaults to '<From> → <To>')."),
|
|
1226
|
+
description: z.string().optional().describe("Optional journey description."),
|
|
1227
|
+
attributionWindowDays: z
|
|
1228
|
+
.number()
|
|
1229
|
+
.int()
|
|
1230
|
+
.min(1)
|
|
1231
|
+
.max(90)
|
|
1232
|
+
.optional()
|
|
1233
|
+
.describe("Optional attribution window in days (1-90). Omit to inherit workspace default."),
|
|
1234
|
+
audienceBucket: z
|
|
1235
|
+
.enum(["production", "beta", "dev"])
|
|
1236
|
+
.optional()
|
|
1237
|
+
.describe("Who this journey enrolls. Default production."),
|
|
1238
|
+
}),
|
|
1239
|
+
handler: async ({ fromKeyEventId, toKeyEventId, name, description, attributionWindowDays, audienceBucket, }) => {
|
|
1240
|
+
try {
|
|
1241
|
+
const res = await apiPost("/api/journeys/from-funnel-gap", {
|
|
1242
|
+
fromKeyEventId,
|
|
1243
|
+
toKeyEventId,
|
|
1244
|
+
...(name !== undefined ? { name } : {}),
|
|
1245
|
+
...(description !== undefined ? { description } : {}),
|
|
1246
|
+
...(attributionWindowDays !== undefined ? { attributionWindowDays } : {}),
|
|
1247
|
+
...(audienceBucket !== undefined ? { audienceBucket } : {}),
|
|
1248
|
+
});
|
|
1249
|
+
const j = res.data?.journey;
|
|
1250
|
+
const g = res.data?.gap;
|
|
1251
|
+
if (!j || !g) {
|
|
1252
|
+
return { content: [{ type: "text", text: `${APEX} Unexpected empty response creating funnel journey.` }], isError: true };
|
|
1253
|
+
}
|
|
1254
|
+
if (!tenantOk(j.workspaceKey ?? res.metadata?.workspace_key))
|
|
1255
|
+
return tenantMismatch();
|
|
1256
|
+
const exits = g.autoExitKeyEvents.map((e) => e.label).join(", ");
|
|
1257
|
+
return {
|
|
1258
|
+
content: [
|
|
1259
|
+
{
|
|
1260
|
+
type: "text",
|
|
1261
|
+
text: [
|
|
1262
|
+
`${APEX} Created funnel-wired draft journey "${j.name}" (id: ${j.id}).`,
|
|
1263
|
+
`• Starts when: someone reaches ${g.from.label} (from now on; past history stays out)`,
|
|
1264
|
+
`• Goal: ${g.to.label}`,
|
|
1265
|
+
`• Auto-exits on: ${exits || g.to.label}`,
|
|
1266
|
+
`Open on the visual canvas: ${journeyLink(j.id)}`,
|
|
1267
|
+
`Next: add_journey_step to drop in waits and letters, then publish_journey once approved.`,
|
|
1268
|
+
].join("\n"),
|
|
1269
|
+
},
|
|
1270
|
+
],
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
catch (err) {
|
|
1274
|
+
return { content: [{ type: "text", text: `${APEX} ${errMsg(err)}` }], isError: true };
|
|
1275
|
+
}
|
|
1276
|
+
},
|
|
1277
|
+
},
|
|
1122
1278
|
list_trigger_contracts: {
|
|
1123
1279
|
description: `${APEX} — List the workspace's trigger contracts (the event bindings you pass to set_journey_trigger / add_journey_exit). Returns each contract's id + the event it fires on. Call this before set_journey_trigger so you use a real id instead of guessing.`,
|
|
1124
1280
|
schema: z.object({}),
|
|
@@ -1995,28 +2151,12 @@ export const letterTools = {
|
|
|
1995
2151
|
},
|
|
1996
2152
|
},
|
|
1997
2153
|
create_segment: {
|
|
1998
|
-
description: `${APEX} — Create a segment from friendly "conditions" (compiled server-side) OR a raw predicate. Conditions grammar: match all|any of groups; each group match all|any of conditions; each condition is an event ({verb:"has"|"hasnt", event, window_days?}), a key event ({verb:"has"|"hasnt", key_event_id, window_days?, scope?:"person"|"account"}; ids from list_key_events; window_days bounds the first time it was reached; scope "account" means their company reached it), or a trait ({attribute, op:"is"|"is_not"|"exists", value?}). Prefer a key event over the raw events behind it: it is what Attribution counts, conditions included. This is the same grammar the dashboard chip builder speaks.`,
|
|
2154
|
+
description: `${APEX} — Create a segment from friendly "conditions" (compiled server-side) OR a raw predicate. Conditions grammar: match all|any of groups; each group match all|any of conditions; each condition is an event ({verb:"has"|"hasnt", event, where?: [{field_path, operator:"equals"|"not_equals"|"in"|"exists"|"not_exists", value?}], at_least?, window_days?}), a key event ({verb:"has"|"hasnt", key_event_id, window_days?, scope?:"person"|"account"}; ids from list_key_events; window_days bounds the first time it was reached; scope "account" means their company reached it), or a trait ({attribute, op:"is"|"is_not"|"exists", value?}). Prefer a key event over the raw events behind it: it is what Attribution counts, conditions included. Use where on an event condition when filtering on specific event properties (e.g. page_view where ft_source_group equals ai_assistant). This is the same grammar the dashboard chip builder speaks.`,
|
|
1999
2155
|
schema: z.object({
|
|
2000
2156
|
name: z.string().describe("Segment name"),
|
|
2001
2157
|
description: z.string().optional(),
|
|
2002
2158
|
scope: z.enum(["workspace", "org"]).optional().describe("Defaults to workspace"),
|
|
2003
|
-
conditions:
|
|
2004
|
-
.object({
|
|
2005
|
-
match: z.enum(["all", "any"]),
|
|
2006
|
-
groups: z.array(z.object({
|
|
2007
|
-
match: z.enum(["all", "any"]),
|
|
2008
|
-
conditions: z.array(z.object({
|
|
2009
|
-
verb: z.enum(["has", "hasnt"]).optional(),
|
|
2010
|
-
event: z.string().optional(),
|
|
2011
|
-
key_event_id: z.string().optional(),
|
|
2012
|
-
scope: z.enum(["person", "account"]).optional(),
|
|
2013
|
-
window_days: z.number().optional(),
|
|
2014
|
-
attribute: z.string().optional(),
|
|
2015
|
-
op: z.enum(["is", "is_not", "exists"]).optional(),
|
|
2016
|
-
value: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
2017
|
-
})),
|
|
2018
|
-
})),
|
|
2019
|
-
})
|
|
2159
|
+
conditions: segmentConditionsSchema
|
|
2020
2160
|
.optional()
|
|
2021
2161
|
.describe("Friendly conditions (preferred). Sub-keys are snake_case."),
|
|
2022
2162
|
predicate: z.record(z.string(), z.unknown()).optional().describe("Raw SegmentPredicate escape hatch"),
|
|
@@ -2039,29 +2179,13 @@ export const letterTools = {
|
|
|
2039
2179
|
},
|
|
2040
2180
|
},
|
|
2041
2181
|
update_segment: {
|
|
2042
|
-
description: `${APEX} — Update an existing custom segment's name, description, friendly conditions, or raw predicate. Starter segments are read-only (clone them with create_segment instead). Same conditions grammar as create_segment.`,
|
|
2182
|
+
description: `${APEX} — Update an existing custom segment's name, description, friendly conditions, or raw predicate. Starter segments are read-only (clone them with create_segment instead). Same conditions grammar as create_segment (including event property where filters).`,
|
|
2043
2183
|
schema: z.object({
|
|
2044
2184
|
segmentId: z.string().min(1).describe("Segment ID from list_segments or create_segment."),
|
|
2045
2185
|
scope: z.enum(["workspace", "org"]).optional().describe("Segment scope (default workspace)."),
|
|
2046
2186
|
name: z.string().min(1).optional().describe("New segment name."),
|
|
2047
2187
|
description: z.string().optional().describe("New segment description."),
|
|
2048
|
-
conditions:
|
|
2049
|
-
.object({
|
|
2050
|
-
match: z.enum(["all", "any"]),
|
|
2051
|
-
groups: z.array(z.object({
|
|
2052
|
-
match: z.enum(["all", "any"]),
|
|
2053
|
-
conditions: z.array(z.object({
|
|
2054
|
-
verb: z.enum(["has", "hasnt"]).optional(),
|
|
2055
|
-
event: z.string().optional(),
|
|
2056
|
-
key_event_id: z.string().optional(),
|
|
2057
|
-
scope: z.enum(["person", "account"]).optional(),
|
|
2058
|
-
window_days: z.number().optional(),
|
|
2059
|
-
attribute: z.string().optional(),
|
|
2060
|
-
op: z.enum(["is", "is_not", "exists"]).optional(),
|
|
2061
|
-
value: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
2062
|
-
})),
|
|
2063
|
-
})),
|
|
2064
|
-
})
|
|
2188
|
+
conditions: segmentConditionsSchema
|
|
2065
2189
|
.optional()
|
|
2066
2190
|
.describe("Replacement friendly conditions (compiled server-side). Sub-keys are snake_case."),
|
|
2067
2191
|
predicate: z.record(z.string(), z.unknown()).optional().describe("Replacement raw SegmentPredicate."),
|