Connect an agent
An agent reaches the gateway through one URL: /mcp. It speaks MCP over streamable HTTP. The
gateway is stateless, so each request carries the player’s identity and nothing is kept in a
session.
What the agent sees
Section titled “What the agent sees”- A tool list. Names, descriptions and argument types, all taken from your manifest. Read
tools are marked read only. Tools in the
sensitivetier are never listed (that tier is disabled), and a coach grant sees only read tools. - Results. A success is
{"ok":true,"data":{...}}. Thedatais whatever your backend returned. - Denials the agent can act on. A refusal comes back as a tool error (
isError) with a body like{"ok":false,"code":"daily_amount_cap","message":"sell_resource: 400 needed, 250 left today"}. The message says what to do next. The same body is also sent asstructuredContent.
Common codes: invalid_arguments (fix the arguments), rate_limited (wait), cooldown or
daily_amount_cap (try later or less), scope_insufficient (ask the player for operator
access), confirmation_required (ask the player to approve, then repeat the exact call),
switched_off (do not retry), backend_unavailable (nothing changed), outcome_unknown (the
game may or may not have applied the call, check state first).
Local trying: dev auth
Section titled “Local trying: dev auth”The demo gateway runs with --dev-auth. It takes the player from an X-Dev-Player header and
trusts it, so keep it on loopback. After docker compose up -d --build, the MCP endpoint is
http://127.0.0.1:8080/mcp.
Any MCP client that can send a custom header can connect:
URL: http://127.0.0.1:8080/mcpHeader: X-Dev-Player: p1Try it with plain curl
Section titled “Try it with plain curl”With --dev-auth you can talk to /mcp without an MCP client. The player and an Accept header that
allows both reply types are required. MCP-Protocol-Version is optional here, and real clients send it.
curl -s -X POST http://127.0.0.1:8080/mcp \ -H 'X-Dev-Player: p1' -H 'Content-Type: application/json' \ -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2025-06-18' \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'The answer lists the tools from the manifest, each with its input schema.
Now make a real agent call. tools/call takes the tool name and its arguments:
curl -s -X POST http://127.0.0.1:8080/mcp \ -H 'X-Dev-Player: p1' -H 'Content-Type: application/json' \ -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2025-06-18' \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_city_state","arguments":{}}}'{"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"{\"data\":{\"coins\":500,\"resources\":{\"food\":60,\"materials\":60,\"water\":60},\"buildings\":0},\"ok\":true}"}],"structuredContent":{"data":{"coins":500,"resources":{"food":60,"materials":60,"water":60},"buildings":0},"ok":true}}}The numbers are those of a fresh city. A denial looks the same, with "isError":true and the
code and message in structuredContent.
Claude Desktop
Section titled “Claude Desktop”For a gateway published on a public HTTPS address, players add it as a custom connector in Claude, with no install. The steps, written for players, are in tutorial 12.
For a gateway on your own machine, Claude Desktop cannot reach an http://localhost URL itself.
gwbridge fills the gap. It speaks stdio to Claude and forwards every call to the gateway’s
/mcp. It holds no policy, so limits, scopes and audit stay in the gateway. Setup steps and the
config snippet are in Use the gateway from Claude Desktop.
Real deployments: OAuth
Section titled “Real deployments: OAuth”Without --dev-auth, /mcp needs a bearer token and the header-trusting dev API is not
mounted. An MCP client finds out how to sign in by itself:
- The client asks
/mcpand gets401with a pointer to the gateway’s OAuth metadata. - It registers itself and starts an authorization request with PKCE.
- The gateway shows a consent page. The player is already logged in on your site, and the
gateway has no login of its own. So your backend asks the gateway for a link ticket, a short
code such as
ABCD-EFGH. It lives 5 minutes and works once. Your site shows it to the player. - The player types the code on the consent page and chooses coach or operator.
- The client receives a token. Access tokens last 15 minutes and refresh tokens rotate.
The link ticket is how the gateway learns which player is behind the agent, without trusting the agent or the client. Your backend mints it with a signed request, so only you can say who the player is.
The player can see and revoke linked agents in your game (you call the signed
/v1/studio/grants endpoints). Revoking takes effect on the agent’s next request. The full flow
and endpoints are in the protocol and
players, grants and confirmations.
Check it works
Section titled “Check it works”Ask the agent to call get_city_state (in the demo). Then watch the gateway log for
agent_call lines, one for every attempt:
docker compose logs -f gateway | grep agent_call