Gate log notifications on the per-request log-level opt-in at 2026-07-28 (#3198)
This commit is contained in:
parent
b61ce388dd
commit
89c5e700f2
1 changed files with 406 additions and 31 deletions
|
|
@ -25,6 +25,7 @@ from mcp_types import (
|
|||
INVALID_PARAMS,
|
||||
INVALID_REQUEST,
|
||||
LATEST_PROTOCOL_VERSION,
|
||||
LOG_LEVEL_META_KEY,
|
||||
METHOD_NOT_FOUND,
|
||||
PROTOCOL_VERSION_META_KEY,
|
||||
SERVER_INFO_META_KEY,
|
||||
|
|
@ -1759,6 +1760,26 @@ async def test_dual_era_loop_legacy_notifications_reach_the_loop_runner(server:
|
|||
await handled.wait()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dual_era_loop_a_notifications_meta_never_opens_the_log_gate(server: SrvT):
|
||||
"""The 2026 log-delivery opt-in is a request's `_meta`: an inbound notification
|
||||
has no request to opt in, so a handler logging in response to one - even
|
||||
with the log-level key in the notification's own `_meta` - sends nothing."""
|
||||
logged = anyio.Event()
|
||||
|
||||
async def log_it(ctx: Ctx, params: NotificationParams | None) -> None:
|
||||
await ctx.session.send_log_message("emergency", "no request opted in") # pyright: ignore[reportDeprecated]
|
||||
logged.set()
|
||||
|
||||
server.add_notification_handler("notifications/custom", NotificationParams, log_it)
|
||||
async with dual_era_client(server) as (client, recorder):
|
||||
await client.send_raw_request("tools/list", _modern_params())
|
||||
meta = {**_modern_envelope(), LOG_LEVEL_META_KEY: "debug"}
|
||||
await client.notify("notifications/custom", {"_meta": meta})
|
||||
await logged.wait()
|
||||
assert [method for method, _ in recorder.notifications] == []
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dual_era_loop_modern_server_notifications_ride_the_pipe(server: SrvT):
|
||||
"""A modern handler's standalone notification reaches the client over the
|
||||
|
|
|
|||
Loading…
Reference in a new issue