Skip to content

Commit e2a7338

Browse files
elsejjdsp-ant
andauthored
enable custom path of sse server (#246)
Co-authored-by: David Soria Parra <[email protected]>
1 parent 04586f8 commit e2a7338

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/mcp/server/fastmcp/server.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
7373
# HTTP settings
7474
host: str = "0.0.0.0"
7575
port: int = 8000
76+
sse_path: str = "/sse"
77+
message_path: str = "/messages/"
7678

7779
# resource settings
7880
warn_on_duplicate_resources: bool = True
@@ -477,7 +479,7 @@ async def run_sse_async(self) -> None:
477479

478480
def sse_app(self) -> Starlette:
479481
"""Return an instance of the SSE server app."""
480-
sse = SseServerTransport("/messages/")
482+
sse = SseServerTransport(self.settings.message_path)
481483

482484
async def handle_sse(request: Request) -> None:
483485
async with sse.connect_sse(
@@ -494,8 +496,8 @@ async def handle_sse(request: Request) -> None:
494496
return Starlette(
495497
debug=self.settings.debug,
496498
routes=[
497-
Route("/sse", endpoint=handle_sse),
498-
Mount("/messages/", app=sse.handle_post_message),
499+
Route(self.settings.sse_path, endpoint=handle_sse),
500+
Mount(self.settings.message_path, app=sse.handle_post_message),
499501
],
500502
)
501503

@@ -650,9 +652,9 @@ async def read_resource(self, uri: str | AnyUrl) -> Iterable[ReadResourceContent
650652
Returns:
651653
The resource content as either text or bytes
652654
"""
653-
assert (
654-
self._fastmcp is not None
655-
), "Context is not available outside of a request"
655+
assert self._fastmcp is not None, (
656+
"Context is not available outside of a request"
657+
)
656658
return await self._fastmcp.read_resource(uri)
657659

658660
async def log(

0 commit comments

Comments
 (0)