Skip to content

Ensure content-length is always stripped from client headers #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 24, 2025

Closes #586

@Copilot Copilot AI review requested due to automatic review settings May 24, 2025 11:39
@jlowin jlowin added the bug Something isn't working label May 24, 2025
@github-actions github-actions bot added documentation Improvements or additions to documentation tests component: openapi component: client labels May 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request ensures that the client headers forwarded to the remote server never include the problematic "content-length" header by replacing header extraction methods and updating relevant tests and documentation.

  • Updated header extraction in server and client modules to use get_http_headers() instead of get_http_request() based helpers
  • Removed obsolete _get_mcp_client_headers() function and updated documentation to reflect these changes

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/client/test_openapi.py Removed an unnecessary client.ping() call
src/fastmcp/server/openapi.py Replaced legacy header extraction with get_http_headers()
src/fastmcp/server/dependencies.py Introduced get_http_headers() with header stripping logic
src/fastmcp/client/transports.py Updated to use the new header extraction via dict union operator
docs/patterns/http-requests.mdx Updated documentation to use and explain get_http_headers()

@jlowin jlowin merged commit ffa2ee1 into main May 24, 2025
6 checks passed
@jlowin jlowin deleted the content-length branch May 24, 2025 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component: client component: openapi documentation Improvements or additions to documentation tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

h11 Protocol Error ("Too little data for declared Content-Length") when FastMCP tool calls downstream service due to forwarded Content-Length header
1 participant