Hand an agent an MCPServerStreamableHttp pointed at MCPmailer and it gets the mail tools for the whole run, with the tool list cached between turns.
Install the SDK
The MCP client ships inside openai-agents; there is nothing else to add.
Create a mailbox
One per agent, so its address and its key are the same identity.
Open the server in a context manager
The async with block owns the connection and closes it.
Put it on an agent
mcp_servers is per agent, so only the agents you list get mail tools.
pip install openai-agentsfrom agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async with MCPServerStreamableHttp(
name="mcpmailer",
params={
"url": "https://connect.mcpmailer.com/mcp",
"headers": {"Authorization": "Bearer mmk_live_..."},
},
cache_tools_list=True,
) as server:
agent = Agent(name="Support", mcp_servers=[server])
result = await Runner.run(agent, "Reply to the newest support email.")cache_tools_list avoids refetching our tool list on every turn. Leave it off while you are still changing which tools the key can reach.
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async def main():
async with MCPServerStreamableHttp(
name="mcpmailer",
params={
"url": "https://connect.mcpmailer.com/mcp",
"headers": {"Authorization": f"Bearer {os.environ['MCPMAILER_KEY']}"},
},
cache_tools_list=True,
) as server:
agent = Agent(
name="Support",
instructions="You answer support email. Reply in thread, never start new ones.",
mcp_servers=[server],
)
result = await Runner.run(agent, "Check for unread mail and answer anything you can.")
print(result.final_output)
asyncio.run(main())mcp_servers hangs off the Agent. In a handoff, the agent you hand off to needs its own reference or it will not have the mail tools.
The params timeout defaults to 5 seconds. wait_for_reply can block for up to 300, so set a timeout above the wait you intend to use or the transport gives up first.
With cache_tools_list=True the list is fetched once per connection. Narrow an OAuth grant and the agent keeps offering tools it can no longer call until you reconnect.
The endpoint speaks Streamable HTTP MCP with 67 tools across mail, contacts, notes, and a vault, including send_email, read_message, search_inbox, and wait_for_reply. Errors are structured so OpenAI Agents SDK can react: a quota rejection includes the reset time.