Skip to content

Commit a465678

Browse files
committed
Deprecate only Context.log for logging, with a capability-level message
The `debug`/`info`/`warning`/`error` convenience helpers delegate to `Context.log`, so deprecating `log` alone covers them - they warn through it instead of each carrying their own marker. Drop their `@deprecated` decorators and the now-stale `# pyright: ignore[reportDeprecated]` on their call sites. Reword every logging deprecation ("The logging capability is deprecated as of ...") so the message names the feature rather than the individual method, and widen the `filterwarnings` pattern to match the new wording.
1 parent a5c1522 commit a465678

17 files changed

Lines changed: 49 additions & 53 deletions

File tree

README.v2.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ mcp = MCPServer(name="Progress Example")
360360
@mcp.tool()
361361
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
362362
"""Execute a task with progress updates."""
363-
await ctx.info(f"Starting: {task_name}") # pyright: ignore[reportDeprecated]
363+
await ctx.info(f"Starting: {task_name}")
364364

365365
for i in range(steps):
366366
progress = (i + 1) / steps
@@ -369,7 +369,7 @@ async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str
369369
total=1.0,
370370
message=f"Step {i + 1}/{steps}",
371371
)
372-
await ctx.debug(f"Completed step {i + 1}") # pyright: ignore[reportDeprecated]
372+
await ctx.debug(f"Completed step {i + 1}")
373373

374374
return f"Task '{task_name}' completed"
375375
```
@@ -707,7 +707,7 @@ mcp = MCPServer(name="Progress Example")
707707
@mcp.tool()
708708
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
709709
"""Execute a task with progress updates."""
710-
await ctx.info(f"Starting: {task_name}") # pyright: ignore[reportDeprecated]
710+
await ctx.info(f"Starting: {task_name}")
711711

712712
for i in range(steps):
713713
progress = (i + 1) / steps
@@ -716,7 +716,7 @@ async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str
716716
total=1.0,
717717
message=f"Step {i + 1}/{steps}",
718718
)
719-
await ctx.debug(f"Completed step {i + 1}") # pyright: ignore[reportDeprecated]
719+
await ctx.debug(f"Completed step {i + 1}")
720720

721721
return f"Task '{task_name}' completed"
722722
```
@@ -982,10 +982,10 @@ mcp = MCPServer(name="Notifications Example")
982982
async def process_data(data: str, ctx: Context) -> str:
983983
"""Process data with logging."""
984984
# Different log levels
985-
await ctx.debug(f"Debug: Processing '{data}'") # pyright: ignore[reportDeprecated]
986-
await ctx.info("Info: Starting processing") # pyright: ignore[reportDeprecated]
987-
await ctx.warning("Warning: This is experimental") # pyright: ignore[reportDeprecated]
988-
await ctx.error("Error: (This is just a demo)") # pyright: ignore[reportDeprecated]
985+
await ctx.debug(f"Debug: Processing '{data}'")
986+
await ctx.info("Info: Starting processing")
987+
await ctx.warning("Warning: This is experimental")
988+
await ctx.error("Error: (This is just a demo)")
989989

