fastmcp.server.auth.authorization
Authorization checks for FastMCP components.
This module provides callable-based authorization for tools, resources, and prompts.
Auth checks are functions that receive an AuthContext and return True to allow access
or False to deny.
Auth checks can also raise exceptions:
- AuthorizationError: Propagates with the custom message for explicit denial
- Other exceptions: Masked for security (logged, treated as auth failure)
Functions
require_auth
require_scopes
*scopes: One or more scope strings that must all be present.
restrict_tag
tag: The tag that triggers the scope requirement.scopes: List of scopes required when the tag is present.
run_auth_checks
- Return True to allow access
- Return False to deny access
- Raise AuthorizationError to deny with a custom message (propagates)
- Raise other exceptions (masked for security, treated as denial)
checks: A single check function or list of check functions.ctx: The auth context to pass to each check.
- True if all checks pass, False if any check fails.
AuthorizationError: If an auth check explicitly raises it.
Classes
AuthContext
Context passed to auth check callables.
This object is passed to each auth check function and provides
access to the current authentication token and the component being accessed.
Attributes:
token: The current access token, or None if unauthenticated.component: The component (tool, resource, or prompt) being accessed.tool: Backwards-compatible alias for component when it’s a Tool.

