gamewarden
README.md
# gamewarden
[](https://github.com/Moustafa-Elgammal/gamewarden/actions/workflows/ci.yml)
[](https://pkg.go.dev/github.com/Moustafa-Elgammal/gamewarden)
[](LICENSE)
[](https://github.com/Moustafa-Elgammal/gamewarden/releases)
**An open-source gateway that lets a player's own AI agent act safely inside a game.**
Players are starting to bring their own AI agents. A studio that lets them in needs limits the
agent cannot talk its way past: caps, cooldowns, confirmations and an off switch. gamewarden puts
those limits in one place, in front of your existing backend, with no change to your game code.
A game studio describes its game actions in a manifest. The gateway turns them into
[MCP](https://modelcontextprotocol.io) tools, applies safety policy (tiers, rate limits,
daily caps, cooldowns, kill switches, player confirmations), calls the studio's backend with a
signed request, and records every attempt in an audit log. It works with any backend language,
because the contract is a manifest plus a signed HTTP request, not a library. Games whose logic
runs in the client can use a WebSocket relay instead.

## What an agent cannot talk its way past
- **Every attempt counts.** Rate limits run before argument checks, so an agent that keeps sending
bad calls is throttled like any other.
- **Failures cost nothing.** A backend call that fails releases its reserved cap and starts no
cooldown.
- **The player approves risky actions.** Tools marked `confirm: true` wait for the player.
- **The studio has an off switch.** Kill switches per tool, per player or for the whole game,
signed with an admin key.
- **The audit log keeps no arguments.** It stores a hash, so a log leak is not a data leak.
## Two modes for players
- **Coach**: read-only. State, prices, advice.
- **Operator**: limited actions on the player's behalf, inside caps the studio controls.
A studio can start a pilot read only for everyone with `--max-scope coach`, then raise it to
operator later.
## Quickstart
You only need Docker with Compose v2. Nothing is installed on your machine.
```bash
git clone https://github.com/Moustafa-Elgammal/gamewarden && cd gamewarden
docker compose up --build # gateway, Redis, Postgres and a fake city backend on 127.0.0.1:8080
# in another terminal: let a player "sell" some food through the gateway
curl -s -X POST -H 'X-Dev-Player: p1' \
-d '{"arguments":{"resource":"food","quantity":50}}' \
http://127.0.0.1:8080/v1/tools/sell_resource/call
docker compose down
```
You should see `{"ok":true,"data":{"coins":600,"earned":100}}`. Ask for more than the daily cap
and you get `{"ok":false,"code":"daily_amount_cap",...}` instead. To watch it happen in about a
minute, run `scripts/demo.sh` (how to record it: [docs/DEMO.md](docs/DEMO.md)).
An expected failure comes back as a result with a machine-readable `code` and a hint, for
example `invalid_arguments`, `rate_limited`, `daily_amount_cap`, `cooldown` or `switched_off`.
The agent can read it and correct itself. The demo runs with `--dev-auth`, which trusts a
header and must stay on loopback. Real deployments use OAuth (see the docs).
The same stack also serves HTTPS on `https://gamewarden.test` and `https://localhost`
(port 443; set `GAMEWARDEN_HTTPS_PORT` to use another host port). Point the domain at your machine
with a `127.0.0.1 gamewarden.test` line in `/etc/hosts`, or pick another name with
`GAMEWARDEN_TLS_DOMAIN`. An nginx service (`https`, config in `deploy/nginx/gateway.conf`)
terminates TLS with a self-signed certificate that the `tls-cert` service creates in the
`tls-certs` volume, and creates again when the domain changes. Use `curl -k`, or export the
certificate with `docker compose cp https:/etc/nginx/certs/tls.crt ./gamewarden-dev.crt` and
trust it. A container, such as the MCP bridge, can mount the volume and set
`SSL_CERT_FILE=/certs/tls.crt`. Step by step: [docs/guides/local-https.md](docs/guides/local-https.md).
Run the tests: `docker compose run --rm dev make test`. To connect Claude Desktop, see
[docs/CLAUDE-DESKTOP.md](docs/CLAUDE-DESKTOP.md).
## Status and compatibility
Version `0.1` (before 1.0). The pipeline, MCP endpoint, OAuth 2.1, Redis and Postgres stores, confirmations,
manifest upload and rollback, activity feed, relay, metrics, a Helm chart, optional OIDC sign-in
at consent, the project site and twelve tutorials are built. The tutorial scripts run in CI,
except the two Kubernetes ones: tutorial 11 (Docker Desktop) has been run against a real cluster,
and tutorial 9 (kind) runs with `make k8s-tutorial-check` and has not been run yet. OIDC sign-in has been run against Dex and Keycloak. Not yet: a hosted offering, a
hosted identity provider, and Unity player builds of the relay client (its sample runs in the Unity
editor; see [docs/ROADMAP.md](docs/ROADMAP.md)).
Before 1.0, the manifest format, the signed request and some protocol details
may still change. Every such change is recorded in [docs/DECISIONS.md](docs/DECISIONS.md) and
the [CHANGELOG](CHANGELOG.md). Pin a version if you build on it.
## Features
- A manifest, written in YAML (JSON also works), becomes MCP tools. Strict validation reports every problem at once.
- Policy: rate limits counted before validation, daily caps with reserve and settle, cooldowns,
tiers, kill switches. Policy outages fail closed.
- Signed backend calls (HMAC-SHA256, timestamp, idempotency key). Go backends can import
[`pkg/agentsig`](pkg/agentsig); other languages follow [docs/PROTOCOL.md](docs/PROTOCOL.md).
- Player confirmations for sensitive tools, linked through an embedded OAuth 2.1 server.
- Versioned manifests with upload, rollback and hot swap, no restart. Key rotation.
- Activity feed for players and studios. Audit stores hashes of arguments, never the arguments.
- Relay for client-authoritative games, across several gateway replicas.
- Sign-in with your own identity provider at consent (OIDC, confidential or public client).
- Metrics, health checks, an SSRF-safe connector, a Helm chart and a runbook.
- Measured, not claimed: a 1 hour soak and an overhead benchmark you can repeat
([results](https://elgx.me/gamewarden/project/soak-history/)).
The full component list is in [docs/FEATURES.md](docs/FEATURES.md).
## Design rules
1. The agent plays by the same rules as a human. No side doors around game logic.
2. Every attempt counts against rate limits, valid or not.
3. Caps reserve first and settle after, so concurrent calls cannot exceed them.
4. Policy outage means action tiers fail closed.
5. Backend results are untrusted data, never instructions.
6. The audit log stores hashes of arguments, not game data.
## Docs
- New here? [Overview](docs/get-started/overview.md), [quickstart](docs/get-started/quickstart.md), [connect an agent](docs/get-started/connect-an-agent.md) and the [glossary](docs/get-started/glossary.md)
- Guides: [learning path](docs/guides/index.md), [best practices](docs/guides/best-practices.md), [cookbook](docs/guides/cookbook.md), [troubleshooting](docs/guides/troubleshooting.md), [FAQ](docs/guides/faq.md)
- Concepts: [how a call flows](docs/concepts/pipeline.md), [tiers and policy](docs/concepts/tiers-and-policy.md), [players, grants and confirmations](docs/concepts/players-grants-confirmations.md)
- [Architecture](docs/ARCHITECTURE.md) and [features](docs/FEATURES.md)
- [Manifest](docs/MANIFEST.md)
- [Signed request protocol](docs/PROTOCOL.md)
- [Security model](docs/SECURITY-MODEL.md)
- [Runbook](docs/RUNBOOK.md) and [releasing](docs/RELEASING.md)
- [Roadmap](docs/ROADMAP.md), [decisions](docs/DECISIONS.md)
## Contributing and security
Small, focused pull requests are easiest to review. Read
[CONTRIBUTING.md](CONTRIBUTING.md) and [AGENTS.md](AGENTS.md). Report vulnerabilities privately,
see [SECURITY.md](SECURITY.md).
This is an independent project. It contains no code, data or API details from any employer or
real game. The example game is fictional.
## License
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE). Contributions are accepted under
Apache-2.0.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues