Skip to content

Add root_path support to properly route subpaths for SSE and streamable-http endpoints when behind Nginx or other HTTP reverse proxies #797

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
# HTTP settings
host: str = "127.0.0.1"
port: int = 8000

root_path: str = "" # Root path, same with root_path in uvicorn config.
# Used for SSE or streamable HTTP.

mount_path: str = "/" # Mount path (e.g. "/github", defaults to root path)
sse_path: str = "/sse"
message_path: str = "/messages/"
Expand Down Expand Up @@ -606,6 +610,7 @@ async def run_sse_async(self, mount_path: str | None = None) -> None:
starlette_app,
host=self.settings.host,
port=self.settings.port,
root_path=self.settings.root_path,
log_level=self.settings.log_level.lower(),
)
server = uvicorn.Server(config)
Expand All @@ -621,6 +626,7 @@ async def run_streamable_http_async(self) -> None:
starlette_app,
host=self.settings.host,
port=self.settings.port,
root_path=self.settings.root_path,
log_level=self.settings.log_level.lower(),
)
server = uvicorn.Server(config)
Expand Down
Loading