Skip to content

Python: [Generated by SRE Agent] Fix MCP allowed_tools empty list handling#6296

Open
chetantoshniwal wants to merge 2 commits into
mainfrom
fix/mcp-allowed-tools-empty-list-handling
Open

Python: [Generated by SRE Agent] Fix MCP allowed_tools empty list handling#6296
chetantoshniwal wants to merge 2 commits into
mainfrom
fix/mcp-allowed-tools-empty-list-handling

Conversation

@chetantoshniwal
Copy link
Copy Markdown
Contributor

@chetantoshniwal chetantoshniwal commented Jun 3, 2026

Summary

When allowed_tools is set to an empty list [], the existing falsy check (if not self.allowed_tools) incorrectly treats it as unconfigured (same as None), causing all MCP tools to be exposed instead of none.

Changes

  • _mcp.py: Changed if not self.allowed_tools: to if self.allowed_tools is None: so that an empty list correctly results in no tools being available.
  • test_mcp.py: Added test case for empty list [] to the existing parametrized test_mcp_tool_allowed_tools test.

Behavior

allowed_tools value Before (bug) After (fix)
None All tools exposed All tools exposed (unchanged)
[] All tools exposed ❌ No tools exposed ✅
["tool_a"] Only tool_a Only tool_a (unchanged)

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>
Copilot AI review requested due to automatic review settings June 3, 2026 01:42
@moonbox3 moonbox3 added the python label Jun 3, 2026
@chetantoshniwal chetantoshniwal changed the title [Generated by SRE Agent] Fix MCP allowed_tools empty list handling Fix MCP allowed_tools empty list handling Jun 3, 2026
@github-actions github-actions Bot changed the title Fix MCP allowed_tools empty list handling Python: [Generated by SRE Agent] Fix MCP allowed_tools empty list handling Jun 3, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 95% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by chetantoshniwal's agents

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a security/behavioral bug in the Python MCP tool filtering logic where allowed_tools=[] (explicitly “allow none”) was treated the same as allowed_tools=None (“allow all”), unintentionally exposing all MCP tools.

Changes:

  • Update MCP tool filtering to treat only None as “unconfigured” (allow all), while [] correctly means “allow none”.
  • Add a test case ensuring an empty allowed_tools list results in zero exposed tools.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/_mcp.py Fixes the allowed_tools check so [] no longer falls into the “allow all tools” path.
python/packages/core/tests/core/test_mcp.py Adds coverage to assert that allowed_tools=[] exposes no tools via functions.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py7886192%160, 179, 325, 385–386, 515, 577, 590, 614–615, 634–637, 639–640, 644, 670, 703–705, 707, 760–762, 817–818, 1001, 1042–1043, 1056, 1059, 1067–1068, 1073–1074, 1080, 1128–1129, 1143–1144, 1152–1153, 1158–1159, 1165, 1224, 1227, 1254, 1277–1281, 1328, 1334, 1412, 1464–1465, 1468, 1942
TOTAL37823442088% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7527 34 💤 0 ❌ 0 🔥 1m 57s ⏱️

def functions(self) -> list[FunctionTool]:
"""Get the list of functions that are allowed."""
if not self.allowed_tools:
if self.allowed_tools is None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the docstring doesn't actually specify either way, what a empty list means, so let's clarify the docstring for the allowed_tools param to ensure this change is clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants