Skip to content

Commit 9b096dc

Browse files
committed
add comments to server example where we use related_request_id
1 parent 46ec72d commit 9b096dc

File tree

2 files changed

+10
-1
lines changed
  • examples/servers/simple-streamablehttp/mcp_simple_streamablehttp
  • src/mcp/server/fastmcp

2 files changed

+10
-1
lines changed

examples/servers/simple-streamablehttp/mcp_simple_streamablehttp/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ async def call_tool(
8282
level="info",
8383
data=f"Notification {i+1}/{count} from caller: {caller}",
8484
logger="notification_stream",
85+
# Associates this notification with the original request
86+
# Ensures notifications are sent to the correct response stream
87+
# Without this, notifications will either go to:
88+
# - a standalone SSE stream (if GET request is supported)
89+
# - nowhere (if GET request isn't supported)
8590
related_request_id=ctx.request_id,
8691
)
8792
if i < count - 1: # Don't wait after the last notification

src/mcp/server/fastmcp/server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ async def run_stdio_async(self) -> None:
466466
async def run_sse_async(self) -> None:
467467
"""Run the server using SSE transport."""
468468
import uvicorn
469+
469470
starlette_app = self.sse_app()
470471

471472
config = uvicorn.Config(
@@ -673,7 +674,10 @@ async def log(
673674
**extra: Additional structured data to include
674675
"""
675676
await self.request_context.session.send_log_message(
676-
level=level, data=message, logger=logger_name
677+
level=level,
678+
data=message,
679+
logger=logger_name,
680+
related_request_id=self.request_id,
677681
)
678682

679683
@property

0 commit comments

Comments
 (0)