Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/tools/test_mcp_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ def test_noninteractive_with_cached_tokens_no_warning(self, tmp_path, monkeypatc

def test_build_client_metadata_basic():
"""_build_client_metadata returns metadata with expected defaults."""
pytest.importorskip("mcp")
from tools.mcp_oauth import _build_client_metadata, _configure_callback_port

cfg = {"client_name": "Test Client"}
Expand All @@ -453,6 +454,7 @@ def test_build_client_metadata_basic():

def test_build_client_metadata_without_secret_is_public():
"""Without client_secret, token endpoint auth is 'none' (public client)."""
pytest.importorskip("mcp")
from tools.mcp_oauth import _build_client_metadata, _configure_callback_port

cfg = {}
Expand All @@ -463,6 +465,7 @@ def test_build_client_metadata_without_secret_is_public():

def test_build_client_metadata_with_secret_is_confidential():
"""With client_secret, token endpoint auth is 'client_secret_post'."""
pytest.importorskip("mcp")
from tools.mcp_oauth import _build_client_metadata, _configure_callback_port

cfg = {"client_secret": "shh"}
Expand Down
10 changes: 7 additions & 3 deletions tools/mcp_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,24 @@
# Lazy imports -- MCP SDK with OAuth support is optional
# ---------------------------------------------------------------------------

_OAUTH_AVAILABLE = False
_OAUTH_AVAILABLE=False
try:
from mcp.client.auth import OAuthClientProvider
from mcp.shared.auth import (
OAuthClientInformationFull,
OAuthClientMetadata,
OAuthToken,
)
from pydantic import AnyUrl

_OAUTH_AVAILABLE = True
_OAUTH_AVAILABLE=True
except ImportError:
logger.debug("MCP OAuth types not available -- OAuth MCP auth disabled")

try:
from pydantic import AnyUrl
except ImportError:
AnyUrl = None # type: ignore[assignment, misc]


# ---------------------------------------------------------------------------
# Exceptions
Expand Down
Loading