Skip to content

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

fix oauth pyright

William Eastond1615dfe20d3
diff --git a/src/fastmcp/client/auth/oauth.py b/src/fastmcp/client/auth/oauth.py
index 06f71253e..9a369bf4d 100644
--- a/src/fastmcp/client/auth/oauth.py
+++ b/src/fastmcp/client/auth/oauth.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import asyncio
import json
import webbrowser
+from _asyncio import Future
from pathlib import Path
from typing import Any, Literal
from urllib.parse import urlparse
@@ -18,6 +19,7 @@ from mcp.shared.auth import (
OAuthToken as OAuthToken,
)
from pydantic import AnyHttpUrl, ValidationError
+from uvicorn.server import Server
from fastmcp import settings as fastmcp_global_settings
from fastmcp.client.oauth_callback import (
@@ -253,14 +255,16 @@ class OAuth(OAuthClientProvider):
async def callback_handler(self) -> tuple[str, str | None]:
"""Handle OAuth callback and return (auth_code, state)."""
# Create a future to capture the OAuth response
- response_future = asyncio.get_running_loop().create_future()
+ response_future: Future[Any] = asyncio.get_running_loop().create_future()
# Create server with the future
- server = create_oauth_callback_server(
+ server: Server = create_oauth_callback_server(
port=self.redirect_port,
server_url=self.server_base_url,
response_future=response_future,
)
+ auth_code: str
+ state: str | None
# Run server until response is received with timeout logic
async with anyio.create_task_group() as tg:
@@ -280,3 +284,5 @@ class OAuth(OAuthClientProvider):
server.should_exit = True
await asyncio.sleep(0.1) # Allow server to shutdown gracefully
tg.cancel_scope.cancel()
+
+ raise RuntimeError("OAuth callback handler could not be started")
\ No newline at end of file