( server: McpServer, context: McpAuthContext, )
| 13 | } from '../shared'; |
| 14 | |
| 15 | export function registerFunnelTools( |
| 16 | server: McpServer, |
| 17 | context: McpAuthContext, |
| 18 | ) { |
| 19 | server.tool( |
| 20 | 'get_funnel', |
| 21 | 'Analyze a conversion funnel between 2 or more events. Returns step-by-step conversion rates and drop-off percentages. For example, analyze sign-up flows, checkout funnels, or onboarding sequences.', |
| 22 | { |
| 23 | projectId: projectIdSchema(context), |
| 24 | ...zDateRange, |
| 25 | steps: z |
| 26 | .array(z.string()) |
| 27 | .min(2) |
| 28 | .max(10) |
| 29 | .describe( |
| 30 | 'Ordered list of event names forming the funnel steps (minimum 2, maximum 10)', |
| 31 | ), |
| 32 | windowHours: z |
| 33 | .number() |
| 34 | .min(1) |
| 35 | .max(720) |
| 36 | .default(24) |
| 37 | .optional() |
| 38 | .describe( |
| 39 | 'Time window in hours within which all steps must occur (default: 24 hours)', |
| 40 | ), |
| 41 | groupBy: z |
| 42 | .enum(['session_id', 'profile_id']) |
| 43 | .default('session_id') |
| 44 | .optional() |
| 45 | .describe( |
| 46 | '"session_id" counts within-session completions, "profile_id" counts cross-session completions (default: session_id)', |
| 47 | ), |
| 48 | }, |
| 49 | async ({ projectId: inputProjectId, startDate: sd, endDate: ed, steps, windowHours, groupBy }) => |
| 50 | withErrorHandling(async () => { |
| 51 | const projectId = await resolveProjectId(context, inputProjectId); |
| 52 | const { startDate, endDate } = resolveDateRange(sd, ed); |
| 53 | return getFunnelCore({ |
| 54 | projectId, |
| 55 | startDate, |
| 56 | endDate, |
| 57 | steps, |
| 58 | windowHours, |
| 59 | groupBy, |
| 60 | }); |
| 61 | }), |
| 62 | ); |
| 63 | } |
no test coverage detected