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:
Azure SRE Agent
2026-06-03 01:42:22 +00:00
Unverified
parent 6086a74302
commit 21a1a0f5e1
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -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"],