Developer docs / AI Fabric tutorials
Stateless MCP server with FastMCP
- Sandbox
- Web endpoint
- Image DSL
Take it for a spin
The whole program in one file, ready to run.
import bladekit
app = bladekit.app("sandbox-mcp")
server_image = (
bladekit.Image.debian_slim(python_version="3.12")
.pip_install("fastmcp", "httpx")
)
sandbox_image = (
bladekit.Image.debian_slim(python_version="3.12")
.pip_install("numpy", "scipy", "pandas")
)
@app.web_endpoint(methods=["POST"], min_replicas=1)
@app.function(image=server_image, timeout=120)
def mcp_handler(item: dict) -> dict:
"""Handle MCP tool-call requests. Each code execution runs in a fresh sandbox."""
tool = item.get("tool")
args = item.get("arguments", {})
if tool == "run_python":
code = args.get("code", "")
with bladekit.Sandbox.create(image=sandbox_image, timeout=30) as sb:
sb.write_file("/work/code.py", code.encode())
proc = sb.exec("python", "/work/code.py")
proc.wait()
return {
"content": [{"type": "text", "text": proc.stdout.read().decode()}],
"isError": proc.returncode != 0,
}
return {"content": [{"type": "text", "text": f"Unknown tool: {tool}"}], "isError": True}Run it
- Deploy:
blade deploy sandbox_mcp.py. - Register the endpoint URL with your MCP client (e.g. Claude Desktop).
- Each
run_pythontool call executes code in a fresh, isolated sandbox, so no state leaks between calls. min_replicas=1keeps the MCP server warm so tool calls respond quickly.
Concepts used: Endpoint, Replica, Cold start