Connect the OpenAI Agents SDK to an agent email inbox

Checked · Markdown

Short answer

Use MCPServerStreamableHttp from agents.mcp with url https://agentline.nz/mcp and an Authorization: Bearer header holding your Agentline NZ API key, then pass the server to your Agent in mcp_servers. Your agent gets Agentline NZ's inbox tools for sending and reading email from its own @agentline.nz address, plus wait_for_code.

Before you start

  • An Agentline NZ API key from Dashboard → API keys, exported as AGENTLINE_KEY. No credit card needed to sign up. Start free with an email inbox, or try Starter or Pro free for 7 days.
  • Your @agentline.nz email inbox works straight away. Texting and phone numbers are coming soon.

Steps

  1. Install the SDK. Install the openai-agents package.
    pip install openai-agents
  2. Connect to Agentline NZ. Open an MCPServerStreamableHttp connection with your key in the headers and give it to the agent.
    import asyncio, os
    from agents import Agent, Runner
    from agents.mcp import MCPServerStreamableHttp
    
    async def main():
        async with MCPServerStreamableHttp(
            name="agentline",
            params={
                "url": "https://agentline.nz/mcp",
                "headers": {"Authorization": f"Bearer {os.environ['AGENTLINE_KEY']}"},
                "timeout": 60,
            },
            cache_tools_list=True,
        ) as agentline:
            agent = Agent(
                name="Assistant",
                instructions="Use Agentline NZ to send and read email and wait for one-time codes.",
                mcp_servers=[agentline],
            )
            result = await Runner.run(agent, "What's my Agentline NZ email address?")
            print(result.final_output)
    
    asyncio.run(main())
  3. Run it. Run the script. The agent should call get_my_number and print your inbox address.

JavaScript

import { Agent, run, MCPServerStreamableHttp } from '@openai/agents';

const agentline = new MCPServerStreamableHttp({
  name: 'agentline',
  url: 'https://agentline.nz/mcp',
  requestInit: { headers: { Authorization: `Bearer ${process.env.AGENTLINE_KEY}` } },
});
await agentline.connect();
const agent = new Agent({ name: 'Assistant', mcpServers: [agentline] });
console.log((await run(agent, "What's my Agentline NZ email address?")).finalOutput);
await agentline.close();

Good to know

  • Set the timeout above 55 seconds if your agent uses wait_for_code with a long timeout, because the tool call waits for the code to arrive.
  • The SDK also has HostedMCPTool, where OpenAI's Responses API connects to the server for you. We've used the local client because its header handling is documented for any server.
  • Texting and phone numbers are coming soon. To hear when they're ready, join the waitlist.

FAQ

What does Agentline NZ cost?

Starter is NZ$29/month and Pro is NZ$79/month, billed in NZ dollars. No credit card needed to sign up. Start free with an email inbox, or try Starter or Pro free for 7 days. You can cancel anytime, and your plan stops at the end of the billing period you've paid for. Refunds follow section 5 of our Terms: fees already paid aren't refunded, except where the Terms or the law say so. Agentline NZ is not GST-registered, so no GST is charged.

When does the inbox work, and can my assistant send texts yet?

Your @agentline.nz email inbox works straight away. Texting and phone numbers are coming soon. To hear when texting is ready, join the waitlist.

Can my assistant send marketing or bulk email?

No. Transactional and assistant messages only: replies, bookings, confirmations, reminders people asked for, and codes. Marketing, promotions, cold messages and bulk messages aren't allowed. See What we don't allow.

Start free · No credit card needed to sign up. Start free with an email inbox, or try Starter or Pro free for 7 days.