mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Fix MCP allowed_tools empty list handling
When allowed_tools is set to an empty list [], the falsy check 'if not self.allowed_tools' incorrectly treats it as unconfigured (same as None), causing all tools to be exposed. Change to an explicit 'is None' check so that an empty list correctly results in no tools being allowed. Co-authored-by: Azure SRE Agent <noreply@microsoft.com>
This commit is contained in:
@@ -544,7 +544,7 @@ class MCPTool:
|
||||
@property
|
||||
def functions(self) -> list[FunctionTool]:
|
||||
"""Get the list of functions that are allowed."""
|
||||
if not self.allowed_tools:
|
||||
if self.allowed_tools is None:
|
||||
return self._functions
|
||||
allowed_names = set(self.allowed_tools)
|
||||
filtered_functions: list[FunctionTool] = []
|
||||
|
||||
@@ -1465,6 +1465,7 @@ def test_mcp_tool_approval_mode_returns_none_for_unmatched_names() -> None:
|
||||
3,
|
||||
["tool_one", "tool_two", "tool_three"],
|
||||
), # None means all tools are allowed
|
||||
([], 0, []), # Empty list means no tools are allowed
|
||||
(["tool_one"], 1, ["tool_one"]), # Only tool_one is allowed
|
||||
(
|
||||
["tool_one", "tool_three"],
|
||||
|
||||
Reference in New Issue
Block a user