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

fix: use Mount instead of Route for SSE message handling #77

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
9 changes: 3 additions & 6 deletions src/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ async def run_stdio_async(self) -> None:
async def run_sse_async(self) -> None:
"""Run the server using SSE transport."""
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.routing import Route, Mount

sse = SseServerTransport("/messages")
sse = SseServerTransport("/messages/")

async def handle_sse(request):
async with sse.connect_sse(
Expand All @@ -442,14 +442,11 @@ async def handle_sse(request):
self._mcp_server.create_initialization_options(),
)

async def handle_messages(request):
await sse.handle_post_message(request.scope, request.receive, request._send)

starlette_app = Starlette(
debug=self.settings.debug,
routes=[
Route("/sse", endpoint=handle_sse),
Route("/messages", endpoint=handle_messages, methods=["POST"]),
Mount("/messages/", app=sse.handle_post_message),
],
)

Expand Down