Skip to main content

Use mails.ai with CrewAI

Give a crew's agent the mails.ai MCP tools, in Python.

This guide connects CrewAI to the hosted mails.ai MCP server at https://api.mails.ai/mcp. It sends your API key in the Authorization header and gets the tools that key may call, as any other MCP client does (the tool list). With a test key (mk_test_…), the tools run in the sandbox and no email leaves mails.ai.

Before you start

The sample reads your key from MAILS_API_KEY. The framework also needs a key for its model provider, set the way its own documentation says.

export MAILS_API_KEY=mk_test_xxxxxxxx

The sample asks the agent to email reply@test.mails.ai. Nothing sent to that address leaves mails.ai, and it answers, so your agent gets a reply.received event back.

Install

pip install crewai

Write the agent

Give the agent the server in mcps, with MCPServerHTTP. CrewAI needs Python 3.10 to 3.13. Its default model is OpenAI’s (OPENAI_MODEL_NAME, or gpt-4); set llm on the agent to use another.

Save this as crew.py:

import os

from crewai import Agent, Crew, Task
from crewai.mcp import MCPServerHTTP

assistant = Agent(
    role="Email assistant",
    goal="Send email for the team",
    backstory="Sends the team's email through mails.ai.",
    mcps=[
        MCPServerHTTP(
            url="https://api.mails.ai/mcp",
            headers={"Authorization": f"Bearer {os.environ['MAILS_API_KEY']}"},
        ),
    ],
)

task = Task(
    description="Email reply@test.mails.ai to say the report is ready.",
    expected_output="The id of the email that was sent.",
    agent=assistant,
)

crew = Crew(agents=[assistant], tasks=[task])
print(crew.kickoff())

Then run python crew.py.

Next steps

Was this page helpful?