Deprecate roots, sampling, and logging methods per SEP-2577 (#2926)
This commit is contained in:
parent
5734acf18e
commit
4573e4ac33
6 changed files with 206 additions and 123 deletions
|
|
@ -1110,10 +1110,10 @@ class TestContextInjection:
|
|||
mcp = MCPServer()
|
||||
|
||||
async def logging_tool(msg: str, ctx: Context) -> str:
|
||||
await ctx.debug("Debug message")
|
||||
await ctx.info("Info message")
|
||||
await ctx.warning("Warning message")
|
||||
await ctx.error("Error message")
|
||||
await ctx.debug("Debug message") # pyright: ignore[reportDeprecated]
|
||||
await ctx.info("Info message") # pyright: ignore[reportDeprecated]
|
||||
await ctx.warning("Warning message") # pyright: ignore[reportDeprecated]
|
||||
await ctx.error("Error message") # pyright: ignore[reportDeprecated]
|
||||
return f"Logged messages for {msg}"
|
||||
|
||||
mcp.add_tool(logging_tool)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ async def test_server_handles_transport_close_with_pending_server_to_client_requ
|
|||
both_started.set()
|
||||
# Blocks on send_request waiting for a client response that never comes.
|
||||
# _receive_loop's finally will wake this with CONNECTION_CLOSED.
|
||||
await ctx.session.list_roots()
|
||||
await ctx.session.list_roots() # pyright: ignore[reportDeprecated]
|
||||
raise AssertionError # pragma: no cover
|
||||
|
||||
server = Server("test", on_call_tool=handle_call_tool)
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ async def test_connection_ping_sends_ping_on_standalone():
|
|||
async def test_connection_log_sends_logging_message_notification():
|
||||
out = StubOutbound()
|
||||
conn = Connection(out, has_standalone_channel=True)
|
||||
await conn.log("info", {"k": "v"}, logger="my.logger")
|
||||
await conn.log("info", {"k": "v"}, logger="my.logger") # pyright: ignore[reportDeprecated]
|
||||
method, params = out.notifications[0]
|
||||
assert method == "notifications/message"
|
||||
assert params is not None
|
||||
|
|
@ -219,7 +219,7 @@ async def test_connection_log_sends_logging_message_notification():
|
|||
async def test_connection_log_with_meta_includes_meta_in_params():
|
||||
out = StubOutbound()
|
||||
conn = Connection(out, has_standalone_channel=True)
|
||||
await conn.log("info", "x", meta={"traceId": "abc"})
|
||||
await conn.log("info", "x", meta={"traceId": "abc"}) # pyright: ignore[reportDeprecated]
|
||||
_, params = out.notifications[0]
|
||||
assert params is not None
|
||||
assert params["_meta"] == {"traceId": "abc"}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ async def test_context_log_sends_request_scoped_message_notification():
|
|||
ctx: Context[_Lifespan] = Context(
|
||||
dctx, lifespan=_Lifespan("app"), connection=Connection(dctx, has_standalone_channel=True)
|
||||
)
|
||||
await ctx.log("debug", "hello")
|
||||
await ctx.log("debug", "hello") # pyright: ignore[reportDeprecated]
|
||||
return {}
|
||||
|
||||
async with running_pair(direct_pair, server_on_request=server_on_request, client_on_notify=c_notify) as (
|
||||
|
|
@ -85,7 +85,7 @@ async def test_context_log_includes_logger_and_meta_when_supplied():
|
|||
ctx: Context[_Lifespan] = Context(
|
||||
dctx, lifespan=_Lifespan("app"), connection=Connection(dctx, has_standalone_channel=True)
|
||||
)
|
||||
await ctx.log("info", "x", logger="my.log", meta={"traceId": "t"})
|
||||
await ctx.log("info", "x", logger="my.log", meta={"traceId": "t"}) # pyright: ignore[reportDeprecated]
|
||||
return {}
|
||||
|
||||
async with running_pair(direct_pair, server_on_request=server_on_request, client_on_notify=c_notify) as (
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ async def test_create_message_with_tools_returns_with_tools_result():
|
|||
session = _make_session(
|
||||
dispatcher, capabilities=ClientCapabilities(sampling=SamplingCapability(tools=SamplingToolsCapability()))
|
||||
)
|
||||
result = await session.create_message(
|
||||
result = await session.create_message( # pyright: ignore[reportDeprecated]
|
||||
messages=[types.SamplingMessage(role="user", content=types.TextContent(type="text", text="hi"))],
|
||||
max_tokens=10,
|
||||
tools=[types.Tool(name="t", input_schema={"type": "object"})],
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ def stateless_session() -> ServerSession:
|
|||
async def test_list_roots_fails_in_stateless_mode(stateless_session: ServerSession):
|
||||
"""Test that list_roots raises StatelessModeNotSupported in stateless mode."""
|
||||
with pytest.raises(StatelessModeNotSupported, match="list_roots"):
|
||||
await stateless_session.list_roots()
|
||||
await stateless_session.list_roots() # pyright: ignore[reportDeprecated]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_message_fails_in_stateless_mode(stateless_session: ServerSession):
|
||||
"""Test that create_message raises StatelessModeNotSupported in stateless mode."""
|
||||
with pytest.raises(StatelessModeNotSupported, match="sampling"):
|
||||
await stateless_session.create_message(
|
||||
await stateless_session.create_message( # pyright: ignore[reportDeprecated]
|
||||
messages=[
|
||||
types.SamplingMessage(
|
||||
role="user",
|
||||
|
|
@ -95,7 +95,7 @@ async def test_elicit_deprecated_fails_in_stateless_mode(stateless_session: Serv
|
|||
async def test_stateless_error_message_is_actionable(stateless_session: ServerSession):
|
||||
"""Test that the error message provides actionable guidance."""
|
||||
with pytest.raises(StatelessModeNotSupported) as exc_info:
|
||||
await stateless_session.list_roots()
|
||||
await stateless_session.list_roots() # pyright: ignore[reportDeprecated]
|
||||
|
||||
error_message = str(exc_info.value)
|
||||
# Should mention it's stateless mode
|
||||
|
|
@ -110,7 +110,7 @@ async def test_stateless_error_message_is_actionable(stateless_session: ServerSe
|
|||
async def test_exception_has_method_attribute(stateless_session: ServerSession):
|
||||
"""Test that the exception has a method attribute for programmatic access."""
|
||||
with pytest.raises(StatelessModeNotSupported) as exc_info:
|
||||
await stateless_session.list_roots()
|
||||
await stateless_session.list_roots() # pyright: ignore[reportDeprecated]
|
||||
|
||||
assert exc_info.value.method == "list_roots"
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ async def test_stateful_mode_does_not_raise_stateless_error(
|
|||
monkeypatch.setattr(stateful_session, "send_request", mock_send_request)
|
||||
|
||||
# This should NOT raise StatelessModeNotSupported
|
||||
result = await stateful_session.list_roots()
|
||||
result = await stateful_session.list_roots() # pyright: ignore[reportDeprecated]
|
||||
|
||||
assert send_request_called
|
||||
assert isinstance(result, types.ListRootsResult)
|
||||
|
|
|
|||
Loading…
Reference in a new issue