What is auth?
Auth covers two things:| Term | Definition | Example |
|---|---|---|
| Authentication | Verify the caller is who they claim to be | Valid API key or credentials |
| Authorization | Verify the caller can access the requested resource | Read-only vs. admin access (RBAC) |
Basic authentication flow
The simplest approach is to require anAuthorization header on every request and validate it in server middleware:
Implementing auth middleware
- Python
- TypeScript
Add Starlette middleware that validates the
Authorization header before the request reaches MCP handlers:Creating the server and Starlette app
Making an authenticated client request
Once your server requires auth, clients must include theAuthorization header:
- Python
- curl
Role-Based Access Control (RBAC)
After verifying identity, you can also check permissions per route or tool:Key takeaways
- Add a middleware layer that validates the
Authorizationheader before requests reach MCP handlers. - Return
401 Unauthorizedfor missing tokens,403 Forbiddenfor invalid ones. - RBAC maps tokens to permission sets and checks per action.
- Upgrade to OAuth 2.1 for production — this basic pattern is a stepping stone, not a final destination.