How to integrate Mailchimp MCP with LlamaIndex

Framework Integration Gradient
Mailchimp Logo
LlamaIndex Logo
divider

Introduction

This guide walks you through connecting Mailchimp to LlamaIndex using the Composio tool router. By the end, you'll have a working Mailchimp agent that can create a new email campaign for subscribers, add a new customer to my mailchimp store, set up a webhook for batch processing updates, add feedback to my latest campaign through natural language commands.

This guide will help you understand how to give your LlamaIndex agent real control over a Mailchimp account through Composio's Mailchimp MCP server.

Before we dive in, let's take a quick look at the key ideas and tools involved.

TL;DR

Here's what you'll learn:
  • Set your OpenAI and Composio API keys
  • Install LlamaIndex and Composio packages
  • Create a Composio Tool Router session for Mailchimp
  • Connect LlamaIndex to the Mailchimp MCP server
  • Build a Mailchimp-powered agent using LlamaIndex
  • Interact with Mailchimp through natural language

What is LlamaIndex?

LlamaIndex is a data framework for building LLM applications. It provides tools for connecting LLMs to external data sources and services through agents and tools.

Key features include:

  • ReAct Agent: Reasoning and acting pattern for tool-using agents
  • MCP Tools: Native support for Model Context Protocol
  • Context Management: Maintain conversation context across interactions
  • Async Support: Built for async/await patterns

What is the Mailchimp MCP server, and what's possible with it?

The Mailchimp MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Mailchimp account. It provides structured and secure access to your email marketing platform, so your agent can perform actions like creating campaigns, managing automations, adding customers, and organizing campaign folders on your behalf.

  • Automated campaign creation and management: Have your agent quickly set up, launch, or organize Mailchimp campaigns tailored to your audience segments.
  • Audience and customer management: Effortlessly add new customers to your store or update subscriber lists so your outreach is always up-to-date.
  • Workflow automation setup: Direct your agent to create classic automations or configure batch webhooks to streamline your marketing flows.
  • Campaign feedback and analysis: Let your agent add feedback to specific campaigns and help you keep track of campaign performance and improvements.
  • Store and site integration: Ask your agent to add carts, line items, or connect new sites and domains—making e-commerce and marketing work together seamlessly.

Supported Tools & Triggers

