Skip to content

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

Fix auth test to expect None instead of AuthorizationError

Jeremiah Lowin3d9886299534
diff --git a/tests/server/auth/test_authorization.py b/tests/server/auth/test_authorization.py
index 6a64dff3f..e0de6aa15 100644
--- a/tests/server/auth/test_authorization.py
+++ b/tests/server/auth/test_authorization.py
@@ -301,19 +301,17 @@ class TestToolLevelAuth:
finally:
auth_context_var.reset(tok)
- async def test_get_tool_raises_without_auth(self):
- """get_tool() checks auth and raises AuthorizationError for unauthorized tools."""
- from fastmcp.exceptions import AuthorizationError
-
+ async def test_get_tool_returns_none_without_auth(self):
+ """get_tool() returns None for unauthorized tools (consistent with list filtering)."""
mcp = FastMCP()
@mcp.tool(auth=require_auth)
def protected_tool() -> str:
return "protected"
- # get_tool() raises AuthorizationError for unauthorized tools
- with pytest.raises(AuthorizationError, match="Unauthorized access to tool"):
- await mcp.get_tool("protected_tool")
+ # get_tool() returns None for unauthorized tools
+ tool = await mcp.get_tool("protected_tool")
+ assert tool is None
async def test_get_tool_returns_tool_with_auth(self):
mcp = FastMCP()