Skip to content

Conversation

@OiPunk
Copy link
Contributor

@OiPunk OiPunk commented Feb 10, 2026

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

  • Added _validate_required_parameters() in src/agents/mcp/server.py.
  • Invoked validation from _MCPServerWithClientSession.call_tool() before remote invocation.
  • Added regression tests in tests/mcp/test_client_session_retries.py covering:
    • missing required params blocks remote call
    • required params present still calls remote
    • missing tool in cache skips validation
    • absent required list skips validation
    • arguments=None path validates against required list
    • non-object arguments rejected before remote call

Why this is useful

  • Prevents avoidable MCP round-trips for invalid calls
  • Reduces token/latency waste during tool retries
  • Returns clearer local errors to the agent loop

Validation

  • uv run --with ruff ruff check src/agents/mcp/server.py tests/mcp/test_client_session_retries.py
  • env -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.py
  • env -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.py
  • env -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.py

Changed executable lines coverage for src/agents/mcp/server.py: 100% (20/20).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

call_tool() does not validate required parameters before invoking MCP tools

1 participant