Tools
Triggers
Add automationCreate a new classic automation in your mailchimp account.
Add batch webhookConfigure a webhook that will fire whenever any batch request completes processing.
Add campaignCreate a new mailchimp campaign.
Add campaign feedbackAdd feedback on a specific campaign.
Add campaign folderCreate a new campaign folder.
Add cartAdd a new cart to a store.
Add cart line itemAdd a new line item to an existing cart.
Add connected siteCreate a new mailchimp connected site.
Add customerAdd a new customer to a store.
Add domain to accountAdd a domain to the account.
Add eventAdd an event for a list member.
Add exportCreate a new account export in your mailchimp account.
Add fileUpload a new image or file to the file manager.
Add folderCreate a new folder in the file manager.
Add interest categoryCreate a new interest category.
Add interest in categoryCreate a new interest or 'group name' for a specific category.
Add landing pageCreate a new mailchimp landing page.
Add listCreate a new list in your mailchimp account.
Add member noteAdd a new note for a specific subscriber.
Add member to listAdd a new member to the list.
Add member to segmentAdd a member to a static segment.
Add merge fieldAdd a new merge field for a specific audience.
Add orderAdd a new order to a store.
Add order line itemAdd a new line item to an existing order.
Add or remove member tagsAdd or remove tags from a list member.
Add or update customerAdd or update a customer.
Add or update list memberAdd or update a list member.
Add or update product variantAdd or update a product variant.
Add productAdd a new product to a store.
Add product imageAdd a new image to the product.
Add product variantAdd a new variant to the product.
Add promo codeAdd a new promo code to a store.
Add promo ruleAdd a new promo rule to a store.
Add segmentCreate a new segment in a specific list.
Add storeAdd a new store to your mailchimp account.
Add subscriber to workflow emailManually add a subscriber to a workflow, bypassing the default trigger settings.
Add templateCreate a new template for the account.
Add template folderCreate a new template folder.
Add webhookCreate a new webhook for a specific list.
Archive automationArchiving will permanently end your automation and keep the report data.
Archive list memberArchive a list member.
Batch add or remove membersBatch add/remove list members to static segment
Batch subscribe or unsubscribeBatch subscribe or unsubscribe list members.
Campaign abuse report detailsGet information about a specific abuse report for a campaign.
Campaign statistics feedbackGet feedback based on a campaign's statistics.
Cancel campaignCancel a regular or plain-text campaign after you send, before all of your recipients receive it.
Create a survey campaignUtilize the list id and survey id to generate a campaign that links to your survey.
Customer journeys api trigger for a contactCreate a trigger step in the customer journey builder via the api.
Customize signup formCustomize a list's default signup form.
Delete batch requestStops a batch request from running.
Delete batch webhookRemove a batch webhook.
Delete campaignRemove a campaign from your mailchimp account.
Delete campaign feedback messageRemove a specific feedback message for a campaign.
Delete campaign folderDelete a specific campaign folder, and mark all the campaigns in the folder as 'unfiled'.
Delete cartDelete a cart.
Delete cart line itemDelete a specific cart line item.
Delete connected siteRemove a connected site from your mailchimp account.
Delete customerDelete a customer from a store.
Delete domainDelete a verified domain from the account.
Delete fileRemove a specific file from the file manager.
Delete folderDelete a specific folder in the file manager.
Delete interest categoryDelete a specific interest category.
Delete interest in categoryDelete interests or group names in a specific category.
Delete landing pageDelete a landing page.
Delete listDelete a list from your mailchimp account.
Delete list memberDelete all personally identifiable information related to a list member, and remove them from a list.
Delete merge fieldDelete a specific merge field.
Delete noteDelete a specific note for a specific list member.
Delete orderDelete an order.
Delete order line itemDelete a specific order line item.
Delete productDelete a product.
Delete product imageDelete a product image.
Delete product variantDelete a product variant.
Delete promo codeDelete a promo code from a store.
Delete promo ruleDelete a promo rule from a store.
Delete segmentDelete a specific segment in a list.
Delete storeDelete a store.
Delete templateDelete a specific template.
Delete template folderDelete a specific template folder, and mark all the templates in the folder as 'unfiled'.
Delete webhookDelete a specific webhook in a list.
Delete workflow emailRemoves an individual classic automation workflow email.
Get abuse reportGet details about a specific abuse report.
Get account export infoGet information about a specific account export.
Get authorized app infoGet information about a specific authorized application.
Get automated email subscriberGet information about a specific subscriber in a classic automation email queue.
Get automation infoGet a summary of an individual classic automation workflow's settings and content.
Get batch operation statusGet the status of a batch request.
Get batch webhook infoGet information about a specific batch webhook.
Get campaign contentGet the the html and plain-text content for a campaign.
Get campaign feedback messageGet a specific feedback message from a campaign.
Get campaign folderGet information about a specific folder used to organize campaigns.
Get campaign infoGet information about a specific campaign.
Get campaign link detailsGet click details for a specific link in a campaign.
Get campaign recipient infoGet information about a specific campaign recipient.
Get campaign reportGet report details for a specific sent campaign.
Get campaign send checklistReview the send checklist for a campaign, and resolve any issues before sending.
Get cart infoGet information about a specific cart.
Get cart line itemGet information about a specific cart line item.
Get clicked link subscriberGet information about a specific subscriber who clicked a link in a specific campaign.
Get connected siteGet information about a specific connected site.
Get conversationApi endpoint for conversations is deprecated, replaced by inbox.
Get customer infoGet information about a specific customer.
Get domain infoGet the details for a single domain on the account.
Get facebook ad infoGet details of a facebook ad.
Get facebook ad reportGet report of a facebook ad.
Get fileGet information about a specific file in the file manager.
Get folderGet information about a specific folder in the file manager.
Get growth history by monthGet a summary of a specific list's growth activity for a specific month and year.
Get information about all surveys for a listGet information about all available surveys for a specific list.
Get interest category infoGet information about a specific interest category.
Get interest in categoryGet interests or 'group names' for a specific category.
Get landing page contentGet the the html for your landing page.
Get landing page infoGet information about a specific page.
Get landing page reportGet report of a landing page.
Get latest chimp chatterReturn the chimp chatter for this account ordered by most recent.
Get list infoGet information about a specific list in your mailchimp account.
Get lists infoGet information about all lists in the account.
Get member infoGet information about a specific list member, including a currently subscribed, unsubscribed, or bounced member.
Get member noteGet a specific note for a specific list member.
Get merge fieldGet information about a specific merge field.
Get messageThe conversation endpoint is outdated and replaced by inbox, which isn't supported by it.
Get opened campaign subscriberGet information about a specific subscriber who opened a campaign.
Get order infoGet information about a specific order.
Get order line itemGet information about a specific order line item.
Get product image infoGet information about a specific product image.
Get product infoGet information about a specific product.
Get product variant infoGet information about a specific product variant.
Get promo codeGet information about a specific promo code.
Get promo ruleGet information about a specific promo rule.
Get segment infoGet information about a specific segment.
Get store infoGet information about a specific store.
Get subscriber email activityGet a specific list member's activity in a campaign including opens, clicks, and bounces.
Get subscriber removed from workflowGet information about a specific subscriber who was removed from a classic automation workflow.
Get surveyGet details about a specific survey.
Get survey question reportGet report for a survey question.
Get survey reportGet report for a survey.
Get survey responseGet a single survey response.
Get template folderGet information about a specific folder used to organize templates.
Get template infoGet information about a specific template.
Get unsubscribed memberGet information about a specific list member who unsubscribed from a campaign.
Get webhook infoGet information about a specific webhook.
Get workflow email infoGet information about an individual classic automation workflow email.
List abuse reportsGet all abuse reports for a specific list.
List account exportsGet a list of account exports for a given account.
List account ordersGet information about an account's orders.
List answers for questionGet answers for a survey question.
List api root resourcesGet links to all other resources available in the api.
List authorized appsGet a list of an account's registered, connected applications.
List automated emailsGet a summary of the emails in a classic automation workflow.
List automated email subscribersGet information about a classic automation email queue.
List automationsGet a summary of an account's classic automations.
List batch requestsGet a summary of batch requests that have been made.
List batch webhooksGet all webhooks that have been configured for batches.
List campaign detailsGet information about clicks on specific links in your mailchimp campaigns.
List campaign feedbackGet team feedback while you're working together on a mailchimp campaign.
List campaign foldersGet all folders used to organize campaigns.
List campaign open detailsGet detailed information about any campaign emails that were opened by a list member.
List campaign product activityGet breakdown of product activity for a campaign
List campaign recipientsGet information about campaign recipients.
List campaign reportsGet campaign reports.
List campaignsGet all campaigns in an account.
List cart line itemsGet information about a cart's line items.
List cartsGet information about a store's carts.
List child campaign reportsGet a list of reports with child campaigns for a specific parent campaign.
List clicked link subscribersGet information about list members who clicked on a specific link in a campaign.
List connected sitesGet all connected sites in an account.
List conversationsList of conversations for an account is available via an endpoint, but it's deprecated in favor of inbox.
List customersGet information about a store's customers.
List domain performance statsGet statistics for the top-performing email domains in a campaign.
List eepurl activityGet a summary of social activity for the campaign, tracked by eepurl.
List email activityGet a list of member's subscriber activity in a specific campaign.
List facebook adsGet list of facebook ads.
List facebook ads reportsGet reports of facebook ads.
List facebook ecommerce reportGet breakdown of product activity for an outreach.
List foldersGet a list of all folders in the file manager.
List growth history dataGet a month-by-month summary of a specific list's growth activity.
List interest categoriesGet information about a list's interest categories.
List interests in categoryGet a list of this category's interests.
List landing pagesGet all landing pages.
List landing pages reportsGet reports of landing pages.
List locationsGet the locations (countries) that the list's subscribers have been tagged to based on geocoding their ip address.
List member eventsGet events for a contact.
List member goal eventsGet the last 50 goal events for a member on a specific list.
List members infoGet information about members in a specific mailchimp list.
List members in segmentGet information about members in a saved segment.
List member tagsGet the tags on a list member.
List merge fieldsGet a list of all merge fields for an audience.
List messagesLegacy "conversations" endpoint is deprecated; use "inbox" for new messages.
List order line itemsGet information about an order's line items.
List ordersGet information about a store's orders.
List productGet information about a store's products.
List product imagesGet information about a product's images.
List product variantsGet information about a product's variants.
List promo codesGet information about a store's promo codes.
List promo rulesGet information about a store's promo rules.
List recent activityGet up to the previous 180 days of daily detailed aggregated activity stats for a list, not including automation activity.
List recent member notesGet recent notes for a specific list member.
List segmentsGet information about all available segments for a specific list.
List sending domainsGet all of the sending domains on the account.
List signup formsGet signup forms for a specific list.
List stored filesGet a list of available images and files stored in the file manager for the account.
List storesGet information about all stores in the account.
List subscribers removed from workflowGet information about subscribers who were removed from a classic automation workflow.
List survey question reportsGet reports for survey questions.
List survey reportsGet reports for surveys.
List survey responsesGet responses to a survey.
List template foldersGet all folders used to organize templates.
List templatesGet a list of an account's available templates.
List top email clientsGet a list of the top email clients based on user-agent strings.
List top open activitiesGet top open locations for a specific campaign.
List unsubscribed membersGet information about members who have unsubscribed from a specific campaign.
List webhooksGet information about all webhooks for a specific list.
Pause automated emailPause an automated email.
Pause automation emailsPause all emails in a specific classic automation workflow.
Pause rss campaignPause an rss-driven campaign.
PingA health check for the api that won't return any account-specific information.
Publish a surveyPublish a survey that is in draft, unpublished, or has been previously published and edited.
Publish landing pagePublish a landing page that is in draft, unpublished, or has been previously published and edited.
Remove list member from segmentRemove a member from the specified static segment.
Remove subscriber from workflowRemove a subscriber from any point in a classic automation workflow; once removed, they cannot be re-added to that workflow.
Replicate campaignReplicate a campaign in saved or send status.
Resend campaignRemove the guesswork for resending a campaign to certain segments.
Resume rss campaignResume an rss-driven campaign.
Retrieve campaign abuse complaintsGet a list of abuse complaints for a specific campaign.
Retrieve folder contentsGet a list of available images and files stored in this folder.
Schedule campaignSchedule a campaign for delivery.
Search campaignsSearch all campaigns for the specified query terms.
Search for tags on a list by nameSearch for tags on a list by name.
Search membersSearch for list members.
Send campaignSend a mailchimp campaign.
Send test emailSend a test email.
Set campaign contentSet the content for a campaign.
Start automated emailStart an automated email.
Start automation emailsStart all emails in a classic automation workflow.
Start batch operationBegin processing a batch operations request.
Unpublish a surveyUnpublish a survey that has been published.
Unpublish landing pageUnpublish a landing page that is in draft or has been published.
Unschedule campaignUnschedule a scheduled campaign that hasn't started sending.
Update batch webhookUpdate a webhook that will fire whenever any batch request completes processing.
Update campaign feedback messageUpdate a specific feedback message for a campaign.
Update campaign folderUpdate a specific folder used to organize campaigns.
Update campaign settingsUpdate some or all of the settings for a specific campaign.
Update cartUpdate a specific cart.
Update cart line itemUpdate a specific cart line item.
Update customerUpdate a customer.
Update fileUpdate a file in the file manager.
Update folderUpdate a specific file manager folder.
Update interest categoryUpdate a specific interest category.
Update interest in categoryUpdate interests or 'group names' for a specific category.
Update landing pageUpdate a landing page.
Update list memberUpdate information for a specific list member.
Update listsUpdate the settings for a specific list.
Update merge fieldUpdate a specific merge field.
Update noteUpdate a specific note for a specific list member.
Update orderUpdate a specific order.
Update order line itemUpdate a specific order line item.
Update productUpdate a specific product.
Update product imageUpdate a product image.
Update product variantUpdate a product variant.
Update promo codeUpdate a promo code.
Update promo ruleUpdate a promo rule.
Update storeUpdate a store.
Update templateUpdate the name, html, or `folder id` of an existing template.
Update template folderUpdate a specific folder used to organize templates.
Update webhookUpdate the settings for an existing webhook.
Update workflow emailUpdate settings for a classic automation workflow email.
Verify connected site scriptVerify that the connected sites script has been installed, either via the script url or fragment.
Verify domainVerify a domain for sending.
View default contentGet the sections that you can edit in a template, including each section's default content.
View recent activityGet a member's activity on a specific list, including opens, clicks, and unsubscribes.
View recent activity 50Get the last 50 events of a member's activity on a specific list, including opens, clicks, and unsubscribes.

