Skip to content

Commit 0e9ef23

Browse files
committed
Add FastMCP OAuth override to fix callback URL printing
1 parent dcc517b commit 0e9ef23

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/mcp_importer/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
)
2424
from src.mcp_importer.merge import MergePolicy, merge_servers
2525
from src.oauth_manager import get_oauth_manager
26+
from src.oauth_override import OpenEdisonOAuth
2627

2728

2829
class CLIENT(str, Enum):
@@ -211,7 +212,6 @@ async def _authorize_async() -> bool:
211212
try:
212213
# Import lazily to avoid import-time side effects
213214
from fastmcp import Client as FastMCPClient # type: ignore
214-
from fastmcp.client.auth import OAuth # type: ignore
215215

216216
# Debug info prior to starting OAuth
217217
print(
@@ -223,7 +223,7 @@ async def _authorize_async() -> bool:
223223
f"client_name={server.oauth_client_name or 'Open Edison Setup'}",
224224
)
225225

226-
oauth = OAuth(
226+
oauth = OpenEdisonOAuth(
227227
mcp_url=remote_url,
228228
scopes=server.oauth_scopes,
229229
client_name=server.oauth_client_name or "Open Edison Setup",

src/oauth_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
)
2020
from loguru import logger as log
2121

22+
from src.oauth_override import OpenEdisonOAuth
23+
2224

2325
class OAuthStatus(Enum):
2426
"""OAuth authentication status for MCP servers."""
@@ -209,7 +211,7 @@ def get_oauth_auth(
209211
return None
210212

211213
try:
212-
oauth = OAuth(
214+
oauth = OpenEdisonOAuth(
213215
mcp_url=mcp_url,
214216
scopes=scopes or info.scopes,
215217
client_name=client_name or info.client_name,

src/oauth_override.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import webbrowser
2+
3+
from fastmcp.client.auth.oauth import OAuth as _FastMCPOAuth
4+
5+
6+
class OpenEdisonOAuth(_FastMCPOAuth):
7+
async def redirect_handler(self, authorization_url: str) -> None: # noqa: ARG002
8+
# Print a clean, single-line URL and still open the browser.
9+
print(f"OAuth authorization URL: {authorization_url}", flush=True)
10+
webbrowser.open(authorization_url)

src/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
create_db_session,
3737
)
3838
from src.oauth_manager import OAuthStatus, get_oauth_manager
39+
from src.oauth_override import OpenEdisonOAuth
3940
from src.single_user_mcp import SingleUserMCP
4041
from src.telemetry import initialize_telemetry, set_servers_installed
4142

@@ -954,10 +955,9 @@ async def oauth_test_connection(
954955

955956
# Import FastMCP client for testing
956957
from fastmcp import Client as FastMCPClient
957-
from fastmcp.client.auth import OAuth
958958

959959
# Create OAuth auth object
960-
oauth = OAuth(
960+
oauth = OpenEdisonOAuth(
961961
mcp_url=remote_url,
962962
scopes=scopes,
963963
client_name=client_name or "OpenEdison MCP Gateway",

src/vulture_whitelist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from src.oauth_override import OpenEdisonOAuth
2+
3+
OpenEdisonOAuth.redirect_handler # noqa: B018 unused method (src/oauth_override.py:7)

0 commit comments

Comments
 (0)