Authentication
This page is about signing in to the MCP server. The REST API signs in differently, with an email and password and a bearer token: see REST API.
The MCP server is an OAuth 2.1 resource server. Access is bound to a Casafari account with an MCP subscription: a token carries exactly that account's rights. Casafari does not use OAuth scopes; rights are per tool and resolved from the account on every call. The canonical, agent-facing version of this page is casafari.com/auth.md.
Discovery
A request without a token answers:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token", resource_metadata="https://mcp.casafari.com/.well-known/oauth-protected-resource"- Fetch the protected resource metadata, https://mcp.casafari.com/.well-known/oauth-protected-resource. Its
resourceis the server's canonical URL: send it as theresourceparameter in every authorization and token request, because tokens are bound to it as their audience. - Fetch the authorization server metadata, https://api.casafari.com/.well-known/oauth-authorization-server, for the registration, authorization and token endpoints.
Sign in on behalf of a person
- Register (once):
POSTto the registration endpoint with your client name and redirect URIs,grant_types["authorization_code", "refresh_token"]andtoken_endpoint_auth_methodnone. Keep theclient_id. - Authorize: send the person to the authorization endpoint with PKCE (
S256),stateandresource. They sign in with their Casafari account and approve. - Exchange the code at the token endpoint, again with
resourceand the PKCE verifier. - Call the server with
Authorization: Bearer <access_token>. - Refresh with the refresh token when
expires_inruns out. A401witherror="invalid_token"on a token that used to work means it expired or was revoked: refresh it, and if that fails, authorize again. Keep the client; do not register again.
Agents without a person
An agent that runs unattended uses the client credentials grant. Such a client cannot register itself: Casafari issues a client_id and client_secret for the account, and the account owner hands them to the agent.
Errors
| Status | Where | Meaning | What to do |
|---|---|---|---|
400 invalid_client_metadata | Registration | Unsupported grant types, redirect URIs or auth method | Fix the request; never ask for client_credentials there |
401 invalid_client | Token endpoint | Unknown client_id or wrong secret | Check the credential |
401 invalid_token | MCP server | Token missing, expired, revoked or bound to another resource | Refresh; if that fails, authorize again |
| Tool missing, or a call refused | MCP server | The account has no right to that tool | Do not retry; the subscription does not cover it |
Request limit reached for this product. | MCP server | The product's quota is used up | Stop calling that product |
5xx | Anywhere | Transient error | Retry with exponential backoff |