Skip to content

Move MCPClient to root-level lib and manage optional dependencies #1238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 22, 2025

Conversation

njbrake
Copy link
Contributor

@njbrake njbrake commented Apr 22, 2025

The readme instructions added in #1200

say to import MCPClient like

from smolagents import MCPClient, CodeAgent

This PR is to add MCPClient to the __init__ so that the code in the readme is accurate

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch.

However, I am afraid that with the current structure of the codebase, we cannot import MCPClient at the root level of the lib because mcp and mcpadapt are optional dependencies.

We should either fix the import to account for the optional nature of those dependencies, or fix the docs accordingly. In principle, I think it would be better to fix the import so the usage is consistent and neat.

@sergiopaniego
Copy link
Member

It can be imported as follows:

from smolagents.mcp_client import MCPClient

Example: https://github.com/sergiopaniego/samples/blob/main/smolagents_mcp.py

@njbrake
Copy link
Contributor Author

njbrake commented Apr 22, 2025

@sergiopaniego Thanks, yep the issue isn't with being able to import it, but rather that the docs are incorrect about how to import it.

@albertvillanova made an update so that the import error is supressed, this should address the optional dependency issue?

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sergiopaniego for chiming in and for your quick workaround: much appreciated. 🤗
And thank you @njbrake for the fast update!

Apologies for the confusion earlier: I realize I wasn't clear in my previous message. I didn't mean to suggest modifying the import at the root level. Rather, my intention was to handle the optional dependencies within the class __init__ method, as we already do for most of the models in models.py.

@njbrake
Copy link
Contributor Author

njbrake commented Apr 22, 2025

@albertvillanova ah, thanks for the clarification! Sorry I misunderstood you 😅 . I've made changes which I believe address your suggestion. Let me know what you think 👍

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix!

I just made a small code style adjustment for alignment, nothing major.

@albertvillanova albertvillanova changed the title import MCPClient according to readme instructions Move MCPClient to root-level lib and manage optional dependencies Apr 22, 2025
@albertvillanova albertvillanova merged commit 778fccf into huggingface:main Apr 22, 2025
3 checks passed
@njbrake njbrake deleted the patch-1 branch April 22, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants