Before you start
- A MudraID account, with your platform registered (step 1 below).
- A FastAPI or Starlette application.
- Python 3.10 or newer.
1. Register your platform
Sign in to the MudraID portal, create a platform, and verify you own its domain (a DNS TXT record). Then define the scopes your routes will require — the permissions you’ll hand out to agents, likeitems:read and items:write.
You’ll get a platform_id. Keep it; it ties tokens to your platform.
2. Get your scopes file
The portal generates amudraid_scopes.yaml for your platform. It maps each route to one of three outcomes: a required scope, an open public route, or a hidden skip route.
3. Install the middleware
During the v0.1 alpha the package isn’t on PyPI yet. Install from source:
pip install -e sdks/mudraid-middleware-python from the repo root.4. Add the middleware
mudraid_scopes.yaml in front of all of them.
Verify it works
With the stack running, try the routes by hand:What just happened
For every incoming request, the middleware now:- Matches the method and path against your YAML.
- Lets public routes through untouched.
- Reads the
Authorization: Bearertoken. - Verifies its signature, issuer, audience, and timing against MudraID’s published keys — locally, no per-request callback.
- Checks the route’s required scope is present in the token.
- Forwards to your handler, or returns a structured
{"error_code", "message"}error.
Troubleshooting
| What you see | What it means | Fix |
|---|---|---|
Every authed call returns WRONG_AUDIENCE | Your YAML’s platform_id doesn’t match what MudraID issued | Re-export mudraid_scopes.yaml from the portal and redeploy |
MIDDLEWARE_NOT_READY (500) | The YAML couldn’t be loaded or parsed | Fix the file; the next request recovers without a restart |
JWKS_UNAVAILABLE (500) | The middleware couldn’t reach MudraID’s keys | Transient network issue to MudraID; check connectivity |
| A route unexpectedly 404s | It has no rule in the YAML, or is marked skip | Add a rule for it |
Next steps
Define scopes
Design the permissions your API exposes.
Manage the scopes lifecycle
How changes roll out safely.
Error responses
The stable error_code contract.
Survive key rotation
Why rotation needs no action from you.

