עבריתLog in

OneLi with Mastra

How to let an agent built with Mastra place Hebrew phone calls through OneLi, follow the call, answer consultations and read the result.

Mastra has a built-in MCP client. Add the OneLi server with your API key in a header and the agent gets every OneLi tool.

Setup

  1. Create an API key at oneli.io/app/connect and store it on the server as ONELI_API_KEY.
  2. Install the packages:
Terminal
npm i @mastra/core @mastra/mcp zod

Checked against: @mastra/core 1.79.0 · @mastra/mcp 2.5.0

Connect over MCP (recommended)

TypeScript
import { MCPClient } from '@mastra/mcp'
import { Agent } from '@mastra/core/agent'

const mcp = new MCPClient({
  id: 'oneli',
  servers: {
    oneli: {
      url: new URL('https://mcp.oneli.io/mcp'),   // url => Streamable HTTP
      requestInit: { headers: { Authorization: `Bearer ${process.env.ONELI_API_KEY}` } },
    },
  },
})

export const callAgent = new Agent({
  id: 'call-agent', name: 'Call Agent',
  instructions: 'Use OneLi to place and follow phone calls.',
  model: 'openai/gpt-5.6-sol',            // any model id you use
  tools: await mcp.listTools(),           // names are namespaced: oneli_create_call_task, …
})

Alternative: your own REST tool

TypeScript
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

export const createCallTask = createTool({
  id: 'create-call-task',
  description: 'Have OneLi place a phone call. to_number in E.164.',
  inputSchema: z.object({ to_number: z.string(), goal: z.string(), instructions: z.string().optional() }),
  execute: async (input, { abortSignal }) => {
    const r = await fetch('https://api.oneli.io/v1/call-tasks', {
      method: 'POST', signal: abortSignal,
      headers: { Authorization: `Bearer ${process.env.ONELI_API_KEY}`, 'Content-Type': 'application/json' },
      body: JSON.stringify({ idempotency_key: crypto.randomUUID(), ...input }),
    })
    if (!r.ok) throw new Error(`OneLi ${r.status}: ${await r.text()}`)
    return r.json()
  },
})

Notes

  • Tool names are prefixed with the server name, for example oneli_create_call_task.
  • In 1.x the method was getTools(); it is now listTools().
  • For a key per user, use listToolsets() and pass the result at generate or stream time.

Phone numbers: OneLi accepts an Israeli number in any common format (050-1234567, +972501234567). Once the call starts, the agent follows it with get_call_events or GET /v1/call-tasks/:id/events to answer consultations and get the summary.

Next steps

Sources: mastra.ai/reference/tools/mcp-client · mastra.ai/docs/agents/using-tools