Spaces:
Sleeping
Sleeping
William Easton commited on
fix oauth pyright
Browse files
src/fastmcp/client/auth/oauth.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
| 3 |
import asyncio
|
| 4 |
import json
|
| 5 |
import webbrowser
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Any, Literal
|
| 8 |
from urllib.parse import urlparse
|
|
@@ -18,6 +19,7 @@ from mcp.shared.auth import (
|
|
| 18 |
OAuthToken as OAuthToken,
|
| 19 |
)
|
| 20 |
from pydantic import AnyHttpUrl, ValidationError
|
|
|
|
| 21 |
|
| 22 |
from fastmcp import settings as fastmcp_global_settings
|
| 23 |
from fastmcp.client.oauth_callback import (
|
|
@@ -253,14 +255,16 @@ class OAuth(OAuthClientProvider):
|
|
| 253 |
async def callback_handler(self) -> tuple[str, str | None]:
|
| 254 |
"""Handle OAuth callback and return (auth_code, state)."""
|
| 255 |
# Create a future to capture the OAuth response
|
| 256 |
-
response_future = asyncio.get_running_loop().create_future()
|
| 257 |
|
| 258 |
# Create server with the future
|
| 259 |
-
server = create_oauth_callback_server(
|
| 260 |
port=self.redirect_port,
|
| 261 |
server_url=self.server_base_url,
|
| 262 |
response_future=response_future,
|
| 263 |
)
|
|
|
|
|
|
|
| 264 |
|
| 265 |
# Run server until response is received with timeout logic
|
| 266 |
async with anyio.create_task_group() as tg:
|
|
@@ -280,3 +284,5 @@ class OAuth(OAuthClientProvider):
|
|
| 280 |
server.should_exit = True
|
| 281 |
await asyncio.sleep(0.1) # Allow server to shutdown gracefully
|
| 282 |
tg.cancel_scope.cancel()
|
|
|
|
|
|
|
|
|
| 3 |
import asyncio
|
| 4 |
import json
|
| 5 |
import webbrowser
|
| 6 |
+
from _asyncio import Future
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any, Literal
|
| 9 |
from urllib.parse import urlparse
|
|
|
|
| 19 |
OAuthToken as OAuthToken,
|
| 20 |
)
|
| 21 |
from pydantic import AnyHttpUrl, ValidationError
|
| 22 |
+
from uvicorn.server import Server
|
| 23 |
|
| 24 |
from fastmcp import settings as fastmcp_global_settings
|
| 25 |
from fastmcp.client.oauth_callback import (
|
|
|
|
| 255 |
async def callback_handler(self) -> tuple[str, str | None]:
|
| 256 |
"""Handle OAuth callback and return (auth_code, state)."""
|
| 257 |
# Create a future to capture the OAuth response
|
| 258 |
+
response_future: Future[Any] = asyncio.get_running_loop().create_future()
|
| 259 |
|
| 260 |
# Create server with the future
|
| 261 |
+
server: Server = create_oauth_callback_server(
|
| 262 |
port=self.redirect_port,
|
| 263 |
server_url=self.server_base_url,
|
| 264 |
response_future=response_future,
|
| 265 |
)
|
| 266 |
+
auth_code: str
|
| 267 |
+
state: str | None
|
| 268 |
|
| 269 |
# Run server until response is received with timeout logic
|
| 270 |
async with anyio.create_task_group() as tg:
|
|
|
|
| 284 |
server.should_exit = True
|
| 285 |
await asyncio.sleep(0.1) # Allow server to shutdown gracefully
|
| 286 |
tg.cancel_scope.cancel()
|
| 287 |
+
|
| 288 |
+
raise RuntimeError("OAuth callback handler could not be started")
|