> ## 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.

# LangChain

> Connect LangChain agents to Mobilerun phones using MCP adapters.

LangChain is a framework for building tool-using agents. Mobilerun gives a LangChain agent tools for working with phones.

## Setup

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

   Install the adapter for the example's language:

   ```bash TypeScript theme={null}
   npm install @langchain/mcp-adapters@^1
   ```

   ```bash Python theme={null}
   pip install langchain-mcp-adapters
   ```

2. Configure the Mobilerun server (`@langchain/mcp-adapters` for TypeScript, `langchain-mcp-adapters` for Python):

```typescript TypeScript theme={null}
import { MultiServerMCPClient } from '@langchain/mcp-adapters';

const client = new MultiServerMCPClient({
  mobilerun: {
    transport: 'http',
    url: 'https://cloud.mobilerun.ai/api/mcp',
    headers: { Authorization: `Bearer ${process.env.MOBILERUN_API_KEY}` },
  },
});
const tools = await client.getTools();
```

```python Python theme={null}
import os
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "mobilerun": {
        "transport": "http",
        "url": "https://cloud.mobilerun.ai/api/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['MOBILERUN_API_KEY']}"},
    }
})
tools = await client.get_tools()
```

3. Set `MOBILERUN_API_KEY` and model credentials in the process environment. Use the example inside an async function and pass `tools` to your LangChain agent. Keep keys server-side and configure action approvals.

## 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.

See [LangChain's MCP documentation](https://docs.langchain.com/oss/python/langchain/mcp) for agent construction and session behavior.


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