# SceneAgent — Agent Integration & MCP Manual

SceneAgent (`https://app.sceneagent.dev`) is the web workbench and MCP control plane for **computational robotics**, **3DGS-to-simulatable-USD conversion (`./real2sim`)**, **digital sisters simulation sweeps**, **bimanual SO-101 policy autoresearch**, **local-first & cloud GPU compute offload**, and **live robots** (each user's own robot setups, cameras and sensors).

## 1. Connect the MCP Server

- **Streamable HTTP Endpoint**: `https://app.sceneagent.dev/mcp` (also served at `https://app.sceneagent.dev/api/mcp`)
- **Authentication Header**: `Authorization: Bearer sa_<your_api_token>`
- **Account & Personal MCP Key**: `https://app.sceneagent.dev/account#agents`
- **Pre-authenticated Browser Handoff Link**: `https://app.sceneagent.dev/login`

### Google Antigravity (`~/.gemini/antigravity/mcp_config.json`)
```json
{
  "mcpServers": {
    "sceneagent": {
      "serverUrl": "https://app.sceneagent.dev/mcp",
      "headers": {
        "Authorization": "Bearer <TOKEN>"
      }
    }
  }
}
```

### Claude Code (`CLI / ~/.claude.json`)
```bash
claude mcp add --transport http sceneagent https://app.sceneagent.dev/mcp --header "Authorization: Bearer <TOKEN>"
```

### OpenAI Codex (`~/.codex/config.toml`)
```toml
[mcp_servers.sceneagent]
url = "https://app.sceneagent.dev/mcp"
http_headers = { Authorization = "Bearer <TOKEN>" }
```

### Cursor (`.cursor/mcp.json`)
```json
{
  "mcpServers": {
    "sceneagent": {
      "url": "https://app.sceneagent.dev/mcp",
      "headers": {
        "Authorization": "Bearer <TOKEN>"
      }
    }
  }
}
```

### Hermes (`~/.hermes/config.yaml`)
```yaml
mcp_servers:
  sceneagent:
    url: "https://app.sceneagent.dev/mcp"
    headers:
      Authorization: "Bearer <TOKEN>"
```

### Verify Connection
```bash
curl -s https://app.sceneagent.dev/mcp \
  -H "Authorization: Bearer <TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_account_context","arguments":{}}}'
```

## 2. Available MCP Tools

### Account & Browser Handoff
1. `get_account_context` — Inspect the authenticated user account, active organization/team, MCP token usage, and pre-authenticated browser links.
2. `get_browser_login_link` — Mint a signed browser login handoff URL (`?handoff=t1...`) for any Scope path (`/`, `/scenes`, `/experiments`, `/live`, `/account`) so your agent browser harness opens directly authenticated.

### 3D Captures & Simulatable USD Scenes (`./real2sim`)
3. `list_scenes` / `inspect_scene` — Browse and inspect converted scenes in `./data_processed` scoped to your user account and organization.
4. `upload_and_process_capture` — Submit a 3DGS (`.ply` / `.spz`), RGB-D scan, or video-to-4D clip to `./real2sim` and register the scene under your account and organization.
5. `estimate_processing` / `submit_processing` / `get_processing_job` / `cancel_processing` — Quote, reserve, submit, inspect, and cancel scene conversion jobs.

### Digital Sisters & Policy Autoresearch Experiments
6. `generate_digital_sisters` — Configure or launch a lighting × size × material digital sisters matrix for a scene or garment twin.
7. `list_experiments` / `get_experiment` / `run_experiment_workflow` — Inspect and launch real2sim2real and bimanual SO-101 policy evaluation campaigns.

### GPU Compute Offload (Local-first GB10 + External Cloud GPU Burst)
8. `list_gpu_offers` — Inspect available GPU compute capacity and external cloud GPU offers.
9. `run_gpu_job` / `get_gpu_job` / `cancel_gpu_job` / `list_gpu_jobs` / `send_job_feedback` — Dispatch, monitor, and manage GPU-accelerated reconstruction, digital sisters, and policy evaluation jobs. Jobs run local-first on available workstation GPUs and automatically burst/fall back to external cloud GPUs when local slots are busy. Submitting a pipeline job returns `estimate`: expected rented hours with boot time and a cost range, from past jobs of the same workload. While a pipeline job runs, `get_gpu_job` also returns its `progress` (latest checkpoint, newest evidence, last agent event), the newest 10 review images and clips with `evidenceTotal` (page with `evidenceOffset` and `evidenceLimit`), gate results and independent critic verdicts. Each file has a `url` relative to the site; open the one `reviewBrowserUrl` to sign a browser in first. The log tail is the last 15 lines (`logLines` for more). `list_gpu_jobs` returns one short row per job, 10 per page (`limit`, `cursor`). `send_job_feedback` sends a running job's agent a correction (wrong part grouping, a missing articulation, a ghosted background) that it must act on and acknowledge.
9a. `resume_gpu_job` — Continue a stopped pipeline job from its newest checkpoint on a new GPU instead of starting over; the earlier review evidence carries over. A job paused because the pipeline agent reached its usage limit (`get_gpu_job` shows `pause` and `resumable`) resumes on its own after the reset, and the box time lost to it is not charged. `list_agent_harnesses` reports `usageLimited` and `resetsAt` for each agent.

### Live Robots & Telemetry (`/live`)
10. `list_live_robots` / `register_robot` / `configure_robot` / `connect_robot_streams` / `get_robot` — Connect the user's own robots, cameras, and joint/force sensors to Live robots (`/live`) and confirm they stream.

### Workspace Skills & Billing
11. `list_skills` — Discover workspace skills under `./.agents/skills`.
12. `get_usage` / `get_balance` / `export_usage` / `purchase_token_pack` — Inspect token and compute balances, export canonical usage CSVs, or create Stripe Checkout sessions for token packs.

## 3. Core Workflows

### Workflow A: 3D Capture to Simulatable USD (`./real2sim`)
1. Call `get_account_context` to confirm the active user and organization slug (e.g. `harvard-computational-robotics-group`).
2. Call `upload_and_process_capture` (or `run_gpu_job` with `workload: "real2sim"`) with your capture name and source path/archive.
3. Poll `get_gpu_job` / `get_processing_job` or `inspect_scene` to verify object poses, collision meshes, and USD articulation.
4. Open the returned `browserUrl` in your browser harness to inspect the 3D scene interactively.

### Workflow B: Connecting a Live Robot (`/live`)
Run these steps on the computer attached to the robot:
1. Inspect the hardware: list cameras (e.g. `v4l2-ctl --list-devices`, OpenCV indices, RTSP URLs) and sensors (arm joint states, gripper, force/torque, IMU). Ask the user what anything ambiguous is.
2. Call `register_robot` with a name, the embodiment and one feed per camera or sensor: `{ "label": "Left wrist", "kind": "camera", "role": "left_wrist" }`, `{ "label": "Left follower joints", "kind": "joint_state", "fields": ["shoulder_pan", ...] }`. Feeds default to `source: { "type": "push" }`. A USB camera plugged into the Scope host itself can use `{ "type": "host_camera", "cameraId": ... }` from `list_live_robots`; a stream the user's browser can reach can use `{ "type": "url", "url": ... }`.
3. The response carries a one-time ingest key and the bridge command. Write `robot-bridge.json` mapping each camera feed to its device and start `scripts/scope-robot-bridge.py`; pipe sensor readings into its stdin as JSON lines `{"feed": "<id>", "values": {...}}`. Without the script, POST JPEG frames to `/api/robots/<id>/feeds/<feedId>/frames` and JSON samples to `/api/robots/<id>/telemetry` with `Authorization: Bearer <key>`.
4. Call `get_robot` until the robot is `online` and every feed is `live`, then open the returned `browserUrl`.
5. To change feeds later use `configure_robot`; to move the bridge or replace a lost key use `connect_robot_streams` (the old key stops working).

### Workflow C: Opening Authenticated Links in Your Agent Browser Harness
Every MCP tool response includes a `browserUrl` field containing a signed handoff ticket (`/api/auth/handoff?ticket=t1...&next=...`). Open this URL directly in your browser tool to view experiments, 3D scenes, and live robots without a login prompt.
