Deprecate roots, sampling, and logging methods per SEP-2577 (#2926)

This commit is contained in:
Marcelo Trylesinski 2026-06-20 17:25:41 +01:00 • committed by GitHub
commit 4573e4ac33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 206 additions and 123 deletions

View file

@ -12,6 +12,7 @@ import anyio
import pytest
from mcp.shared.dispatcher import DispatchContext
from mcp.shared.exceptions import MCPDeprecationWarning
from mcp.shared.peer import ClientPeer, dump_params
from mcp.shared.transport_context import TransportContext
from mcp.types import (
@ -46,7 +47,7 @@ async def test_peer_sample_sends_create_message_and_returns_typed_result():
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
result = await peer.sample(
result = await peer.sample( # pyright: ignore[reportDeprecated]
[SamplingMessage(role="user", content=TextContent(type="text", text="hello"))],
max_tokens=10,
)
@ -66,7 +67,7 @@ async def test_peer_sample_validates_result_alias_only():
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
result = await peer.sample(
result = await peer.sample( # pyright: ignore[reportDeprecated]
[SamplingMessage(role="user", content=TextContent(type="text", text="q"))], max_tokens=1
)
assert isinstance(result, CreateMessageResult)
@ -79,7 +80,7 @@ async def test_peer_sample_with_tools_returns_with_tools_result():
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
result = await peer.sample(
result = await peer.sample( # pyright: ignore[reportDeprecated]
[SamplingMessage(role="user", content=TextContent(type="text", text="q"))],
max_tokens=5,
tools=[Tool(name="t", input_schema={"type": "object"})],
@ -124,7 +125,7 @@ async def test_peer_list_roots_sends_roots_list_and_returns_typed_result():
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
result = await peer.list_roots()
result = await peer.list_roots() # pyright: ignore[reportDeprecated]
method, _ = rec.seen[0]
assert method == "roots/list"
assert isinstance(result, ListRootsResult)
@ -138,12 +139,25 @@ async def test_peer_list_roots_with_meta_sends_meta_in_params():
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
await peer.list_roots(meta={"traceId": "t1"})
await peer.list_roots(meta={"traceId": "t1"}) # pyright: ignore[reportDeprecated]
method, params = rec.seen[0]
assert method == "roots/list"
assert params == {"_meta": {"traceId": "t1"}}
@pytest.mark.anyio
async def test_peer_list_roots_is_deprecated_sep_2577():
rec = _Recorder({"roots": []})
async with running_pair(direct_pair, server_on_request=rec.on_request) as (client, *_):
peer = ClientPeer(client)
with anyio.fail_after(5):
with pytest.warns(
MCPDeprecationWarning, match=r"The roots capability is deprecated as of 2026-07-28 \(SEP-2577\)\."
):
await peer.list_roots() # pyright: ignore[reportDeprecated]
assert rec.seen[0][0] == "roots/list"
def test_dump_params_merges_meta_over_model_meta():
out = dump_params(None, None)
assert out is None

View file

@ -212,7 +212,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
return CallToolResult(content=[TextContent(type="text", text=f"Called {name}")])
elif name == "test_sampling_tool":
sampling_result = await ctx.session.create_message(
sampling_result = await ctx.session.create_message( # pyright: ignore[reportDeprecated]
messages=[
types.SamplingMessage(
role="user",
@ -234,7 +234,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
)
elif name == "wait_for_lock_with_notification":
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="First notification before lock",
logger="lock_tool",
@ -243,7 +243,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
await ctx.lifespan_context.lock.wait()
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="Second notification after lock",
logger="lock_tool",
@ -257,7 +257,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
return CallToolResult(content=[TextContent(type="text", text="Lock released")])
elif name == "tool_with_stream_close":
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="Before close",
logger="stream_close_tool",
@ -266,7 +266,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
assert ctx.close_sse_stream is not None
await ctx.close_sse_stream()
await anyio.sleep(0.1)
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="After close",
logger="stream_close_tool",
@ -275,7 +275,7 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
return CallToolResult(content=[TextContent(type="text", text="Done")])
elif name == "tool_with_multiple_notifications_and_close":
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="notification1",
logger="multi_notif_tool",
@ -284,13 +284,13 @@ async def _handle_call_tool(ctx: ServerRequestContext[ServerState], params: Call
assert ctx.close_sse_stream is not None
await ctx.close_sse_stream()
await anyio.sleep(0.1)
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="notification2",
logger="multi_notif_tool",
related_request_id=ctx.request_id,
)
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data="notification3",
logger="multi_notif_tool",
@ -2085,7 +2085,7 @@ async def test_streamable_http_multiple_reconnections() -> None:
async def handle_call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> CallToolResult:
assert params.name == "multi_close_tool"
for i, milestone in enumerate(milestones.values()):
await ctx.session.send_log_message(
await ctx.session.send_log_message( # pyright: ignore[reportDeprecated]
level="info",
data=f"checkpoint_{i}",
logger="multi_close_tool",