Skip to content

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

Merged
eavanvalkenburg merged 4 commits into
mainfrom
fix/mcp-allowed-tools-empty-list-handling
Jun 11, 2026
Merged

Python: [Generated by SRE Agent] Fix MCP allowed_tools empty list handling#6296
eavanvalkenburg merged 4 commits into
mainfrom
fix/mcp-allowed-tools-empty-list-handling

Conversation

@chetantoshniwal

@chetantoshniwal chetantoshniwal commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py11819292%306, 325, 523, 583–584, 716, 778, 791, 815–816, 835–838, 840–841, 845, 871, 905–907, 909, 962–964, 1023–1024, 1293, 1334–1335, 1348, 1351, 1360–1361, 1366–1367, 1373, 1421–1422, 1438–1439, 1448–1449, 1454–1455, 1461, 1536, 1539, 1566, 1589–1593, 1616–1618, 1623, 1627–1628, 1730, 1737, 1739, 1752, 1758, 1820, 1835–1836, 1843–1844, 1849–1850, 1855, 1859, 1874, 1936, 2119, 2121, 2143, 2145–2148, 2161–2162, 2206, 2268, 2667–2668, 2890–2891, 2909
TOTAL38624441788% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7759 34 💤 0 ❌ 0 🔥 2m 6s ⏱️

Comment thread python/packages/core/agent_framework/_mcp.py
Per Eduard's review on PR #6296: explicitly document that None exposes all tools and [] exposes none, across all four MCPTool / MCPStdioTool / MCPStreamableHTTPTool / MCPWebsocketTool docstrings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread python/packages/core/agent_framework/_mcp.py Outdated
Per Eduard's follow-up on PR #6296: `load_tools=False` is the cleaner idiom when you don't want to expose any tools. Reframe `allowed_tools=[]` in the docstring as a runtime guard / inspection-only path and cross-reference `load_tools`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit 4149f24 Jun 11, 2026
37 checks passed
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