Skip to content

fix: use normalized path for sse message endpoint #1000

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ async def handle_sse(scope: Scope, receive: Receive, send: Send):
)
routes.append(
Mount(
self.settings.message_path,
normalized_message_endpoint,
app=RequireAuthMiddleware(sse.handle_post_message, required_scopes),
)
)
Expand All @@ -762,7 +762,7 @@ async def sse_endpoint(request: Request) -> Response:
)
routes.append(
Mount(
self.settings.message_path,
normalized_message_endpoint,
app=sse.handle_post_message,
)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/server/fastmcp/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def test_starlette_routes_with_mount_path(self):

# Verify path values
assert sse_routes[0].path == "/sse", "SSE route path should be /sse"
assert mount_routes[0].path == "/messages", "Mount route path should be /messages"
assert mount_routes[0].path == "/api/messages", "Mount route path should be /api/messages"

# Test with mount path as parameter
mcp = FastMCP()
Expand All @@ -115,7 +115,7 @@ async def test_starlette_routes_with_mount_path(self):

# Verify path values
assert sse_routes[0].path == "/sse", "SSE route path should be /sse"
assert mount_routes[0].path == "/messages", "Mount route path should be /messages"
assert mount_routes[0].path == "/param/messages", "Mount route path should be /param/messages"

@pytest.mark.anyio
async def test_non_ascii_description(self):
Expand Down
Loading