Skip to content

Ensure behavior-affecting headers are excluded when forwarding proxies/openapi #620

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 4 commits into from
May 28, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 28, 2025

Closes #601

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 22:30
@jlowin jlowin added the bug Something isn't working label May 28, 2025
@github-actions github-actions bot added documentation Improvements or additions to documentation tests labels May 28, 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 PR standardizes on using x-server-header in tests, expands the default headers excluded by get_http_headers(), and updates documentation to reflect the new exclusions.

  • Tests in test_openapi.py now use x-server-header instead of X-SERVER and add checks around excluded headers.
  • The get_http_headers dependency in dependencies.py grows its exclusion set (including proxy-related headers) and enforces lowercase.
  • Documentation in http-requests.mdx is updated to mention host and content-length exclusions.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/client/test_openapi.py Renamed headers in tests, added a new excluded-header test, and left a large commented block.
src/fastmcp/server/dependencies.py Expanded exclude_headers set with additional headers and added an assert for lowercase enforcement.
docs/patterns/http-requests.mdx Updated prose to reflect that host and content-length are excluded by default.
Comments suppressed due to low confidence (2)

tests/client/test_openapi.py:193

  • [nitpick] The test name suggests that the header is ignored, but the assertion checks it’s overwritten. Consider renaming to reflect the actual behavior (e.g. test_client_excluded_header_is_overwritten).
async def test_client_with_excluded_header_is_ignored(self, sse_server: str):

src/fastmcp/server/dependencies.py:51

  • You’ve added several new headers (connection, proxy-authorization, etc.) to the exclusion set. Consider adding tests to verify that each type of header is actually stripped.
exclude_headers = {

@jlowin jlowin merged commit f61d1cc into main May 28, 2025
5 checks passed
@jlowin jlowin deleted the headers branch May 28, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client's Header is getting replaced by mcp_header in OpenAPI implementation when API is deployed remote
1 participant