Gate log notifications on the per-request log-level opt-in at 2026-07-28 (#3198)

This commit is contained in:
Max 2026-07-28 02:20:33 +01:00 • committed by GitHub
commit 89c5e700f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 406 additions and 31 deletions

View file

@ -15,7 +15,9 @@ async def main(target: Target, *, mode: str = "auto") -> None:
async def on_log(params: LoggingMessageNotificationParams) -> None:
logs.append(params)
async with Client(target, mode=mode, logging_callback=on_log) as client:
# `log_level` is the 2026-07-28 per-request opt-in: without it a modern server
# sends no log notifications at all (pre-2026 servers ignore it and send anyway).
async with Client(target, mode=mode, logging_callback=on_log, log_level="info") as client:
# ── progress + logging: a short countdown delivers exactly `steps` of each, in order ──
updates: list[tuple[float, float | None, str | None]] = []

View file

@ -16,9 +16,10 @@ def build_server() -> MCPServer:
try:
for i in range(1, steps + 1):
await ctx.report_progress(float(i), float(steps), f"step {i}/{steps}")
# No non-deprecated logging helper on Context yet, so send the raw
# notification. `related_request_id` keeps it on this request's response
# stream (matters over streamable HTTP).
# Protocol logging is deprecated (SEP-2577), so the raw notification
# keeps this warning-free. On 2026-07-28+ the client only receives it
# because it opts in with `log_level=`; `related_request_id` keeps it on
# this request's response stream (matters over streamable HTTP).
await ctx.request_context.session.send_notification(
types.LoggingMessageNotification(
params=types.LoggingMessageNotificationParams(