feat: add MCP_ALLOWED_HOSTS support for reverse proxy configuration

This commit is contained in:
sha
2026-03-21 00:00:43 +02:00
parent a4180cc6f6
commit 3f67f7b0da
4 changed files with 14 additions and 0 deletions
+7
View File
@@ -9,6 +9,8 @@ Environment variables:
MCP_HOST — bind host for HTTP transport (default: 0.0.0.0)
MCP_PORT — bind port for HTTP transport (default: 8000)
MCP_AUTH_TOKEN — Bearer token for HTTP transport auth (optional)
MCP_ALLOWED_HOSTS — Comma-separated extra allowed Host headers, e.g. redmine.mcp.example.com
(FastMCP only allows localhost by default — required when behind a reverse proxy)
"""
import os
@@ -24,6 +26,11 @@ if __name__ == "__main__":
port = int(os.environ.get("MCP_PORT", "8000"))
token = os.environ.get("MCP_AUTH_TOKEN", "")
allowed_hosts = os.environ.get("MCP_ALLOWED_HOSTS", "")
if allowed_hosts:
for h in (h.strip() for h in allowed_hosts.split(",")):
mcp.settings.transport_security.allowed_hosts.append(h)
app = mcp.streamable_http_app()
if token: