From 3d988629953483bd7ff1b4b812adcd4c15d00e90 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 17 Jan 2026 14:25:29 -0500 Subject: [PATCH] Fix auth test to expect None instead of AuthorizationError --- tests/server/auth/test_authorization.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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()