fix(mcp): decouple AnyUrl import from mcp dependency#16043
Closed
vominh1919 wants to merge 1 commit into
Closed
Conversation
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.
Contributor
|
Salvaged via #19695 onto current main - your commit authorship was preserved. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AnyUrlwas imported inside the sametryblock asmcp.client.auth. When themcppackage was not installed,AnyUrlwas undefined and_build_client_metadata()raisedNameErrorat runtime.Fix
Moved the
AnyUrlimport to its owntry/exceptblock so it's available wheneverpydanticis installed (a core dependency), regardless of whether themcpSDK is present.Also added
pytest.importorskip('mcp')to the threetest_build_client_metadatatests that exercise_build_client_metadata, since that function depends onOAuthClientMetadatafrom themcppackage.Tests
test_mcp_oauth.pytests now properly skip whenmcpis not installed