# Magicweave — LLM / AI-agent integration brief Hand-maintained index of the docs at https://docs.magicweave.xyz. Each section states the rules an agent must not get wrong and points at the page that holds the detail; it does not repeat those pages. There is no generator in this zero-build repo — when a page it summarises changes, update this file in the same commit. Endpoints below are the v2 client API (the game runtime) and the v2 control API (design time, reached through the console or the MCP). Magicweave is a REST backend for games: player sign-in, per-project currencies, stats, events & rules, sessions, leaderboards, streaks, shops, items, rewarded ads, saves, documents, realtime rooms — and MagicCoin, the one network-wide currency that follows a human across every game in the network. Sections 0-6 are the REFERENCE (what exists). To BUILD a game and ship it, run the BUILD HARNESS in section 7. To EDIT a game that already exists, run the MAINTENANCE HARNESS in section 8. Section 9 maps both onto any coding agent. Section 10 indexes the design-time pages (the document tree, tiers, tools, operate, reference, migration). ================================================================================ GUARDRAILS — READ BEFORE WRITING ANY CODE (do not hallucinate) ================================================================================ DO NOT INVENT endpoints, paths, query params, request fields, or response shapes. If a call is not in the list below or on a page it links to, it does not exist. If this file and a module page ever disagree, the module page wins — report the drift. THE CLIENT API (game runtime; base https://edge.oasis.magicweave.xyz; nothing else exists): Health : GET /healthz (no auth) Auth : POST /v1/auth/providers · /v1/auth/code · /v1/auth/token · /v1/auth/refresh Install : POST /v1/install/challenge · /v1/install/enrol · /v1/install/token Player : GET /v1/me · GET/PUT/DELETE /v1/me/profile · POST/GET/DELETE /v1/account/deletion Currency: GET /v1/currencies · GET /v1/wallet · GET /v1/wallet/history (read-only) Stats : GET /v1/stats (read-only) Events : POST /v1/events Sessions: POST /v1/sessions · GET /v1/sessions/active · POST /v1/sessions/{sessionId}/finish · POST /v1/sessions/{sessionId}/abandon Boards : GET /v1/leaderboards/{leaderboard} (read-only) Entries : GET /v1/entries/costs · GET /v1/entries/costs/{cost} · POST /v1/entries · POST /v1/entries/{entry_id}/refund Wheels (RETIRED: do not author new ones): GET /v1/wheels · GET /v1/wheels/spins · GET /v1/wheels/{wheel} · POST /v1/wheels/{wheel}/spin Streaks : GET /v1/streaks · GET /v1/streaks/{rule} · GET /v1/streaks/{rule}/history Shops : GET /v1/shops · GET /v1/shops/{shop}/listings · GET /v1/shops/{shop}/listings/{listing} · GET/POST /v1/shops/{shop}/listings/{listing}/purchases Items : GET /v1/items · GET /v1/items/{item} · GET /v1/items/{item}/history · POST /v1/items/{item}/consume · POST /v1/items/{item}/instances/{instance}/(equip|unequip|use-charge) Boxes (RETIRED: do not author new ones): GET /v1/boxes · GET /v1/boxes/{box} · GET/POST /v1/boxes/{box}/draws Ads : POST /v1/ads/intent · GET /v1/ads/eligibility MagicCoin: GET /v1/coins · POST /v1/coins/join Saves : GET /v1/saves · GET/PUT/DELETE /v1/saves/{slot} Documents: GET /v1/documents · GET/POST /v1/documents/{collection} · GET/PUT/PATCH/DELETE /v1/documents/{collection}/{documentId} Rooms : GET /v1/rooms/{room}/state · GET/PUT/DELETE /v1/rooms/{room}/state/{key} Realtime: POST /v1/realtime/ticket (then the socket) · POST /v1/realtime/presence HARD RULES (these are the classic hallucinations — do not make them): • Balances, stats and scores are READ-ONLY from the client. There is NO endpoint to write a balance, a stat or a score, and no "submit score". They change only as the outcome of a rule (reacting to POST /v1/events or a finished session), a wheel spin, a shop purchase, a box draw, an entry charge/refund, or a session feeding its own leaderboard. • There is NO client API for DEFINITIONS (currencies, stats, items, shops, leaderboards, games, event types, rules, ad placements). They are YAML documents in a versioned draft, authored in the console or through the MCP (section 7), then published as a release. • Credentials are JSON BODY fields (client_id, client_secret) on /v1/auth/* only. There is no x-client-id / x-client-secret header. Every other call sends only Authorization: Bearer . • Each write has its own retry-safe id — event_id, spin_id, purchase_id, draw_id, entry_id — or the Idempotency-Key HEADER (POST /v1/sessions only). Resend the same one to retry; generate a fresh one per distinct action. • Branch on error.code, never on error.message. Every failure carries the envelope {error:{code, message, hint?, docs_url?, request_id?}}. • V2 has no gems. The network currency is MagicCoin, and there is no /v1/coins/spend route: coins are spent through a coin_price shop listing. • If a capability is not here, it is NOT supported. Stop and tell the human. ================================================================================ 0 · START HERE ================================================================================ Build something the person can play first. Don't create a project, apply a setup or write any definitions until they've played it or asked for the backend. If they already have a game, go straight to connecting it. Naming Magicweave or a leaderboard in the first request is not asking for the backend yet: there is no game to connect, so build it first. Until Magicweave is connected, show coins and scores as plain numbers in the game. Don't write rules, limits or rewards in game code: Magicweave decides those once it's connected. The client key goes in the game. The server key stays on your own server and never goes in a game. Full page: /start/ (get_doc with slug "start"). Magicweave has an SDK for web games and React Native games. Nothing else today. ================================================================================ 0b · CONNECT THE GAME — AFTER IT IS PLAYABLE, IN ORDER ================================================================================ 1. PROJECT + CREDENTIALS — a project, its development environment and a first `client` credential, created together (console, or the MCP's create_project_setup). The MCP returns the secret ONCE as a .env block (MW_BASE_URL, MW_CLIENT_ID, MW_CLIENT_SECRET): write it to .env once, .env.example without it. The client key goes in the game. The server key stays on your own server and never goes in a game. 2. AUTHENTICATE A PLAYER — POST /v1/auth/token {client_id, client_secret, provider, ...}. There is no separate signup: the first sign-in creates the player. `guest` needs no console setup. 3. (Optional) PROFILE — PUT /v1/me/profile when the player picks a name. It provisions nothing: a wallet balance is created lazily on first movement. Without an authenticated player, every game-layer call returns 401. Pages: /connect/, /getting-started/, /integration-guide/. ================================================================================ 1 · CONNECT AND SIGN IN ================================================================================ Base URL: https://edge.oasis.magicweave.xyz (staging: https://edge.oasis.staging.magicweave.xyz). GET /healthz -> {"status":"ok"} with no auth confirms you have the right host. create_project_setup and issue_credential return it as base_url, so an agent never has to look it up. Keys issued outside the console (source mcp, cli or third_party) are capped at five live per environment and twenty-five per organisation, the project-setup key included; past either, 409 credential_limit, and revoking one frees a slot. An MCP or third-party caller may issue only client keys, never in production (otherwise 403 credential_issue_forbidden), and may rotate only a non-production client key that was itself issued outside the console (otherwise 403 credential_rotation_forbidden). The CLI is capped too, but may issue server and production keys. The key create_project_setup issues takes one of its development environment's five slots, so four more can be issued there. .env names (what the MCP emits): MW_BASE_URL, MW_CLIENT_ID, MW_CLIENT_SECRET, passed to connect({ baseUrl, clientId, clientSecret }). A browser or app bundler only exposes prefixed names: Vite VITE_MW_BASE_URL…, Expo EXPO_PUBLIC_MW_BASE_URL…. create_project_setup and the credential tools need admin scopes: the hosted connector at /mcp grants admin; a local stdio server needs MW_MCP_MODE=admin. Credential kinds (per environment; rotate any of them without reissuing others): client — safe to ship in a build; can NEVER grant currency. server — your own backend only; the only kind that may grant currency or name another player (event:attest). Never ship it. preview — sandboxes every wallet debit, grant and purchase into a separate, parallel wallet. It does NOT target the draft. Sign-in (all on /v1/auth/*, credentials in the body): POST /v1/auth/providers — what this environment lets a player sign in with; ask before drawing the sign-in screen rather than hardcoding buttons. POST /v1/auth/code — email a one-time sign-in code (202). POST /v1/auth/token — exchange a credential for {access_token, refresh_token, token_type, expires_in, player_id}. Providers: guest, email, google, apple. POST /v1/auth/refresh — rotate the pair. A guest never links to anything and can't be recovered on a new device; the same VERIFIED email through a second provider resolves to the same player. 400 = provider disabled/unconfigured (do not log the player out); 401 = the credential was refused; 429 = rate-limited, honour Retry-After. Console: only social sign-in needs setup — per environment, a list of `audiences` (Google web/Android/iOS client ids; Apple bundle id and Services ID) plus Enabled. No per-provider secrets. Page: /auth/. A browser game can call Magicweave only from a web address listed on any Magicweave environment, so list it on yours (https; http only for localhost, 127.0.0.1, [::1] and *.localhost; max 32 each; changes apply within a minute; HTTP and realtime socket alike). A browser build may carry a `client` credential; a `server` credential never ships, so anything needing it goes behind your own backend. PostHog (opt-in, page /posthog/): connect({ ..., posthog: { key, host?, consent? } }) or posthog: { client } with your own posthog-js instance. Key is the public project key (phc_…) only; host https://us.i.posthog.com (default) or https://eu.i.posthog.com. Nothing loads or sends until mw.analytics.setConsent(true); setConsent(false) stops. Events: magicweave_event_reported {event_type, event_id}, magicweave_purchase_completed {shop, listing, purchase_id}, magicweave_wheel_spun {wheel, spin_id, segment_index}, magicweave_box_opened {box, draw_id, pulls}; the player's Magicweave id is PostHog's distinct id. Data goes browser -> the developer's PostHog, never through Magicweave. Two environments of one game on the same PostHog project (copy the setup with "Copy from" in the console, or type it) each count only (once both are switched on) events tagged with their own environment id, which needs SDK 2.1+; one project per environment is still simplest. Key mode is browser-only; elsewhere pass `client`. Optional read-back: a personal API key with only Query Read, limited to one project, pasted in the console at Observe > Analytics > Connect integration (then switch on "Use it in this environment") once per environment; Magicweave reads daily counts (players, sessions, events, economy actions, top purchases, top events, platforms, countries) and shows them in Analytics. Never put a personal key in a build or in chat. ================================================================================ 2 · CORE CONCEPTS ================================================================================ - Everything game-layer lives in one project + one environment, decided by the credential that minted the token. You never pass a project or environment id. - A player is environment-scoped: the same human in development and production is two players. Only their opt-in MagicCoin link crosses games. - Value system: currencies (yours, per project; whole numbers, optional cap), stats (per-player integers: add/set/max/min), items (stacked or individually tracked), and MagicCoin (network-wide; belongs to the human; each coin expires 12 months after issue). Pages: /core-concepts/, /overview/, /magic-coins/. ================================================================================ ENVIRONMENTS & RELEASES ================================================================================ Environment KIND: development · production (the plan caps the total per project: one too many is 402). Each environment has its own RESOLUTION MODE, a separate setting: `latest_draft` serves the working draft live; `pinned_release` (the default for production) serves the release last activated on it, and serves nothing until one is. Lifecycle: one project-level working DRAFT -> PUBLISH freezes it as a new, numbered, immutable RELEASE -> ACTIVATE points an environment at a release -> PROMOTE points another environment at the release a source environment serves -> ROLL BACK re-activates an older one. One release may be live in several environments. Which release is served never depends on the credential. Control operations behind this (console or MCP): putDraftDocument, diffDraft, publishRelease (POST /v1/projects/{projectId}/releases), moveRelease (PUT /v1/environments/{envId}/release, action activated|rolled_back|promoted). Web addresses: setAllowedOrigins (PUT /v1/environments/{envId}/allowed-origins, MCP set_allowed_origins) replaces the list of addresses a browser game runs from. Console: Connect & SDKs -> Web addresses -> Add address. Pages: /environments/, /concepts/drafts-and-releases/, /concepts/environments-and-credentials/. ================================================================================ 3 · GAME-LAYER MODULES — DEFINITION + API ================================================================================ Every definition is a YAML document at //.yaml in the draft (full field lists: /reference/document-kinds/). Keys are IMMUTABLE. Author in dependency order: currencies + stats first, then items, then leaderboards and games, then event types + rules, then shops/listings. --- CURRENCIES (economy/currencies/) --- console: Economy -> Create currency definition (name, key, symbol, weight, decimals, initial balance, max balance). GET /v1/currencies (what the release serves) · GET /v1/wallet (every balance, release order, including untouched currencies at their opening balance) · GET /v1/wallet/history?limit= (ledger, newest first). A preview credential has its own separate wallet. Manual corrections are a console (or MCP adjust_balance) action, never a client call. Page: /currencies/. --- STATS (progression/stats/) --- console: Progression -> Create stat definition (name, key, decimals, default, min/max; out-of-bounds writes clamp). GET /v1/stats. Only a rule writes a stat: op add|set|max|min — max/min keep the best value under a race, so there is no client "only if better" guard. A stat has no separate preview wallet. Page: /stats/. --- EVENTS & RULES (rules/event-types/, rules/rules/) --- console: Build -> Game Rules (Events tab, Rules tab). POST /v1/events {event_id, type, occurred_at?, data?, player_id? (event:attest only), stage?, signature?} -> 200 with an `effects` array, always present, empty when nothing paid. A rule with `sync: true` returns its effect in that response; otherwise effects land a moment later — poll. Rules count against received_at, never occurred_at. Trust tier comes from the credential: `claimed` (game build) or `verified` (event:attest). An event type declared `trust: confirmed` refuses claimed events; an UNDECLARED type is accepted and stored but no rule can see it. Rule shape: WHEN · COUNT · TALLY · WHERE · WITHIN · THEN. Pages: /events/, /concepts/events-and-rules/, /concepts/platform-events/, /reference/rules-grammar/. --- GAMES + SESSIONS (progression/games/) --- a game document declares session policy (expiry, concurrency), which `outcome` field is the score, and which leaderboards it feeds directly. POST /v1/sessions (header Idempotency-Key, body {game}) -> play client-side -> POST /v1/sessions/{id}/finish {outcome}. The finish response carries `standings` only for boards the game feeds directly; rewards from rules on `session.finished` are ALWAYS asynchronous — poll /v1/wallet and /v1/stats. A second concurrent start is 409: recover with GET /v1/sessions/active -> POST .../abandon -> start again. Page: /integration-guide/ (step 6). --- LEADERBOARDS (progression/leaderboards/) --- console: Progression -> Create leaderboard (name, key, stat, sort, reset never|daily|weekly|monthly, up to 12 leagues, announce top). Fed by a rule writing its stat (same transaction) or directly by a game's score field. GET /v1/leaderboards/{leaderboard} returns the top of the board and this player's standing in one call; a null standing means unranked, not last. A reset opens a new period; the old one stays readable. Closing a period early is admin-only (MCP roll_leaderboard). Pages: /leaderboards/, /operate/leaderboards/. --- ENTRY COSTS (economy/entry_costs/) --- GET /v1/entries/costs[/{cost}] · POST /v1/entries {entry_id, cost} charges (402 insufficient_balance) · POST /v1/entries/{entry_id}/refund. Independent of the session. Page: /inventory/. --- WHEELS (economy/wheels/ — RETIRED: do not author new ones) --- published wheels keep serving: GET /v1/wheels · /v1/wheels/{wheel} (spins_remaining, period_ends_at) · /v1/wheels/spins · POST /v1/wheels/{wheel}/spin {spin_id}. Stop the animation on the returned segment_index. Weights are never published. Do NOT author new wheels: no MCP tool writes one. Page: /wheels/. --- STREAKS --- a streak is a rule with a COUNT clause; standing is computed on read, never swept. GET /v1/streaks · /v1/streaks/{rule} · /v1/streaks/{rule}/history. Page: /streaks/. --- SHOPS (economy/shops//shop.yaml + listings/.yaml) --- a listing is priced EITHER `price` (a project currency) OR `coin_price` (MagicCoin), never both; `grants` are currencies/items; optional `limit` (lifetime, never resets) and sale window. A listing may not grant more of its own price currency than it charges. Key `magicweave` is reserved for the Magicweave Shop. POST .../purchases {purchase_id} buys ONE; read `state` (processing settles on its own). 402 insufficient_balance · 402 purchase_limit_reached · 404 listing_not_available · 409 no active release. Page: /shops/. --- ITEMS + GACHA BOXES (economy/items/, economy/boxes/ — boxes RETIRED: do not author new ones, existing boxes still served) --- items: stackable or individually tracked (slot = equippable, charges = chargeable, both force non-stackable), consumable, lifetime_seconds, maximum. Boxes publish each prize's probability; a draw {draw_id} pays a prize, never nothing; pity optional. Page: /inventory/. --- REWARDED ADS (ads/placements/) --- POST /v1/ads/intent for a single-use ticket before the ad plays · GET /v1/ads/eligibility. The reward is paid only when the ad network's own server confirms, as an `ad.watched` event a rule pays on, capped only by WITHIN {period: day|week|month, max_times}. Page: /ads/. --- NOTIFICATIONS --- credential storage for FCM/APNs only, set on the Integrations screen. There is NO send API yet. Page: /notifications/. ================================================================================ 4 · PLAYER, MAGICCOIN AND PLAYER-OWNED DATA ================================================================================ --- PROFILE --- GET/PUT/DELETE /v1/me/profile (what the player is called). GET /v1/me is the signed-in player. Page: /profiles/. --- ACCOUNT DELETION --- POST/GET/DELETE /v1/account/deletion (request, read, cancel). Page: /profiles/. --- MAGICCOIN WALLET (read-only) --- MagicCoin belongs to a HUMAN, not a player: the same wallet in every game in the network, opt-in, and each coin expires 12 months after the studio that issued it minted it. GET /v1/coins -> {joined, coins, next_expiry, expiring_next, tranches[]} — NOT a balance: draw coins + next_expiry + expiring_next together. joined:false = not linked yet (show an invitation, not an error); 403 = your studio is not a network member; 402 = it is, but has stopped paying. POST /v1/coins/join (no body; verified-email sign-in, production environment only; guests 403; 409 = already linked to another human). Spend through a coin_price shop listing (section 3, SHOPS); there is no /v1/coins/spend. Minting is a console action or a rule's `then: coin`, never a player request. Pages: /wallet/, /magic-coins/. --- SAVES --- opaque per-player slots: GET /v1/saves · GET/PUT/DELETE /v1/saves/{slot}. Writes take expected_version (0 create · the version you read · -1 overwrite). No page on this site yet. --- DOCUMENTS --- a player's own searchable JSON records, grouped into collections that exist the moment you write into them (no console setup). Owned by ONE player; names are names, not paths (no slashes, no sub-collections). GET /v1/documents (collections) · GET /v1/documents/{collection} (paged, filterable) · POST (we choose the id) · GET/PUT/PATCH/DELETE /v1/documents/{collection}/{documentId}. Writes take expected_version as above. Page: /documents/. --- REALTIME (rooms, presence, socket) --- room state is a (room, key) store: any authenticated player in the environment may read/write any room whose name they know (the name is the authority; last_writer records who). <=64 keys per room, <=32 KiB per value (any JSON). GET /v1/rooms/{room}/state -> {entries} (never paged) · GET .../{key} (404 never written) · PUT .../{key} {value, expected_version} — REQUIRED compare-and-swap: 0 = create, the version you read = conditional, -1 = overwrite. 409 conflict (re-read, retry) · 409 room_key_limit_reached · 413 room_value_too_large · DELETE .../{key} -> 204 always. No patch/merge, no multi-key transaction, no TTL. Every accepted write or delete emits room.state_changed onto the event spine; declare that event type (default trust) and a rule can pay on it. Presence: POST /v1/realtime/presence {room, present?} every ~10s (read heartbeat_seconds/expires_in_seconds from the response); present:false leaves now. Socket: POST /v1/realtime/ticket -> {ticket, expires_at, url}; dial url?ticket=..., send ONE message {op:"subscribe", subscribe:{room, types, from}}. Read-only: frames ready · event · presence.sync/join/leave · error. Pages: /realtime/, /concepts/rooms/, /reference/rooms/. ================================================================================ 5 · BOOTSTRAP ORDER (after a player authenticates) ================================================================================ 1. (When the player names themselves) PUT /v1/me/profile; otherwise GET /v1/me/profile. 2. Hydrate in parallel — GET /v1/wallet, GET /v1/currencies, GET /v1/stats (and GET /v1/coins if the game shows MagicCoin). No ordering dependency on step 1. 3. Load what the screen needs — shop listings, leaderboards, GET /v1/streaks, GET /v1/sessions/active, wheel state. ================================================================================ 6 · WORKED EXAMPLE — closing the loop (a run pays a currency and a best score) ================================================================================ A `then` pays ONE shape (a stat alone), so this is two rules on one event: rules/event-types/run.ended.yaml version: rules/v1 name: run.ended label: a run ends fields: - { name: distance_m, type: number, required: true } - { name: coins, type: number, required: true } rules/rules/run_coins.yaml version: rules/v1 key: run_coins name: Coins collected in a run sync: true when: run.ended within: { period: day, max_amount: 5000 } then: currency: { key: coins, op: add, per_field: data.coins } rules/rules/record_best_run.yaml version: rules/v1 key: record_best_run name: Record the best run when: run.ended within: { period: day, max_times: 100 } then: stat: key: best_distance op: max per_field: data.distance_m per_field_rate: 1 Publish and activate, then POST /v1/events {event_id, type: "run.ended", data: {distance_m, coins}}. run_coins is sync, so its effect is in `effects`; record_best_run lands a moment later — read GET /v1/stats. A leaderboard ranking best_distance moves in the same write. Both rules carry `within` because a rule paying from a `reported` event with no `count` and no `within` is refused at publish as unbounded (see /events/ and /reference/rules-grammar/). ================================================================================ 7 · BUILD HARNESS — PHASES AND GATES (concept -> live) ================================================================================ Sections 0-6 are the REFERENCE. This is the PROCESS. Run the phases IN ORDER as one agent wearing each role in turn; the GATES and ORDER are the invariants, the agent topology is not. A multi-agent runtime MAY run phases marked INDEPENDENT in parallel. Never trade a gate for speed. Full version: /agent-guide/. Ready rules blocks for Cursor, Codex, Gemini CLI and Copilot: /agent-rules/. EVERY PHASE INHERITS: the GUARDRAILS block above (no phase invents endpoints, paths, fields or shapes), the order in sections 0 and 0b, and ends by confirming its output before the next phase starts. TWO AUTHORING CHANNELS FOR DEFINITIONS (the client API has none): • TOOL-DRIVEN — the Magicweave MCP (https://mcp.magicweave.xyz/mcp). Definitions are YAML documents in ONE versioned tree per project: a working draft plus immutable releases. Author with the typed write_ tools, each of which creates OR replaces one document: write_currency, write_stat, write_item, write_entry_cost, write_shop, write_listing, write_game, write_leaderboard, write_event_type, write_rule, write_ad_placement (write_draft_document for any other path). Read back with list_draft_documents / read_draft_document. Check with lint_draft, diff_draft, simulate_economy and try_event (runs an event through the real rules, writes nothing). Ship with publish_release and move_release. recommend_blueprints / read_blueprint / apply_blueprint start from a whole genre economy. There are no create_*_definition / update_* / get_* tools — that was the v1 server. • MANUAL CONSOLE — no MCP: emit the console steps from section 3 for the human, wait for confirmation, then read back over the client API once the release is active. A supported path, not a degraded mode. Project + credentials: a human in the console, OR create_project_setup (admin tier), which returns the client SECRET once as a .env block. Write it to .env. The client key goes in the game. The server key stays on your own server and never goes in a game. Server credentials and production stay in the console. ROLES (hats, not workers): ORCHESTRATOR owns the pipeline, gates and SPEC; never calls the API. ECONOMY ARCHITECT designs the SPEC, checking the blueprint library first. DEFINITIONS AUTHOR writes + verifies definitions (write_, lint_draft, scan_references). CLIENT INTEGRATOR wires auth, bootstrap and the game loop into the client. VERIFIER plays the closed loop and every rejection path (try_event, read_trace). RELEASE ENGINEER publishes a release and promotes it to production. PIPELINE (gates are BLOCKING): PHASE 0 · PLAYABLE FIRST (see /start/) then connect. Build the playable version with plain numbers. To make it real: project + development environment + client credential (section 0b), then confirm a test player can sign in with POST /v1/auth/token before any game-layer definitions. PHASE 1 · DESIGN THE SPEC (Economy Architect) — BLOCKING, design only. recommend_blueprints first. Then: currencies (key, initial, max); stats (key, default, min/max — a personal best is a rule with op: max); items; the game (session policy, score field, boards it feeds); leaderboards (stat or game feed, sort, reset, leagues); event types (fields, trust) and rules (when, count/tally, where, within caps, then); shops/listings. Name every key once. PHASE 2 · AUTHOR + VERIFY (Definitions Author) — BLOCKING. In dependency order: currencies + stats -> items -> leaderboards + game -> event types + rules -> shops/listings. After each batch: lint_draft, diff_draft against a development environment, try_event on every new rule. A missing or renamed key surfaces later only as a silent refusal — catch it here. PHASE 3 · CLIENT INTEGRATION (Client Integrator) — INDEPENDENT, after Phase 2. Sign in and store the token pair; bootstrap (section 5) on every launch; loop = (optional entry charge) -> POST /v1/sessions -> play -> finish {outcome} -> poll for rewards. Never write a balance, stat or score. A browser game keeps any server credential behind its own backend. PHASE 4 · VERIFY (Verifier) — BLOCKING before ship. Close the loop and confirm the reward lands. Trip: 409 on a second concurrent session (recover: GET /v1/sessions/active -> abandon -> start), insufficient_balance, no_spins_remaining, purchase_limit_reached, entry_cost_not_in_release, and idempotent replay of each write id. Debug with read_trace / rules_activity (operate toolset, reached via run_read_tool). PHASE 5 · SHIP (Release Engineer). publish_release -> move_release activated on development -> verify -> promote into production FROM THE CONSOLE (the hosted MCP refuses any operation aimed at a production environment). Ship the production environment's client credential. Rewards stay pull-only. If a phase can't proceed because a capability isn't in these docs, it STOPS and reports the gap — it does not invent a workaround. ================================================================================ 8 · MAINTENANCE HARNESS — EDITING A GAME THAT ALREADY EXISTS ================================================================================ Same guardrails and roles; the entry point flips — DISCOVER first, never design from scratch. Full version: /agent-guide/ and /operate/lint-and-simulate/. EDITING CHANNEL: the write_ tool that created a document, called again, replaces it in the draft; delete_draft_document (admin) removes one. There are no update_* / delete_* tools per kind. Keys are IMMUTABLE: a rename is create-new + repoint references + delete-old. THE EDIT LOOP (gates BLOCKING): E0 · SCOPE — state the change in definition vocabulary (currency, stat, item, leaderboard, game, event type, rule, shop/listing). ADDITIVE, or a MUTATION of something referenced or live? E1 · DISCOVER (read-only) — list_draft_documents / read_draft_document for the draft; list_releases / diff_releases for what is live. Never edit blind. E2 · IMPACT SCAN — scan_references for every key you will touch. A stat is referenced by leaderboards and rules; a currency by rules, entry costs and listings; an event type by every rule naming it in `when`; a game edit changes every future session. E3 · CLASSIFY + GATE — additive -> proceed. Breaking (deleting a referenced definition, renaming a key, changing a live payout) -> STOP, show the blast radius, get EXPLICIT HUMAN CONFIRMATION before any write_ or delete_draft_document. Prefer additive: new key, then cut over. E4 · APPLY — smallest change, in a development environment first (diff_draft against it). Migration order: create new -> repoint every reference -> verify -> only then delete the old one. E5 · VERIFY — lint_draft, simulate_economy if economic, and the section 7 closed loop. No dangling references; boards still resolve their feed; no session stranded on an old game shape. E6 · PROMOTE — publish_release, then promote into production (console) only after a green verify. Changes are pull-only: players pick them up on their next read. EDITING HAZARDS: • A player mid-run holds a session against the OLD game document; prefer additive changes or let sessions drain. • A payout change on a live rule is an economy rebalance — gate it as breaking. • Irreversible tools (adjust_balance, roll_leaderboard, import_players, revoke_credential, rotate_credential, revoke_install, write_player_document) return a "nothing changed" preview unless called with confirm: true. Read the preview before confirming. • Never hand-edit production first; the hosted MCP refuses production. ================================================================================ 9 · RUNNING THE HARNESSES FROM ANY CODING AGENT ================================================================================ Sections 7 and 8 assume NOTHING about your runtime. A) SINGLE-LOOP AGENT WITH MCP Run the phases strictly in order, wearing each hat in turn. Connect https://mcp.magicweave.xyz/mcp once. It lists 45 tools: 42 core plus three handles, find_tools, run_read_tool and run_write_tool. The other 37 (live-ops `operate`, `migrate`, credential and sign-in admin `projects`) are reached by name through those handles, or listed with the MW-MCP-Toolsets header. Optional narrower doors: /mcp/readonly, /mcp/x/operate, /mcp/x/migrate. Seven irreversible tools preview unless called with confirm: true; apply_blueprint already worked this way. Read this file via get_doc('llms'). See /agent-guide/, /auth/tiers-and-scopes/, /tools/. B) AGENT WITHOUT MCP Identical phases, identical gates. Fetch this file over HTTPS (https://docs.magicweave.xyz/llms.txt). Author definitions through the MANUAL CONSOLE channel and read the results back over the client API. C) MULTI-AGENT / ORCHESTRATING RUNTIME You MAY assign hats to separate workers and run INDEPENDENT phases concurrently. Every BLOCKING gate still serializes the pipeline; give each worker the GUARDRAILS block. If in doubt, run sequentially. PUT MAGICWEAVE IN YOUR REPO'S AGENT INSTRUCTIONS. Starter block for AGENTS.md: ## Magicweave backend This game uses Magicweave (REST) for identity, currencies, stats, events, sessions, leaderboards, shops and MagicCoin. - Before backend work, read https://docs.magicweave.xyz/llms.txt (or get_doc('llms') if the Magicweave MCP at https://mcp.magicweave.xyz/mcp is connected). Section 7 = build a game; section 8 = edit a live game. - Never invent endpoints: if a call is not in llms.txt, it does not exist. - Balances, stats and scores are READ-ONLY from the client — the only writers are a rule (POST /v1/events, or a finished session), a wheel spin, a shop purchase, a box draw, an entry charge/refund, or a session feeding its own leaderboard. - Each write has its own retry-safe id (event_id, spin_id, purchase_id, draw_id, entry_id) or an Idempotency-Key header (POST /v1/sessions only). - Definition keys are immutable: a rename = create new + migrate + delete old. - Editing anything live: scan references FIRST (llms.txt section 8); get explicit human sign-off before destructive or economy-altering changes. ================================================================================ 10 · DESIGN-TIME PAGES — BUILDING, OPERATING AND MIGRATING WITH THE MCP ================================================================================ The pages the Magicweave MCP server links to: how a project's configuration is a versioned document tree, how drafts become releases, what each tier and tool does, how to operate a live game, and how to move an existing one across. One line per page: --- BUILDING WITH THE MCP --- The Document Tree — https://docs.magicweave.xyz/concepts/the-document-tree/ Drafts & Releases — https://docs.magicweave.xyz/concepts/drafts-and-releases/ Environments & Credentials — https://docs.magicweave.xyz/concepts/environments-and-credentials/ Rooms — https://docs.magicweave.xyz/concepts/rooms/ Events & Rules — https://docs.magicweave.xyz/concepts/events-and-rules/ Platform Events — https://docs.magicweave.xyz/concepts/platform-events/ Signing In — https://docs.magicweave.xyz/auth/signing-in/ Tiers & Scopes — https://docs.magicweave.xyz/auth/tiers-and-scopes/ Tools — https://docs.magicweave.xyz/tools/ (MCP prompts: skill_build, skill_migrate, skill_edit, skill_deploy, skill_liveops) --- OPERATE --- Debugging a Request — https://docs.magicweave.xyz/operate/debugging-a-request/ Players — https://docs.magicweave.xyz/operate/players/ Importing Players — https://docs.magicweave.xyz/operate/importing-players/ Leaderboards — https://docs.magicweave.xyz/operate/leaderboards/ Economy Health — https://docs.magicweave.xyz/operate/economy-health/ Lint & Simulate — https://docs.magicweave.xyz/operate/lint-and-simulate/ Projects, Environments & Credentials — https://docs.magicweave.xyz/operate/projects-environments-credentials/ --- REFERENCE --- Document Kinds — https://docs.magicweave.xyz/reference/document-kinds/ Rules Grammar — https://docs.magicweave.xyz/reference/rules-grammar/ Errors — https://docs.magicweave.xyz/reference/errors/ Scopes — https://docs.magicweave.xyz/reference/scopes/ Rooms — https://docs.magicweave.xyz/reference/rooms/ --- MIGRATE --- Migration Recipes — https://docs.magicweave.xyz/migrate/ From localStorage — https://docs.magicweave.xyz/migrate/from-localstorage/ From Your Own Server — https://docs.magicweave.xyz/migrate/from-own-server/ From Firebase — https://docs.magicweave.xyz/migrate/from-firebase/ From PlayFab — https://docs.magicweave.xyz/migrate/from-playfab/ From Supabase — https://docs.magicweave.xyz/migrate/from-supabase/