smartlead_get_campaigns_by_lead
Retrieve all email marketing campaigns associated with a specific lead by providing the lead ID to track campaign participation and engagement.
Instructions
Fetch all campaigns that a lead belongs to.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lead_id | Yes | ID of the lead to fetch campaigns for |
Implementation Reference
- src/handlers/campaign.ts:385-421 (handler)The handler function that implements the core logic: validates input using isGetCampaignsByLeadParams and performs a GET request to `/leads/${lead_id}/campaigns` via the API client.async function handleGetCampaignsByLead( args: unknown, apiClient: AxiosInstance, withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> ) { if (!isGetCampaignsByLeadParams(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for smartlead_get_campaigns_by_lead' ); } try { const response = await withRetry( async () => apiClient.get(`/leads/${args.lead_id}/campaigns`), 'get campaigns by lead' ); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], isError: false, }; } catch (error: any) { return { content: [{ type: 'text', text: `API Error: ${error.response?.data?.message || error.message}` }], isError: true, }; } }
- src/tools/campaign.ts:257-271 (schema)Defines the tool's metadata, description, category, and input schema requiring a numeric lead_id.export const GET_CAMPAIGNS_BY_LEAD_TOOL: CategoryTool = { name: 'smartlead_get_campaigns_by_lead', description: 'Fetch all campaigns that a lead belongs to.', category: ToolCategory.CAMPAIGN_MANAGEMENT, inputSchema: { type: 'object', properties: { lead_id: { type: 'number', description: 'ID of the lead to fetch campaigns for', }, }, required: ['lead_id'], }, };
- src/types/campaign.ts:170-177 (schema)Type guard function used in the handler to validate that the input arguments contain a valid numeric lead_id.export function isGetCampaignsByLeadParams(args: unknown): args is GetCampaignsByLeadParams { return ( typeof args === 'object' && args !== null && 'lead_id' in args && typeof (args as { lead_id: unknown }).lead_id === 'number' ); }
- src/index.ts:197-199 (registration)Registers the campaign tools (including smartlead_get_campaigns_by_lead) with the central ToolRegistry if the campaignManagement category is enabled.if (enabledCategories.campaignManagement) { toolRegistry.registerMany(campaignTools); }
- src/handlers/campaign.ts:51-52 (registration)Switch case in handleCampaignTool that routes calls to this specific tool to its handler function.case 'smartlead_get_campaigns_by_lead': { return handleGetCampaignsByLead(args, apiClient, withRetry);