Extend resolver DI to sampling and roots requests (#3049)
This commit is contained in:
parent
53117cb3a9
commit
d287c9868f
1 changed files with 1134 additions and 200 deletions
|
|
@ -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"}})
|
||||
|
|
|
|||
Loading…
Reference in a new issue