https://github.com/e2b-dev/mcp-gateway-demo
E2B MCP Gateway Demo
https://github.com/e2b-dev/mcp-gateway-demo
Last synced: 30 days ago
JSON representation
E2B MCP Gateway Demo
- Host: GitHub
- URL: https://github.com/e2b-dev/mcp-gateway-demo
- Owner: e2b-dev
- License: apache-2.0
- Created: 2025-10-11T14:33:41.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-11-20T15:27:29.000Z (8 months ago)
- Last Synced: 2026-06-15T05:35:04.930Z (30 days ago)
- Language: TypeScript
- Size: 69.3 KB
- Stars: 5
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MCP Gateway Demo
A demonstration of using Model Context Protocol (MCP) servers with E2B sandboxes and Mastra agents. This project showcases how to run MCP servers in secure E2B sandboxes and integrate them with AI agents.
## What This Does
This demo creates an AI agent that can access MCP servers (like Context7 for documentation) running inside an E2B sandbox. The agent can then use the tools provided by these MCP servers to answer questions.
## Prerequisites
Before getting started, you'll need:
- [Bun](https://bun.sh/) installed (or Node.js)
- An [E2B API key](https://e2b.dev/docs/getting-started/api-key)
- An OpenAI API key
## Getting Started
### 1. Clone and Install
```bash
# Install dependencies
bun install
```
### 2. Set Up Environment Variables
Create a `.env` file in the project root:
```bash
# E2B API key for sandbox creation
E2B_API_KEY=your_e2b_api_key
# OpenAI API key for the agent
OPENAI_API_KEY=your_openai_api_key
```
### 3. Run the Demo
```bash
bun run index.ts
```
The demo will:
1. Create an E2B sandbox with the Context7 MCP server
2. Initialize a Mastra agent with access to the MCP tools
3. Ask the agent "How to create an E2B Sandbox?"
4. Display the agent's response
## How It Works
### Architecture
```
┌─────────────┐
│ Mastra Agent│
└──────┬──────┘
│
▼
┌─────────────┐
│ MCP Client │
└──────┬──────┘
│
▼
┌─────────────┐
│ E2B Sandbox │
│ ┌────────┐ │
│ │Context7│ │
│ │ MCP │ │
│ └────────┘ │
└─────────────┘
```
1. **E2B Sandbox**: Provides a secure, isolated environment for MCP servers
2. **MCP Client**: Connects to the MCP servers through the E2B gateway
3. **Mastra Agent**: Uses the MCP tools to answer questions
### Key Files
- `index.ts` - Main entry point, creates the agent and runs a query
- `mcp.ts` - Sets up the E2B sandbox with MCP servers and creates the MCP client
## Customizing
### Adding More MCP Servers
Edit the `servers` configuration in `index.ts`:
```typescript
const servers: McpServer = {
context7: {},
// Add more MCP servers here
// Example:
// filesystem: {
// args: ["/path/to/directory"]
// }
};
```
### Changing the Agent
Modify the agent configuration in `index.ts`:
```typescript
const agent = new Agent({
name: "DocsAgent",
instructions: "Your custom instructions here",
model: "openai/gpt-4o", // or another model
tools: await E2BMCPClient.getTools(),
});
```
### Running Different Queries
Update the query in `index.ts`:
```typescript
const result = await agent.generate("Your question here");
```
## Learn More
- [E2B Documentation](https://e2b.dev/docs)
- [Mastra Documentation](https://mastra.ai/docs)
- [MCP Protocol](https://modelcontextprotocol.io/)