Skip to main content

fastmcp.server.middleware.authorization

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:

Classes

AuthMiddleware

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).
Methods:

on_list_tools

Filter tools/list response based on auth checks.

on_call_tool

Check auth before tool execution.

on_list_resources

Filter resources/list response based on auth checks.

on_read_resource

Check auth before resource read.

on_list_resource_templates

Filter resource templates/list response based on auth checks.

on_list_prompts

Filter prompts/list response based on auth checks.

on_get_prompt

Check auth before prompt render.