enable custom path of sse server (#246)
Co-authored-by: David Soria Parra <167242713+dsp-ant@users.noreply.github.com>
This commit is contained in:
parent
04586f8f86
commit
e2a7338730
1 changed files with 8 additions and 6 deletions
|
|
@ -73,6 +73,8 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
|
||||||
# HTTP settings
|
# HTTP settings
|
||||||
host: str = "0.0.0.0"
|
host: str = "0.0.0.0"
|
||||||
port: int = 8000
|
port: int = 8000
|
||||||
|
sse_path: str = "/sse"
|
||||||
|
message_path: str = "/messages/"
|
||||||
|
|
||||||
# resource settings
|
# resource settings
|
||||||
warn_on_duplicate_resources: bool = True
|
warn_on_duplicate_resources: bool = True
|
||||||
|
|
@ -477,7 +479,7 @@ class FastMCP:
|
||||||
|
|
||||||
def sse_app(self) -> Starlette:
|
def sse_app(self) -> Starlette:
|
||||||
"""Return an instance of the SSE server app."""
|
"""Return an instance of the SSE server app."""
|
||||||
sse = SseServerTransport("/messages/")
|
sse = SseServerTransport(self.settings.message_path)
|
||||||
|
|
||||||
async def handle_sse(request: Request) -> None:
|
async def handle_sse(request: Request) -> None:
|
||||||
async with sse.connect_sse(
|
async with sse.connect_sse(
|
||||||
|
|
@ -494,8 +496,8 @@ class FastMCP:
|
||||||
return Starlette(
|
return Starlette(
|
||||||
debug=self.settings.debug,
|
debug=self.settings.debug,
|
||||||
routes=[
|
routes=[
|
||||||
Route("/sse", endpoint=handle_sse),
|
Route(self.settings.sse_path, endpoint=handle_sse),
|
||||||
Mount("/messages/", app=sse.handle_post_message),
|
Mount(self.settings.message_path, app=sse.handle_post_message),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -650,9 +652,9 @@ class Context(BaseModel, Generic[ServerSessionT, LifespanContextT]):
|
||||||
Returns:
|
Returns:
|
||||||
The resource content as either text or bytes
|
The resource content as either text or bytes
|
||||||
"""
|
"""
|
||||||
assert (
|
assert self._fastmcp is not None, (
|
||||||
self._fastmcp is not None
|
"Context is not available outside of a request"
|
||||||
), "Context is not available outside of a request"
|
)
|
||||||
return await self._fastmcp.read_resource(uri)
|
return await self._fastmcp.read_resource(uri)
|
||||||
|
|
||||||
async def log(
|
async def log(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue