From 57d1936f2906affede2ded7a6397a6465f9be88c Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:16:13 -0400 Subject: [PATCH] Return AuthorizationCodeResult from OAuth callback_handler (SDK v2) --- fastmcp_slim/fastmcp/client/auth/oauth.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fastmcp_slim/fastmcp/client/auth/oauth.py b/fastmcp_slim/fastmcp/client/auth/oauth.py index 7c7d5cb84..2a15697b6 100644 --- a/fastmcp_slim/fastmcp/client/auth/oauth.py +++ b/fastmcp_slim/fastmcp/client/auth/oauth.py @@ -14,6 +14,7 @@ from key_value.aio.stores.memory import MemoryStore from mcp.client.auth import OAuthClientProvider, TokenStorage from mcp.shared._httpx_utils import McpHttpClientFactory from mcp.shared.auth import ( + AuthorizationCodeResult, OAuthClientInformationFull, OAuthClientMetadata, OAuthToken, @@ -360,8 +361,8 @@ class OAuth(OAuthClientProvider): logger.info(f"OAuth authorization URL: {authorization_url}") webbrowser.open(authorization_url) - async def callback_handler(self) -> tuple[str, str | None]: - """Handle OAuth callback and return (auth_code, state).""" + async def callback_handler(self) -> AuthorizationCodeResult: + """Handle OAuth callback and return the authorization code result.""" # Create result container and event to capture the OAuth response result = OAuthCallbackResult() result_ready = anyio.Event() @@ -387,7 +388,11 @@ class OAuth(OAuthClientProvider): await result_ready.wait() if result.error: raise result.error - return result.code, result.state # type: ignore + # `result.code` is set once `result_ready` fires without error. + return AuthorizationCodeResult( + code=result.code, # type: ignore[arg-type] # ty:ignore[invalid-argument-type] + state=result.state, + ) except TimeoutError as e: raise TimeoutError( f"OAuth callback timed out after {self._callback_timeout} seconds"