Agent Sandbox Registry

agent-sandbox

Decision: MCP FC Streamable HTTP Transport

无中文版

.agents/notes/implemented/feature/2026-09-23-mcp-fc-streamable-http.md

Decision: MCP FC Streamable HTTP Transport

Status: implemented

Problem

The Agent Sandbox MCP Server currently only supports STDIO transport for local IDE integration (Cursor, Claude Desktop, VS Code). This limits MCP to local use — remote teams, CI/CD pipelines, and cloud-native agent frameworks cannot access sandbox tools via MCP without running a local process. We need a remote-accessible MCP Server deployment option.

Decision

Implement MCP Streamable HTTP transport (2025-06-18 specification) as a Starlette ASGI application. The new abx mcp deploy command generates an artifact and manual instructions for Alibaba Cloud Function Compute (FC); it does not call an FC deployment API.

Architecture

Session Affinity

Session affinity requires an FC runtime that supports Mcp-Session-Id header routing. The ASGI app sets Mcp-Session-Id on the initialize response; operators must configure the platform to route subsequent requests with that header to the same instance. Clients should call DELETE /mcp when finished so the server can clean up sandboxes promptly.

Protocol Version

The HTTP transport uses MCP_PROTOCOL_VERSION = "2025-06-18" (Streamable HTTP). The existing STDIO transport retains "2024-11-05". Both coexist without conflict.

2026-09-29 correction (per-transport version negotiation): the shared SandboxMCPServer._handle_initialize() originally hard-coded the STDIO constant, so HTTP initialize responded 2024-11-05 while GET /health declared 2025-06-18 (found in real E2E; see .agents/evidence/2026-09-29-mcp-e2e.md). Fix: SandboxMCPServer now accepts a supported_protocol_versions sequence (default (2024-11-05,), preserving STDIO); the HTTP SessionStore passes (2025-06-18,). initialize echoes a supported requested protocolVersion and falls back to the preferred (first) supported version for missing/unsupported requests — the MCP spec rule that the server responds with another version it supports (the client may disconnect). STDIO behavior is unchanged; HTTP health and initialize now report the same version.

API Design

ASGI App Factory

def create_mcp_app(
    auth_token: str | None = None,
    api_key: str | None = None,
    api_url: str | None = None,
    domain: str | None = None,
    template: str = "base",
) -> Starlette:
    """Create the MCP Streamable HTTP Starlette application."""

CLI Command

abx mcp deploy \
  --name agent-sandbox-mcp \
  --region cn-hangzhou \
  --template python-base \
  --memory 512 --timeout 600 \
  --generate-token \
  --api-key $E2B_API_KEY \
  --output-dir ./deploy-artifact \
  [--custom-domain mcp.example.com]

Module-Level ASGI Entry Point

# For: uvicorn agent_sandbox.agent.mcp_http:asgi_app
asgi_app: Any = _LazyApp()

Alternatives considered

Dependencies

Test Strategy

Acceptance criteria

Completed

  1. POST /mcp with initialize creates a bounded, expiring session and returns Mcp-Session-Id
  2. Subsequent POST /mcp with the session header routes to the correct MCP server
  3. DELETE /mcp terminates the session and cleans up sandboxes
  4. Bearer token auth uses constant-time comparison; missing or configured-empty credentials fail closed with 401
  5. All 7 existing tools are delegated through SandboxMCPServer.handle_request() over HTTP
  6. abx mcp deploy --output-dir generates requirements.txt, app.py, and config.yaml, plus manual FC deployment steps
  7. Existing STDIO mode (abx mcp start) retains its transport behavior; malformed non-object JSON is now rejected with a JSON-RPC error instead of crashing
  8. GET /mcp explicitly returns 501 until Phase 2 SSE notifications are implemented
  9. (2026-09-29) HTTP initialize negotiates 2025-06-18, consistent with GET /health; STDIO retains 2024-11-05; supported requested versions are echoed, missing/unsupported ones fall back to the transport's preferred version

Follow-up

  1. Integrate an official, verified Alibaba Cloud FC function and HTTP Trigger SDK workflow for automatic deployment
  2. Implement SSE server notifications for GET /mcp
  3. Validate session-affinity configuration against the selected FC runtime before enabling it