Skip to content

Change default binding from 0.0.0.0 to 127.0.0.1 to align with security recommendations #738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/servers/simple-prompt/mcp_simple_prompt/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def handle_sse(request):

import uvicorn

uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)
else:
from mcp.server.stdio import stdio_server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def handle_sse(request):

import uvicorn

uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)
else:
from mcp.server.stdio import stdio_server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:

import uvicorn

uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)

return 0
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:

import uvicorn

uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)

return 0
2 changes: 1 addition & 1 deletion examples/servers/simple-tool/mcp_simple_tool/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def handle_sse(request):

import uvicorn

uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)
else:
from mcp.server.stdio import stdio_server

Expand Down
2 changes: 1 addition & 1 deletion src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"

# HTTP settings
host: str = "0.0.0.0"
host: str = "127.0.0.1"
port: int = 8000
mount_path: str = "/" # Mount path (e.g. "/github", defaults to root path)
sse_path: str = "/sse"
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/server/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def handle_sse(request):

# Create and run Starlette app
starlette_app = Starlette(routes=routes)
uvicorn.run(starlette_app, host="0.0.0.0", port=port)
uvicorn.run(starlette_app, host="127.0.0.1", port=port)
```

Note: The handle_sse function must return a Response to avoid a "TypeError: 'NoneType'
Expand Down
Loading