Skip to content

[Feature] Add MCP Protocol API as Alternative Interface to E2B#165

Open
bcfre wants to merge 1 commit intoopenkruise:masterfrom
bcfre:mcp-dev
Open

[Feature] Add MCP Protocol API as Alternative Interface to E2B#165
bcfre wants to merge 1 commit intoopenkruise:masterfrom
bcfre:mcp-dev

Conversation

@bcfre
Copy link
Copy Markdown
Contributor

@bcfre bcfre commented Feb 27, 2026

Ⅰ. Describe what this PR does

┌─────────────┐    ┌─────────────┐
│   E2B API   │    │   MCP API   │   <-- External Protocol Interfaces
└──────┬──────┘    └──────┬──────┘
       │                  │
       └────────┬─────────┘
                ▼
        ┌───────────────┐
        │ SandboxManager│              <-- Unified Management Layer
        └───────┬───────┘
                ▼
        ┌───────────────┐
        │  Sandbox CRs  │              <-- Kubernetes Resources
        └───────────────┘

Both E2B and MCP APIs share the same underlying sandbox infrastructure - they are simply different protocol adapters over the unified sandbox management layer.

Changes
1. MCP Server Integration (cmd/sandbox-manager/main.go)

  • Add MCP server alongside existing E2B server
  • Configure via environment variables: MCP_SERVER_ENABLED, MCP_SERVER_PORT, MCP_SANDBOX_TTL, MCP_SESSION_SYNC_PORT

2. Sandbox Event Callback (pkg/sandbox-manager/infra/)

  • Add SandboxEventHandler interface to propagate sandbox lifecycle events to MCP session layer
  • Enable MCP sessions to track their associated sandbox state

3. Session-Sandbox Binding (api/v1alpha1/sandboxset_types.go)

  • Add AnnotationMCPSessionID to link MCP sessions with underlying sandboxes

4. Expose Shared Components (pkg/servers/e2b/core.go, pkg/sandbox-manager/core.go)

  • Expose SandboxManager and KeyStorage for MCP server reuse
  • Add ListPeers() for MCP cluster discovery

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 79.27171% with 148 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.99%. Comparing base (edaad73) to head (136236a).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
pkg/servers/mcp/sandbox.go 63.52% 29 Missing and 2 partials ⚠️
pkg/servers/mcp/handler.go 87.94% 22 Missing and 5 partials ⚠️
pkg/servers/mcp/server.go 69.31% 24 Missing and 3 partials ⚠️
pkg/sandbox-manager/infra/sandboxcr/infra.go 4.76% 18 Missing and 2 partials ⚠️
pkg/servers/mcp/session.go 77.27% 18 Missing and 2 partials ⚠️
pkg/sandbox-manager/core.go 0.00% 9 Missing ⚠️
pkg/servers/e2b/core.go 0.00% 4 Missing ⚠️
pkg/servers/mcp/peer.go 93.84% 2 Missing and 2 partials ⚠️
pkg/servers/mcp/middleware.go 93.75% 1 Missing and 2 partials ⚠️
pkg/utils/sandbox-manager/proxyutils/default.go 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
+ Coverage   74.65%   74.99%   +0.34%     
==========================================
  Files         141      150       +9     
  Lines        9836    10546     +710     
==========================================
+ Hits         7343     7909     +566     
- Misses       2183     2310     +127     
- Partials      310      327      +17     
Flag Coverage Δ
unittests 74.99% <79.27%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pkg/servers/mcp/deps.go Outdated
Comment thread pkg/servers/mcp/handler.go
Comment thread pkg/servers/mcp/handler.go Outdated
Comment thread pkg/servers/mcp/handler.go Outdated
Comment thread pkg/servers/mcp/handler.go Outdated
Comment thread pkg/servers/mcp/sandbox.go Outdated
Comment thread pkg/servers/mcp/sandbox.go Outdated
Comment thread pkg/servers/mcp/sandbox.go
Comment thread pkg/servers/mcp/server.go Outdated
@AiRanthem
Copy link
Copy Markdown
Member

The coverage of 59.87805% seems to be not high enough

Comment thread docs/best-practices/use-mcp.md Outdated
Comment thread docs/best-practices/use-mcp.md Outdated
@kruise-bot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kruise-bot
Copy link
Copy Markdown

@bcfre: PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants