Give a Mastra agent a cloud Android phone with MCPClient.
The code
Install with npm install @mastra/core @mastra/mcp and a model provider such as @ai-sdk/openai:
import { Agent } from "@mastra/core/agent";
import { MCPClient } from "@mastra/mcp";
import { openai } from "@ai-sdk/openai";
const mcp = new MCPClient({
servers: {
phonebox: {
url: new URL("https://phonebox.dev/mcp"),
requestInit: { headers: { Authorization: `Bearer ${process.env.PHONEBOX_API_KEY}` } },
},
},
});
const agent = new Agent({
id: "android-operator",
name: "Android operator",
instructions: "You control cloud Android phones through Phonebox. Park every phone you start when you're done.",
model: openai(process.env.OPENAI_MODEL!),
tools: await mcp.listTools(), // named phonebox_create_phone, phonebox_observe, ...
});
try {
const result = await agent.generate("Create a phone named settings-check, open Settings, tell me the Android version, then park the phone.", { maxSteps: 30 });
console.log(result.text);
} finally {
await mcp.disconnect();
}Tool names in Mastra
Mastra prefixes each tool with the server's key in servers, so naming the server phonebox gives phonebox_list_phones, phonebox_create_phone, phonebox_observe, phonebox_act and phonebox_park_phone, among the 34. Refer to those names in your instructions if you want the agent to prefer one, for example to always call phonebox_park_phone at the end.
Why does my Mastra agent stop early?
An agent call runs at most 5 tool-call steps unless you pass maxSteps or set it in the agent's default options. Looking at the screen and acting each take a step, so the example passes 30.
Keys, costs and cleanup
Create an Agent key in API keys and export it as PHONEBOX_API_KEY. An Agent key can create, start, use and park phones but can't delete them, which is the right default for an agent. Give the key an expiry, and set a monthly spending limit in Settings: it stops new sessions when it's reached.
Tell the agent to park every phone it starts. A parked phone costs nothing and keeps its apps, files and sign-ins for the next run. Phonebox also parks a phone after its idle timeout and ends a session at its maximum length, so a crashed script doesn't leave a phone running.
Phonebox's tool schemas also list context (a short reason for the call) and llm_model, which are used only for analytics. Models fill them in from the schema, so an agent needs nothing extra. The server doesn't reject a call without them, so code that calls a tool directly can leave them out.
What was checked
Checked on December 1, 2026 with @mastra/mcp 2.11.0 and @mastra/core 1.86.0: the framework's MCP client connected to https://phonebox.dev/mcp with a project API key, listed all 14 Phonebox tools and called get_account. That check didn't start a phone or run a model; the agent code on this page was type-checked against those versions. See Mastra's MCP docs for more options.
Mastra: common questions
How do I add a remote MCP server to Mastra?
Create an MCPClient with a server entry that has a url and requestInit headers, then pass await mcp.listTools() to your Agent. For Phonebox, the url is https://phonebox.dev/mcp and the header is Authorization: Bearer with your project API key.
What are the Phonebox tools called in Mastra?
Mastra prefixes tool names with the server key, so a server named phonebox gives tools such as phonebox_create_phone, phonebox_observe, phonebox_act and phonebox_park_phone.