Skip to content

ALLOWED_HOSTS environment variable not documented/configured for streamable-http transport #373

@cbcoutinho

Description

@cbcoutinho

Description

When deploying the Nextcloud MCP server behind an ingress/reverse proxy using the streamable-http transport, connections are rejected with HTTP 421 (Misdirected Request) due to Host header validation.

Environment

  • Transport: streamable-http
  • Deployment: Kubernetes with Ingress
  • MCP Server Version: 0.48.6
  • Ingress Hostname: mcp.cloud.internal.example.com

Current Behavior

The MCP server logs show:

{
  "level": "WARNING",
  "name": "mcp.server.transport_security",
  "message": "Invalid Host header: mcp.cloud.internal.example.com"
}

And the HTTP response is:

10.1.31.2:43958 - "POST /mcp HTTP/1.1" 421

Root Cause

The MCP SDK's transport security validates the Host header to prevent DNS rebinding attacks. By default, it only accepts localhost or 127.0.0.1. When accessed through an ingress with a different hostname, the request is rejected.

Expected Behavior

There should be a documented way to configure allowed hosts via environment variable (e.g., ALLOWED_HOSTS or MCP_ALLOWED_HOSTS) that can be set in deployment configurations.

Workaround

Currently investigating if this can be configured through existing environment variables or if it requires code changes.

Suggested Solution

  1. Add an ALLOWED_HOSTS environment variable to the server configuration
  2. Document this requirement in deployment guides, especially for Kubernetes/Ingress setups
  3. Update Helm chart examples to include this configuration

Related

This affects any deployment scenario where the MCP server is accessed through:

  • Ingress controllers
  • Reverse proxies
  • Load balancers
  • Any scenario where the Host header differs from localhost

Additional Context

The issue is particularly relevant for production deployments where the MCP server needs to be accessible through a proper domain name rather than localhost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions