Skip to content

Play via MCP

Restfall is exposed as a Model Context Protocol (MCP) server. Every game API endpoint is an MCP tool, so any MCP-capable agent can play the full game — no HTTP client code required.

60-second quickstart

Claude Code

Terminal window
claude mcp add --transport http restfall https://YOUR-RESTFALL-HOST/mcp

Claude Desktop / claude.ai

Add a custom connector with the URL https://YOUR-RESTFALL-HOST/mcp.

Clients without remote MCP support

Terminal window
uvx restfall-mcp

Set RESTFALL_URL to the server’s /mcp endpoint and (optionally) RESTFALL_TOKEN to a realm token to skip the browser auth flow. A realm token is bound to its realm, so the account-level tools refuse it too. For interactive OAuth over stdio, use uvx fastmcp-remote https://YOUR-RESTFALL-HOST/mcp.

Authentication

MCP access requires an API-access entitlement — premium or creator. This applies to every request reaching /mcp, including one carrying a realm token you set as RESTFALL_TOKEN. Without one you get 403 and a message saying so. Ask the operator for a grant.

Your OAuth client also has to be approved. Registration is open, so your client registers itself on first connect and then needs an administrator to approve it before /oauth/authorize will complete — the operator runs scripts/grant_entitlement.py approve-client. Send the operator the client_id your client printed. What a registration may hold is listed under Registering a client, and registering is rate limited per address.

Every MCP request counts against your token’s rate limit, and a tool call counts once. Over it, a call fails with 429 and a Retry-After header; the how_to_play prompt tells the agent to wait that long.

On first connect your client opens a browser page where you log in (or create an account), pick a realm, and authorize the agent. The agent receives a token scoped to that realm’s active season — a player is created for you automatically. The page’s sign-in, “Create a new account” and “send a new link” forms each show the same human check as the web client’s. A form whose check has not passed is refused with 400 and the page says so, before the password is checked or anything is mailed. A new account must verify its email first: “Create a new account” makes the account and emails you a link, and authorizes nothing yet; open the link, then log in on the same page. Logging in with an account that is not verified is refused there with a button that emails a new link. Tokens expire after 30 days; your client will re-run the flow when that happens. Your agent’s token also counts toward the account’s token limit: if you sign in elsewhere until the account is full, the oldest account or realm token is revoked first. The agent’s token goes only when nothing else is left to revoke, and then it re-runs the flow the same way.

If the account has no API-access entitlement, the browser flow completes but the final token exchange fails with access_denied. That is the entitlement check, not a broken client.

If an administrator revokes your API access, or withdraws your client’s approval, the tokens already issued through OAuth are deleted immediately.

What the agent’s token can do

The agent’s token is bound to the realm you picked. It plays there, and it can ask who it is (me). It cannot act on your account: list_players, create_player, delete_player, realm_login and list_tokens answer 403, because those need the account token from password login. So the agent cannot list your other realms, join or abandon one, or mint itself a token for one.

A second realm

To let an agent play another realm, authorize it again and pick that realm. In Claude Code, add the server a second time under another name, for example claude mcp add --transport http restfall-fast https://YOUR-RESTFALL-HOST/mcp. Each authorization issues a separate token for its own realm. If your client registers itself anew for the second entry, that registration needs an administrator’s approval like the first one.

Learning the game

Ask your agent to read the how_to_play MCP prompt — it explains the core loop (found a town, place it, build, train, fight). The game state endpoint is the recommended first call of every decision cycle.

The core loop the prompt teaches:

  1. get_state — one call returning your towns, resources, buildings, queues, incoming attacks, and research. Start every decision here.
  2. create_town (if you have none), then place it on the map (place_town) before interacting with other players.
  3. create_building / upgrade_building — production buildings (farm, lumber mill, quarry) compound your economy. Costs are charged immediately; construction finishes after a real-time delay.
  4. train_units in military buildings, respecting idle population.
  5. launch_attack / send_scouts — travel time scales with map distance and your slowest unit. Combat resolves deterministically on arrival. send_scouts only accepts the realm’s dedicated scout unit type, and a target garrisoning its own scouts can screen the mission — send too few and the whole party is intercepted with no report. See Scouting.
  6. list_quests and claim_quest for resource rewards; list_events to react to what happened while you were away.

Timing matters more than frequency: most actions complete lazily when next observed, so poll get_state at sensible intervals rather than hammering individual endpoints.

For tool authors

The tool surface is generated 1:1 from the OpenAPI schema: tool names are operation ids, descriptions are endpoint docs, schemas are the Pydantic models. Infrastructure routes (/health/, the /oauth/* endpoints and /.well-known/* metadata) are excluded. If you build against the REST API directly, you’re seeing exactly what agents see — with two exceptions, published in the schema but deliberately excluded from the tool surface. The administrator routes under /api/v1/admin/ are not tools, so no agent can grant itself an entitlement. Nor are the web client’s password and email forms, which carry its human check: POST /api/v1/token/login/, POST /api/v1/users/, POST /api/v1/users/verify-email/, POST /api/v1/users/verify-email/resend/ and the widget’s GET /api/v1/turnstile/site-key/. An agent is signed in by the OAuth flow and never needs them.

For client developers

What an MCP client meets on the OAuth endpoints, if you are building one. Restfall is an OAuth 2.1 server for public clients: open dynamic registration (RFC 7591), the authorization code grant with PKCE S256 (RFC 7636), no client secret. There are no refresh tokens: when a token expires (after 30 days) or is revoked, the client runs the flow again.

Registering a client

POST /oauth/register takes:

  • client_name: 1 to 64 characters.

  • redirect_uris: 1 to 10 of them, each at most 2,048 characters, and each an absolute URI with one of these schemes:

    • https://, with a host;
    • http://, only on a loopback host: localhost, 127.0.0.1 (any 127.x.x.x) or [::1] (RFC 8252);
    • a native app’s own private-use scheme, such as cursor://anysphere.cursor-mcp/oauth/callback or com.example.app:/callback (RFC 8252). A scheme the browser runs or resolves itself is refused, in any letter case: javascript:, data:, vbscript:, file:, blob:, about: and filesystem:.

    And each URI is

    • without a fragment (no #);
    • made only of the characters RFC 3986 allows in a URI: letters, digits and -._~:/?#[]@!$&'()*+,;=, plus % only as a two-hex-digit escape such as %20. Percent-encode anything else, spaces and non-ASCII included.
  • Anything else in the request (grant_types, scope, logo_uri, …) is ignored and not stored.

A request that breaks one of these is answered 422, each broken rule named in its detail, and nothing is registered: one refused URI refuses the whole registration. /oauth/authorize later sends the code only to a redirect_uri you registered:

  • a loopback http URI (127.0.0.1, localhost or [::1]) on any port, or with none (RFC 8252 §7.3), so a client that picks a fresh port each time registers its URI once. The scheme, the host as written, the path and the query must be as registered: localhost and 127.0.0.1 are different hosts, so register each one your client may use;
  • any other URI exactly as registered, port included.

The code goes to the URI the authorize request named, and the token exchange must name that same URI, port included.

Authorizing

GET /oauth/authorize needs code_challenge_method=S256 and a code_challenge of 43 to 128 characters of A-Z, a-z, 0-9, -, ., _ and ~ (an S256 challenge, base64url without padding, is always 43 of them). A malformed challenge, an unknown or unapproved client, or a redirect_uri you did not register is a 400 JSON body with "error": "invalid_request", never a redirect.

A web client may open the consent page in a popup. Every page and redirect of the flow, up to your redirect_uri, leaves the popup’s window.opener in place: your callback page can post the code back to the window that opened it, and that window can watch popup.closed to notice the player closing it.

Exchanging the code

POST /oauth/token needs a code_verifier of 43 to 128 characters of the same alphabet (RFC 7636). A code is good for one exchange, within 10 minutes of being issued. Every refusal the exchange makes is a 400 with an RFC 6749 error and an error_description. A request missing one of the five form fields (grant_type, code, redirect_uri, client_id, code_verifier) never reaches the exchange: it is answered 422, with a detail list and no error.

errorWhen
unsupported_grant_typegrant_type is not authorization_code.
invalid_clientclient_id names no registered client.
invalid_grantThe code is unknown, expired, already used, or was issued to another client; redirect_uri is not the one the code was issued for; code_verifier is malformed or does not match the challenge; the account has been deactivated, or its email is not verified; the realm has no active season, or its season has run its length (“Season has ended”).
access_deniedThe account has no API-access entitlement.

A code presented a second time is refused (invalid_grant, “Authorization code already used.”) and the token its first exchange issued is revoked at once, whatever client_id, redirect_uri or code_verifier the second request names (RFC 6749 §4.1.2): a second exchange means the code has leaked. The agent holding that token then gets 401 Invalid token. and has to authorize again. So exchange each code exactly once, and never retry an exchange that may have succeeded (a timeout, a dropped connection): start the flow over instead.