An open API service indexing awesome lists of open source software.

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

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/)