Skip to content

feat(fetch): implement streaming byte cap to prevent resource exhaustion - #4185

Open
neuralmanacle wants to merge 3 commits into
modelcontextprotocol:mainfrom
neuralmanacle:fix/fetch-limit-and-streaming
Open

feat(fetch): implement streaming byte cap to prevent resource exhaustion#4185
neuralmanacle wants to merge 3 commits into
modelcontextprotocol:mainfrom
neuralmanacle:fix/fetch-limit-and-streaming

Conversation

@neuralmanacle

Copy link
Copy Markdown

Description

This PR addresses the response-size vulnerabilities outlined in #4116 by implementing a defensive streaming byte cap (2MB limit) inside the Python fetch server.

Server Details

  • Server: fetch
  • Changes to: tools (fetch execution logic)

Motivation and Context

Prior to this change, letting an autonomous AI agent loose on arbitrary URLs could allow a single massive file or unconstrained stream to exhaust memory and crash the server runtime. This isolates a critical server-side performance safeguard approved by the maintainers.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • New and existing tests pass locally
  • I have added appropriate error handling

- Refactor fetch_url to use streaming for memory-safe downloads
- Add MAX_RESPONSE_BYTES safety cap (2MB) to prevent resource exhaustion
- Improve error handling for timeouts and network failures
- Update and fix tests to support async streaming logic
- Add new test cases for size limit enforcement
- Consolidate tool configuration into pyproject.toml
@BossChaos

This comment was marked as abuse.

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