-
Notifications
You must be signed in to change notification settings - Fork 785
[Tiny Agents] Add tools to config #3242
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
Wauplin
merged 7 commits into
huggingface:main
from
NielsRogge:feature/add_tools_exclusion
Sep 1, 2025
+22
−2
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33eac44
Add tools to config
NielsRogge 147a2a1
Merge remote-tracking branch 'upstream/main' into feature/add_tools_e…
NielsRogge 19b5b9e
Simplify MCP tool filtering to use allowed_tools parameter
NielsRogge 69d21dd
Merge remote-tracking branch 'upstream/main' into feature/add_tools_e…
NielsRogge 809774d
Address comments
NielsRogge 582eecf
Merge remote-tracking branch 'upstream/main' into feature/add_tools_e…
NielsRogge c52aae1
Update src/huggingface_hub/inference/_mcp/mcp_client.py
Wauplin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,4 +139,7 @@ dmypy.json | |
# Spell checker config | ||
cspell.json | ||
|
||
tmp* | ||
tmp* | ||
|
||
# Claude Code | ||
CLAUDE.md |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Copyright 2025 The HuggingFace Team. All rights reserved. | ||
NielsRogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from huggingface_hub.inference._mcp.mcp_client import MCPClient | ||
|
||
|
||
class TestMCPClient(unittest.TestCase): | ||
def setUp(self): | ||
self.client = MCPClient(model="test-model", provider="test-provider") | ||
|
||
def test_filter_tools_no_allowed_tools(self): | ||
"""Test that _filter_tools returns all tools when no allowed_tools is specified.""" | ||
# Create mock tools | ||
mock_tools = [ | ||
MagicMock(name="tool1"), | ||
MagicMock(name="tool2"), | ||
MagicMock(name="tool3"), | ||
] | ||
|
||
result = self.client._filter_tools(mock_tools, None) | ||
|
||
self.assertEqual(len(result), 3) | ||
self.assertEqual(result, mock_tools) | ||
|
||
def test_filter_tools_with_allowed_tools(self): | ||
"""Test that _filter_tools correctly filters tools based on allowed_tools list.""" | ||
# Create mock tools | ||
mock_tool1 = MagicMock() | ||
mock_tool1.name = "tool1" | ||
mock_tool2 = MagicMock() | ||
mock_tool2.name = "tool2" | ||
mock_tool3 = MagicMock() | ||
mock_tool3.name = "tool3" | ||
|
||
mock_tools = [mock_tool1, mock_tool2, mock_tool3] | ||
allowed_tools = ["tool1", "tool3"] | ||
|
||
result = self.client._filter_tools(mock_tools, allowed_tools) | ||
|
||
self.assertEqual(len(result), 2) | ||
self.assertIn(mock_tool1, result) | ||
self.assertIn(mock_tool3, result) | ||
self.assertNotIn(mock_tool2, result) | ||
|
||
def test_filter_tools_with_empty_allowed_tools(self): | ||
"""Test that _filter_tools returns empty list when allowed_tools is empty.""" | ||
mock_tools = [ | ||
MagicMock(name="tool1"), | ||
MagicMock(name="tool2"), | ||
] | ||
|
||
result = self.client._filter_tools(mock_tools, []) | ||
|
||
self.assertEqual(len(result), 0) | ||
|
||
def test_filter_tools_with_nonexistent_tools(self): | ||
"""Test that _filter_tools handles non-existent tool names gracefully.""" | ||
mock_tool1 = MagicMock() | ||
mock_tool1.name = "tool1" | ||
mock_tools = [mock_tool1] | ||
|
||
# Include a non-existent tool in allowed_tools | ||
allowed_tools = ["tool1", "nonexistent_tool"] | ||
|
||
with self.assertLogs(level="WARNING") as log: | ||
result = self.client._filter_tools(mock_tools, allowed_tools) | ||
|
||
# Should only return existing tools | ||
self.assertEqual(len(result), 1) | ||
self.assertEqual(result[0], mock_tool1) | ||
|
||
# Should log a warning about missing tools | ||
self.assertIn("not found on server", log.output[0]) | ||
|
||
def test_filter_tools_all_nonexistent_tools(self): | ||
"""Test that _filter_tools returns empty list when all allowed_tools are non-existent.""" | ||
mock_tool1 = MagicMock() | ||
mock_tool1.name = "tool1" | ||
mock_tools = [mock_tool1] | ||
|
||
allowed_tools = ["nonexistent_tool1", "nonexistent_tool2"] | ||
|
||
with self.assertLogs(level="WARNING") as log: | ||
result = self.client._filter_tools(mock_tools, allowed_tools) | ||
|
||
self.assertEqual(len(result), 0) | ||
self.assertIn("not found on server", log.output[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.