E2B logo

E2B

Execute code securely in cloud sandboxes with support for multiple programming languages, package management, and environment configuration.

How to Use Model Context Protocol (MCP) in Cursor

What is MCP?

Model Context Protocol (MCP) is an open protocol that allows you to provide custom tools to agentic LLMs (Large Language Models) in Cursor's Composer feature.

Installation Steps

  1. Open Cursor Settings
    • Navigate to Cursor Settings > Features > MCP
    • Click the "+ Add New MCP Server" button
  2. Configure the Server
    • Name: Give your server a nickname
    • Type: Select the transport type (stdio or sse)
    • Command/URL: Enter either:
      • For SSE servers: The URL of the SSE endpoint
      • For stdio servers: A valid shell command to run the server

Example Configurations

For stdio Server (E2B Example):

Command: node ~/mcp-quickstart/e2b-server/build/index.js --api-key $E2B_API_KEY --sandbox-id $E2B_SANDBOX_ID

For SSE Server:

URL: https://api.e2b.dev/v1/sse

Using MCP Tools

Tool Availability

  • • After adding a server, it will appear in your MCP servers list
  • • You may need to click the refresh button to populate the tool list

Using Tools in Composer

  • • The Composer Agent automatically uses MCP tools when relevant
  • • You can explicitly prompt tool usage by:
    • Referring to the tool by name
    • Describing the tool's function

Tool Execution Process

  • • Displays a message in chat requesting approval
  • • Shows tool call arguments (expandable)
  • • Executes the tool upon user approval
  • • Displays the tool's response in the chat

Important Notes

  • • MCP tools may not work with all models
  • • MCP tools are only available to the Agent in Composer
  • • For E2B integration, you need to set up E2B_API_KEY and E2B_SANDBOX_ID environment variables
  • • Create an account on E2B and get your API key from the dashboard
  • • Create a sandbox and note its ID from the E2B console
  • • For security, use a wrapper script that sets the environment variables before running the server
  • • Configure resource limits for CPU, memory, and storage
  • • Set appropriate timeouts for code execution
  • • Implement proper error handling for execution failures
  • • Monitor sandbox resource usage and performance
  • • Use environment-specific sandboxes for different stages
  • • Consider implementing retry logic for transient failures
  • • Follow security best practices for code execution
  • • Be mindful of concurrent execution limits