smartlead-mcp-server
Version:
MCP server for Smartlead campaign management integration. Features include creating campaigns, updating campaign settings, and managing campaign sequences.
173 lines • 6.57 kB
JavaScript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
import { isGetVendorsParams, isSearchDomainParams, isAutoGenerateMailboxesParams, isPlaceOrderParams, isGetDomainListParams } from '../types/smartSenders.js';
// Smart Senders API base URL - different from the main SmartLead API
const SMART_SENDERS_API_URL = 'https://smart-senders.smartlead.ai/api/v1';
// Handler for Smart Senders-related tools
export async function handleSmartSendersTool(toolName, args, apiClient, withRetry) {
switch (toolName) {
case 'smartlead_get_vendors': {
return handleGetVendors(args, apiClient, withRetry);
}
case 'smartlead_search_domain': {
return handleSearchDomain(args, apiClient, withRetry);
}
case 'smartlead_auto_generate_mailboxes': {
return handleAutoGenerateMailboxes(args, apiClient, withRetry);
}
case 'smartlead_place_order_mailboxes': {
return handlePlaceOrderMailboxes(args, apiClient, withRetry);
}
case 'smartlead_get_domain_list': {
return handleGetDomainList(args, apiClient, withRetry);
}
default:
throw new Error(`Unknown Smart Senders tool: ${toolName}`);
}
}
// Create a modified client for Smart Senders API with the correct base URL
function createSmartSendersClient(apiClient) {
return {
get: (url, config) => apiClient.get(`${SMART_SENDERS_API_URL}${url}`, config),
post: (url, data, config) => apiClient.post(`${SMART_SENDERS_API_URL}${url}`, data, config),
put: (url, data, config) => apiClient.put(`${SMART_SENDERS_API_URL}${url}`, data, config),
delete: (url, config) => apiClient.delete(`${SMART_SENDERS_API_URL}${url}`, config)
};
}
// Individual handlers for each tool
async function handleGetVendors(args, apiClient, withRetry) {
if (!isGetVendorsParams(args)) {
throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_get_vendors');
}
try {
const smartSendersClient = createSmartSendersClient(apiClient);
const response = await withRetry(async () => smartSendersClient.get('/smart-senders/get-vendors'), 'get vendors');
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
isError: false,
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `API Error: ${error.response?.data?.message || error.message}`
}],
isError: true,
};
}
}
async function handleSearchDomain(args, apiClient, withRetry) {
if (!isSearchDomainParams(args)) {
throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_search_domain');
}
try {
const smartSendersClient = createSmartSendersClient(apiClient);
const { domain_name, vendor_id } = args;
const response = await withRetry(async () => smartSendersClient.get(`/smart-senders/search-domain?domain_name=${domain_name}&vendor_id=${vendor_id}`), 'search domain');
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
isError: false,
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `API Error: ${error.response?.data?.message || error.message}`
}],
isError: true,
};
}
}
async function handleAutoGenerateMailboxes(args, apiClient, withRetry) {
if (!isAutoGenerateMailboxesParams(args)) {
throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_auto_generate_mailboxes');
}
try {
const smartSendersClient = createSmartSendersClient(apiClient);
const response = await withRetry(async () => smartSendersClient.post('/smart-senders/auto-generate-mailboxes', args), 'auto-generate mailboxes');
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
isError: false,
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `API Error: ${error.response?.data?.message || error.message}`
}],
isError: true,
};
}
}
async function handlePlaceOrderMailboxes(args, apiClient, withRetry) {
if (!isPlaceOrderParams(args)) {
throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_place_order_mailboxes');
}
try {
const smartSendersClient = createSmartSendersClient(apiClient);
const response = await withRetry(async () => smartSendersClient.post('/smart-senders/place-order', args), 'place order for mailboxes');
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
isError: false,
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `API Error: ${error.response?.data?.message || error.message}`
}],
isError: true,
};
}
}
async function handleGetDomainList(args, apiClient, withRetry) {
if (!isGetDomainListParams(args)) {
throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_get_domain_list');
}
try {
const smartSendersClient = createSmartSendersClient(apiClient);
const response = await withRetry(async () => smartSendersClient.get('/smart-senders/get-domain-list'), 'get domain list');
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
isError: false,
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `API Error: ${error.response?.data?.message || error.message}`
}],
isError: true,
};
}
}
//# sourceMappingURL=smartSenders.js.map