Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(computer-server): expose HTTP and MCP interfaces simultaneously (#861)

Francesco Bonaccid7f327717fb8
diff --git a/libs/python/computer-server/README.md b/libs/python/computer-server/README.md
index b51973aac6..1ff09c8426 100644
--- a/libs/python/computer-server/README.md
+++ b/libs/python/computer-server/README.md
@@ -6,15 +6,10 @@ Server component for the Computer-Use Interface (CUI) framework providing low-le
## Interfaces
-The Computer Server supports multiple interfaces with **automatic mode detection**:
+The Computer Server exposes multiple interfaces simultaneously:
-- **HTTP/WebSocket** - REST API and WebSocket for programmatic access (interactive terminal)
-- **MCP via HTTP** - Model Context Protocol over streamable HTTP at `/mcp` endpoint (interactive terminal)
-- **MCP via stdio** - Model Context Protocol for Claude Code, OpenCode, Cursor, and other MCP-compatible tools (auto-detected when run as subprocess)
-
-The server automatically detects how it's being run:
-- **Interactive terminal** (stdin is TTY) → HTTP server with MCP at `/mcp`
-- **Subprocess** (stdin is pipe, e.g., spawned by Claude Code) → MCP stdio mode
+- **HTTP/WebSocket** - REST API and WebSocket for programmatic access
+- **MCP via HTTP** - Model Context Protocol over streamable HTTP at `/mcp` endpoint
## Installation
@@ -22,22 +17,21 @@ The server automatically detects how it's being run:
# Basic installation (HTTP/WebSocket only)
pip install cua-computer-server
-# With MCP support (enables both HTTP and stdio modes)
+# With MCP support
pip install cua-computer-server[mcp]
```
## Usage
-### Interactive Mode (run from terminal)
-
-When you run the server from a terminal, it starts HTTP + MCP:
-
```bash
# Start the server on default port 8000
python -m computer_server
# Or with custom port
python -m computer_server --port 8080
+
+# With resolution scaling (useful for Retina displays or VMs)
+python -m computer_server --width 1512 --height 982
```
This provides:
@@ -46,16 +40,6 @@ This provides:
MCP clients can connect via streamable HTTP at `http://localhost:8000/mcp`.
-### Subprocess Mode (Claude Code integration)
-
-When spawned as a subprocess (e.g., by Claude Code), the server automatically uses MCP stdio mode:
-
-```bash
-# Resolution options work in both modes
-python -m computer_server --detect-resolution
-python -m computer_server --width 1512 --height 982
-```
-
#### Resolution Scaling
When running on Retina displays or in VMs where the coordinate system may differ, use the `--width` and `--height` flags to specify the target resolution:
@@ -68,24 +52,14 @@ This ensures the AI model sees consistent coordinates between screenshots and mo
#### Claude Code Integration
-Add to your Claude Code configuration:
-
+1. Start the server (or run as a service/LaunchAgent):
```bash
-# Add the MCP server (auto-detects stdio mode when spawned as subprocess)
-claude mcp add cua-computer-server -- python -m computer_server
+python -m computer_server --port 8000
```
-Or manually add to `~/.claude/claude_desktop_config.json`:
-
-```json
-{
- "mcpServers": {
- "cua-computer-server": {
- "command": "python",
- "args": ["-m", "computer_server"]
- }
- }
-}
+2. Add the MCP server URL to Claude Code:
+```bash
+claude mcp add cua-computer-server --transport http http://localhost:8000/mcp
```
## Available MCP Tools
diff --git a/libs/python/computer-server/computer_server/cli.py b/libs/python/computer-server/computer_server/cli.py
index 03e99b99f1..aa68351321 100644
--- a/libs/python/computer-server/computer_server/cli.py
+++ b/libs/python/computer-server/computer_server/cli.py
@@ -86,34 +86,6 @@ def main() -> None:
stream=sys.stderr, # Use stderr for MCP compatibility
)
- # Auto-detect mode based on stdin:
- # - If stdin is NOT a TTY (it's a pipe), we're being run as a subprocess (e.g., by Claude Code)
- # → use MCP stdio mode for direct communication
- # - If stdin IS a TTY (interactive terminal), user is running from command line
- # → use HTTP server with MCP available at /mcp endpoint
- use_mcp_stdio = not sys.stdin.isatty()
-
- if use_mcp_stdio:
- logger.info("Detected subprocess mode (stdin is pipe) - starting MCP stdio server...")
- try:
- from .mcp_server import run_mcp_server
- run_mcp_server(
- target_width=args.width,
- target_height=args.height,
- detect_resolution=args.detect_resolution,
- )
- except ImportError as e:
- logger.error(f"MCP stdio mode requires fastmcp package: {e}")
- logger.error("Install with: pip install 'cua-computer-server[mcp]'")
- sys.exit(1)
- except KeyboardInterrupt:
- logger.info("MCP server stopped by user")
- sys.exit(0)
- except Exception as e:
- logger.error(f"Error running MCP server: {e}")
- sys.exit(1)
- return
-
# Check if watchdog should be enabled
container_name = os.environ.get("CONTAINER_NAME")
enable_watchdog = (args.watchdog or bool(container_name)) and not sys.platform.startswith("win")
diff --git a/libs/python/computer-server/pyproject.toml b/libs/python/computer-server/pyproject.toml
index 9295455b95..e270975ed7 100644
--- a/libs/python/computer-server/pyproject.toml
+++ b/libs/python/computer-server/pyproject.toml
@@ -78,5 +78,5 @@ dev = [
]
[tool.pdm.scripts]
-# Mode is auto-detected: TTY → HTTP server, pipe → MCP stdio
+# Starts HTTP server with MCP at /mcp endpoint
api = "python -m computer_server"
\ No newline at end of file