Skip to content

Commit 8ec8150

Browse files
committed
fix(qr-server): allow Docker bridge IP in transport security
Add 172.17.0.1:* to allowed_hosts to fix 421 Misdirected Request errors when the server is accessed from Docker containers.
1 parent 49c16fc commit 8ec8150

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/qr-server/server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import qrcode
2020
import uvicorn
2121
from mcp.server.fastmcp import FastMCP
22+
from mcp.server.transport_security import TransportSecuritySettings
2223
from mcp import types
2324
from starlette.middleware.cors import CORSMiddleware
2425

@@ -161,7 +162,11 @@ def view() -> str:
161162
mcp.run(transport="stdio")
162163
else:
163164
# HTTP mode for basic-host (default) - with CORS
164-
app = mcp.streamable_http_app(stateless_http=True)
165+
# Allow Docker bridge IP for container-to-host communication
166+
security = TransportSecuritySettings(
167+
allowed_hosts=["127.0.0.1:*", "localhost:*", "[::1]:*", "172.17.0.1:*"]
168+
)
169+
app = mcp.streamable_http_app(stateless_http=True, transport_security=security)
165170
app.add_middleware(
166171
CORSMiddleware,
167172
allow_origins=["*"],

0 commit comments

Comments
 (0)