Mastra on Android: phone tools for your agent.
Mastra agents can automate Android apps through Mobilebox. MCPClient connects to the hosted Mobilebox MCP server, listTools() hands the agent its phone tools, and the agent reads a cloud phone’s screen as numbered elements, then taps, types and installs apps.
TypeScript, 29 lines, the hosted MCP server and its 13 tools. Android and iPhone over one API.
- 1
Get a key
Sign up with GitHub and create an API key in the dashboard. New accounts get $2 of credit.
- 2
Install Mastra
npm i @mastra/core @mastra/mcp - 3
Run the example
node agent.tswithMOBILESANDBOX_API_KEYandOPENAI_API_KEYset. It creates a phone, gives the agent one task and deletes the phone, also when the run fails.
The whole example
model takes any Mastra model id, so the same file runs on OpenAI, Anthropic or any other provider in the model router.
// Mastra + Mobilebox: a Mastra agent drives a cloud Android phone over MCP.
// npm i @mastra/core @mastra/mcp
// MOBILESANDBOX_API_KEY=... OPENAI_API_KEY=... node agent.ts
import { Agent } from '@mastra/core/agent'
import { MCPClient } from '@mastra/mcp'
const API = 'https://mobilebox.dev'
const AUTH = { Authorization: `Bearer ${process.env.MOBILESANDBOX_API_KEY}` }
async function phones(method: string, path = '') { // your code owns the phone: create it, and always delete it
const res = await fetch(`${API}/v1/phones${path}`, { method, headers: AUTH })
if (!res.ok) throw new Error(`${method} /v1/phones${path}: ${res.status} ${await res.text()}`)
return res.status === 204 ? null : res.json()
}
const phone = (await phones('POST', '?wait=ready')).id
const mcp = new MCPClient({ servers: { mobilebox: { url: new URL(`${API}/mcp`), requestInit: { headers: AUTH } } } })
try {
const agent = new Agent({
id: 'phone-operator',
name: 'Phone operator',
instructions: `You operate the Android phone ${phone} with the Mobilebox tools. ` +
'Observe, act, and check each result on the returned screen. Don\'t create or delete phones.',
model: process.env.MODEL ?? 'openai/gpt-5.4-mini', // any Mastra model id
tools: await mcp.listTools(),
})
const result = await agent.generate('Open Settings > Display and tell me the brightness level.', { maxSteps: 20 })
console.log(result.text)
} finally {
await mcp.disconnect()
await phones('DELETE', `/${phone}`)
}
Ran once against production on 5 November 2026: the agent answered “Brightness level: 83%” in 33 s, and the phone was deleted. Run log
Questions
Before you wire Mastra to a phone.
Can I use the phone tools in a Mastra workflow?
Yes. listTools() returns Mastra tools: give them to the agent a workflow step calls, and pass the phone id in the step’s input.
Does it run in serverless functions?
Yes. The MCP connection is plain HTTPS with a bearer header, so it runs wherever Mastra runs. Disconnect when the run ends, as the example does.
Can the agent install my app?
Yes. install_app takes a public APK or split-bundle URL, or your code uploads the file over REST; then the agent opens it with {"type":"open_app","package":…}. See installing APKs and split bundles.
Does it work on iPhone?
Yes. Create the phone with platform: "ios" and the agent uses the same tools. See iPhone and iPad.
What does a run like this cost?
A ready phone costs $0.01 a minute, billed per second with a one-minute minimum; boot time and parked phones are free, so a run like the one above costs about a cent. See pricing.
Read more
Give your coding agent an Android sandbox over MCP
Add the remote MCP server to Claude Code or Cursor, see every phone tool, run a bounded first task and know what is proven.
A timeout does not mean the tap never happened
Reconcile phone creation, inspect partial action batches and check side effects before retrying an uncertain Android operation.
Using another framework? OpenAI Agents SDK, LangGraph, CrewAI, browser-use, Vercel AI SDK, Claude Agent SDK.
All integrations