Skip to content

Commit 924f123

Browse files
committed
docs: add migration entry for Context logging changes
Github-Issue: #397
1 parent e304743 commit 924f123

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/migration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,26 @@ mcp._lowlevel_server._add_request_handler("resources/subscribe", handle_subscrib
467467

468468
This is a private API and may change. A public way to register these handlers on `MCPServer` is planned; until then, use this workaround or use the lowlevel `Server` directly.
469469

470+
### `MCPServer`'s `Context` logging: `message` renamed to `data`, `extra` removed
471+
472+
On the high-level `Context` object (`mcp.server.mcpserver.Context`), `log()`, `.debug()`, `.info()`, `.warning()`, and `.error()` now take `data: Any` instead of `message: str`, matching the MCP spec's `LoggingMessageNotificationParams.data` field which allows any JSON-serializable value. The `extra` parameter has been removed — pass structured data directly as `data`.
473+
474+
The lowlevel `ServerSession.send_log_message(data: Any)` already accepted arbitrary data and is unchanged.
475+
476+
`Context.log()` also now accepts all eight RFC-5424 log levels (`debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert`, `emergency`) via the `LoggingLevel` type, not just the four it previously allowed.
477+
478+
```python
479+
# Before
480+
await ctx.info("Connection failed", extra={"host": "localhost", "port": 5432})
481+
await ctx.log(level="info", message="hello")
482+
483+
# After
484+
await ctx.info({"message": "Connection failed", "host": "localhost", "port": 5432})
485+
await ctx.log(level="info", data="hello")
486+
```
487+
488+
Positional calls (`await ctx.info("hello")`) are unaffected.
489+
470490
### Replace `RootModel` by union types with `TypeAdapter` validation
471491

472492
The following union types are no longer `RootModel` subclasses:

0 commit comments

Comments
 (0)