MCP server fails to response due to 421 Misdirected Request #133
+319
−1
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.
🔄 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_securitysettings 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
🧪 Testing
task test)🔬 Test Commands Run
🛠️ New Tools Added (if applicable)
new_tool_name📸 Screenshots (if applicable)
✅ Checklist
📚 Related Issues
Fixes #(issue number)
Related to #(issue number)
🤔 Additional Context
🎉 Thank you for contributing! Your effort helps make Spark monitoring more intelligent.