Skip to content

e2b-dev/mcp-gateway-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

Getting Started

1. Clone and Install

# Install dependencies
bun install

2. Set Up Environment Variables

Create a .env file in the project root:

# 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

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:

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:

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:

const result = await agent.generate("Your question here");

Learn More

About

E2B MCP Gateway Demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published