Extend resolver DI to sampling and roots requests (#3049)

This commit is contained in:
Max 2026-07-06 18:25:57 +01:00 • committed by GitHub
commit d287c9868f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,7 @@ from mcp_types import (
SamplingMessage,
TextContent,
Tool,
ToolChoice,
)
from mcp.shared.dispatcher import DispatchContext
@ -91,6 +92,21 @@ async def test_peer_sample_with_tools_returns_with_tools_result():
assert isinstance(result, CreateMessageResultWithTools)
@pytest.mark.anyio
async def test_peer_sample_with_tool_choice_only_returns_with_tools_result():
# tool_choice alone is tools-mode: the answer may carry array content.
rec = _Recorder({"role": "assistant", "content": [{"type": "text", "text": "x"}], "model": "m"})
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( # pyright: ignore[reportDeprecated]
[SamplingMessage(role="user", content=TextContent(type="text", text="q"))],
max_tokens=5,
tool_choice=ToolChoice(mode="none"),
)
assert isinstance(result, CreateMessageResultWithTools)
@pytest.mark.anyio
async def test_peer_elicit_form_sends_elicitation_create_with_form_params():
rec = _Recorder({"action": "accept", "content": {"name": "Max"}})