# SDK Studio: agents (MCP) and Consoles and Apps

Two parts of [SDK Studio](studio.md) that talk to something outside the Studio: agents over MCP, and your
apps on the 360sona server.

## Agents: the Studio hosts sona-mcp

The Studio runs the SDK's MCP server ([sona-mcp](mcp.md)) inside itself, with the Studio's own sources, catalogue,
licence and Projects folder. Claude Code, or any agent that speaks MCP, can then search items, build and dress avatars,
render pictures (they come back as images), make a project from a template, build and run it, and read its log and
frame stats.

- **HTTP:** on while the Studio runs, at `http://127.0.0.1:47360/mcp` (Tools > Agents (MCP) shows the address; if the
  port is taken it picks a free one). Requests need the bearer token kept in the profile's `mcp-token` file; the
  dialog shows the line to give Claude Code:

  ```text
  claude mcp add --transport http sona-studio http://127.0.0.1:47360/mcp --header "Authorization: Bearer <token>"
  ```

  Stop HTTP and Start HTTP are in the same dialog (setting `mcp_http`, port `mcp_port`).
- **stdio:** start the Studio with `--mcp` and it also serves MCP on its standard input and output, so an agent can
  start it itself. `sona-studio --headless --mcp` serves without a window until standard input ends.
- **Asking you:** an agent writes freely inside the Projects folder. A write anywhere else, or building or running a
  project an agent has changed, opens a dialog in the Studio (Allow or Refuse); the agent's call waits for the
  answer (a timeout of 5 minutes, then it is refused). Without a window nobody can be asked, so it is refused, unless
  `--mcp-answer allow|deny` answers for you.
- **Pictures:** the server renders on a device of its own (Vulkan, else the headless device), and on the Studio's
  own device when it has none; on macOS it uses the Studio's device first. `--mcp-device studio|own` picks which is
  tried first. Renders on the Studio's device run between its frames.
- **Log:** every MCP line (tool calls, results, the asks and the answers) is in the Log pane under the Agents source.
  The status bar shows the port.

| Option | What |
|---|---|
| `--mcp` | serve MCP on stdin and stdout too |
| `--mcp-port <n>` | serve HTTP on this port (0: a free one), also headless |
| `--mcp-port-file <file>` | write the port there |
| `--mcp-token-file <file>` | the bearer token, read from a file (default: the profile's `mcp-token`, made on first use, readable only by you) |
| `--mcp-answer allow\|deny` | answer the asks without the dialog |
| `--mcp-device studio\|own` | where the server renders first (default: studio on macOS, else own) |
| `--mcp-click allow\|refuse[,...]`, `--mcp-ask-shot <prefix>` | for tests: draw each ask and click its button in turn, saving a picture of each |
| `--log-out <file>` | write the whole log there at exit |

## Consoles and Apps

The pane signs in with your app id and the app's key (`sak_...`, shown once when the app was made) and works with the
developer API of the 360sona server (default `https://test.360sona.com`), the same calls as `sona app`:

| Part | What it does | API |
|---|---|---|
| App | name, id, what it uses, scopes, redirect, developer, homepage, when it was made | `GET /sona/v1/apps/{id}` |
| Origins | the web origins that may draw with the app id: add and remove | `PUT /sona/v1/apps/{id}` with `origins` |
| SDK Licence | accepted on which day, or read it and type the sentence to accept | `POST /sona/v1/apps/{id}/sdk-licence` |
| Downloads | the SDK made for the app: web or a native platform, with the offline catalogue if ticked, saved to `~/Downloads/360sona SDK/` | `GET /sona/v1/apps/{id}/sdk?platform=` |
| Builds | every native build made for the app, its checks, and Turn off (revoke) | `GET .../builds`, `POST .../builds/{build}/revoke` |
| Usage | today's items and answers at the busiest address, against the allowance | `GET .../usage` |
| Consoles | the avatar items stored in each `console:<Content folder>` source, and any Content folder you look at | read from the package headers |

The key you type is kept in the profile's `app-key` file (readable only by you on Linux and macOS); the server and app
id are settings. The key only goes to an `https://` server, or to `http://` on this machine (localhost, 127.0.0.1) for
a local test server; redirects are not followed, and an answer that stops before its end is an error, not a short
answer. A server whose certificate is not trusted is refused before the key is sent. On Linux and macOS (libcurl),
`$SONA_CA_FILE` names a PEM file of certificate authorities to trust instead of the system's bundle, as `curl --cacert` does (a libcurl built with a default CA path, as on Debian and Ubuntu, still trusts that path too);
on Windows https uses the Windows certificate store and `$SONA_CA_FILE` is refused. New app opens the developer site's access form. Calls run off the UI thread; the Log pane shows each
one under the Server source.

A console's Content folder is `Content/<profile>/<title>/00009000/<package>`, as copied off a development kit or its
drive. Each avatar item package is listed with its name (the catalogue's when it knows the id), id, profile and title.
Add the folder as a source (File > Sources, `console:<folder>`) to draw what is stored on it.

Headless, for checks and screenshots: `--server <url> --app <id> --app-key-file <file>` signs in at start and
`--apps-do <steps>` runs steps one after another: `origin-add:<o>`, `origin-remove:<o>`, `licence`,
`download:<platform>`, `revoke:first` (or a build id), `refresh`, `scan:<Content folder>`. For the Projects pane,
`--projects-new <template>:<name>` opens New project, picks the template from the pane's list and clicks Create.
