Connect Mastra agents to their own email inbox

Checked · Markdown

Short answer

Create an MCPClient from @mastra/mcp with a server entry whose url is new URL('https://agentline.nz/mcp') and whose requestInit headers carry your Agentline NZ API key as a Bearer token, then give the agent await mcp.listTools(). The agent can then send and read email from its own @agentline.nz inbox and wait for one-time codes sent by email.

Before you start

  • An Agentline NZ API key from Dashboard → API keys, set 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 MCP package. @mastra/mcp v2 needs @mastra/core 1.76 or later.
    npm install @mastra/mcp
  2. Connect Agentline NZ and build the agent. Giving a url selects Streamable HTTP.
    import { MCPClient } from '@mastra/mcp';
    import { Agent } from '@mastra/core/agent';
    
    const mcp = new MCPClient({
      servers: {
        agentline: {
          url: new URL('https://agentline.nz/mcp'),
          requestInit: {
            headers: { Authorization: `Bearer ${process.env.AGENTLINE_KEY}` },
          },
        },
      },
    });
    
    export const assistant = new Agent({
      id: 'assistant',
      name: 'Assistant',
      instructions: 'Use Agentline NZ to send and read email and wait for one-time codes.',
      model: 'openai/gpt-5.6-sol',
      tools: await mcp.listTools(),
    });
  3. Check the tool names. Mastra namespaces tools as serverName_toolName, so the agent sees agentline_send_email, agentline_wait_for_code and so on.

Good to know

  • Older Mastra code uses getTools; it was renamed listTools.
  • If you use OAuth instead of an API key, note that @mastra/mcp v2 removed dynamic client registration.
  • 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.