What is the Composio tool router, and how does it fit here?

What is Tool Router?

Composio's Tool Router helps agents find the right tools for a task at runtime. You can plug in multiple toolkits (like Gmail, HubSpot, and GitHub), and the agent will identify the relevant app and action to complete multi-step workflows. This can reduce token usage and improve the reliability of tool calls. Read more here: Getting started with Tool Router

The tool router generates a secure MCP URL that your agents can access to perform actions.

How the Tool Router works

The Tool Router follows a three-phase workflow:

  1. Discovery: Searches for tools matching your task and returns relevant toolkits with their details.
  2. Authentication: Checks for active connections. If missing, creates an auth config and returns a connection URL via Auth Link.
  3. Execution: Executes the action using the authenticated connection.

Step-by-step Guide

Prerequisites

Before you begin, make sure you have:
  • Python 3.8/Node 16 or higher installed
  • A Composio account with the API key
  • An OpenAI API key
  • A Mailchimp account and project
  • Basic familiarity with async Python/Typescript

Getting API Keys for OpenAI, Composio, and Mailchimp

OpenAI API key (OPENAI_API_KEY)
  • Go to the OpenAI dashboard
  • Create an API key if you don't have one
  • Assign it to OPENAI_API_KEY in .env
Composio API key and user ID
  • Log into the Composio dashboard
  • Copy your API key from Settings
    • Use this as COMPOSIO_API_KEY
  • Pick a stable user identifier (email or ID)
    • Use this as COMPOSIO_USER_ID

Installing dependencies

pip install composio-llamaindex llama-index llama-index-llms-openai llama-index-tools-mcp python-dotenv

Create a new Python project and install the necessary dependencies:

  • composio-llamaindex: Composio's LlamaIndex integration
  • llama-index: Core LlamaIndex framework
  • llama-index-llms-openai: OpenAI LLM integration
  • llama-index-tools-mcp: MCP client for LlamaIndex
  • python-dotenv: Environment variable management

Set environment variables

bash
OPENAI_API_KEY=your-openai-api-key
COMPOSIO_API_KEY=your-composio-api-key
COMPOSIO_USER_ID=your-user-id

Create a .env file in your project root:

These credentials will be used to:

  • Authenticate with OpenAI's GPT-5 model
  • Connect to Composio's Tool Router
  • Identify your Composio user session for Mailchimp access

Import modules

import asyncio
import os
import dotenv

from composio import Composio
from composio_llamaindex import LlamaIndexProvider
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.workflow import Context
from llama_index.llms.openai import OpenAI
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

dotenv.load_dotenv()

Create a new file called mailchimp_llamaindex_agent.py and import the required modules:

Key imports:

  • asyncio: For async/await support
  • Composio: Main client for Composio services
  • LlamaIndexProvider: Adapts Composio tools for LlamaIndex
  • ReActAgent: LlamaIndex's reasoning and action agent
  • BasicMCPClient: Connects to MCP endpoints
  • McpToolSpec: Converts MCP tools to LlamaIndex format

