Skip to content

fix(mcp): decouple AnyUrl import from mcp dependency#16043

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/mcp-oauth-anyurl-import
Closed

fix(mcp): decouple AnyUrl import from mcp dependency#16043
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/mcp-oauth-anyurl-import

Conversation

@vominh1919
Copy link
Copy Markdown
Contributor

Problem

AnyUrl was imported inside the same try block as mcp.client.auth. When the mcp package was not installed, AnyUrl was undefined and _build_client_metadata() raised NameError at runtime.

NameError: name 'AnyUrl' is not defined
  at tools/mcp_oauth.py:478

Fix

Moved the AnyUrl import to its own try/except block so it's available whenever pydantic is installed (a core dependency), regardless of whether the mcp SDK is present.

Also added pytest.importorskip('mcp') to the three test_build_client_metadata tests that exercise _build_client_metadata, since that function depends on OAuthClientMetadata from the mcp package.

Tests

  • 3 previously failing test_mcp_oauth.py tests now properly skip when mcp is not installed
  • All other tests continue to pass

AnyUrl was imported inside the same try block as mcp.client.auth, so
when the mcp package was not installed, AnyUrl was undefined and
_build_client_metadata raised NameError at runtime.

Moved the AnyUrl import to its own try/except block so it's available
whenever pydantic is installed (which is a core dependency), regardless
of whether the mcp SDK is present.

Also added pytest.importorskip('mcp') to the three
test_build_client_metadata tests that exercise _build_client_metadata,
since that function depends on OAuthClientMetadata from the mcp package.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth labels Apr 26, 2026
@teknium1
Copy link
Copy Markdown
Contributor

teknium1 commented May 4, 2026

Salvaged via #19695 onto current main - your commit authorship was preserved. Thanks!

@teknium1 teknium1 closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants