fix(fetch): handle 5xx responses and add timeout in robots.txt check#4482
Open
isheng-eqi wants to merge 1 commit into
Open
fix(fetch): handle 5xx responses and add timeout in robots.txt check#4482isheng-eqi wants to merge 1 commit into
isheng-eqi wants to merge 1 commit into
Conversation
Two fixes in check_may_autonomously_fetch_url: 1. 5xx responses from robots.txt were silently falling through to the robots.txt parsing block, causing error pages to be parsed as robots.txt content. Now raises McpError for server errors. 2. The robots.txt fetch had no timeout, unlike the main fetch_url function which uses timeout=30. Added the same 30s timeout to prevent the client from hanging indefinitely on unresponsive robots.txt endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Two fixes in
check_may_autonomously_fetch_urlin the fetch server.Problem 1: 5xx responses silently parsed as robots.txt
When a robots.txt endpoint returns 5xx, the code fell through to the robots.txt parsing block. The error page HTML was fed to
Protego.parse(), which would silently produce a default-allow parser. The 4xx check on line 92 only covers 400–499; 500+ had no branch.Problem 2: No timeout on robots.txt fetch
The
check_may_autonomously_fetch_urlfunction'sclient.get()had notimeoutparameter. If the robots.txt endpoint hangs (network partition, slow server), the client hangs indefinitely. The mainfetch_urlfunction already usestimeout=30— this is a consistency fix.Changes
src/fetch/src/mcp_server_fetch/server.py(+6 lines):elif response.status_code >= 500branch that raisesMcpErrorinstead of parsing the error page as robots.txttimeout=30to theclient.get()call for robots.txtTesting