Description
Describe the bug
According to the MCP spec, the data that may be logged can be of any type.
/**
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
*/
data: unknown;
You can even see an example here.
However, ctx.info
and friends have message typed as str
:
async def info(self, message: str, **extra: Any) -> None:
Even so, the underlying ServerSession.send_log_message
does indicate that data is Any
type:
async def send_log_message(
self, level: types.LoggingLevel, data: Any, logger: str | None = None
) -> None:
And so does LoggingMessageNotificationParams
:
data: Any
"""
The data to be logged, such as a string message or an object. Any JSON serializable
type is allowed here.
"""
Also, it is unclear what the extra
parameters should be for.
To Reproduce
Just look at the source file:
https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/fastmcp/server.py#L703
Expected behavior
This library should follow the spec and allow any JSON serializable type to be logged.
For example, this should work without giving a type error:
ctx.info({"test": "Hello World!"})
MCP servers can use logging to send rich notifications back to the client.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
mcp 1.4.1