This is page 3 of 3. Use http://codebase.md/jean-technologies/smartlead-mcp-server-local?lines=true&page={x} to view the full context. # Directory Structure ``` ├── .env.example ├── .gitignore ├── DEVELOPER_ONBOARDING.md ├── Dockerfile ├── jest.config.js ├── llms-install.md ├── mcp_settings_example.json ├── package-lock.json ├── package.json ├── README.md ├── server │ └── license-server.js ├── smithery.yaml ├── src │ ├── cli.ts │ ├── config │ │ └── feature-config.ts │ ├── handlers │ │ ├── campaign.ts │ │ ├── clientManagement.ts │ │ ├── email.ts │ │ ├── lead.ts │ │ ├── smartDelivery.ts │ │ ├── smartSenders.ts │ │ ├── statistics.ts │ │ └── webhooks.ts │ ├── index.ts │ ├── licensing │ │ ├── index.ts │ │ └── stripe-integration.js │ ├── n8n │ │ └── index.ts │ ├── registry │ │ └── tool-registry.ts │ ├── supergateway-mock.ts │ ├── supergateway.ts │ ├── tools │ │ ├── campaign.ts │ │ ├── clientManagement.ts │ │ ├── email.d.ts │ │ ├── email.ts │ │ ├── lead.d.ts │ │ ├── lead.ts │ │ ├── smartDelivery.d.ts │ │ ├── smartDelivery.ts │ │ ├── smartSenders.ts │ │ ├── statistics.d.ts │ │ ├── statistics.ts │ │ └── webhooks.ts │ ├── types │ │ ├── campaign.ts │ │ ├── clientManagement.ts │ │ ├── common.ts │ │ ├── email.d.ts │ │ ├── email.ts │ │ ├── lead.ts │ │ ├── smartDelivery.ts │ │ ├── smartSenders.ts │ │ ├── statistics.d.ts │ │ ├── statistics.ts │ │ ├── supergateway.d.ts │ │ └── webhooks.ts │ └── utils │ └── download-tracker.ts └── tsconfig.json ``` # Files -------------------------------------------------------------------------------- /src/handlers/smartDelivery.ts: -------------------------------------------------------------------------------- ```typescript 1 | import { AxiosInstance } from 'axios'; 2 | import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; 3 | import { 4 | isGetRegionWiseProvidersParams, 5 | isCreateManualPlacementTestParams, 6 | isCreateAutomatedPlacementTestParams, 7 | isGetSpamTestDetailsParams, 8 | isDeleteSmartDeliveryTestsParams, 9 | isStopAutomatedTestParams, 10 | isListAllTestsParams, 11 | isProviderWiseReportParams, 12 | isGroupWiseReportParams, 13 | isSenderAccountWiseReportParams, 14 | isSpamFilterDetailsParams, 15 | isDkimDetailsParams, 16 | isSpfDetailsParams, 17 | isRdnsDetailsParams, 18 | isSenderAccountsParams, 19 | isBlacklistParams, 20 | isEmailContentParams, 21 | isIpAnalyticsParams, 22 | isEmailHeadersParams, 23 | isScheduleHistoryParams, 24 | isIpDetailsParams, 25 | isMailboxSummaryParams, 26 | isMailboxCountParams, 27 | isGetAllFoldersParams, 28 | isCreateFolderParams, 29 | isGetFolderByIdParams, 30 | isDeleteFolderParams 31 | } from '../types/smartDelivery.js'; 32 | 33 | // SmartDelivery API base URL 34 | const SMART_DELIVERY_API_URL = 'https://smartdelivery.smartlead.ai/api/v1'; 35 | 36 | // Handler for SmartDelivery-related tools 37 | export async function handleSmartDeliveryTool( 38 | toolName: string, 39 | args: unknown, 40 | apiClient: AxiosInstance, 41 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 42 | ) { 43 | switch (toolName) { 44 | case 'smartlead_get_region_wise_providers': { 45 | return handleGetRegionWiseProviders(args, apiClient, withRetry); 46 | } 47 | case 'smartlead_create_manual_placement_test': { 48 | return handleCreateManualPlacementTest(args, apiClient, withRetry); 49 | } 50 | case 'smartlead_create_automated_placement_test': { 51 | return handleCreateAutomatedPlacementTest(args, apiClient, withRetry); 52 | } 53 | case 'smartlead_get_spam_test_details': { 54 | return handleGetSpamTestDetails(args, apiClient, withRetry); 55 | } 56 | case 'smartlead_delete_smart_delivery_tests': { 57 | return handleDeleteSmartDeliveryTests(args, apiClient, withRetry); 58 | } 59 | case 'smartlead_stop_automated_test': { 60 | return handleStopAutomatedTest(args, apiClient, withRetry); 61 | } 62 | case 'smartlead_list_all_tests': { 63 | return handleListAllTests(args, apiClient, withRetry); 64 | } 65 | case 'smartlead_get_provider_wise_report': { 66 | return handleGetProviderWiseReport(args, apiClient, withRetry); 67 | } 68 | case 'smartlead_get_group_wise_report': { 69 | return handleGetGroupWiseReport(args, apiClient, withRetry); 70 | } 71 | case 'smartlead_get_sender_account_wise_report': { 72 | return handleGetSenderAccountWiseReport(args, apiClient, withRetry); 73 | } 74 | case 'smartlead_get_spam_filter_details': { 75 | return handleGetSpamFilterDetails(args, apiClient, withRetry); 76 | } 77 | case 'smartlead_get_dkim_details': { 78 | return handleGetDkimDetails(args, apiClient, withRetry); 79 | } 80 | case 'smartlead_get_spf_details': { 81 | return handleGetSpfDetails(args, apiClient, withRetry); 82 | } 83 | case 'smartlead_get_rdns_details': { 84 | return handleGetRdnsDetails(args, apiClient, withRetry); 85 | } 86 | case 'smartlead_get_sender_accounts': { 87 | return handleGetSenderAccounts(args, apiClient, withRetry); 88 | } 89 | case 'smartlead_get_blacklist': { 90 | return handleGetBlacklist(args, apiClient, withRetry); 91 | } 92 | case 'smartlead_get_email_content': { 93 | return handleGetEmailContent(args, apiClient, withRetry); 94 | } 95 | case 'smartlead_get_ip_analytics': { 96 | return handleGetIpAnalytics(args, apiClient, withRetry); 97 | } 98 | case 'smartlead_get_email_headers': { 99 | return handleGetEmailHeaders(args, apiClient, withRetry); 100 | } 101 | case 'smartlead_get_schedule_history': { 102 | return handleGetScheduleHistory(args, apiClient, withRetry); 103 | } 104 | case 'smartlead_get_ip_details': { 105 | return handleGetIpDetails(args, apiClient, withRetry); 106 | } 107 | case 'smartlead_get_mailbox_summary': { 108 | return handleGetMailboxSummary(args, apiClient, withRetry); 109 | } 110 | case 'smartlead_get_mailbox_count': { 111 | return handleGetMailboxCount(args, apiClient, withRetry); 112 | } 113 | case 'smartlead_get_all_folders': { 114 | return handleGetAllFolders(args, apiClient, withRetry); 115 | } 116 | case 'smartlead_create_folder': { 117 | return handleCreateFolder(args, apiClient, withRetry); 118 | } 119 | case 'smartlead_get_folder_by_id': { 120 | return handleGetFolderById(args, apiClient, withRetry); 121 | } 122 | case 'smartlead_delete_folder': { 123 | return handleDeleteFolder(args, apiClient, withRetry); 124 | } 125 | default: 126 | throw new Error(`Unknown SmartDelivery tool: ${toolName}`); 127 | } 128 | } 129 | 130 | // Create a modified client for SmartDelivery API with the correct base URL 131 | function createSmartDeliveryClient(apiClient: AxiosInstance) { 132 | return { 133 | get: (url: string, config?: any) => 134 | apiClient.get(`${SMART_DELIVERY_API_URL}${url}`, config), 135 | post: (url: string, data?: any, config?: any) => 136 | apiClient.post(`${SMART_DELIVERY_API_URL}${url}`, data, config), 137 | put: (url: string, data?: any, config?: any) => 138 | apiClient.put(`${SMART_DELIVERY_API_URL}${url}`, data, config), 139 | delete: (url: string, config?: any) => 140 | apiClient.delete(`${SMART_DELIVERY_API_URL}${url}`, config) 141 | }; 142 | } 143 | 144 | // Individual handlers for each tool 145 | async function handleGetRegionWiseProviders( 146 | args: unknown, 147 | apiClient: AxiosInstance, 148 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 149 | ) { 150 | if (!isGetRegionWiseProvidersParams(args)) { 151 | throw new McpError( 152 | ErrorCode.InvalidParams, 153 | 'Invalid arguments for smartlead_get_region_wise_providers' 154 | ); 155 | } 156 | 157 | try { 158 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 159 | 160 | const response = await withRetry( 161 | async () => smartDeliveryClient.get('/spam-test/seed/providers'), 162 | 'get region wise providers' 163 | ); 164 | 165 | return { 166 | content: [ 167 | { 168 | type: 'text', 169 | text: JSON.stringify(response.data, null, 2), 170 | }, 171 | ], 172 | isError: false, 173 | }; 174 | } catch (error: any) { 175 | return { 176 | content: [{ 177 | type: 'text', 178 | text: `API Error: ${error.response?.data?.message || error.message}` 179 | }], 180 | isError: true, 181 | }; 182 | } 183 | } 184 | 185 | async function handleCreateManualPlacementTest( 186 | args: unknown, 187 | apiClient: AxiosInstance, 188 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 189 | ) { 190 | if (!isCreateManualPlacementTestParams(args)) { 191 | throw new McpError( 192 | ErrorCode.InvalidParams, 193 | 'Invalid arguments for smartlead_create_manual_placement_test' 194 | ); 195 | } 196 | 197 | try { 198 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 199 | 200 | const response = await withRetry( 201 | async () => smartDeliveryClient.post('/spam-test/manual', args), 202 | 'create manual placement test' 203 | ); 204 | 205 | return { 206 | content: [ 207 | { 208 | type: 'text', 209 | text: JSON.stringify(response.data, null, 2), 210 | }, 211 | ], 212 | isError: false, 213 | }; 214 | } catch (error: any) { 215 | return { 216 | content: [{ 217 | type: 'text', 218 | text: `API Error: ${error.response?.data?.message || error.message}` 219 | }], 220 | isError: true, 221 | }; 222 | } 223 | } 224 | 225 | async function handleCreateAutomatedPlacementTest( 226 | args: unknown, 227 | apiClient: AxiosInstance, 228 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 229 | ) { 230 | if (!isCreateAutomatedPlacementTestParams(args)) { 231 | throw new McpError( 232 | ErrorCode.InvalidParams, 233 | 'Invalid arguments for smartlead_create_automated_placement_test' 234 | ); 235 | } 236 | 237 | try { 238 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 239 | 240 | const response = await withRetry( 241 | async () => smartDeliveryClient.post('/spam-test/schedule', args), 242 | 'create automated placement test' 243 | ); 244 | 245 | return { 246 | content: [ 247 | { 248 | type: 'text', 249 | text: JSON.stringify(response.data, null, 2), 250 | }, 251 | ], 252 | isError: false, 253 | }; 254 | } catch (error: any) { 255 | return { 256 | content: [{ 257 | type: 'text', 258 | text: `API Error: ${error.response?.data?.message || error.message}` 259 | }], 260 | isError: true, 261 | }; 262 | } 263 | } 264 | 265 | async function handleGetSpamTestDetails( 266 | args: unknown, 267 | apiClient: AxiosInstance, 268 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 269 | ) { 270 | if (!isGetSpamTestDetailsParams(args)) { 271 | throw new McpError( 272 | ErrorCode.InvalidParams, 273 | 'Invalid arguments for smartlead_get_spam_test_details' 274 | ); 275 | } 276 | 277 | try { 278 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 279 | const { spam_test_id } = args; 280 | 281 | const response = await withRetry( 282 | async () => smartDeliveryClient.get(`/spam-test/${spam_test_id}`), 283 | 'get spam test details' 284 | ); 285 | 286 | return { 287 | content: [ 288 | { 289 | type: 'text', 290 | text: JSON.stringify(response.data, null, 2), 291 | }, 292 | ], 293 | isError: false, 294 | }; 295 | } catch (error: any) { 296 | return { 297 | content: [{ 298 | type: 'text', 299 | text: `API Error: ${error.response?.data?.message || error.message}` 300 | }], 301 | isError: true, 302 | }; 303 | } 304 | } 305 | 306 | async function handleDeleteSmartDeliveryTests( 307 | args: unknown, 308 | apiClient: AxiosInstance, 309 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 310 | ) { 311 | if (!isDeleteSmartDeliveryTestsParams(args)) { 312 | throw new McpError( 313 | ErrorCode.InvalidParams, 314 | 'Invalid arguments for smartlead_delete_smart_delivery_tests' 315 | ); 316 | } 317 | 318 | try { 319 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 320 | 321 | const response = await withRetry( 322 | async () => smartDeliveryClient.post('/spam-test/delete', args), 323 | 'delete smart delivery tests' 324 | ); 325 | 326 | return { 327 | content: [ 328 | { 329 | type: 'text', 330 | text: JSON.stringify(response.data, null, 2), 331 | }, 332 | ], 333 | isError: false, 334 | }; 335 | } catch (error: any) { 336 | return { 337 | content: [{ 338 | type: 'text', 339 | text: `API Error: ${error.response?.data?.message || error.message}` 340 | }], 341 | isError: true, 342 | }; 343 | } 344 | } 345 | 346 | async function handleStopAutomatedTest( 347 | args: unknown, 348 | apiClient: AxiosInstance, 349 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 350 | ) { 351 | if (!isStopAutomatedTestParams(args)) { 352 | throw new McpError( 353 | ErrorCode.InvalidParams, 354 | 'Invalid arguments for smartlead_stop_automated_test' 355 | ); 356 | } 357 | 358 | try { 359 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 360 | const { spam_test_id } = args; 361 | 362 | const response = await withRetry( 363 | async () => smartDeliveryClient.put(`/spam-test/${spam_test_id}/stop`), 364 | 'stop automated test' 365 | ); 366 | 367 | return { 368 | content: [ 369 | { 370 | type: 'text', 371 | text: JSON.stringify(response.data, null, 2), 372 | }, 373 | ], 374 | isError: false, 375 | }; 376 | } catch (error: any) { 377 | return { 378 | content: [{ 379 | type: 'text', 380 | text: `API Error: ${error.response?.data?.message || error.message}` 381 | }], 382 | isError: true, 383 | }; 384 | } 385 | } 386 | 387 | async function handleListAllTests( 388 | args: unknown, 389 | apiClient: AxiosInstance, 390 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 391 | ) { 392 | if (!isListAllTestsParams(args)) { 393 | throw new McpError( 394 | ErrorCode.InvalidParams, 395 | 'Invalid arguments for smartlead_list_all_tests' 396 | ); 397 | } 398 | 399 | try { 400 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 401 | const { testType, limit = 10, offset = 0 } = args; 402 | 403 | const response = await withRetry( 404 | async () => smartDeliveryClient.post(`/spam-test/report?testType=${testType}`, { limit, offset }), 405 | 'list all tests' 406 | ); 407 | 408 | return { 409 | content: [ 410 | { 411 | type: 'text', 412 | text: JSON.stringify(response.data, null, 2), 413 | }, 414 | ], 415 | isError: false, 416 | }; 417 | } catch (error: any) { 418 | return { 419 | content: [{ 420 | type: 'text', 421 | text: `API Error: ${error.response?.data?.message || error.message}` 422 | }], 423 | isError: true, 424 | }; 425 | } 426 | } 427 | 428 | async function handleGetProviderWiseReport( 429 | args: unknown, 430 | apiClient: AxiosInstance, 431 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 432 | ) { 433 | if (!isProviderWiseReportParams(args)) { 434 | throw new McpError( 435 | ErrorCode.InvalidParams, 436 | 'Invalid arguments for smartlead_get_provider_wise_report' 437 | ); 438 | } 439 | 440 | try { 441 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 442 | const { spam_test_id } = args; 443 | 444 | const response = await withRetry( 445 | async () => smartDeliveryClient.post(`/spam-test/report/${spam_test_id}/providerwise`), 446 | 'get provider wise report' 447 | ); 448 | 449 | return { 450 | content: [ 451 | { 452 | type: 'text', 453 | text: JSON.stringify(response.data, null, 2), 454 | }, 455 | ], 456 | isError: false, 457 | }; 458 | } catch (error: any) { 459 | return { 460 | content: [{ 461 | type: 'text', 462 | text: `API Error: ${error.response?.data?.message || error.message}` 463 | }], 464 | isError: true, 465 | }; 466 | } 467 | } 468 | 469 | async function handleGetGroupWiseReport( 470 | args: unknown, 471 | apiClient: AxiosInstance, 472 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 473 | ) { 474 | if (!isGroupWiseReportParams(args)) { 475 | throw new McpError( 476 | ErrorCode.InvalidParams, 477 | 'Invalid arguments for smartlead_get_group_wise_report' 478 | ); 479 | } 480 | 481 | try { 482 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 483 | const { spam_test_id } = args; 484 | 485 | const response = await withRetry( 486 | async () => smartDeliveryClient.post(`/spam-test/report/${spam_test_id}/groupwise`), 487 | 'get group wise report' 488 | ); 489 | 490 | return { 491 | content: [ 492 | { 493 | type: 'text', 494 | text: JSON.stringify(response.data, null, 2), 495 | }, 496 | ], 497 | isError: false, 498 | }; 499 | } catch (error: any) { 500 | return { 501 | content: [{ 502 | type: 'text', 503 | text: `API Error: ${error.response?.data?.message || error.message}` 504 | }], 505 | isError: true, 506 | }; 507 | } 508 | } 509 | 510 | async function handleGetSenderAccountWiseReport( 511 | args: unknown, 512 | apiClient: AxiosInstance, 513 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 514 | ) { 515 | if (!isSenderAccountWiseReportParams(args)) { 516 | throw new McpError( 517 | ErrorCode.InvalidParams, 518 | 'Invalid arguments for smartlead_get_sender_account_wise_report' 519 | ); 520 | } 521 | 522 | try { 523 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 524 | const { spam_test_id } = args; 525 | 526 | const response = await withRetry( 527 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/sender-account-wise`), 528 | 'get sender account wise report' 529 | ); 530 | 531 | return { 532 | content: [ 533 | { 534 | type: 'text', 535 | text: JSON.stringify(response.data, null, 2), 536 | }, 537 | ], 538 | isError: false, 539 | }; 540 | } catch (error: any) { 541 | return { 542 | content: [{ 543 | type: 'text', 544 | text: `API Error: ${error.response?.data?.message || error.message}` 545 | }], 546 | isError: true, 547 | }; 548 | } 549 | } 550 | 551 | async function handleGetSpamFilterDetails( 552 | args: unknown, 553 | apiClient: AxiosInstance, 554 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 555 | ) { 556 | if (!isSpamFilterDetailsParams(args)) { 557 | throw new McpError( 558 | ErrorCode.InvalidParams, 559 | 'Invalid arguments for smartlead_get_spam_filter_details' 560 | ); 561 | } 562 | 563 | try { 564 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 565 | const { spam_test_id } = args; 566 | 567 | const response = await withRetry( 568 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/spam-filter-details`), 569 | 'get spam filter details' 570 | ); 571 | 572 | return { 573 | content: [ 574 | { 575 | type: 'text', 576 | text: JSON.stringify(response.data, null, 2), 577 | }, 578 | ], 579 | isError: false, 580 | }; 581 | } catch (error: any) { 582 | return { 583 | content: [{ 584 | type: 'text', 585 | text: `API Error: ${error.response?.data?.message || error.message}` 586 | }], 587 | isError: true, 588 | }; 589 | } 590 | } 591 | 592 | async function handleGetDkimDetails( 593 | args: unknown, 594 | apiClient: AxiosInstance, 595 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 596 | ) { 597 | if (!isDkimDetailsParams(args)) { 598 | throw new McpError( 599 | ErrorCode.InvalidParams, 600 | 'Invalid arguments for smartlead_get_dkim_details' 601 | ); 602 | } 603 | 604 | try { 605 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 606 | const { spam_test_id } = args; 607 | 608 | const response = await withRetry( 609 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/dkim-details`), 610 | 'get DKIM details' 611 | ); 612 | 613 | return { 614 | content: [ 615 | { 616 | type: 'text', 617 | text: JSON.stringify(response.data, null, 2), 618 | }, 619 | ], 620 | isError: false, 621 | }; 622 | } catch (error: any) { 623 | return { 624 | content: [{ 625 | type: 'text', 626 | text: `API Error: ${error.response?.data?.message || error.message}` 627 | }], 628 | isError: true, 629 | }; 630 | } 631 | } 632 | 633 | async function handleGetSpfDetails( 634 | args: unknown, 635 | apiClient: AxiosInstance, 636 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 637 | ) { 638 | if (!isSpfDetailsParams(args)) { 639 | throw new McpError( 640 | ErrorCode.InvalidParams, 641 | 'Invalid arguments for smartlead_get_spf_details' 642 | ); 643 | } 644 | 645 | try { 646 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 647 | const { spam_test_id } = args; 648 | 649 | const response = await withRetry( 650 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/spf-details`), 651 | 'get SPF details' 652 | ); 653 | 654 | return { 655 | content: [ 656 | { 657 | type: 'text', 658 | text: JSON.stringify(response.data, null, 2), 659 | }, 660 | ], 661 | isError: false, 662 | }; 663 | } catch (error: any) { 664 | return { 665 | content: [{ 666 | type: 'text', 667 | text: `API Error: ${error.response?.data?.message || error.message}` 668 | }], 669 | isError: true, 670 | }; 671 | } 672 | } 673 | 674 | async function handleGetRdnsDetails( 675 | args: unknown, 676 | apiClient: AxiosInstance, 677 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 678 | ) { 679 | if (!isRdnsDetailsParams(args)) { 680 | throw new McpError( 681 | ErrorCode.InvalidParams, 682 | 'Invalid arguments for smartlead_get_rdns_details' 683 | ); 684 | } 685 | 686 | try { 687 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 688 | const { spam_test_id } = args; 689 | 690 | const response = await withRetry( 691 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/rdns-details`), 692 | 'get rDNS details' 693 | ); 694 | 695 | return { 696 | content: [ 697 | { 698 | type: 'text', 699 | text: JSON.stringify(response.data, null, 2), 700 | }, 701 | ], 702 | isError: false, 703 | }; 704 | } catch (error: any) { 705 | return { 706 | content: [{ 707 | type: 'text', 708 | text: `API Error: ${error.response?.data?.message || error.message}` 709 | }], 710 | isError: true, 711 | }; 712 | } 713 | } 714 | 715 | async function handleGetSenderAccounts( 716 | args: unknown, 717 | apiClient: AxiosInstance, 718 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 719 | ) { 720 | if (!isSenderAccountsParams(args)) { 721 | throw new McpError( 722 | ErrorCode.InvalidParams, 723 | 'Invalid arguments for smartlead_get_sender_accounts' 724 | ); 725 | } 726 | 727 | try { 728 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 729 | const { spam_test_id } = args; 730 | 731 | const response = await withRetry( 732 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/sender-accounts`), 733 | 'get sender accounts' 734 | ); 735 | 736 | return { 737 | content: [ 738 | { 739 | type: 'text', 740 | text: JSON.stringify(response.data, null, 2), 741 | }, 742 | ], 743 | isError: false, 744 | }; 745 | } catch (error: any) { 746 | return { 747 | content: [{ 748 | type: 'text', 749 | text: `API Error: ${error.response?.data?.message || error.message}` 750 | }], 751 | isError: true, 752 | }; 753 | } 754 | } 755 | 756 | async function handleGetBlacklist( 757 | args: unknown, 758 | apiClient: AxiosInstance, 759 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 760 | ) { 761 | if (!isBlacklistParams(args)) { 762 | throw new McpError( 763 | ErrorCode.InvalidParams, 764 | 'Invalid arguments for smartlead_get_blacklist' 765 | ); 766 | } 767 | 768 | try { 769 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 770 | const { spam_test_id } = args; 771 | 772 | const response = await withRetry( 773 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/blacklist`), 774 | 'get blacklist' 775 | ); 776 | 777 | return { 778 | content: [ 779 | { 780 | type: 'text', 781 | text: JSON.stringify(response.data, null, 2), 782 | }, 783 | ], 784 | isError: false, 785 | }; 786 | } catch (error: any) { 787 | return { 788 | content: [{ 789 | type: 'text', 790 | text: `API Error: ${error.response?.data?.message || error.message}` 791 | }], 792 | isError: true, 793 | }; 794 | } 795 | } 796 | 797 | async function handleGetEmailContent( 798 | args: unknown, 799 | apiClient: AxiosInstance, 800 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 801 | ) { 802 | if (!isEmailContentParams(args)) { 803 | throw new McpError( 804 | ErrorCode.InvalidParams, 805 | 'Invalid arguments for smartlead_get_email_content' 806 | ); 807 | } 808 | 809 | try { 810 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 811 | const { spam_test_id } = args; 812 | 813 | const response = await withRetry( 814 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/email-content`), 815 | 'get email content' 816 | ); 817 | 818 | return { 819 | content: [ 820 | { 821 | type: 'text', 822 | text: JSON.stringify(response.data, null, 2), 823 | }, 824 | ], 825 | isError: false, 826 | }; 827 | } catch (error: any) { 828 | return { 829 | content: [{ 830 | type: 'text', 831 | text: `API Error: ${error.response?.data?.message || error.message}` 832 | }], 833 | isError: true, 834 | }; 835 | } 836 | } 837 | 838 | async function handleGetIpAnalytics( 839 | args: unknown, 840 | apiClient: AxiosInstance, 841 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 842 | ) { 843 | if (!isIpAnalyticsParams(args)) { 844 | throw new McpError( 845 | ErrorCode.InvalidParams, 846 | 'Invalid arguments for smartlead_get_ip_analytics' 847 | ); 848 | } 849 | 850 | try { 851 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 852 | const { spam_test_id } = args; 853 | 854 | const response = await withRetry( 855 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/ip-analytics`), 856 | 'get IP analytics' 857 | ); 858 | 859 | return { 860 | content: [ 861 | { 862 | type: 'text', 863 | text: JSON.stringify(response.data, null, 2), 864 | }, 865 | ], 866 | isError: false, 867 | }; 868 | } catch (error: any) { 869 | return { 870 | content: [{ 871 | type: 'text', 872 | text: `API Error: ${error.response?.data?.message || error.message}` 873 | }], 874 | isError: true, 875 | }; 876 | } 877 | } 878 | 879 | async function handleGetEmailHeaders( 880 | args: unknown, 881 | apiClient: AxiosInstance, 882 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 883 | ) { 884 | if (!isEmailHeadersParams(args)) { 885 | throw new McpError( 886 | ErrorCode.InvalidParams, 887 | 'Invalid arguments for smartlead_get_email_headers' 888 | ); 889 | } 890 | 891 | try { 892 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 893 | const { spam_test_id, reply_id } = args; 894 | 895 | const response = await withRetry( 896 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/sender-account-wise/${reply_id}/email-headers`), 897 | 'get email headers' 898 | ); 899 | 900 | return { 901 | content: [ 902 | { 903 | type: 'text', 904 | text: JSON.stringify(response.data, null, 2), 905 | }, 906 | ], 907 | isError: false, 908 | }; 909 | } catch (error: any) { 910 | return { 911 | content: [{ 912 | type: 'text', 913 | text: `API Error: ${error.response?.data?.message || error.message}` 914 | }], 915 | isError: true, 916 | }; 917 | } 918 | } 919 | 920 | async function handleGetScheduleHistory( 921 | args: unknown, 922 | apiClient: AxiosInstance, 923 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 924 | ) { 925 | if (!isScheduleHistoryParams(args)) { 926 | throw new McpError( 927 | ErrorCode.InvalidParams, 928 | 'Invalid arguments for smartlead_get_schedule_history' 929 | ); 930 | } 931 | 932 | try { 933 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 934 | const { spam_test_id } = args; 935 | 936 | const response = await withRetry( 937 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/schedule-history`), 938 | 'get schedule history' 939 | ); 940 | 941 | return { 942 | content: [ 943 | { 944 | type: 'text', 945 | text: JSON.stringify(response.data, null, 2), 946 | }, 947 | ], 948 | isError: false, 949 | }; 950 | } catch (error: any) { 951 | return { 952 | content: [{ 953 | type: 'text', 954 | text: `API Error: ${error.response?.data?.message || error.message}` 955 | }], 956 | isError: true, 957 | }; 958 | } 959 | } 960 | 961 | async function handleGetIpDetails( 962 | args: unknown, 963 | apiClient: AxiosInstance, 964 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 965 | ) { 966 | if (!isIpDetailsParams(args)) { 967 | throw new McpError( 968 | ErrorCode.InvalidParams, 969 | 'Invalid arguments for smartlead_get_ip_details' 970 | ); 971 | } 972 | 973 | try { 974 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 975 | const { spam_test_id, reply_id } = args; 976 | 977 | const response = await withRetry( 978 | async () => smartDeliveryClient.get(`/spam-test/report/${spam_test_id}/sender-account-wise/${reply_id}/ip-details`), 979 | 'get IP details' 980 | ); 981 | 982 | return { 983 | content: [ 984 | { 985 | type: 'text', 986 | text: JSON.stringify(response.data, null, 2), 987 | }, 988 | ], 989 | isError: false, 990 | }; 991 | } catch (error: any) { 992 | return { 993 | content: [{ 994 | type: 'text', 995 | text: `API Error: ${error.response?.data?.message || error.message}` 996 | }], 997 | isError: true, 998 | }; 999 | } 1000 | } 1001 | 1002 | async function handleGetMailboxSummary( 1003 | args: unknown, 1004 | apiClient: AxiosInstance, 1005 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1006 | ) { 1007 | if (!isMailboxSummaryParams(args)) { 1008 | throw new McpError( 1009 | ErrorCode.InvalidParams, 1010 | 'Invalid arguments for smartlead_get_mailbox_summary' 1011 | ); 1012 | } 1013 | 1014 | try { 1015 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1016 | const { limit = 10, offset = 0 } = args; 1017 | 1018 | const response = await withRetry( 1019 | async () => smartDeliveryClient.get(`/spam-test/report/mailboxes-summary?limit=${limit}&offset=${offset}`), 1020 | 'get mailbox summary' 1021 | ); 1022 | 1023 | return { 1024 | content: [ 1025 | { 1026 | type: 'text', 1027 | text: JSON.stringify(response.data, null, 2), 1028 | }, 1029 | ], 1030 | isError: false, 1031 | }; 1032 | } catch (error: any) { 1033 | return { 1034 | content: [{ 1035 | type: 'text', 1036 | text: `API Error: ${error.response?.data?.message || error.message}` 1037 | }], 1038 | isError: true, 1039 | }; 1040 | } 1041 | } 1042 | 1043 | async function handleGetMailboxCount( 1044 | args: unknown, 1045 | apiClient: AxiosInstance, 1046 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1047 | ) { 1048 | if (!isMailboxCountParams(args)) { 1049 | throw new McpError( 1050 | ErrorCode.InvalidParams, 1051 | 'Invalid arguments for smartlead_get_mailbox_count' 1052 | ); 1053 | } 1054 | 1055 | try { 1056 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1057 | 1058 | const response = await withRetry( 1059 | async () => smartDeliveryClient.get('/spam-test/report/mailboxes-count'), 1060 | 'get mailbox count' 1061 | ); 1062 | 1063 | return { 1064 | content: [ 1065 | { 1066 | type: 'text', 1067 | text: JSON.stringify(response.data, null, 2), 1068 | }, 1069 | ], 1070 | isError: false, 1071 | }; 1072 | } catch (error: any) { 1073 | return { 1074 | content: [{ 1075 | type: 'text', 1076 | text: `API Error: ${error.response?.data?.message || error.message}` 1077 | }], 1078 | isError: true, 1079 | }; 1080 | } 1081 | } 1082 | 1083 | async function handleGetAllFolders( 1084 | args: unknown, 1085 | apiClient: AxiosInstance, 1086 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1087 | ) { 1088 | if (!isGetAllFoldersParams(args)) { 1089 | throw new McpError( 1090 | ErrorCode.InvalidParams, 1091 | 'Invalid arguments for smartlead_get_all_folders' 1092 | ); 1093 | } 1094 | 1095 | try { 1096 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1097 | const { limit = 10, offset = 0, name = '' } = args; 1098 | 1099 | const queryParams = new URLSearchParams(); 1100 | queryParams.append('limit', limit.toString()); 1101 | queryParams.append('offset', offset.toString()); 1102 | if (name) { 1103 | queryParams.append('name', name); 1104 | } 1105 | 1106 | const response = await withRetry( 1107 | async () => smartDeliveryClient.get(`/spam-test/folder?${queryParams.toString()}`), 1108 | 'get all folders' 1109 | ); 1110 | 1111 | return { 1112 | content: [ 1113 | { 1114 | type: 'text', 1115 | text: JSON.stringify(response.data, null, 2), 1116 | }, 1117 | ], 1118 | isError: false, 1119 | }; 1120 | } catch (error: any) { 1121 | return { 1122 | content: [{ 1123 | type: 'text', 1124 | text: `API Error: ${error.response?.data?.message || error.message}` 1125 | }], 1126 | isError: true, 1127 | }; 1128 | } 1129 | } 1130 | 1131 | async function handleCreateFolder( 1132 | args: unknown, 1133 | apiClient: AxiosInstance, 1134 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1135 | ) { 1136 | if (!isCreateFolderParams(args)) { 1137 | throw new McpError( 1138 | ErrorCode.InvalidParams, 1139 | 'Invalid arguments for smartlead_create_folder' 1140 | ); 1141 | } 1142 | 1143 | try { 1144 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1145 | const { name } = args; 1146 | 1147 | const response = await withRetry( 1148 | async () => smartDeliveryClient.post('/spam-test/folder', { name }), 1149 | 'create folder' 1150 | ); 1151 | 1152 | return { 1153 | content: [ 1154 | { 1155 | type: 'text', 1156 | text: JSON.stringify(response.data, null, 2), 1157 | }, 1158 | ], 1159 | isError: false, 1160 | }; 1161 | } catch (error: any) { 1162 | return { 1163 | content: [{ 1164 | type: 'text', 1165 | text: `API Error: ${error.response?.data?.message || error.message}` 1166 | }], 1167 | isError: true, 1168 | }; 1169 | } 1170 | } 1171 | 1172 | async function handleGetFolderById( 1173 | args: unknown, 1174 | apiClient: AxiosInstance, 1175 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1176 | ) { 1177 | if (!isGetFolderByIdParams(args)) { 1178 | throw new McpError( 1179 | ErrorCode.InvalidParams, 1180 | 'Invalid arguments for smartlead_get_folder_by_id' 1181 | ); 1182 | } 1183 | 1184 | try { 1185 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1186 | const { folder_id } = args; 1187 | 1188 | const response = await withRetry( 1189 | async () => smartDeliveryClient.get(`/spam-test/folder/${folder_id}`), 1190 | 'get folder by ID' 1191 | ); 1192 | 1193 | return { 1194 | content: [ 1195 | { 1196 | type: 'text', 1197 | text: JSON.stringify(response.data, null, 2), 1198 | }, 1199 | ], 1200 | isError: false, 1201 | }; 1202 | } catch (error: any) { 1203 | return { 1204 | content: [{ 1205 | type: 'text', 1206 | text: `API Error: ${error.response?.data?.message || error.message}` 1207 | }], 1208 | isError: true, 1209 | }; 1210 | } 1211 | } 1212 | 1213 | async function handleDeleteFolder( 1214 | args: unknown, 1215 | apiClient: AxiosInstance, 1216 | withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> 1217 | ) { 1218 | if (!isDeleteFolderParams(args)) { 1219 | throw new McpError( 1220 | ErrorCode.InvalidParams, 1221 | 'Invalid arguments for smartlead_delete_folder' 1222 | ); 1223 | } 1224 | 1225 | try { 1226 | const smartDeliveryClient = createSmartDeliveryClient(apiClient); 1227 | const { folder_id } = args; 1228 | 1229 | const response = await withRetry( 1230 | async () => smartDeliveryClient.delete(`/spam-test/folder/${folder_id}`), 1231 | 'delete folder' 1232 | ); 1233 | 1234 | return { 1235 | content: [ 1236 | { 1237 | type: 'text', 1238 | text: JSON.stringify(response.data, null, 2), 1239 | }, 1240 | ], 1241 | isError: false, 1242 | }; 1243 | } catch (error: any) { 1244 | return { 1245 | content: [{ 1246 | type: 'text', 1247 | text: `API Error: ${error.response?.data?.message || error.message}` 1248 | }], 1249 | isError: true, 1250 | }; 1251 | } 1252 | } ```