-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add support for MCP Servers tools as ToolCollection
#232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are conflicts with the main branch, could you please fix them?
Additionally, I would suggest setting mcpadapt
as an optional dependency with an mcp
extra?
Hi @albertvillanova many thanks for the review!
|
Yes, I would suggest making it optional. In fact, we are in the process of moving most of the current dependencies to optional. |
Oh, I noticed you closed your PR!? |
that's odd not sure how |
I put as optional dependencies and made sure to raise a nice error if someone try to load tool collection from_mcp without the extra |
@albertvillanova let me know if any other changes required :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great.
Yes, that is the way we are doing it: trying the optional import, and raising a error message if not installed. See:
On the other hand, I would suggest setting both from_hub
and from_mcp
as class methods instead of static methods. What do you think?
I have used static here because I don't use the 'cls' arg but could change it to classmethod if you prefer. I see above the |
I think |
hmm ok let's go for classmethod as it relates to the class still then |
…that they return a ToolCollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may not have explained myself clearly earlier. My intention was to use class methods so that the returned instances are created with the cls
argument.
Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
@albertvillanova make sense haha a bit silly to not use cls to instanciate indeed |
fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure about the functionality, do you think it is feasible to include a test?
Yes definitely in the meantime you can try by running the example added |
ah wait I think I have a better test :) |
Oh, sorry, I thought you preferred me to try a test... I misunderstood! 😅 |
no problem I think it's better because we don't need to mock we can actually test the functionality for real :) |
all good for me |
tests/test_tools.py
Outdated
# def test_agent_type_output(self): | ||
# inputs = create_inputs(self.tool.inputs) | ||
# output = self.tool(**inputs, sanitize_inputs_outputs=True) | ||
# if self.tool.output_type != "any": | ||
# agent_type = AGENT_TYPE_MAPPING[self.tool.output_type] | ||
# self.assertTrue(isinstance(output, agent_type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you commented this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry my bad I had issues to run the test on my ubuntu machine with the import with torch so I commented everything out let me fix
tests/test_tools.py
Outdated
@pytest.fixture | ||
def mock_server_parameters(): | ||
return MagicMock() | ||
|
||
|
||
@pytest.fixture | ||
def mock_mcp_adapt(): | ||
with patch("mcpadapt.core.MCPAdapt") as mock: | ||
mock.return_value.__enter__.return_value = ["tool1", "tool2"] | ||
mock.return_value.__exit__.return_value = None | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_smolagents_adapter(): | ||
with patch("mcpadapt.smolagents_adapter.SmolAgentsAdapter") as mock: | ||
yield mock | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need these mocks for my unit test.
I think we can keep both tests: my unit and your integration test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure let's put it back
(cherry picked from commit 9284d9e)
let's hope we pass the tests now ;) |
we have an issue with the unit test you want to fix or? |
Let me fix it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @grll! Thanks a lot! 🤗
@albertvillanova Thanks for the support in merging this! |
Thanks a lot for your contribution @grll ! |
@aymeric-roucher thanks for the initial pointers! Any ideas around next release timeline plans ? |
Just in progress... |
Done! Release notes here 😃 |
This Pull Request add support for any MCP Servers by making tools from an MCP server accessible as a
ToolCollection
object to the user.It changes
ToolCollection
to enable two behaviors one load from the hub viafrom_hub
(same as previous behavior). one to load tools from an mcp server viafrom_mcp
.I updated the documentation and added example, let me know if there is any further additions to make!
Fix #60