Files

65 lines
7.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Campaign workshop / MCP
The relay exposes a stateless Streamable HTTP MCP endpoint at **`/mcp`**. It lets a connected assistant write playable campaigns through the same strict compiler used by the game. It has no shell, arbitrary file access, player impersonation, backend credential access or relay-settings write tools.
## Connect
1. Start the updated server and unlock `/admin` with your admin key.
2. Open **MCP access**. Give the key a label, choose permissions and an expiry (default 30 days), then **Generate API key**.
3. Copy the secret before dismissing it. The server only returns it once. Give each assistant its own key.
4. Configure your MCP client with the displayed URL, **Streamable HTTP**, and `Authorization: Bearer <key>`. Use the client's secret store or environment-variable support instead of committing credentials to configuration files.
For a local server the URL is `http://127.0.0.1:1337/mcp`. For private access to a hosted relay, forward it over SSH:
```sh
ssh -N -L 9080:127.0.0.1:1337 your-server
```
Then use `http://127.0.0.1:9080/mcp` in a client on your computer. A cloud-hosted MCP client cannot reach this local tunnel. Clients must support pre-issued bearer headers; OAuth discovery, dynamic client registration and legacy HTTP+SSE are not implemented.
MCP has the same access policy as administration: loopback by default; `--lan --lan-admin` for trusted LAN testing. The supplied public Caddy configuration continues to block `/mcp`. No public route or firewall is opened by upgrading. If deliberately exposing MCP, configure HTTPS, the relay's explicit remote-admin policy, matching proxy/body limits and an exact `/mcp` route; the [private tunnel](internet-hosting.md) remains the default.
## Permissions and tools
| Permission | Tools |
| --- | --- |
| `campaign.read` | `campaign_list`, `campaign_get`, `campaign_guide`, `campaign_validate`, `campaign_preview` |
| `campaign.write` | `campaign_create`, `campaign_save` |
| `campaign.publish` | `campaign_publish`, `campaign_unpublish` |
| `relay.read` | `relay_status` (name, narrator counters, room summaries) |
The UI defaults to reading and editing drafts, with publication and relay monitoring unchecked. Both discovery and direct calls enforce scopes. None of these permissions allow issuing API keys or changing inference settings. Scopes apply to all campaigns on this relay, not to an individual project. Campaign authors can read spoilers and hidden role content in campaign documents; do not issue author keys to ordinary players.
Suggested request to your assistant:
> Read the campaign guide and schema. Create a new draft called The Lost Frequency, using the dead-channel template. Keep its bounded clock and multiple endings, but rewrite the scenes and clues around a deserted coastal telephone exchange. Validate it, fix errors, preview each role's opening, and show me the result before publishing.
`campaign_create` copies a template with a new ID/title/version and adds the author while preserving attribution and license. Its story remains the template until the assistant rewrites it. An assistant can instead supply a completely new document using `campaign_save` with `expectedHash: null`. The relay does not call an LLM to generate the document itself.
## Edit, review, publish
1. `campaign_guide` with `kind: "guide"` or `"schema"` supplies the bundled format reference. `campaign_get` reads `source: "draft"` or `"published"`; the latter reads the shared installed library, including built-ins and hidden packages. `campaign_list` marks installed campaigns with `enabled`.
2. `campaign_save` takes a complete JSON **object**, plus the previous draft's `expectedHash`. Use null only for the first save. Invalid documents return path-specific diagnostics without writing. Warnings are reported but do not block publication.
3. `campaign_preview` starts an isolated opening for the requested role: scene, actions/check previews, objectives, exits and intro log. It creates no live room and runs no LLM. This is not a full playthrough; test branches and endings in the app too. Publication rejects campaigns whose minimum crew exceeds this relay's two seats.
4. `campaign_publish` requires the current `draftHash` and `expectedPublishedHash` (null only when the ID is not installed in the library). The campaign is saved as a `.dpc` in the same library used by Studio and catalogs, and appears in the app's campaign picker immediately. When changing a previously published document, raise `meta.version`; normal package version checks still apply. Hash checks reject stale edits from MCP, Studio or catalog updates, and publication of an unreviewed draft version.
5. `campaign_unpublish` requires the current published hash. It hides the custom campaign from the picker while preserving its installed package, draft and games already in progress. An admin can offer it again from Campaign library.
Built-ins cannot be overwritten or unpublished. Copy them with a new ID. Each room pins its exact campaign document by hash; later updates and unpublishing do not alter that room. Custom campaigns load again on server restart.
Publishing is a real change to the player catalogue. Tool descriptions ask the assistant to obtain user approval, and tool annotations mark writes; the MCP client is responsible for presenting its approval UI. For enforced separation, give the writing assistant no publishing scope and use a separate publisher key.
## Storage and limits
- `DATA_DIR/mcp-keys.json`: labels, scopes, creation/expiry timestamps and SHA-256 digests of randomly generated 256-bit keys. File permissions are 0600 on supported filesystems. At most 32 unexpired keys; expiry is 1–365 days. Revocation takes effect on subsequent requests and survives restart. It does not cancel an operation already authenticated and running.
- `DATA_DIR/campaigns/drafts/`: at most 100 valid draft documents, up to 512 KiB each.
- `DATA_DIR/campaigns/library/`: shared installed `.dpc` packages. `MAX_CAMPAIGNS` (default 50, including built-ins) limits the library. Draft edits never update these packages implicitly.
- `DATA_DIR/campaigns/pinned/`: exact versions referenced by rooms, preserved as before.
MCP requests are limited to 576 KiB and JSON nesting to 64 levels. The compiler's stricter campaign/effect limits remain in place. Two MCP requests can execute at once. Per-key limits are 60 requests/minute with a burst of 20, in addition to shared IP/global request limits. Responses use JSON, with GET/DELETE returning 405 instead of opening an SSE stream or allocating sessions. Supported protocol versions: `2025-03-26`, `2025-06-18`, `2025-11-25`.
The relay validates hosts/origins, accepts keys only in Authorization headers, and does not enable CORS. Tool audit messages record the tool name, key ID and outcome; campaign text, bearer secrets and inference keys are not logged. Treat campaign content as untrusted fiction rather than instructions for the assistant. Back up the data directory privately.
Admin key-management API (admin bearer required): `GET /admin/api/mcp/keys`, `POST /admin/api/mcp/keys` with `{ "label": "Writer", "scopes": ["campaign.read", "campaign.write"], "days": 30 }`, and `POST /admin/api/mcp/revoke` with `{ "id": "<key ID>" }`. Listing never returns secrets or their digests.
The transport follows the [MCP Streamable HTTP specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports); discovery and results follow [MCP tools](https://modelcontextprotocol.io/specification/2025-11-25/server/tools).