990990
# Notify about resource changes
991991
await ctx.session.send_resource_list_changed()

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ The user-facing methods for these features now carry `typing_extensions.deprecat
12241224

12251225
- Sampling: `ServerSession.create_message()`, `ClientPeer.sample()`
12261226
- Roots: `ServerSession.list_roots()`, `ClientPeer.list_roots()`, `ClientSession.send_roots_list_changed()`, `Client.send_roots_list_changed()`
1227-
- Logging: `ServerSession.send_log_message()`, `ClientSession.set_logging_level()`, `Client.set_logging_level()`, and the `MCPServer` `Context` helpers `log()`, `debug()`, `info()`, `warning()`, `error()`
1227+
- Logging: `ServerSession.send_log_message()`, `ClientSession.set_logging_level()`, `Client.set_logging_level()`, and `MCPServer` `Context.log()`. The `Context.debug()` / `info()` / `warning()` / `error()` helpers delegate to `log()`, so they warn through it rather than carrying their own marker.
12281228

12291229
The runtime warning is emitted as `mcp.MCPDeprecationWarning`, which subclasses `UserWarning` (not `DeprecationWarning`) so it is visible by default. To silence it, filter that category:
12301230

examples/servers/everything-server/mcp_everything_server/server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ def test_multiple_content_types() -> list[TextContent | ImageContent | EmbeddedR
143143
@mcp.tool()
144144
async def test_tool_with_logging(ctx: Context) -> str:
145145
"""Tests tool that emits log messages during execution"""
146-
await ctx.info("Tool execution started") # pyright: ignore[reportDeprecated]
146+
await ctx.info("Tool execution started")
147147
await asyncio.sleep(0.05)
148148

149-
await ctx.info("Tool processing data") # pyright: ignore[reportDeprecated]
149+
await ctx.info("Tool processing data")
150150
await asyncio.sleep(0.05)
151151

152-
await ctx.info("Tool execution completed") # pyright: ignore[reportDeprecated]
152+
await ctx.info("Tool execution completed")
153153
return "Tool with logging executed successfully"
154154

155155

@@ -314,13 +314,13 @@ def test_error_handling() -> str:
314314
@mcp.tool()
315315
async def test_reconnection(ctx: Context) -> str:
316316
"""Tests SSE polling by closing stream mid-call (SEP-1699)"""
317-
await ctx.info("Before disconnect") # pyright: ignore[reportDeprecated]
317+
await ctx.info("Before disconnect")
318318

319319
await ctx.close_sse_stream()
320320

321321
await asyncio.sleep(0.2) # Wait for client to reconnect
322322

323-
await ctx.info("After reconnect") # pyright: ignore[reportDeprecated]
323+
await ctx.info("After reconnect")
324324
return "Reconnection test completed"
325325

326326

examples/snippets/servers/notifications.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
async def process_data(data: str, ctx: Context) -> str:
88
"""Process data with logging."""
99
# Different log levels
10-
await ctx.debug(f"Debug: Processing '{data}'") # pyright: ignore[reportDeprecated]
11-
await ctx.info("Info: Starting processing") # pyright: ignore[reportDeprecated]
12-
await ctx.warning("Warning: This is experimental") # pyright: ignore[reportDeprecated]
13-
await ctx.error("Error: (This is just a demo)") # pyright: ignore[reportDeprecated]
10+
await ctx.debug(f"Debug: Processing '{data}'")
11+
await ctx.info("Info: Starting processing")
12+
await ctx.warning("Warning: This is experimental")
13+
await ctx.error("Error: (This is just a demo)")
1414

1515
# Notify about resource changes
1616
await ctx.session.send_resource_list_changed()

examples/snippets/servers/tool_progress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@mcp.tool()
77
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
88
"""Execute a task with progress updates."""
9-
await ctx.info(f"Starting: {task_name}") # pyright: ignore[reportDeprecated]
9+
await ctx.info(f"Starting: {task_name}")
1010

1111
for i in range(steps):
1212
progress = (i + 1) / steps
@@ -15,6 +15,6 @@ async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str
1515
total=1.0,
1616
message=f"Step {i + 1}/{steps}",
1717
)
18-
await ctx.debug(f"Completed step {i + 1}") # pyright: ignore[reportDeprecated]
18+
await ctx.debug(f"Completed step {i + 1}")
1919

2020
return f"Task '{task_name}' completed"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ filterwarnings = [
216216
# SEP-2577 deprecates the roots/sampling/logging methods; the SDK still calls
217217
# them internally (e.g. `ctx.debug` -> `log` -> `send_log_message`), so the
218218
# advisory warning is silenced. Tests asserting it opt back in with pytest.warns.
219-
"ignore:`.*` is deprecated as of 2026-07-28 \\(SEP-2577\\).:mcp.MCPDeprecationWarning",
219+
"ignore:.*is deprecated as of 2026-07-28 \\(SEP-2577\\).:mcp.MCPDeprecationWarning",
220220
]
221221

222222
[tool.markdown.lint]

src/mcp/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def send_progress_notification(
198198
message=message,
199199
)
200200

201-
@deprecated("`set_logging_level` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
201+
@deprecated("The logging capability is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
202202
async def set_logging_level(self, level: LoggingLevel, *, meta: RequestParamsMeta | None = None) -> EmptyResult:
203203
"""Set the logging level on the server."""
204204
return await self.session.set_logging_level(level=level, meta=meta) # pyright: ignore[reportDeprecated]

src/mcp/client/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ async def send_progress_notification(
386386
)
387387
)
388388

389-
@deprecated("`set_logging_level` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
389+
@deprecated("The logging capability is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
390390
async def set_logging_level(
391391
self,
392392
level: types.LoggingLevel,

src/mcp/server/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def headers(self) -> Mapping[str, str] | None:
9393
"""
9494
return self.transport.headers
9595

96-
@deprecated("`log` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
96+
@deprecated("The logging capability is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
9797
async def log(self, level: LoggingLevel, data: Any, logger: str | None = None, *, meta: Meta | None = None) -> None:
9898
"""Send a request-scoped `notifications/message` log entry.
9999

src/mcp/server/mcpserver/context.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async def elicit_url(
191191
related_request_id=self.request_id,
192192
)
193193

194-
@deprecated("`log` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
194+
@deprecated("The logging capability is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
195195
async def log(
196196
self,
197197
level: LoggingLevel,
@@ -268,22 +268,18 @@ async def close_standalone_sse_stream(self) -> None:
268268
await self._request_context.close_standalone_sse_stream()
269269

270270
# Convenience methods for common log levels
271-
@deprecated("`debug` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
272271
async def debug(self, data: Any, *, logger_name: str | None = None) -> None:
273272
"""Send a debug log message."""
274273
await self.log("debug", data, logger_name=logger_name) # pyright: ignore[reportDeprecated]
275274

276-
@deprecated("`info` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
277275
async def info(self, data: Any, *, logger_name: str | None = None) -> None:
278276
"""Send an info log message."""
279277
await self.log("info", data, logger_name=logger_name) # pyright: ignore[reportDeprecated]
280278

281-
@deprecated("`warning` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
282279
async def warning(self, data: Any, *, logger_name: str | None = None) -> None:
283280
"""Send a warning log message."""
284281
await self.log("warning", data, logger_name=logger_name) # pyright: ignore[reportDeprecated]
285282

286-
@deprecated("`error` is deprecated as of 2026-07-28 (SEP-2577).", category=MCPDeprecationWarning)
287283
async def error(self, data: Any, *, logger_name: str | None = None) -> None:
288284
"""Send an error log message."""
289285
await self.log("error", data, logger_name=logger_name) # pyright: ignore[reportDeprecated]

0 commit comments

Comments
 (0)