Skip to content

Commit 7d4579a

Browse files
committed
fix: use normalized path for sse message endpoint
1 parent d0443a1 commit 7d4579a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ async def handle_sse(scope: Scope, receive: Receive, send: Send):
742742
)
743743
routes.append(
744744
Mount(
745-
self.settings.message_path,
745+
normalized_message_endpoint,
746746
app=RequireAuthMiddleware(sse.handle_post_message, required_scopes),
747747
)
748748
)
@@ -762,7 +762,7 @@ async def sse_endpoint(request: Request) -> Response:
762762
)
763763
routes.append(
764764
Mount(
765-
self.settings.message_path,
765+
normalized_message_endpoint,
766766
app=sse.handle_post_message,
767767
)
768768
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
from mcp.server.fastmcp.server import FastMCP
4+
5+
6+
@pytest.mark.parametrize("mount_path", ["/sse", "/custom/mount/path", None])
7+
async def test_mount_path_included_in_sse_message_path(mount_path):
8+
"""Test that the mount path is included in the SSE message path when specified."""
9+
app = FastMCP("Test App")
10+
starlette_app = app.sse_app(mount_path)
11+
12+
message_mount = starlette_app.routes[1]
13+
14+
assert message_mount.path == f"{mount_path}/message" if mount_path else "/message" # type: ignore

0 commit comments

Comments
 (0)