Give a Vercel AI SDK app a cloud Android phone through MCP.
The code
Install with npm install ai @ai-sdk/mcp and a provider package such as @ai-sdk/openai. Any model that supports tool calls works.
import { generateText, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";
import { openai } from "@ai-sdk/openai";
const phonebox = await createMCPClient({
transport: {
type: "http",
url: "https://phonebox.dev/mcp",
headers: { Authorization: `Bearer ${process.env.PHONEBOX_API_KEY}` },
},
});
try {
const { text } = await generateText({
model: openai(process.env.OPENAI_MODEL!), // any AI SDK model that supports tool calls
tools: await phonebox.tools(),
stopWhen: stepCountIs(30),
system: "You control cloud Android phones through Phonebox. Park every phone you start when you're done.",
prompt: "Create a phone named settings-check, open Settings, tell me the Android version, then park the phone.",
});
console.log(text);
} finally {
await phonebox.close();
}Close the client when the request ends. In a route handler that streams, close it in onFinish rather than straight after streamText returns.
Why does the model stop after its first tool call?
Without a stop condition, generateText runs one step. The model calls create_phone and the result comes back to you instead of to the model. A stop condition such as stepCountIs(30) lets it keep going: create or start a phone, observe the screen, act, observe again, and park.
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.
Phones for your users
If your app gives each of its users a phone, keep one Phonebox phone per user and store its ID with the user, then pass it in the prompt or system message. A parked phone keeps that user's apps and sign-ins. See phones for many users.
What was checked
Checked on December 1, 2026 with ai 7.0.186 and @ai-sdk/mcp 2.0.107: 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 the AI SDK MCP docs for the client's other options.
Vercel AI SDK: common questions
Can the Vercel AI SDK use a remote MCP server?
Yes. createMCPClient from @ai-sdk/mcp takes an http transport with a URL and headers. For Phonebox, the URL is https://phonebox.dev/mcp and the header is Authorization: Bearer with your project API key.
Why does generateText stop after one tool call?
generateText runs a single step unless you set stopWhen. Use a condition such as stepCountIs(30) so the model can look at the phone's screen and act several times.