Skip to content

fetch: map Pydantic ValidationError to INVALID_PARAMS; add robots.txt timeout; tests - #4599

Open
eltypical wants to merge 3 commits into
modelcontextprotocol:mainfrom
eltypical:fix-validate-args-and-timeout
Open

fetch: map Pydantic ValidationError to INVALID_PARAMS; add robots.txt timeout; tests#4599
eltypical wants to merge 3 commits into
modelcontextprotocol:mainfrom
eltypical:fix-validate-args-and-timeout

Conversation

@eltypical

Copy link
Copy Markdown

Problem

  • Tool invocation path (call_tool) only caught ValueError when parsing arguments into the Fetch pydantic model. On pydantic>=2, invalid/missing inputs raise ValidationError which does not inherit from ValueError, bubbling up as unhandled exceptions, violating MCP error contract and causing integrity failures in multi-tenant tool pipelines.
  • robots.txt fetch in check_may_autonomously_fetch_url had no explicit timeout, risking event-loop starvation / availability loss when upstream hosts hang.

Fix

  • Add parse_fetch_args() helper wrapping Fetch(**arguments) and catching ValidationError, re-raising McpError(ErrorData(code=INVALID_PARAMS, ...)).
  • Use parse_fetch_args in call_tool; preserve explicit URL-blank guard.
  • Add timeout=15 to robots.txt GET call.

Tests

  • New TestArgumentParsing::test_parse_fetch_args_maps_validation_error asserts INVALID_PARAMS mapping for missing required fields.
  • New TestCheckMayAutonomouslyFetchUrl::test_robots_fetch_has_timeout verifies timeout kwarg passed to httpx.AsyncClient.get("/robots.txt", ..., timeout=15).

Security/Resilience Impact

  • CIA: Integrity improved by ensuring invalid input never contaminates execution path; Availability improved with bounded robots.txt fetch.

Signed-off-by: Kiell Tampubolon yeheskieltampubolon@gmail.com

…tor parse helper; add robots.txt timeout

call_tool previously caught ValueError only, but pydantic>=2 raises ValidationError on model construction. That propagated as an unhandled exception instead of standardized INVALID_PARAMS.

- Add parse_fetch_args() catching ValidationError and raising McpError(INVALID_PARAMS)
- Use helper in call_tool
- Add timeout=15 to robots.txt fetch to avoid hanging on slow sites

Signed-off-by: Kiell Tampubolon <yeheskieltampubolon@gmail.com>
…bots.txt timeout

- Simulate pydantic ValidationError on Fetch construction and assert INVALID_PARAMS via McpError
- Ensure robots.txt fetch passes timeout to AsyncClient.get

Signed-off-by: Kiell Tampubolon <yeheskieltampubolon@gmail.com>
Copilot AI review requested due to automatic review settings July 31, 2026 02:32

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Protego.can_fetch expects (user_agent, url). Passing (url, user_agent) could allow or deny erroneously under certain robots.txt, causing CI test failures in the fetch server package.

Also retains explicit 15s timeout for robots.txt preflight and centralized Pydantic ValidationError→MCP INVALID_PARAMS mapping.

Signed-off-by: Kiell Tampubolon <113831023+eltypical@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants