Skip to content

Tutorial 1: Play the example game with an agent

Verified against gamewarden v0.2.0 (see the changelog). About 15 minutes. The script 01-play-the-example-game.sh runs every command below against a throwaway Docker project, and CI runs that script.

You will start the example game, call its tools by hand, run into a daily cap and a cooldown, connect an agent through the gwbridge stdio bridge, and read the audit trail.

  • Docker with Compose v2. Nothing else is installed on your machine.
  • The repository: git clone https://github.com/Moustafa-Elgammal/gamewarden && cd gamewarden
  • Optional, for the last step of the agent part: Claude Desktop, or any MCP client that can launch a stdio server.

The basics (start, call, denials) are in the quickstart. This tutorial repeats only what it needs and then goes deeper.

Terminal window
docker compose up --build -d
curl -s http://127.0.0.1:8080/healthz

The gateway runs with --dev-auth, so the player comes from the X-Dev-Player header. That is for local trying only. The script uses port 18101 instead of 8080 so it never collides with a demo you already have running. Everything else is identical.

A small helper makes the next commands shorter:

Terminal window
call() { curl -s -X POST -H 'X-Dev-Player: p1' -d "$2" "http://127.0.0.1:8080/v1/tools/$1/call"; }
call get_city_state '{}'
call sell_resource '{"arguments":{"resource":"food","quantity":50}}'

You should see "coins":500 first and "earned":100 after the sale.

In examples/city/manifest.yaml, sell_resource has caps: {per_day_amount: 300, amount_param: quantity}. The cap counts the amount sold, not the number of calls. You have sold 50. Ask for 400 more:

Terminal window
call sell_resource '{"arguments":{"resource":"water","quantity":400}}'
{"ok":false,"code":"daily_amount_cap","message":"sell_resource: 400 needed, 250 left today"}

The call never reached the game. The gateway reserves the amount before it calls the backend, so concurrent calls cannot slip past the cap. The message says how much is left today, so an agent can ask for less. The game may still refuse a smaller sale: the demo city starts with 60 of each resource, shared by every player, so a retry with 250 gets backend_rejected with not_enough_water. The cap is the gateway’s limit; the stock is the game’s.

collect_taxes has caps: {cooldown_seconds: 60}:

Terminal window
call collect_taxes '{}'
call collect_taxes '{}'
{"ok":true,"data":{"coins":625,"collected":25}}
{"ok":false,"code":"cooldown","message":"collect_taxes is available again in 60 seconds"}

Claude Desktop launches stdio MCP servers. It cannot reach http://localhost, so gwbridge sits in between: MCP over stdio on one side, the gateway’s /mcp endpoint on the other. It holds no policy, so the caps above apply to the agent exactly as they applied to curl.

Build the image:

Terminal window
docker compose build bridge

Ask it for the tool list, the way an MCP client does. This sends three JSON-RPC lines (initialize, initialized, tools/list) to the bridge’s stdin. The network name is <project>_default, and the project is gamewarden unless you changed it:

Terminal window
{
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"tutorial","version":"1"}}}'
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
sleep 3
} | docker run -i --rm --network gamewarden_default gamewarden-bridge:latest \
--url http://gateway:8080/mcp --header "X-Dev-Player: desktop"

The reply lists get_city_state, collect_taxes, build_structure and sell_resource, each with the description and parameter schema from the manifest. A call goes the same way, with "method":"tools/call","params":{"name":"get_city_state","arguments":{}}.

To use it from Claude Desktop, add this to claude_desktop_config.json (use the absolute path to your docker):

{"mcpServers":{"city":{"command":"/usr/local/bin/docker","args":["run","-i","--rm","gamewarden-bridge:latest","--url","http://host.docker.internal:8080/mcp","--header","X-Dev-Player: desktop"]}}}

host.docker.internal exists on Docker Desktop (macOS and Windows). On Linux it does not, and the demo publishes its ports on 127.0.0.1 only, which a container cannot reach. Join the demo’s network instead, as the test above does:

{"mcpServers":{"city":{"command":"/usr/bin/docker","args":["run","-i","--rm","--network","gamewarden_default","gamewarden-bridge:latest","--url","http://gateway:8080/mcp","--header","X-Dev-Player: desktop"]}}}

Restart Claude Desktop and ask it: “Look at my city, then sell 5 food.” The city is shared by every player, and your curl sale left it with about 10 food, so keep the amount small. Then ask it to sell 400 water. It meets the same daily_amount_cap and, because the code and message are plain, it will usually adjust the amount by itself. More on this in Connect an agent.

X-Dev-Player only works against a gateway started with --dev-auth. A real deployment gives the bridge a bearer token instead. That is tutorial 4.

Every attempt, allowed or refused, is an audit event. In the demo they go to the gateway log:

Terminal window
docker compose logs --no-log-prefix gateway | grep agent_call

You will find the denials and the bridge’s calls ("player":"desktop"):

{"time":"...","level":"INFO","msg":"agent_call","tenant":"dev","player":"p1","tool":"sell_resource","tier":"medium","outcome":"denied","code":"daily_amount_cap","args_sha256":"..."}
{"time":"...","level":"INFO","msg":"agent_call","tenant":"dev","player":"desktop","tool":"get_city_state","tier":"read","outcome":"ok","code":"","args_sha256":"..."}

Look at what is not there: the arguments. The audit stores a SHA-256 of them, so it can prove two calls were identical without keeping game data. With OAuth the same events feed the player’s activity feed (/v1/studio/activity).

Terminal window
docker compose down
  • A cap counts what you can lose (units sold), a cooldown spaces calls out, and both answer with a code the agent can read.
  • gwbridge turns any gateway into a stdio MCP server, and it adds no policy of its own.
  • The audit log records every attempt and never the arguments.

Tutorial 2: describe your game’s actions.