Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Use specific ValidationError instead of broad Exception catch

Jeremiah Lowin7b5ef3e5e5e0
diff --git a/src/fastmcp/server/auth/providers/bearer.py b/src/fastmcp/server/auth/providers/bearer.py
index e544802f9..a4f3a8e48 100644
--- a/src/fastmcp/server/auth/providers/bearer.py
+++ b/src/fastmcp/server/auth/providers/bearer.py
@@ -17,7 +17,7 @@ from mcp.shared.auth import (
OAuthClientInformationFull,
OAuthToken,
)
-from pydantic import AnyHttpUrl, SecretStr
+from pydantic import AnyHttpUrl, SecretStr, ValidationError
from fastmcp.server.auth.auth import (
ClientRegistrationOptions,
@@ -183,7 +183,7 @@ class BearerAuthProvider(OAuthProvider):
# This allows the issuer claim validation to work with string issuers per RFC 7519
try:
issuer_url = AnyHttpUrl(issuer) if issuer else "https://fastmcp.example.com"
- except Exception:
+ except ValidationError:
# Issuer is not a valid URL, use default for parent class
issuer_url = "https://fastmcp.example.com"