Skip to content

Commit 1cce329

Browse files
committed
docs: add migration entry for Context logging changes
Github-Issue: #397
1 parent 59b7506 commit 1cce329

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
@@ -343,6 +343,26 @@ async def my_tool(x: int, ctx: Context) -> str:
343343

344344
The internal layers (`ToolManager.call_tool`, `Tool.run`, `Prompt.render`, `ResourceTemplate.create_resource`, etc.) now require `context` as a positional argument.
345345

346+
### `MCPServer`'s `Context` logging: `message` renamed to `data`, `extra` removed
347+
348+
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`.
349+
350+
The lowlevel `ServerSession.send_log_message(data: Any)` already accepted arbitrary data and is unchanged.
351+
352+
`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.
353+
354+
```python
355+
# Before
356+
await ctx.info("Connection failed", extra={"host": "localhost", "port": 5432})
357+
await ctx.log(level="info", message="hello")
358+
359+
# After
360+
await ctx.info({"message": "Connection failed", "host": "localhost", "port": 5432})
361+
await ctx.log(level="info", data="hello")
362+
```
363+
364+
Positional calls (`await ctx.info("hello")`) are unaffected.
365+
346366
### Replace `RootModel` by union types with `TypeAdapter` validation
347367

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

0 commit comments

Comments
 (0)