Repository navigation
Replies: 2 comments
|
Those log messages are sent over the MCP notifications channel using the How it works (protocol level)After the {
"jsonrpc": "2.0",
"method": "notifications/message",
"params": {
"level": "info",
"logger": "my_server",
"data": "My message to the client here!"
}
}The Transport differencesSSE transport: notifications arrive as Streamable-HTTP transport (newer): notifications are delivered in the response stream of the Client-side (Python
|
|
At the wire level, yes: One correction to the earlier client example: FastMCP clients receive this through the import mcp.types
from fastmcp import Client
from fastmcp.client.messages import MessageHandler
class Logs(MessageHandler):
async def on_logging_message(
self, notification: mcp.types.LoggingMessageNotification
) -> None:
p = notification.params
print(f"[{p.level}] {p.logger or '-'}: {p.data}")
client = Client("server.py", message_handler=Logs())
async with client:
await client.call_tool("my_tool", {})With Streamable HTTP, the notification arrives on the response stream already opened by the call; there is no second SSE connection required just to receive a log emitted during that call. There is also a version distinction now: on the modern References: FastMCP notification handlers and the current logging FAQ. |
Uh oh!
There was an error while loading. Please reload this page.
The FastMCP docs describe enabling server-to-client logs via
Contexthere: https://gofastmcp.com/servers/context#logging , and here: https://gofastmcp.com/servers/logging - for example,ctx.info("My message to the client here!").Which MCP "method" are these sent over, per the spec? Curious about the client-side implementation to consume these. After establishing an MCP connection via
"method":"initialize", and before calling a tool via"method":"tools/call", what needs to happen to receive these logs? An SSE connection? A request to"notifications/message"? Something else?Many thanks!
All reactions