Skip to content

Conversation

@zemin-piao
Copy link
Contributor

🔄 Pull Request

📝 Description

This PR solves the issue caused by modelcontextprotocol/python-sdk#1798
TL;DR when the host field in request header does not match with the default ones in the transport_security settings for the FastMCP instance, the mcp server will return 421 response code with 421 Misdirected Request / Invalid Host Header error. This happens usually at an environment where requests are already handled and redirected from a proxy / gateway before arriving to the mcp server.

There is no centralised fix, this PR is the quick fix for making sure 421 response code does not happen due to above reasons.

Please note that this issue happens when mcp package version is higher than 1.23.0.
We currently set mcp[cli]~=1.9.0 hence there is possibility of hitting this bug.

🎯 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📖 Documentation update
  • 🧪 Test improvement
  • 🔧 Refactoring (no functional changes)

🧪 Testing

  • ✅ All existing tests pass (task test)
  • 🔬 Tested with MCP Inspector
  • 📊 Tested with sample Spark data
  • 🚀 Tested with real Spark History Server (if applicable)

🔬 Test Commands Run

# Example:
# task test
# npx @modelcontextprotocol/inspector uv run -m spark_history_mcp.core.main

🛠️ New Tools Added (if applicable)

  • Tool Name: new_tool_name
  • Purpose: What it does
  • Usage: Example parameters

📸 Screenshots (if applicable)

✅ Checklist

  • 🔍 Code follows project style guidelines
  • 🧪 Added tests for new functionality
  • 📖 Updated documentation (README, TESTING.md, etc.)
  • 🔧 Pre-commit hooks pass
  • 📝 Added entry to CHANGELOG.md (if significant change)

📚 Related Issues

Fixes #(issue number)
Related to #(issue number)

🤔 Additional Context


🎉 Thank you for contributing! Your effort helps make Spark monitoring more intelligent.

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nabuskey for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zemin-piao zemin-piao force-pushed the mcp_421_invalid_header branch from 4d57e7e to 4cc43fd Compare January 20, 2026 20:11
Copy link
Collaborator

@nabuskey nabuskey left a comment

Choose a reason for hiding this comment

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

Your comment is spot on. Would be great if we can standardize this so we don't have to do this for every single project out there.

modelcontextprotocol/python-sdk#1798 (comment)

Comment on lines +12 to +17
try:
# mcp version higher than 1.23.0 we are able to import TransportSecuritySettings
from mcp.server.transport_security import TransportSecuritySettings
except ImportError:
TransportSecuritySettings = None

Copy link
Collaborator

Choose a reason for hiding this comment

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

will open an issue to remove this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants