# scorpiox-scorpioplayer-agent-control-server (`spctl_`)

Embedded pure-C99 HTTP/1.1 REST API + optional MCP (Streamable HTTP JSON-RPC 2.0) control & visual-debugging server DLL for **SCORPIO PLAYER 2027**.

## Highlights
- **100% in-process pure C99** — zero `fork`, zero `exec`, zero `popen`, zero external dependencies beyond vendored `yyjson`. Runs identically inside iOS/tvOS/macOS App Sandbox, Xbox UWP AppContainer, Windows WinUI3, Android Kotlin/Compose, and Linux GTK4.
- **26 exported `spctl_*` symbols** — strict `-fvisibility=hidden` + `spctl.map` + `exports.json`.
- **Single `spctl_backend` vtable (ABI 1)** — 23 optional callbacks covering playback, tracks, chapters, subtitles, library/sources, server-driven templates (`SetttingsGroup`), dynamic menu handlers, decoded video frame PNG capture, UI window PNG capture, logs, and custom actions.
- **REST API (`/api/v1/*`) + Optional MCP Server (`POST /mcp`)** — speaks the exact MCP Streamable HTTP JSON-RPC 2.0 dialect (`protocolVersion: "2024-11-05"`) of `scorpiox-server`, returning genuine MCP `image/png` base64 content for `player_capture_frame` and `player_capture_ui`.
- **Security by default** — defaults to `127.0.0.1`; non-loopback binds require authentication automatically; 6-digit pairing with 5-failures/60s rate limiting, constant-time Bearer verification, and optional read-only mode.
- **Built-in fake player backend** (`spctl_install_fake_backend`) — deterministic offline testing and CLI demo mode (`spctl --serve --port 19363 --mcp --fake`).

## Build & Test
```bash
make && make test       # shared lib + CLI + selftest + unit/loopback REST & MCP + exports-check
make asan               # Clang ASAN + UBSAN + LeakSanitizer
make fuzz               # libFuzzer on HTTP parser/router + MCP JSON-RPC (>=60,000 runs each)
make win                # MinGW-w64 x64 .dll + spctl.exe
```

## Quick CLI Demo
```bash
./build/spctl --serve --port 19363 --mcp --fake
curl -s http://127.0.0.1:19363/api/v1/health
curl -s http://127.0.0.1:19363/api/v1/state
curl -s http://127.0.0.1:19363/api/v1/debug/frame.png -o frame.png
curl -s -X POST http://127.0.0.1:19363/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

See [SPEC.md](SPEC.md) for the complete architecture, ABI contract, REST routes, MCP tools, and security decisions.
