smartlead_add_lead_to_campaign
Add a new lead with email and contact details to a specific email marketing campaign for automated outreach.
Instructions
Add a new lead to a campaign.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaign_id | Yes | ID of the campaign to add the lead to | |
| company | No | Company of the lead | |
| custom_fields | No | Custom fields for the lead | |
| Yes | Email address of the lead | ||
| first_name | No | First name of the lead | |
| last_name | No | Last name of the lead | |
| phone | No | Phone number of the lead | |
| title | No | Job title of the lead |
Implementation Reference
- src/handlers/lead.ts:148-184 (handler)Core handler function that validates the input arguments and executes the POST API call to add a lead to a specific campaign in Smartlead.async function handleAddLeadToCampaign( args: unknown, apiClient: AxiosInstance, withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> ) { if (!isAddLeadToCampaignParams(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for smartlead_add_lead_to_campaign' ); } try { const response = await withRetry( async () => apiClient.post(`/campaigns/${args.campaign_id}/leads`, args), 'add lead to campaign' ); 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/lead.ts:59-101 (schema)Tool definition with input schema specifying parameters for adding a lead to a campaign, including required fields campaign_id and email.export const ADD_LEAD_TO_CAMPAIGN_TOOL: CategoryTool = { name: 'smartlead_add_lead_to_campaign', description: 'Add a new lead to a campaign.', category: ToolCategory.LEAD_MANAGEMENT, inputSchema: { type: 'object', properties: { campaign_id: { type: 'number', description: 'ID of the campaign to add the lead to', }, email: { type: 'string', description: 'Email address of the lead', }, first_name: { type: 'string', description: 'First name of the lead', }, last_name: { type: 'string', description: 'Last name of the lead', }, company: { type: 'string', description: 'Company of the lead', }, title: { type: 'string', description: 'Job title of the lead', }, phone: { type: 'string', description: 'Phone number of the lead', }, custom_fields: { type: 'object', description: 'Custom fields for the lead', }, }, required: ['campaign_id', 'email'], }, };
- src/types/lead.ts:124-162 (schema)Type guard function for validating input parameters match AddLeadToCampaignParams interface, used in the handler for runtime checks.export function isAddLeadToCampaignParams(args: unknown): args is AddLeadToCampaignParams { if ( typeof args !== 'object' || args === null || !('campaign_id' in args) || !('email' in args) || typeof (args as { campaign_id: unknown }).campaign_id !== 'number' || typeof (args as { email: unknown }).email !== 'string' ) { return false; } const params = args as AddLeadToCampaignParams; // Optional fields validation if (params.first_name !== undefined && typeof params.first_name !== 'string') { return false; } if (params.last_name !== undefined && typeof params.last_name !== 'string') { return false; } if (params.company !== undefined && typeof params.company !== 'string') { return false; } if (params.title !== undefined && typeof params.title !== 'string') { return false; } if (params.phone !== undefined && typeof params.phone !== 'string') { return false; } if ( params.custom_fields !== undefined && (typeof params.custom_fields !== 'object' || params.custom_fields === null) ) { return false; } return true; }
- src/index.ts:207-209 (registration)Registers all lead management tools, including smartlead_add_lead_to_campaign, to the tool registry when the leadManagement category is enabled.if (enabledCategories.leadManagement) { toolRegistry.registerMany(leadTools); }
- src/index.ts:350-352 (registration)Dispatches calls to lead management tools, including smartlead_add_lead_to_campaign, to the handleLeadTool function based on tool category.case ToolCategory.LEAD_MANAGEMENT: return await handleLeadTool(name, toolArgs, apiClient, withRetry); case ToolCategory.CAMPAIGN_STATISTICS: