---
title: "MCP Gateway integration"
description: "Turn on MCP servers inside an E2B sandbox and connect any MCP client to them through one gateway URL. 200+ servers from the Docker MCP Catalog."
url: "https://e2b.dev/integrations/mcp"
---

# MCP Gateway

> Turn on MCP servers when you create a sandbox, then connect any MCP client to all of them through one gateway. Choose from 200+ servers in the Docker MCP Catalog, or bring your own.

Tools & MCP · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Gateway runs inside the sandbox
- **Package:** e2b
- **Language:** TypeScript, Python
- **Upstream:** [modelcontextprotocol/modelcontextprotocol · ★ 9.7k](https://github.com/modelcontextprotocol/modelcontextprotocol)
- **Example:** [e2b-cookbook/mcp-client-js](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/mcp-client-js)

## Get started

Paste the prompt into your coding agent, or follow the steps yourself.

### Paste this into your coding agent

```text
Add the E2B MCP Gateway to this project.

1. Install e2b and an MCP client SDK (@modelcontextprotocol/sdk for TypeScript, mcp for Python) using the project's package manager.
2. The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it. Ask me for each MCP server's keys the same way.
3. Follow the MCP Gateway guide at https://docs.e2b.dev/mcp-gateway: create a sandbox with the MCP servers I need in its mcp config, then connect a client to sandbox.getMcpUrl() with the token from getMcpToken() as a Bearer header.
4. List the tools once and show me what came back from the gateway, then kill the sandbox.
```

## Or set it up yourself

### 1. Install the SDKs

```bash
npm install e2b @modelcontextprotocol/sdk
```

### 2. Set your API keys

```bash
export E2B_API_KEY="e2b_..."
export EXA_API_KEY="..."
```

### 3. Turn on MCP servers in a sandbox

```typescript
import Sandbox from 'e2b'

const sandbox = await Sandbox.create({
    mcp: {
        exa: {
            apiKey: process.env.EXA_API_KEY!,
        },
    },
});
```

### 4. Connect a client to the gateway

```typescript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const client = new Client({
    name: 'e2b-mcp-client',
    version: '1.0.0'
});

const transport = new StreamableHTTPClientTransport(
    new URL(sandbox.getMcpUrl()),
    {
        requestInit: {
            headers: {
                'Authorization': `Bearer ${await sandbox.getMcpToken()}`
            }
        }
    }
);

await client.connect(transport);

const tools = await client.listTools();
console.log('Available tools:', tools.tools.map(t => t.name));

await client.close();
await sandbox.kill();
```

## What runs in the sandbox

The MCP servers run inside the sandbox, on an internet-connected Linux machine, not on your host.

- **Servers:** The MCP servers you list in the mcp config, from the Docker MCP Catalog or a custom GitHub repo.
- **Access:** Clients connect through the gateway URL with a per-sandbox Bearer token. Inside the sandbox it is at localhost:50005/mcp.
- **Secrets:** Each server's keys go in the mcp config when you create the sandbox, so the server can use them there.
- **Lifetime:** The gateway lives with its sandbox. Call kill() when your agent is done with the tools.

## More tools & MCP

Other tools your agent can reach from an E2B sandbox.

- [Firecrawl](https://docs.e2b.dev/mcp-gateway/available-servers): Scrape the web with Firecrawl, then analyze the results in a sandbox. Also in the MCP Gateway.
- [Composio](https://docs.composio.dev/toolkits/e2b): Call E2B from Composio's toolkit catalog alongside 1,000+ other tools.
- [Arcade](https://docs.arcade.dev/en/resources/integrations/development/e2b): Use Arcade's E2B toolkit so agents can run code through Arcade-authorized tools.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/mcp-gateway)
- [E2B documentation](https://docs.e2b.dev)
