Skip to content

MCP Gateway

MCP Gateway is a service that enables you to run and manage multiple Model Context Protocol (MCP) servers within your AgentBox sandbox. It provides a unified gateway interface to access various third-party services and tools through a single endpoint.

MCP Gateway supports many different MCP servers, including:

  • Search & Web: DuckDuckGo, Brave, Exa, ArXiv, Wikipedia
  • Databases: PostgreSQL, MySQL, MongoDB, Redis, Chroma, Pinecone
  • Cloud Services: AWS, Azure, GCP, Vercel, Heroku
  • Development Tools: GitHub, GitLab, Code Interpreter, Filesystem
  • AI Services: OpenAI, Anthropic, Hugging Face, ElevenLabs
  • Communication: Slack, Discord, Gmail, Notion
  • And many more…

Browse all available servers →


To create a sandbox with MCP Gateway, specify the MCP configuration when creating the sandbox. The mcp-gateway template will be automatically selected.

Create a sandbox with a single MCP server:

from agentbox import Sandbox

sandbox = Sandbox.create(
   api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxx",
   mcp={
       "duckduckgo": {}
   }
)

You can configure multiple MCP servers in a single sandbox:

from agentbox import Sandbox

sandbox = Sandbox.create(
   api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxx",
   mcp={
       "duckduckgo": {},
       "arxiv": {"storagePath": "/tmp/arxiv"},
       "context7": {}
   }
)

After creating a sandbox with MCP Gateway, you can retrieve the URL and token to connect to it:

from agentbox import Sandbox

sandbox = Sandbox(api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxx",
                 sandbox_id="your-sandbox-id")

# Get MCP connection info
mcp_url = sandbox.get_mcp_url()
mcp_token = sandbox.get_mcp_token()

print(f"MCP URL: {mcp_url}")
print(f"MCP Token: {mcp_token}")

The URL format is: https://{sandbox-domain}:50005/mcp


Once you have the MCP URL and token, you can connect to it from various MCP clients.

Using the official MCP Python client:

from mcp.client.session import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from datetime import timedelta

async def connect_to_mcp(mcp_url, mcp_token):
   async with streamablehttp_client(
       url=mcp_url,
       headers={"Authorization": f"Bearer {mcp_token}"},
       timeout=timedelta(seconds=600)
   ) as (read_stream, write_stream, _):
       async with ClientSession(read_stream, write_stream) as session:
           await session.initialize()
           
           # List available tools
           tools = await session.list_tools()
           print(f"Available tools: {[tool.name for tool in tools.tools]}")
           
           # Use a tool
           result = await session.call_tool("duckduckgo_search", {
               "query": "AgentBox MCP Gateway"
           })
           print(result)

Using the official MCP TypeScript client:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

async function connectToMCP(mcpUrl: string, mcpToken: string) {
 const transport = new SSEClientTransport(
   new URL(mcpUrl),
   {
     headers: {
       Authorization: `Bearer ${mcpToken}`,
     },
   }
 );

 const client = new Client(
   {
     name: "agentbox-mcp-client",
     version: "1.0.0",
   },
   {
     capabilities: {},
   }
 );

 await client.connect(transport);

 // List available tools
 const tools = await client.listTools();
 console.log("Available tools:", tools.tools.map(t => t.name));

 // Use a tool
 const result = await client.callTool({
   name: "duckduckgo_search",
   arguments: { query: "AgentBox MCP Gateway" },
 });
 console.log(result);
}

To use MCP Gateway with Claude Desktop, add it to your Claude Desktop configuration:

// ~/Library/Application Support/Claude/claude_desktop_config.json
{
 "mcpServers": {
   "agentbox-mcp-gateway": {
     "transport": {
       "type": "sse",
       "url": "https://sandbox-abc123.agentbox.cloud:50005/mcp",
       "headers": {
         "Authorization": "Bearer your-mcp-token"
       }
     }
   }
 }
}

Connection timeout: Make sure your sandbox is running and not paused.

Authentication error: Verify that you’re using the correct token and that it hasn’t expired.

Server not found: Ensure the MCP server is properly configured in your sandbox.