### Run All Examples Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Provides commands to run each of the main example scripts: github_integration.py, filesystem_integration.py, multi_server_example.py, and custom_server_example.py. ```bash python examples/github_integration.py python examples/filesystem_integration.py python examples/multi_server_example.py python examples/custom_server_example.py ``` -------------------------------- ### Install Dependencies for Examples Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Installs the e2b-mcp Python package. This is a prerequisite for running any of the provided examples. ```bash pip install e2b-mcp ``` -------------------------------- ### Run Basic Example Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute a basic usage example script. Ensure the E2B API key is set. ```bash export E2B_API_KEY="your_api_key" python examples/basic_usage.py ``` -------------------------------- ### Setting up PyPI Credentials and Installing Release Tools Source: https://github.com/cased/e2b-mcp/blob/main/README.md Lists the prerequisites for using the release script, including setting PyPI credentials as environment variables and installing necessary Python packages like `build` and `twine`. Optionally, it shows how to install the GitHub CLI. ```bash # 1. Set PyPI credentials (required) export TWINE_USERNAME=__token__ export TWINE_PASSWORD='your-pypi-api-token' # 2. Install required tools pip install build twine # 3. Optional: Install GitHub CLI for release creation brew install gh # or equivalent for your system ``` -------------------------------- ### Run Custom Server Creation Example Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Executes the custom server creation example script. This demonstrates building custom MCP servers from scratch, including tools like a calculator and text processor. ```bash python examples/custom_server_example.py ``` -------------------------------- ### Add Node.js MCP Server Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of adding a Node.js MCP server, including installation commands for Node.js and necessary packages. ```python runner.add_server_from_dict("nodejs_server", { "command": "node mcp-server.js", "install_commands": [ "curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -", "sudo apt-get install -y nodejs", "npm install @modelcontextprotocol/server-filesystem" ], "description": "Node.js MCP server" }) ``` -------------------------------- ### Run Multi-Server Integration Example Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Executes the multi-server integration example script. This demonstrates using multiple MCP servers simultaneously, including GitHub and Filesystem servers. ```bash export GITHUB_PERSONAL_ACCESS_TOKEN="your_token" # Optional python examples/multi_server_example.py ``` -------------------------------- ### Run GitHub Integration Example Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Executes the GitHub integration example script. Requires the GITHUB_PERSONAL_ACCESS_TOKEN environment variable to be set for authentication with the GitHub API. ```bash export GITHUB_PERSONAL_ACCESS_TOKEN="your_token" python examples/github_integration.py ``` -------------------------------- ### Add Rust MCP Server Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of adding a Rust-based MCP server, including installation commands for Rust and building the release binary. ```python runner.add_server_from_dict("rust_server", { "command": "./target/release/mcp-server", "install_commands": [ "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y", "source ~/.cargo/env", "cargo build --release" ], "description": "Rust-based MCP server" }) ``` -------------------------------- ### Configure MCP Servers with Various Package Managers Source: https://context7.com/cased/e2b-mcp/llms.txt Examples of configuring MCP servers using `ServerConfig` with different package managers (pip, npm, apt, cargo) and installation commands. This allows for setting up servers with specific dependencies and environments. ```python from e2b_mcp import E2BMCPRunner, ServerConfig runner = E2BMCPRunner() # Python packages via pip runner.add_server(ServerConfig( name="python_server", command="python -m mcp_server_pandas", install_commands=["pip install pandas numpy requests"], description="Python MCP server with pip packages" )) # Node.js MCP server with npm runner.add_server(ServerConfig( name="nodejs_server", command="node mcp-server.js", install_commands=[ "curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -", "sudo apt-get install -y nodejs", "npm install @modelcontextprotocol/server-filesystem" ], description="Node.js MCP server" )) # System packages + Python packages runner.add_server(ServerConfig( name="git_server", command="python mcp_git_server.py", install_commands=[ "sudo apt-get update", "sudo apt-get install -y git curl", "pip install gitpython" ], description="Git MCP server with system dependencies" )) # Rust MCP server from source runner.add_server(ServerConfig( name="rust_server", command="./target/release/mcp-rust-server", install_commands=[ "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y", "source ~/.cargo/env", "cargo build --release" ], description="Rust MCP server built from source" )) # Complex setup with multiple package managers runner.add_server(ServerConfig( name="complex_setup", command="python complex_mcp_server.py", install_commands=[ "sudo apt-get update", "sudo apt-get install -y build-essential libssl-dev", "pip install --upgrade pip", "pip install requests beautifulsoup4 lxml", "mkdir -p /tmp/mcp_data", "chmod 755 /tmp/mcp_data" ], env={"MCP_DATA_DIR": "/tmp/mcp_data", "SSL_VERIFY": "true"}, description="Complex MCP server setup" )) ``` -------------------------------- ### Add a complex server with installation commands Source: https://context7.com/cased/e2b-mcp/llms.txt Configure a server that requires specific installation commands before execution. This is useful for servers with external dependencies. ```bash e2b-mcp server add complex_server \ --command "python /app/server.py" \ --install-commands "apt-get update" \ --install-commands "apt-get install -y git curl" \ --install-commands "pip install requests beautifulsoup4" \ --env DATA_DIR=/app/data ``` -------------------------------- ### Run Filesystem Operations Example Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Executes the filesystem integration example script. This demonstrates safe file and directory operations within E2B sandboxes. ```bash python examples/filesystem_integration.py ``` -------------------------------- ### Add Filesystem Server Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of adding a server for filesystem operations, specifying the command and base directory. ```bash e2b-mcp server add fs \ --command "npx -y @modelcontextprotocol/server-filesystem /tmp" ``` -------------------------------- ### Execute Filesystem Write Tool Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of using the 'write_file' tool on the filesystem server, providing path and content via parameters. ```bash e2b-mcp tools execute fs write_file \ --param path=/tmp/test.txt \ --param content="Hello CLI!" ``` -------------------------------- ### Execute GitHub Search Tool Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of executing the 'search_repositories' tool on the GitHub server with specific parameters. ```bash e2b-mcp tools execute github search_repositories \ --params '{"query": "e2b", "per_page": 3}' ``` -------------------------------- ### Add Server with System and Node.js Packages Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure a server with a Node.js command and specify installation commands for system packages, Node.js, and npm packages. ```python runner.add_server(ServerConfig( name="multi_lang_server", command="node server.js", install_commands=[ # System packages "apt-get update", "apt-get install -y build-essential", # Node.js ecosystem "curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -", "apt-get install -y nodejs", "npm install express @modelcontextprotocol/server-filesystem", # Python packages "pip install requests beautifulsoup4", # Custom setup "mkdir -p /app/data", "chmod 755 /app/data" ] )) ``` -------------------------------- ### Set Environment Variables for Examples Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Sets the E2B API key and optionally the GitHub personal access token. These are required for the examples to authenticate with E2B and GitHub services. ```bash export E2B_API_KEY="your_e2b_api_key" export GITHUB_PERSONAL_ACCESS_TOKEN="your_github_token" # Optional ``` -------------------------------- ### Python API: Basic Runner Setup and Tool Execution Source: https://github.com/cased/e2b-mcp/blob/main/README.md Demonstrates how to initialize the E2BMCPRunner, add a server configuration, discover tools, and execute a tool using the Python API. Requires asyncio. ```python import asyncio from e2b_mcp import E2BMCPRunner, ServerConfig async def main(): # Create runner runner = E2BMCPRunner() # Add MCP server runner.add_server(ServerConfig( name="filesystem", command="npx -y @modelcontextprotocol/server-filesystem /tmp", description="File system operations" )) # Discover tools tools = await runner.discover_tools("filesystem") print(f"Found {len(tools)} tools") # Execute a tool result = await runner.execute_tool( "filesystem", "write_file", {"path": "/tmp/example.txt", "content": "Hello World!"} ) print(result) # Run async code asyncio.run(main()) ``` -------------------------------- ### Add Server using Dictionary Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure an MCP server by providing a dictionary of settings, including command, installation commands, description, timeout, and environment variables. ```python runner.add_server_from_dict("my_server", { "command": "python -m my_mcp_server --stdio", "install_commands": [ "pip install requests beautifulsoup4", "apt-get install -y curl" ], "description": "My custom MCP server", "timeout_minutes": 10, "env": {"DEBUG": "1"} }) ``` -------------------------------- ### Add GitHub Server Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of adding a GitHub integration server. Requires setting the GITHUB_TOKEN environment variable. ```bash export GITHUB_TOKEN="your_token" e2b-mcp server add github \ --command "npx -y @modelcontextprotocol/server-github" \ --env GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_TOKEN ``` -------------------------------- ### Execute Filesystem Read Tool Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of using the 'read_file' tool on the filesystem server to read the content of a specified file. ```bash e2b-mcp tools execute fs read_file \ --param path=/tmp/test.txt ``` -------------------------------- ### Install e2b-mcp Source: https://context7.com/cased/e2b-mcp/llms.txt Install the e2b-mcp library using pip. Ensure your E2B API key is set as an environment variable. ```bash uv pip install e2b-mcp ``` ```bash export E2B_API_KEY="your_api_key_here" ``` -------------------------------- ### Install e2b-mcp Source: https://github.com/cased/e2b-mcp/blob/main/README.md Install the e2b-mcp package using uv pip. Ensure you have Python and pip/uv installed. ```bash uv pip install e2b-mcp ``` -------------------------------- ### Cloning Repository and Installing Dependencies Source: https://github.com/cased/e2b-mcp/blob/main/README.md Provides bash commands to clone the e2b-mcp repository and install it in development mode with extra development dependencies. ```bash # Clone the repository git clone https://github.com/cased/e2b-mcp.git cd e2b-mcp # Install in development mode pip install -e ".[dev]" # Format and lint code using the provided script ./scripts/format # Or run individual tools manually black . ruff check . ``` -------------------------------- ### Install e2b-mcp and Set Environment Variables Source: https://github.com/cased/e2b-mcp/blob/main/examples/README.md Installs the e2b-mcp Python package and sets necessary environment variables for API keys. Ensure you replace placeholders with your actual credentials. ```bash pip install e2b-mcp export E2B_API_KEY="your_e2b_key_here" export GITHUB_PERSONAL_ACCESS_TOKEN="your_github_token" ``` -------------------------------- ### Tool Class Initialization and Properties Source: https://context7.com/cased/e2b-mcp/llms.txt Demonstrates how to create a Tool object from MCP response data and access its properties like name, description, and server name. It also shows how to get the full tool name. ```python from e2b_mcp import Tool # Create tool from MCP response data tool_data = { "name": "write_file", "description": "Write content to a file", "inputSchema": { "type": "object", "properties": { "path": {"type": "string", "description": "File path"}, "content": {"type": "string", "description": "File content"} }, "required": ["path", "content"] } } tool = Tool.from_mcp_tool(tool_data, server_name="filesystem") # Access tool properties print(f"Name: {tool.name}") # 'write_file' print(f"Description: {tool.description}") # 'Write content to a file' print(f"Server: {tool.server_name}") # 'filesystem' print(f"Full name: {tool.get_full_name()}") # 'filesystem.write_file' ``` -------------------------------- ### Add Node.js MCP Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure a Node.js MCP server using a dictionary, including system package installation and npm package installation. ```python runner.add_server_from_dict("nodejs_mcp", { "command": "node mcp-server.js", "install_commands": [ "apt-get update", "apt-get install -y nodejs npm", "npm install express sqlite3" ] }) ``` -------------------------------- ### Add Complex Server with Install Commands via CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Add a complex MCP server configuration that requires multiple installation steps before execution. This is useful for servers with many dependencies. ```bash # Multi-package installation with install-commands e2b-mcp server add complex_server \ --command "python /app/server.py" \ --install-commands "apt-get update" \ --install-commands "apt-get install -y git curl" \ --install-commands "pip install requests beautifulsoup4" \ --env DATA_DIR=/app/data ``` -------------------------------- ### Add Server using ServerConfig Class Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure an MCP server using the ServerConfig class, specifying command, installation commands, description, timeout, and environment variables. ```python from e2b_mcp import ServerConfig config = ServerConfig( name="my_server", command="python -m my_mcp_server --stdio", install_commands=[ "apt-get update", "apt-get install -y nodejs npm", "npm install express", "pip install additional-package" ], description="My custom MCP server", timeout_minutes=10, env={"DEBUG": "1"} ) runner.add_server(config) ``` -------------------------------- ### Quick Execute for Filesystem List Directory Source: https://github.com/cased/e2b-mcp/blob/main/README.md Example of using quick execute to list directory contents, specifying the command, tool, parameters, and requesting JSON output. ```bash e2b-mcp quick "npx -y @modelcontextprotocol/server-filesystem /tmp" \ list_directory --param path=/tmp --json ``` -------------------------------- ### Integrate with GitHub MCP Server for Repository Operations Source: https://context7.com/cased/e2b-mcp/llms.txt Configure and interact with the official GitHub MCP server using a personal access token. This example demonstrates discovering tools, searching repositories, retrieving file contents, and searching code across GitHub. ```python import asyncio import os from e2b_mcp import E2BMCPRunner async def main(): runner = E2BMCPRunner() # Configure GitHub MCP server with token runner.add_server_from_dict("github", { "command": "npx -y @modelcontextprotocol/server-github", "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": os.getenv("GITHUB_TOKEN") } }) # Discover available tools tools = await runner.discover_tools("github") print(f"Found {len(tools)} GitHub tools") # Search repositories result = await runner.execute_tool( "github", "search_repositories", {"query": "e2b sandbox", "per_page": 5} ) print(f"Search results: {result}") # Get file contents from a repository result = await runner.execute_tool( "github", "get_file_contents", { "owner": "modelcontextprotocol", "repo": "servers", "path": "README.md" } ) print(f"README content: {result}") # Search code across GitHub result = await runner.execute_tool( "github", "search_code", {"q": "jsonrpc mcp in:file language:python", "per_page": 3} ) print(f"Code search: {result}") asyncio.run(main()) ``` -------------------------------- ### Add Rust MCP Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure a Rust MCP server using a dictionary, including Rust installation and build commands. ```python runner.add_server_from_dict("rust_mcp", { "command": "./target/release/mcp-server", "install_commands": [ "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y", "source ~/.cargo/env", "cargo build --release" ] }) ``` -------------------------------- ### ServerConfig Class Configuration Source: https://context7.com/cased/e2b-mcp/llms.txt Illustrates various ways to configure an MCP server using the ServerConfig class, including basic settings, environment variables, and installation commands. ```APIDOC ## ServerConfig Class Configuration ### Description This section details how to create and configure `ServerConfig` objects for different MCP servers, demonstrating options for commands, environment variables, installation steps, timeouts, and dictionary conversions. ### Method Python ### Endpoint N/A (Python Library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from e2b_mcp import ServerConfig # Basic configuration config = ServerConfig( name="my_server", command="python -m my_mcp_server --stdio", description="My custom MCP server", timeout_minutes=10 ) # Configuration with environment variables config = ServerConfig( name="github", command="npx -y @modelcontextprotocol/server-github", description="GitHub MCP server", env={"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx..."} ) # Configuration with installation commands config = ServerConfig( name="complex_server", command="python server.py", install_commands=[ "apt-get update", "apt-get install -y git curl", "pip install requests beautifulsoup4" ], env={"DATA_DIR": "/app/data"}, timeout_minutes=15, initialization_timeout=30 # seconds to wait for server startup ) # Convert to/from dictionary config_dict = config.to_dict() config = ServerConfig.from_dict("my_server", config_dict) ``` ### Response #### Success Response (200) N/A (Configuration object creation) #### Response Example N/A ``` -------------------------------- ### Add Node.js Filesystem Server via CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure and add a Node.js-based MCP server for filesystem operations. This includes installing Node.js and the necessary npm package. ```bash # Node.js MCP server setup e2b-mcp server add nodejs_fs \ --command "node filesystem-server.js" \ --install-commands "curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -" \ --install-commands "apt-get install -y nodejs" \ --install-commands "npm install @modelcontextprotocol/server-filesystem" ``` -------------------------------- ### Add Python MCP Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Configure a Python MCP server using a dictionary, specifying the command and pip package installation. ```python runner.add_server_from_dict("python_mcp", { "command": "python server.py", "install_commands": [ "pip install --upgrade pip", "pip install fastapi uvicorn pandas numpy" ] }) ``` -------------------------------- ### Configure MCP Server with ServerConfig Source: https://context7.com/cased/e2b-mcp/llms.txt Define MCP server settings using ServerConfig, including command, environment variables, and installation commands. ServerConfig can be converted to and from dictionaries. ```python from e2b_mcp import ServerConfig # Basic configuration config = ServerConfig( name="my_server", command="python -m my_mcp_server --stdio", description="My custom MCP server", timeout_minutes=10 ) # Configuration with environment variables config = ServerConfig( name="github", command="npx -y @modelcontextprotocol/server-github", description="GitHub MCP server", env={"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx..."} ) # Configuration with installation commands config = ServerConfig( name="complex_server", command="python server.py", install_commands=[ "apt-get update", "apt-get install -y git curl", "pip install requests beautifulsoup4" ], env={"DATA_DIR": "/app/data"}, timeout_minutes=15, initialization_timeout=30 # seconds to wait for server startup ) # Convert to/from dictionary config_dict = config.to_dict() config = ServerConfig.from_dict("my_server", config_dict) ``` -------------------------------- ### Execute a tool and get raw JSON output Source: https://context7.com/cased/e2b-mcp/llms.txt Execute a tool and receive its raw output directly in JSON format. This is useful for parsing tool results programmatically. ```bash e2b-mcp tools execute filesystem read_file \ --param path=/tmp/test.txt --json ``` -------------------------------- ### Basic Tool Execution with E2BMCPRunner Source: https://github.com/cased/e2b-mcp/blob/main/README.md Demonstrates how to add a server and execute tools asynchronously using E2BMCPRunner. Ensure the server command is valid and the tools exist on the server. ```python import asyncio from e2b_mcp import E2BMCPRunner async def main(): runner = E2BMCPRunner() # Add a simple test server runner.add_server_from_dict("test", { "command": "python /tmp/test_mcp_server.py", "description": "Test server with basic tools" }) # Execute tools time_result = await runner.execute_tool("test", "get_time", {"format": "iso"}) echo_result = await runner.execute_tool("test", "echo", {"text": "Hello!"}) print(f"Time: {time_result}") print(f"Echo: {echo_result}") asyncio.run(main()) ``` -------------------------------- ### List tools from a configured server Source: https://context7.com/cased/e2b-mcp/llms.txt Discover and list the available tools provided by a specific configured server. ```bash e2b-mcp tools list github ``` -------------------------------- ### Initialize and Use E2BMCPRunner Source: https://context7.com/cased/e2b-mcp/llms.txt Initialize the E2BMCPRunner, add server configurations, discover tools, and execute them. The runner can use the E2B_API_KEY environment variable or accept the key directly. ```python import asyncio from e2b_mcp import E2BMCPRunner, ServerConfig, MCPError async def main(): # Initialize runner (uses E2B_API_KEY env var by default) runner = E2BMCPRunner() # Or provide API key explicitly runner = E2BMCPRunner(api_key="your_e2b_api_key") # Add a server configuration runner.add_server(ServerConfig( name="filesystem", command="npx -y @modelcontextprotocol/server-filesystem /tmp", description="File system operations", timeout_minutes=10 )) # Discover available tools tools = await runner.discover_tools("filesystem") print(f"Found {len(tools)} tools") for tool in tools: print(f" - {tool.name}: {tool.description}") # Execute a tool result = await runner.execute_tool( "filesystem", "write_file", {"path": "/tmp/hello.txt", "content": "Hello World!"} ) print(f"Result: {result}") asyncio.run(main()) ``` -------------------------------- ### Synchronous Tool Execution with E2BMCPRunner Source: https://github.com/cased/e2b-mcp/blob/main/README.md Shows how to add a server and execute tools synchronously. This method blocks until the tool execution is complete. ```python from e2b_mcp import E2BMCPRunner runner = E2BMCPRunner() runner.add_server_from_dict("test", { "command": "python /tmp/test_mcp_server.py" }) # Synchronous execution result = runner.execute_tool_sync("test", "get_time", {"format": "readable"}) print(result) ``` -------------------------------- ### List all configured servers Source: https://context7.com/cased/e2b-mcp/llms.txt View a list of all servers that have been configured with e2b-mcp. ```bash e2b-mcp server list ``` -------------------------------- ### Quick execution with environment variables Source: https://context7.com/cased/e2b-mcp/llms.txt Perform a quick, one-shot tool execution while also setting environment variables for the server process. The output is returned in JSON format. ```bash e2b-mcp quick "npx -y @modelcontextprotocol/server-github" \ search_repositories \ --params '{"query": "e2b"}' \ --env GITHUB_PERSONAL_ACCESS_TOKEN=your_token \ --json ``` -------------------------------- ### Discover Tools with E2BMCPRunner Source: https://context7.com/cased/e2b-mcp/llms.txt Use discover_tools to find all available tools on an MCP server. This requires creating a temporary sandbox session. ```python import asyncio from e2b_mcp import E2BMCPRunner async def main(): runner = E2BMCPRunner() runner.add_server_from_dict("filesystem", { "command": "npx -y @modelcontextprotocol/server-filesystem /tmp" }) # Discover tools from the server tools = await runner.discover_tools("filesystem") for tool in tools: print(f"Tool: {tool.name}") print(f" Description: {tool.description}") print(f" Required params: {tool.get_required_parameters()}") print(f" Optional params: {tool.get_optional_parameters()}") print(f" Full name: {tool.get_full_name()}") # e.g., "filesystem.write_file" # Get info about specific parameter param_info = tool.get_parameter_info("path") if param_info: print(f" 'path' param type: {param_info.get('type')}") asyncio.run(main()) ``` -------------------------------- ### CLI Documentation: Add Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Command syntax for adding a new MCP server configuration via the CLI. Requires a name, command, and optional parameters. ```bash # Add a new MCP server configuration e2b-mcp server add --command "" [options] ``` -------------------------------- ### List Tools from a Configured Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Retrieve a list of available tools from a specified server. Use the --json flag for raw JSON output. ```bash e2b-mcp tools list [--json] ``` -------------------------------- ### Discover Tools via CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md List available tools for a configured MCP server using the CLI. This helps in understanding the capabilities of the server. ```bash # Discover available tools e2b-mcp tools list github ``` -------------------------------- ### add_server_from_dict and add_servers Methods Source: https://context7.com/cased/e2b-mcp/llms.txt Shows how to add MCP server configurations to the E2BMCPRunner using dictionary formats, including adding single servers and multiple servers at once. ```APIDOC ## add_server_from_dict and add_servers Methods ### Description This section demonstrates adding MCP server configurations to an `E2BMCPRunner` instance using dictionaries. It covers adding a single server via `add_server_from_dict` and multiple servers using the `add_servers` method. It also shows how to list configured servers and retrieve server information. ### Method Python ### Endpoint N/A (Python Library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from e2b_mcp import E2BMCPRunner runner = E2BMCPRunner() # Add server from dictionary runner.add_server_from_dict("github", { "command": "npx -y @modelcontextprotocol/server-github", "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx..."}, "description": "GitHub integration", "timeout_minutes": 10 }) # Add multiple servers at once runner.add_servers({ "filesystem": { "command": "npx -y @modelcontextprotocol/server-filesystem /tmp", "description": "File system operations" }, "git": { "command": "python -m mcp_server_git --stdio", "install_commands": ["pip install mcp-server-git"], "description": "Git repository operations" } }) # List configured servers print(runner.list_servers()) # ['github', 'filesystem', 'git'] # Get server info info = runner.get_server_info("github") print(info) ``` ### Response #### Success Response (200) Output from `list_servers` is a list of server names. Output from `get_server_info` is a dictionary containing server configuration details. #### Response Example ```json { "name": "github", "command": "npx -y @modelcontextprotocol/server-github", "description": "GitHub integration", "timeout_minutes": 10, "requires_installation": false, "display_name": "GitHub integration", "env_vars": ["GITHUB_PERSONAL_ACCESS_TOKEN"], "install_commands": [] } ``` ``` -------------------------------- ### Manual Session Management with E2BMCPRunner Source: https://github.com/cased/e2b-mcp/blob/main/README.md Illustrates advanced session management by manually creating and managing the session lifecycle using an async context manager. The session is automatically cleaned up upon exiting the context. ```python async def advanced_usage(): runner = E2BMCPRunner() runner.add_server_from_dict("filesystem", { "command": "python -m mcp_server_filesystem --stdio", "package": "mcp-server-filesystem" }) # Manage session lifecycle manually async with runner.create_session("filesystem") as session: print(f"Session ID: {session.session_id}") print(f"Sandbox ID: {session.sandbox_id}") # Session automatically cleaned up when exiting context ``` -------------------------------- ### Quick Execute CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute tools directly without saving server configurations. ```APIDOC ## Quick Execute a tool ### Description Executes a tool immediately using a provided command and tool name, without persistent server configuration. ### Method CLI Command ### Endpoint e2b-mcp quick "" [options] ### Parameters #### Path Parameters - **command** (string) - Required - The command to run the MCP server for this execution. - **tool_name** (string) - Required - The name of the tool to execute. #### Query Parameters - **--params** (string) - Optional - Tool parameters provided as a JSON string. - **--param key=value** (string) - Optional - Individual parameters for the tool (can be used multiple times). - **--env KEY=VALUE** (string) - Optional - Environment variables for the server (can be used multiple times). - **--json** (boolean) - Optional - Output the raw JSON response. ``` -------------------------------- ### E2BMCPRunner Class Usage Source: https://context7.com/cased/e2b-mcp/llms.txt Demonstrates the core functionality of the E2BMCPRunner class, including initialization, adding server configurations, discovering tools, and executing tools. ```APIDOC ## E2BMCPRunner Class Usage ### Description This snippet shows how to initialize the `E2BMCPRunner`, add server configurations, discover available tools for a server, and execute a specific tool with its parameters. ### Method Python ### Endpoint N/A (Python Library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import asyncio from e2b_mcp import E2BMCPRunner, ServerConfig, MCPError async def main(): # Initialize runner (uses E2B_API_KEY env var by default) runner = E2BMCPRunner() # Or provide API key explicitly # runner = E2BMCPRunner(api_key="your_e2b_api_key") # Add a server configuration runner.add_server(ServerConfig( name="filesystem", command="npx -y @modelcontextprotocol/server-filesystem /tmp", description="File system operations", timeout_minutes=10 )) # Discover available tools tools = await runner.discover_tools("filesystem") print(f"Found {len(tools)} tools") for tool in tools: print(f" - {tool.name}: {tool.description}") # Execute a tool result = await runner.execute_tool( "filesystem", "write_file", {"path": "/tmp/hello.txt", "content": "Hello World!"} ) print(f"Result: {result}") asyncio.run(main()) ``` ### Response #### Success Response (200) Output from the executed tool, typically a JSON object or string. #### Response Example ```json { "message": "File written successfully" } ``` ``` -------------------------------- ### Show Current Configuration Source: https://github.com/cased/e2b-mcp/blob/main/README.md Display the current E2B MCP configuration settings. The --show flag is optional and typically implied. ```bash e2b-mcp config [--show] ``` -------------------------------- ### List tools as JSON Source: https://context7.com/cased/e2b-mcp/llms.txt Retrieve the list of tools from a server in JSON format. ```bash e2b-mcp tools list github --json ``` -------------------------------- ### Add Server Configurations using Dictionaries Source: https://context7.com/cased/e2b-mcp/llms.txt Add MCP server configurations to the runner using dictionary format, including single servers, multiple servers, and retrieving server information. This is useful for loading configurations from JSON. ```python from e2b_mcp import E2BMCPRunner runner = E2BMCPRunner() # Add server from dictionary runner.add_server_from_dict("github", { "command": "npx -y @modelcontextprotocol/server-github", "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx..."}, "description": "GitHub integration", "timeout_minutes": 10 }) # Add multiple servers at once runner.add_servers({ "filesystem": { "command": "npx -y @modelcontextprotocol/server-filesystem /tmp", "description": "File system operations" }, "git": { "command": "python -m mcp_server_git --stdio", "install_commands": ["pip install mcp-server-git"], "description": "Git repository operations" } }) # List configured servers print(runner.list_servers()) # ['github', 'filesystem', 'git'] # Get server info info = runner.get_server_info("github") print(info) # { # "name": "github", # "command": "npx -y @modelcontextprotocol/server-github", # "description": "GitHub integration", # "timeout_minutes": 10, # "requires_installation": False, # "display_name": "GitHub integration", # "env_vars": ["GITHUB_PERSONAL_ACCESS_TOKEN"], # "install_commands": [] # } ``` -------------------------------- ### Execute a tool with individual parameters Source: https://context7.com/cased/e2b-mcp/llms.txt Execute a tool by providing each parameter individually. This is a convenient way to pass simple key-value arguments. ```bash e2b-mcp tools execute filesystem write_file \ --param path=/tmp/test.txt \ --param content="Hello CLI!" ``` -------------------------------- ### Show current e2b-mcp configuration Source: https://context7.com/cased/e2b-mcp/llms.txt Display the current configuration settings for e2b-mcp. ```bash e2b-mcp config --show ``` -------------------------------- ### Run Release Script Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute the release script with a specified version to manage package releases. ```bash ./scripts/release 0.2.0 ``` -------------------------------- ### List servers as JSON Source: https://context7.com/cased/e2b-mcp/llms.txt Retrieve the list of configured servers in JSON format for programmatic use. ```bash e2b-mcp server list --json ``` -------------------------------- ### Python API - E2BMCPRunner Initialization Source: https://github.com/cased/e2b-mcp/blob/main/README.md Initializes the E2BMCPRunner class, which is the main entry point for managing MCP servers programmatically. ```APIDOC ## Initialize E2BMCPRunner ### Description Initializes the main runner class for interacting with E2B MCP servers. ### Method Python Class Initialization ### Endpoint `E2BMCPRunner(api_key: Optional[str] = None)` ### Parameters #### Path Parameters - **api_key** (string) - Optional - Your E2B API key. If not provided, it may attempt to use environment variables or default configurations. ``` -------------------------------- ### Execute a Tool on a Server Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute a specific tool on a configured server. Parameters can be provided as a JSON string or individual key-value pairs. Use --json for raw output. ```bash e2b-mcp tools execute [options] ``` -------------------------------- ### Server Management CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Commands for adding, removing, and managing server configurations via the CLI. ```APIDOC ## Remove a server configuration ### Description Removes a configured server by its name. ### Method CLI Command ### Endpoint e2b-mcp server remove [--yes] ### Parameters #### Path Parameters - **name** (string) - Required - The name of the server to remove. #### Query Parameters - **--yes** (boolean) - Optional - Confirm removal without prompting. ### Request Example ```bash e2b-mcp server remove my_server --yes ``` ``` ```APIDOC ## Add a server configuration ### Description Adds a new server configuration to the MCP tool. ### Method CLI Command ### Endpoint e2b-mcp server add [options] ### Parameters #### Path Parameters - **name** (string) - Required - The name for the new server configuration. #### Query Parameters - **--command** (string) - Required - The command to run the MCP server. - **--env KEY=VALUE** (string) - Optional - Environment variables for the server (can be used multiple times). - **--install-commands** (string) - Optional - Installation commands to run before starting the server (can be used multiple times). - **--description** (string) - Optional - A description for the server. - **--timeout** (integer) - Optional - Timeout in minutes for the server (default: 10). ### Request Example ```bash e2b-mcp server add github \ --command "npx -y @modelcontextprotocol/server-github" \ --env GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_TOKEN ``` ``` -------------------------------- ### CLI Documentation: List Servers Source: https://github.com/cased/e2b-mcp/blob/main/README.md Command to list all configured MCP servers. An optional --json flag can be used to output the list in JSON format. ```bash # List all configured servers e2b-mcp server list [--json] ``` -------------------------------- ### Discover Tools API Source: https://context7.com/cased/e2b-mcp/llms.txt Discover all available tools from an MCP server by creating a temporary sandbox session. ```APIDOC ## discover_tools Method ### Description Discover all available tools from an MCP server by creating a temporary sandbox session. ### Method POST (Implicit, as it's an API call within the runner) ### Endpoint N/A (This is a client-side method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import asyncio from e2b_mcp import E2BMCPRunner async def main(): runner = E2BMCPRunner() runner.add_server_from_dict("filesystem", { "command": "npx -y @modelcontextprotocol/server-filesystem /tmp" }) # Discover tools from the server tools = await runner.discover_tools("filesystem") for tool in tools: print(f"Tool: {tool.name}") print(f" Description: {tool.description}") print(f" Required params: {tool.get_required_parameters()}") print(f" Optional params: {tool.get_optional_parameters()}") print(f" Full name: {tool.get_full_name()}") # e.g., "filesystem.write_file" # Get info about specific parameter param_info = tool.get_parameter_info("path") if param_info: print(f" 'path' param type: {param_info.get('type')}") asyncio.run(main()) ``` ### Response #### Success Response (200) - **tools** (list) - A list of discovered tool objects, each with properties like `name`, `description`, `get_required_parameters()`, `get_optional_parameters()`, `get_full_name()`, and `get_parameter_info(param_name)`. #### Response Example ```json [ { "name": "write_file", "description": "Writes content to a file at the specified path.", "required_parameters": ["path", "content"], "optional_parameters": [], "full_name": "filesystem.write_file" } ] ``` ``` -------------------------------- ### Run Integration Tests Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute integration tests that create real E2B sandboxes. Requires setting the E2B_API_KEY environment variable. ```bash export E2B_API_KEY="your_api_key" pytest tests/test_integration.py -v ``` ```bash pytest -v ``` -------------------------------- ### Running the Format Script Source: https://github.com/cased/e2b-mcp/blob/main/README.md Executes the `./scripts/format` script, which automatically formats and lints the codebase using tools like black, ruff, and mypy. ```bash ./scripts/format ``` -------------------------------- ### Execute Tool API (Async) Source: https://context7.com/cased/e2b-mcp/llms.txt Execute a tool on an MCP server with automatic parameter validation, sandbox creation, and cleanup. ```APIDOC ## execute_tool Method ### Description Execute a tool on an MCP server with automatic parameter validation, sandbox creation, and cleanup. ### Method POST (Implicit, as it's an API call within the runner) ### Endpoint N/A (This is a client-side method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **server_name** (string) - Required - The name of the MCP server to execute the tool on. - **tool_name** (string) - Required - The name of the tool to execute. - **parameters** (object) - Required - A dictionary of parameters for the tool. ### Request Example ```python import asyncio from e2b_mcp import E2BMCPRunner, MCPError async def main(): runner = E2BMCPRunner() runner.add_server_from_dict("filesystem", { "command": "npx -y @modelcontextprotocol/server-filesystem /tmp" }) try: # Write a file result = await runner.execute_tool( "filesystem", "write_file", {"path": "/tmp/example.txt", "content": "Hello from e2b-mcp!"} ) print(f"Write result: {result}") # Read the file back result = await runner.execute_tool( "filesystem", "read_file", {"path": "/tmp/example.txt"} ) print(f"Read result: {result}") # List directory contents result = await runner.execute_tool( "filesystem", "list_directory", {"path": "/tmp"} ) print(f"Directory contents: {result}") except MCPError as e: print(f"MCP Error: {e}") print(f" Server: {e.server_name}") print(f" Tool: {e.tool_name}") asyncio.run(main()) ``` ### Response #### Success Response (200) - **result** (any) - The result returned by the executed tool. #### Response Example ```json { "result": "File written successfully." } ``` ``` -------------------------------- ### Quick One-Shot Execution via CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Perform a quick, one-off execution of a command within a sandbox without saving the server configuration. Useful for immediate tasks. ```bash # Quick one-shot execution (no config save) e2b-mcp quick "npx -y @modelcontextprotocol/server-filesystem /tmp" \ list_directory --param path=/tmp ``` -------------------------------- ### Quick Execute a Command and Tool Source: https://github.com/cased/e2b-mcp/blob/main/README.md Execute a command and tool without saving the server configuration. Useful for one-off operations. Supports JSON string or individual parameters and environment variables. ```bash e2b-mcp quick "" [options] ``` -------------------------------- ### Add GitHub MCP Server via CLI Source: https://github.com/cased/e2b-mcp/blob/main/README.md Add a GitHub MCP server configuration using the CLI. This command specifies the server executable and environment variables. ```bash # Add a GitHub MCP server e2b-mcp server add github \ --command "npx -y @modelcontextprotocol/server-github" \ --env GITHUB_PERSONAL_ACCESS_TOKEN=your_token ``` -------------------------------- ### Tool Class Parameter Information and Validation Source: https://context7.com/cased/e2b-mcp/llms.txt Shows how to retrieve information about a tool's parameters, including required and optional ones, and how to validate input parameters against the tool's schema. ```python from e2b_mcp import Tool # Create tool from MCP response data tool_data = { "name": "write_file", "description": "Write content to a file", "inputSchema": { "type": "object", "properties": { "path": {"type": "string", "description": "File path"}, "content": {"type": "string", "description": "File content"} }, "required": ["path", "content"] } } tool = Tool.from_mcp_tool(tool_data, server_name="filesystem") # Get parameter information print(f"Required: {tool.get_required_parameters()}") # ['path', 'content'] print(f"Optional: {tool.get_optional_parameters()}") # [] path_info = tool.get_parameter_info("path") print(f"Path type: {path_info['type']}") # 'string' # Validate parameters errors = tool.validate_parameters({"path": "/tmp/test.txt"}) print(f"Errors: {errors}") # ['Missing required parameter: content'] errors = tool.validate_parameters({"path": "/tmp/test.txt", "content": "Hello"}) print(f"Errors: {errors}") # [] ``` -------------------------------- ### Add a new MCP server configuration Source: https://context7.com/cased/e2b-mcp/llms.txt Use this command to add a new server configuration to e2b-mcp. Specify the command to run the server, environment variables, a description, and a timeout. ```bash e2b-mcp server add github \ --command "npx -y @modelcontextprotocol/server-github" \ --env GITHUB_PERSONAL_ACCESS_TOKEN=your_token \ --description "GitHub integration" \ --timeout 10 ```