> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mobilerun.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Use Mobilerun phones with the OpenAI Agents SDK through MCP.

The OpenAI Agents SDK builds tool-using agents. Connect the Mobilerun MCP server to give an agent phone tools.

## Setup

1. [Set up a phone](https://docs.mobilerun.ai/devices.md), install the SDK, and create a Mobilerun [API key](https://docs.mobilerun.ai/api-keys.md).

   ```bash TypeScript theme={null}
   npm install @openai/agents zod
   ```

   ```bash Python theme={null}
   pip install openai-agents
   ```

2. Attach the server to your agent:

```typescript TypeScript theme={null}
import { Agent, MCPServerStreamableHttp, run } from '@openai/agents';

const server = new MCPServerStreamableHttp({
  name: 'mobilerun',
  url: 'https://cloud.mobilerun.ai/api/mcp',
  requestInit: { headers: { Authorization: `Bearer ${process.env.MOBILERUN_API_KEY}` } },
});
await server.connect();
try {
  const agent = new Agent({ name: 'Phone assistant', mcpServers: [server] });
  const result = await run(agent, 'List my Mobilerun devices.');
  console.log(result.finalOutput);
} finally {
  await server.close();
}
```

```python Python theme={null}
import asyncio
import os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    async with MCPServerStreamableHttp(
        name="mobilerun",
        params={
            "url": "https://cloud.mobilerun.ai/api/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['MOBILERUN_API_KEY']}"},
        },
    ) as server:
        agent = Agent(name="Phone assistant", mcp_servers=[server])
        result = await Runner.run(agent, "List my Mobilerun devices.")
        print(result.final_output)

asyncio.run(main())
```

3. Set `MOBILERUN_API_KEY` and model credentials in the process environment before running the example. Configure approvals for actions and keep keys server-side.

## First task

> List my Mobilerun devices and take a screenshot of the ready device.

See [MCP Server](https://docs.mobilerun.ai/mcp-server.md) for available tools and the [OpenAI Agents SDK MCP documentation](https://openai.github.io/openai-agents-python/mcp/) for configuration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.