Repository navigation
Python: Add a default approval mode to MCP approval policies - #9828
Eduard van Valkenburg (eavanvalkenburg) wants to merge 3 commits into
Conversation
Add an optional `default` key to `MCPSpecificApproval` that sets the approval mode for tools and prompts named in neither list. - Resolve a policy in order: always list, never list, `default`, then the existing fallback (no approval). - Validate `default` when the MCP tool is constructed. - Warn once at construction when `never_require_approval` is set without `default`, because that fallback may change in a future release. - Treat a name list given as a single string as one name instead of a substring pattern. - Document the resolution order and add tests.
There was a problem hiding this comment.
🟡 Changes recommended
The new non-fixture test helpers violate the coding standard and must move to explicitly imported helper modules, with captured test state passed as arguments.
1 open issue
What changed in this PR
Adds an explicit default approval policy for local Python MCP tools and prompts while preserving the existing fallback when no default is set.
Changes:
- Adds and validates
MCPSpecificApproval.default, with explicit name lists taking precedence. - Warns about implicit fallback policies and treats bare-string approval names as exact names.
- Documents policy behavior and tests precedence, warning locations, discovery refreshes, and streaming/non-streaming approval gating.
| File | Description |
|---|---|
python/packages/core/tests/core/test_mcp.py |
Adds approval-policy coverage and updates existing policies to avoid unintended warnings. |
python/packages/core/AGENTS.md |
Documents resolution order, warnings, and local-only default behavior. |
python/packages/core/agent_framework/_mcp.py |
Implements default validation and resolution, exact-name handling, and caller-targeted warnings. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 558f4d578260
Model: gpt-5.6-sol
Overview
The change adds an explicit fallback to local MCP approval policies while preserving the current implicit no-approval behavior when no default is supplied. Construction-time validation, explicit precedence, exact handling of single-string names, and coverage across prompts, progressive disclosure, reloads, and streaming/non-streaming approval flows provide strong guardrails. No Critical, High, or Medium defect is supported by the reviewed evidence.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Move the non-fixture helpers added for the approval-policy tests out of `test_mcp.py` into `mcp_approval_helpers.py`, import them explicitly, and pass the test state to them as arguments, as the Python coding standard requires.
`_mcp_approval_default` now owns both the validation of `default` and the warning for a `never_require_approval` list without `default`. Constructors opt in to the warning with `warn_stacklevel`, so it still fires once per construction and points at the calling code. The per-tool resolver calls the same function without it, so discovery and reloads stay silent. Add a test that discovery and reloads do not repeat the warning.
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: No findings
Scope: 2 net-new commit(s): 75377872f993, ee2d1ff69abb
Model: gpt-5.6-sol
Overview
This incremental update centralizes construction-time warning emission in _mcp_approval_default while keeping discovery-time resolution silent, and moves reusable test code into a standards-compliant helper module. Constructor validation, explicit stack-level handling, and tests covering exact caller attribution and repeated discovery provide concrete guardrails. No supported Critical, High, or Medium defect remains after reconciling the four perspectives against the previous head and current source.
Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

Motivation & Context
Per-tool approval policies for local MCP tools (
MCPSpecificApproval) let callers list the tools that always or never require approval. They did not let callers state the approval mode for tools and prompts named in neither list. Those silently used the framework default, which does not require approval. Hosted MCP services apply their own default to unnamed tools, so the same policy shape could mean different things for local and hosted tools.This change adds an explicit
defaultso callers can state the intent, and it flags the implicit fallback ahead of a possible future change.Description & Review Guide
defaultkey ("always_require"or"never_require") toMCPSpecificApproval. A tool or prompt resolves in this order:always_require_approval,never_require_approval,default, then the existing fallback (no approval).defaultalso applies to tools and prompts discovered later, for example aftertools/list_changed. It is validated when the MCP tool is constructed and is read only by local MCP tools (the hostedget_mcp_toolhelpers are unchanged).FutureWarningonce at construction whennever_require_approvalis set withoutdefault. Behavior is unchanged in that case. The warning points at the code that constructs the tool, including through subclass constructors such asFoundryToolbox.MCPSpecificApprovaland constructor docstrings and inpython/packages/core/AGENTS.md. Add tests, and adddefaultto existing test policies that would otherwise emit the new warning.defaultor passes a name list as a single string. Callers who setnever_require_approvalwithoutdefaultsee aFutureWarning. Settingdefaultsilences it:"never_require"keeps today's behavior and"always_require"requires approval for tools and prompts named in neither list.Related Issue
N/A - trivial change. It is a small, additive option on an existing parameter, and behavior is unchanged unless the new key is set.
AI Assistance
AI assistance details: Implementation, tests, documentation, and this PR description were drafted with GitHub Copilot.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.