Skip to content

fix: allow non-localhost connections by configuring trusted_hosts#91

Open
VedantMadane wants to merge 2 commits intodocling-project:mainfrom
VedantMadane:fix/issue-89-421-error
Open

fix: allow non-localhost connections by configuring trusted_hosts#91
VedantMadane wants to merge 2 commits intodocling-project:mainfrom
VedantMadane:fix/issue-89-421-error

Conversation

@VedantMadane
Copy link
Copy Markdown

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

  • Server started with --host 0.0.0.0 --port 8000
  • ✅ Connections via localhost work
  • ✅ Connections via IP address (172.16.x.x) now work
  • ✅ Custom Host headers are allowed

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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

DCO Check Passed

Thanks @VedantMadane, all your commits are properly signed off. 🎉

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 2, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@VedantMadane
Copy link
Copy Markdown
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>
@alansfyeung
Copy link
Copy Markdown

alansfyeung commented Apr 3, 2026

@VedantMadane I tried running your proposed fix but it doesn't work. (Python 3.12)

image

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 = False

Other projects are adding env vars for allowed hosts, etc. as documented in modelcontextprotocol/python-sdk#1798
so that approach can also be done for this repo

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

421 error when trying connect to non-localhost

2 participants