Load environment variables and initialize Composio

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
COMPOSIO_USER_ID = os.getenv("COMPOSIO_USER_ID")

if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY is not set in the environment")
if not COMPOSIO_API_KEY:
    raise ValueError("COMPOSIO_API_KEY is not set in the environment")
if not COMPOSIO_USER_ID:
    raise ValueError("COMPOSIO_USER_ID is not set in the environment")

What's happening:

This ensures missing credentials cause early, clear errors before the agent attempts to initialise.

Create a Tool Router session and build the agent function

async def build_agent() -> ReActAgent:
    composio_client = Composio(
        api_key=COMPOSIO_API_KEY,
        provider=LlamaIndexProvider(),
    )

    session = composio_client.create(
        user_id=COMPOSIO_USER_ID,
        toolkits=["mailchimp"],
    )

    mcp_url = session.mcp.url
    print(f"Composio MCP URL: {mcp_url}")

    mcp_client = BasicMCPClient(mcp_url, headers={"x-api-key": COMPOSIO_API_KEY})
    mcp_tool_spec = McpToolSpec(client=mcp_client)
    tools = await mcp_tool_spec.to_tool_list_async()

    llm = OpenAI(model="gpt-5")

    description = "An agent that uses Composio Tool Router MCP tools to perform Mailchimp actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Mailchimp actions.
    """
    return ReActAgent(tools=tools, llm=llm, description=description, system_prompt=system_prompt, verbose=True)

What's happening here:

  • We create a Composio client using your API key and configure it with the LlamaIndex provider
  • We then create a tool router MCP session for your user, specifying the toolkits we want to use (in this case, mailchimp)
  • The session returns an MCP HTTP endpoint URL that acts as a gateway to all your configured tools
  • LlamaIndex will connect to this endpoint to dynamically discover and use the available Mailchimp tools.
  • The MCP tools are mapped to LlamaIndex-compatible tools and plug them into the Agent.

Create an interactive chat loop

async def chat_loop(agent: ReActAgent) -> None:
    ctx = Context(agent)
    print("Type 'quit', 'exit', or Ctrl+C to stop.")

    while True:
        try:
            user_input = input("\nYou: ").strip()
        except (KeyboardInterrupt, EOFError):
            print("\nBye!")
            break

        if not user_input or user_input.lower() in {"quit", "exit"}:
            print("Bye!")
            break

        try:
            print("Agent: ", end="", flush=True)
            handler = agent.run(user_input, ctx=ctx)

            async for event in handler.stream_events():
                # Stream token-by-token from LLM responses
                if hasattr(event, "delta") and event.delta:
                    print(event.delta, end="", flush=True)
                # Show tool calls as they happen
                elif hasattr(event, "tool_name"):
                    print(f"\n[Using tool: {event.tool_name}]", flush=True)

            # Get final response
            response = await handler
            print()  # Newline after streaming
        except KeyboardInterrupt:
            print("\n[Interrupted]")
            continue
        except Exception as e:
            print(f"\nError: {e}")

What's happening here:

  • We're creating a direct terminal interface to chat with your Mailchimp database
  • The LLM's responses are streamed to the CLI for faster interaction.
  • The agent uses context to maintain conversation history
  • You can type 'quit' or 'exit' to stop the chat loop gracefully
  • Agent responses and any errors are displayed in a clear, readable format

Define the main entry point

async def main() -> None:
    agent = await build_agent()
    await chat_loop(agent)

if __name__ == "__main__":
    # Handle Ctrl+C gracefully
    signal.signal(signal.SIGINT, lambda s, f: (print("\nBye!"), exit(0)))
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nBye!")

What's happening here:

  • We're orchestrating the entire application flow
  • The agent gets built with proper error handling
  • Then we kick off the interactive chat loop so you can start talking to Mailchimp

Run the agent

npx ts-node llamaindex-agent.ts

When prompted, authenticate and authorise your agent with Mailchimp, then start asking questions.

Complete Code

Here's the complete code to get you started with Mailchimp and LlamaIndex:

import asyncio
import os
import signal
import dotenv

from composio import Composio
from composio_llamaindex import LlamaIndexProvider
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.workflow import Context
from llama_index.llms.openai import OpenAI
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

dotenv.load_dotenv()

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
COMPOSIO_USER_ID = os.getenv("COMPOSIO_USER_ID")

if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY is not set")
if not COMPOSIO_API_KEY:
    raise ValueError("COMPOSIO_API_KEY is not set")
if not COMPOSIO_USER_ID:
    raise ValueError("COMPOSIO_USER_ID is not set")

async def build_agent() -> ReActAgent:
    composio_client = Composio(
        api_key=COMPOSIO_API_KEY,
        provider=LlamaIndexProvider(),
    )

    session = composio_client.create(
        user_id=COMPOSIO_USER_ID,
        toolkits=["mailchimp"],
    )

    mcp_url = session.mcp.url
    print(f"Composio MCP URL: {mcp_url}")

    mcp_client = BasicMCPClient(mcp_url, headers={"x-api-key": COMPOSIO_API_KEY})
    mcp_tool_spec = McpToolSpec(client=mcp_client)
    tools = await mcp_tool_spec.to_tool_list_async()

    llm = OpenAI(model="gpt-5")
    description = "An agent that uses Composio Tool Router MCP tools to perform Mailchimp actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Mailchimp actions.
    """
    return ReActAgent(
        tools=tools,
        llm=llm,
        description=description,
        system_prompt=system_prompt,
        verbose=True,
    );

async def chat_loop(agent: ReActAgent) -> None:
    ctx = Context(agent)
    print("Type 'quit', 'exit', or Ctrl+C to stop.")

    while True:
        try:
            user_input = input("\nYou: ").strip()
        except (KeyboardInterrupt, EOFError):
            print("\nBye!")
            break

        if not user_input or user_input.lower() in {"quit", "exit"}:
            print("Bye!")
            break

        try:
            print("Agent: ", end="", flush=True)
            handler = agent.run(user_input, ctx=ctx)

            async for event in handler.stream_events():
                # Stream token-by-token from LLM responses
                if hasattr(event, "delta") and event.delta:
                    print(event.delta, end="", flush=True)
                # Show tool calls as they happen
                elif hasattr(event, "tool_name"):
                    print(f"\n[Using tool: {event.tool_name}]", flush=True)

            # Get final response
            response = await handler
            print()  # Newline after streaming
        except KeyboardInterrupt:
            print("\n[Interrupted]")
            continue
        except Exception as e:
            print(f"\nError: {e}")

async def main() -> None:
    agent = await build_agent()
    await chat_loop(agent)

if __name__ == "__main__":
    # Handle Ctrl+C gracefully
    signal.signal(signal.SIGINT, lambda s, f: (print("\nBye!"), exit(0)))
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nBye!")

