Every setting has a default, so a new application needs none of them; this page lists each one with its environment variable.
The settings are the McpOAuthConfig config section. Set them in .env, or change the section in your own provider's config.
| Setting | Environment variable | Default | What it sets |
|---|---|---|---|
resource_path | MCP_OAUTH_RESOURCE_PATH | /mcp | The path of your MCP route. With APP_URL it is the resource tokens are issued for |
route_prefix | MCP_OAUTH_ROUTE_PREFIX | /oauth | Where register, authorize, token and revoke live |
scopes | MCP_OAUTH_SCOPES | mcp | At least one space-separated RFC 6749 scope token. The first is the default. An empty environment value uses the framework default. offline_access is always offered |
dynamic_registration | MCP_OAUTH_DCR | true | Dynamic client registration |
client_metadata_documents | MCP_OAUTH_CIMD | true | Client ID Metadata Documents |
access_token_ttl_seconds | MCP_OAUTH_ACCESS_TTL | 3600 | How long an access token works |
refresh_token_days | MCP_OAUTH_REFRESH_DAYS | 180 | How long a refresh token works, from issue |
refresh_grace_seconds | MCP_OAUTH_REFRESH_GRACE | 120 | The retry window for a refresh whose answer was lost |
code_ttl_seconds | MCP_OAUTH_CODE_TTL | 300 | How long an authorization code works |
pending_ttl_seconds | MCP_OAUTH_PENDING_TTL | 1800 | How long the approval page waits for a decision |
metadata_cache_hours | MCP_OAUTH_METADATA_CACHE_HOURS | 24 | How long a client's metadata document is cached |
metadata_max_stale_hours | MCP_OAUTH_METADATA_MAX_STALE_HOURS | 168 | How long cached metadata may stand in during a refresh or after a transient failure |
retention_days | MCP_OAUTH_RETENTION_DAYS | 90 | How long revoked grants stay in the connections list |
token_prefix | MCP_OAUTH_TOKEN_PREFIX | mcp_ | Gives mcp_at_, mcp_rt_ and mcp_ac_ |
client_id_prefix | MCP_OAUTH_CLIENT_ID_PREFIX | mcp_c_ | The start of dynamically registered client IDs |
table_prefix | MCP_OAUTH_TABLE_PREFIX | mcp_ | The start of the five table names. Use a distinct prefix for each resource |
migrations | MCP_OAUTH_MIGRATIONS | true | Whether the crate's migrations run. Turn off when another application owns the tables |
schedule_prune | MCP_OAUTH_SCHEDULE_PRUNE | true | Whether mcp-oauth:prune runs daily |
authorizations_per_hour | MCP_OAUTH_AUTHORIZATIONS_PER_HOUR | 60 | Per address, checked before any metadata document is fetched |
registrations_per_hour | MCP_OAUTH_REGISTRATIONS_PER_HOUR | 30 | Per address |
tokens_per_minute | MCP_OAUTH_TOKENS_PER_MINUTE | 60 | Per address with independent limits for the token and revocation endpoints |
approvals_per_hour | MCP_OAUTH_APPROVALS_PER_HOUR | 10 | Per account |
unauthorized_message | MCP_OAUTH_UNAUTHORIZED_MESSAGE | "Connect your account to use this server." | The description in the 401 |
The application refuses to start when a lifetime is zero, a prefix contains characters that aren't safe in tokens or SQL names, or APP_URL isn't HTTPS outside local and testing.
Provider options
Hooks and lists that an environment variable can't hold go on the provider:
| Method | What it does | Page |
|---|---|---|
can_approve(f) | Who may approve a connection | The approval page |
can_use(f) | Whether a user's tokens work right now | Protecting routes |
register_url(url) | The create-account link for guests | The approval page |
user_display(f) | The name and email the approval page shows | The approval page |
scope_label(scope, label) | What a scope lets the app do | The approval page |
protect_name(name) | A name unreviewed apps may not imitate | The approval page |
known_client(client) | An assistant to show as verified | Clients |
on_grant(f) | Runs after an approval | Tokens and connections |
with_integer_user_ids() | Integer user IDs in tables your application owns | Existing tables |
with_documents(fake) | Serve metadata documents from memory, for tests | Testing |
One resource per table set
The crate protects the MCP resource at APP_URL plus resource_path. Each set of tables serves
exactly one resource. Set a different table_prefix for each application with a different resource.
Only implementations of the same resource may share tables.
If you change resource_path under the same prefix, existing tokens keep working. To end those
connections, call McpOAuth::revoke_all for each user.