Connect Mastra agents to a NZ phone number, SMS and email

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 text from a New Zealand 028 number, read and send email and wait for one-time codes.

Before you start

  • An Agentline NZ API key from Dashboard → API keys, set as AGENTLINE_KEY. Start free with an email inbox (no card), or take a 7-day trial of Starter or Pro to get a number.
  • Your 028 number is set up within a few days of signup. Your email inbox works straight away.

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 text, 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_sms, 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.
  • Standard NZ mobile numbers only (020–029). No landlines, short codes, premium or international numbers.

FAQ

What does Agentline NZ cost?

Starter is NZ$29/month and Pro is NZ$79/month, billed in NZ dollars. Start free with an email inbox (no card), or take a 7-day trial of Starter or Pro to get a number. Agentline NZ is not GST-registered, so no GST is charged.

How long does it take to get the 028 number?

Your 028 number is set up within a few days of signup. Your email inbox works straight away. Full refund if your number hasn't arrived within 30 days of paying.

Can my assistant send marketing or bulk texts?

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

Start free · Start free with an email inbox (no card), or take a 7-day trial of Starter or Pro to get a number.