Mobilebox
Menu

Vercel AI SDK on Android: phone tools for generateText.

The Vercel AI SDK can drive Android apps through Mobilebox. createMCPClient connects to the hosted Mobilebox MCP server, mcp.tools() returns AI SDK tools, and generateText loops through observe and act on a cloud phone until the task is done.

TypeScript, 29 lines, the hosted MCP server and its 13 tools. Android and iPhone over one API.

Run it in three steps.

Your code owns the phone; the agent only drives it.

Read the quickstart
  1. 1

    Get a key

    Sign up with GitHub and create an API key in the dashboard. New accounts get $2 of credit.

  2. 2

    Install Vercel AI SDK

    npm i ai @ai-sdk/mcp @ai-sdk/openai

  3. 3

    Run the example

    node agent.ts with MOBILESANDBOX_API_KEY and OPENAI_API_KEY set. It creates a phone, gives the agent one task and deletes the phone, also when the run fails.

The whole example

stopWhen: stepCountIs(20) lets the model take up to 20 tool steps; the same tools work in streamText.

typescript · agent.ts
// Vercel AI SDK + Mobilebox: generateText drives a cloud Android phone with the Mobilebox MCP tools.
//   npm i ai @ai-sdk/mcp @ai-sdk/openai
//   MOBILESANDBOX_API_KEY=... OPENAI_API_KEY=... node agent.ts
import { generateText, stepCountIs } from 'ai'
import { createMCPClient } from '@ai-sdk/mcp'
import { openai } from '@ai-sdk/openai'

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 = await createMCPClient({ transport: { type: 'http', url: `${API}/mcp`, headers: AUTH } })
try {
  const { text } = await generateText({
    model: openai.chat(process.env.MODEL ?? 'gpt-5.4-mini'), // or any AI SDK provider
    tools: await mcp.tools(),
    stopWhen: stepCountIs(20),
    system: `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.',
    prompt: 'Open Settings > Display and tell me the brightness level.',
  })
  console.log(text)
} finally {
  await mcp.close()
  await phones('DELETE', `/${phone}`)
}

Ran once against production on 5 November 2026: the agent answered “Brightness level: 83%” in 32 s, and the phone was deleted. Run log

Questions

Before you wire Vercel AI SDK to a phone.

Does it work with streamText and useChat?

Yes. mcp.tools() returns ordinary AI SDK tools: pass them to streamText in a route handler and stream the steps to useChat. Close the client when the response finishes.

Which providers can drive the phone?

Any AI SDK provider whose model calls tools. The example uses the Chat Completions model from @ai-sdk/openai, which also reaches OpenAI-compatible endpoints through OPENAI_BASE_URL.

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

Using another framework? OpenAI Agents SDK, LangGraph, CrewAI, browser-use, Mastra, Claude Agent SDK.

All integrations