fix(mcp): validate required params before call_tool #2453
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2449 by adding a local pre-flight validation step in MCP
call_tool().When cached tool schema contains
inputSchema.required, the SDK now validates required fields before sending the request to the MCP server.What changed
_validate_required_parameters()insrc/agents/mcp/server.py._MCPServerWithClientSession.call_tool()before remote invocation.tests/mcp/test_client_session_retries.pycovering:requiredlist skips validationarguments=Nonepath validates against required listWhy this is useful
Validation
uv run --with ruff ruff check src/agents/mcp/server.py tests/mcp/test_client_session_retries.pyenv -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy uv run --with mypy mypy src/agents/mcp/server.py tests/mcp/test_client_session_retries.pyenv -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy uv run --with pytest pytest -q tests/mcp/test_client_session_retries.pyenv -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy uv run --with coverage coverage run -m pytest -q tests/mcp/test_client_session_retries.pyChanged executable lines coverage for
src/agents/mcp/server.py: 100% (20/20).