Repository navigation
Python: Validate agent MCP tool arguments - #10036
Eduard van Valkenburg (eavanvalkenburg) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the changes enforcing JSON Schema validation before argument conversion and agent execution.
No open issues 🎉
What changed in this PR
This PR makes Python’s AgentMCPTool enforce its advertised JSON Schema before argument conversion, agent execution, or session-store access.
Changes:
- Add full-schema validation, returning
INVALID_PARAMSfor invalid arguments while allowing schema configuration errors to propagate. - Add regression coverage for direct calls and both native MCP protocol modes, including rejected calls causing no execution or session-store access.
- Declare
jsonschemaas a direct dependency and update documentation and native MCP callback examples.
| File | Description |
|---|---|
skills/agent-framework-builder-python/references/hosting-and-deployment.md |
Clarifies adapter validation and direct-conversion responsibilities. |
python/uv.lock |
Records the direct jsonschema dependency. |
python/packages/hosting-mcp/tests/hosting_mcp/test_agent_tool.py |
Tests schema constraints, protocol modes, option overrides, and rejection side effects. |
python/packages/hosting-mcp/README.md |
Documents validation behavior and updates native MCP examples. |
python/packages/hosting-mcp/pyproject.toml |
Declares the supported jsonschema dependency range. |
python/packages/hosting-mcp/AGENTS.md |
Updates guidance on the adapter’s validation responsibilities. |
python/packages/hosting-mcp/agent_framework_hosting_mcp/_agent_tool.py |
Validates arguments against the generated schema before conversion and execution. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): de5aa6320957
Model: gpt-5.6-sol
Overview
The PR validates AgentMCPTool arguments against its generated schema and has strong regression coverage across direct calls, both MCP protocol modes, nested constraints, and session-store isolation. Invalid ordinary inputs are rejected before conversion, agent execution, or session access. One residual risk remains: synchronous evaluation of a host-configured backtracking regex can let a small untrusted argument stall the shared event loop.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hosting-mcp/agent_framework_hosting_mcp/_agent_tool.py
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: No findings
Scope: 1 net-new commit(s): 0edaddf53a3a
Model: gpt-5.6-sol
Overview
This incremental commit documents the configured-schema trust boundary, synchronous event-loop validation, absence of an execution timeout, and the need for a terminable process boundary across the package and hosting guidance. The existing implementation centralizes advertised and enforced schema generation, and its regression matrix verifies rejection before conversion, agent execution, or session-store access across direct and native MCP paths. The documentation-only range introduces no publishable Critical, High, or Medium defect.
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
Make
AgentMCPToolvalidate incoming arguments against the same JSON Schema it advertises throughlist_tools(). The adapter now enforces the configured parameter constraints before converting arguments, running the agent, or accessing the session store.Description & Review Guide
jsonschema, declare the direct dependency, and add regression coverage for direct calls and both native MCP protocol modes. Update the package documentation and consumer hosting guidance, including the native MCP callback example.INVALID_PARAMSbefore execution or session-store access. Valid configured chat options still override agent defaults. The generic conversion helpers, public API signatures, and application-owned authentication and session policies remain unchanged.Local checks on the updated base:
uv run --directory python --package agent-framework-hosting-mcp --locked --group dev --no-sync pytest -p no:cacheprovider --import-mode=importlib packages/hosting-mcp/tests/hosting_mcp -m 'not integration'- passed: 329 tests, one integration test deselected, and the existingSessionStoreexperimental warning.uv build --project python/packages/hosting-mcp --no-sources --out-dir "$build_dir"- passed: source distribution and wheel built.build_dirwas an output directory outside the checkout.Related Issue
N/A
AI Assistance
AI assistance details: GitHub Copilot assisted with the implementation, tests, documentation, and PR description.
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.