Skip to content
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

enable custom path of sse server #246

Open
wants to merge 1 commit 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
14 changes: 8 additions & 6 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
# HTTP settings
host: str = "0.0.0.0"
port: int = 8000
sse_path: str = "/sse"
message_path: str = "/messages/"

# resource settings
warn_on_duplicate_resources: bool = True
Expand Down Expand Up @@ -478,7 +480,7 @@ async def run_sse_async(self) -> None:
from starlette.applications import Starlette
from starlette.routing import Mount, Route

sse = SseServerTransport("/messages/")
sse = SseServerTransport(self.settings.message_path)

async def handle_sse(request):
async with sse.connect_sse(
Expand All @@ -493,8 +495,8 @@ async def handle_sse(request):
starlette_app = Starlette(
debug=self.settings.debug,
routes=[
Route("/sse", endpoint=handle_sse),
Mount("/messages/", app=sse.handle_post_message),
Route(self.settings.sse_path, endpoint=handle_sse),
Mount(self.settings.message_path, app=sse.handle_post_message),
],
)

Expand Down Expand Up @@ -658,9 +660,9 @@ async def read_resource(self, uri: str | AnyUrl) -> Iterable[ReadResourceContent
Returns:
The resource content as either text or bytes
"""
assert (
self._fastmcp is not None
), "Context is not available outside of a request"
assert self._fastmcp is not None, (
"Context is not available outside of a request"
)
return await self._fastmcp.read_resource(uri)

async def log(
Expand Down