fix: allow non-localhost connections by configuring trusted_hosts#91
Open
VedantMadane wants to merge 2 commits intodocling-project:mainfrom
Open
fix: allow non-localhost connections by configuring trusted_hosts#91VedantMadane wants to merge 2 commits intodocling-project:mainfrom
VedantMadane wants to merge 2 commits intodocling-project:mainfrom
Conversation
Fixes docling-project#89: 421 Misdirected Request error when accessing MCP server via IP address When the server is configured with --host 0.0.0.0 (which allows connections from any interface), uvicorn's Host header validation would reject requests made via IP address because the trusted_hosts list wasn't configured to accept them. This fix adds uvicorn_kwargs configuration to allow any valid Host header when the server is bound to all interfaces (0.0.0.0), enabling access from both localhost and IP addresses in Kubernetes and other containerized environments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
✅ DCO Check Passed Thanks @VedantMadane, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Author
|
Friendly bump -- this PR is still mergeable and ready for review. Let me know if anything needs updating. |
…noreply.github.com> I, Vedant Madane <6527493+VedantMadane@users.noreply.github.com>, hereby add my Signed-off-by to this commit: f4ffe78 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
|
@VedantMadane I tried running your proposed fix but it doesn't work. (Python 3.12)
What did work was an approach that set the flag to false - obviously not an elegant or final solution. # When host is "0.0.0.0", we need to allow any valid connection
if host == "0.0.0.0" and mcp.settings.transport_security:
mcp.settings.transport_security.enable_dns_rebinding_protection = FalseOther projects are adding env vars for allowed hosts, etc. as documented in modelcontextprotocol/python-sdk#1798 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Fixes #89: 421 Misdirected Request error when accessing MCP server via IP address
When the server is configured with --host 0.0.0.0 (which allows connections from any interface), uvicorn's Host header validation would reject requests made via IP address because the trusted_hosts list wasn't configured to accept them.
This fix adds uvicorn_kwargs configuration to allow any valid Host header when the server is bound to all interfaces (0.0.0.0), enabling access from both localhost and IP addresses in Kubernetes and other containerized environments.
Testing