-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
ai-review-readyPR created, awaiting reviewPR created, awaiting reviewbugSomething isn't workingSomething isn't working
Description
Description
Several prepare_* methods crash with unhelpful errors when required fields are missing at runtime. Since MCP tool calls come from AI agents that may omit required parameters, the services must handle missing fields gracefully.
Example 1: prepareCreateFunnelAnalysis without steps
❌ Cannot read properties of undefined (reading 'length')
The method calls validateFunnelSteps(input.steps) where input.steps is undefined. The validator does steps.length < 2 which crashes on undefined.
Example 2: prepareCreateRetentionAnalysis without name
❌ Cannot read properties of undefined (reading 'trim')
Same pattern — calling .trim() on an undefined field.
Root Cause
The TypeScript interfaces mark these fields as required, but:
- MCP tool inputs are
Record<string, unknown>— no TypeScript enforcement at runtime - AI agents may omit fields they don't know about
- The validation functions assume the fields are present
Fix
Add null/undefined guards at the start of each prepare_* method:
if (!input.steps || !Array.isArray(input.steps)) {
throw new Error('steps is required and must be an array of FunnelStep objects.');
}This pattern should be applied to ALL prepare_* methods across all services.
Affected Services
Any service with required complex fields:
- Funnels (
stepsrequired) - Segmentations (
conditionsrequired) - Data Manager (various required fields)
- Tag Manager
- Campaign Settings
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ai-review-readyPR created, awaiting reviewPR created, awaiting reviewbugSomething isn't workingSomething isn't working