Authorization middleware for FastMCP.This module provides middleware-based authorization using callable auth checks.
AuthMiddleware applies auth checks globally to all components on the server.Example:
from fastmcp import FastMCPfrom fastmcp.server.auth import require_scopes, restrict_tagfrom fastmcp.server.middleware import AuthMiddleware# Require specific scope for all componentsmcp = FastMCP(middleware=[ AuthMiddleware(auth=require_scopes("api"))])# Tag-based: components tagged "admin" require "admin" scopemcp = FastMCP(middleware=[ AuthMiddleware(auth=restrict_tag("admin", scopes=["admin"]))])
Global authorization middleware using callable checks.This middleware applies auth checks to all components (tools, resources,
prompts) on the server. It uses the same callable API as component-level
auth checks.The middleware:
Filters tools/resources/prompts from list responses based on auth checks
Checks auth before tool execution, resource read, and prompt render
Skips all auth checks for STDIO transport (no OAuth concept)
Args:
auth: A single auth check function or list of check functions.
All checks must pass for authorization to succeed (AND logic).