Conclusion

You've successfully connected Mailchimp to LlamaIndex through Composio's Tool Router MCP layer. Key takeaways:
  • Tool Router dynamically exposes Mailchimp tools through an MCP endpoint
  • LlamaIndex's ReActAgent handles reasoning and orchestration; Composio handles integrations
  • The agent becomes more capable without increasing prompt size
  • Async Python provides clean, efficient execution of agent workflows
You can easily extend this to other toolkits like Gmail, Notion, Stripe, GitHub, and more by adding them to the toolkits parameter.

How to build Mailchimp MCP Agent with another framework

FAQ

What are the differences in Tool Router MCP and Mailchimp MCP?

With a standalone Mailchimp MCP server, the agents and LLMs can only access a fixed set of Mailchimp tools tied to that server. However, with the Composio Tool Router, agents can dynamically load tools from Mailchimp and many other apps based on the task at hand, all through a single MCP endpoint.

Can I use Tool Router MCP with LlamaIndex?

Yes, you can. LlamaIndex fully supports MCP integration. You get structured tool calling, message history handling, and model orchestration while Tool Router takes care of discovering and serving the right Mailchimp tools.

Can I manage the permissions and scopes for Mailchimp while using Tool Router?

Yes, absolutely. You can configure which Mailchimp scopes and actions are allowed when connecting your account to Composio. You can also bring your own OAuth credentials or API configuration so you keep full control over what the agent can do.

How safe is my data with Composio Tool Router?

All sensitive data such as tokens, keys, and configuration is fully encrypted at rest and in transit. Composio is SOC 2 Type 2 compliant and follows strict security practices so your Mailchimp data and credentials are handled as safely as possible.

Used by agents from

Context
ASU
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai
Context
ASU
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai
Context
ASU
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai

Never worry about agent reliability

We handle tool reliability, observability, and security so you never have to second-guess an agent action.