This commit is contained in:
parent
3a6f2996cd
commit
837ef904f8
1 changed files with 1757 additions and 567 deletions
|
|
@ -119,6 +119,7 @@ async def test_client_is_initialized(app: MCPServer):
|
|||
tools=ToolsCapability(list_changed=False),
|
||||
)
|
||||
)
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "test"
|
||||
|
||||
|
||||
|
|
@ -134,7 +135,8 @@ async def test_client_with_simple_server(simple_server: Server):
|
|||
resources = await client.list_resources()
|
||||
assert resources == snapshot(
|
||||
ListResourcesResult(
|
||||
resources=[Resource(name="Test Resource", uri="memory://test", description="A test resource")]
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test_server", "version": ""}},
|
||||
resources=[Resource(name="Test Resource", uri="memory://test", description="A test resource")],
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -150,6 +152,7 @@ async def test_client_list_tools(app: MCPServer):
|
|||
result = await client.list_tools()
|
||||
assert result == snapshot(
|
||||
ListToolsResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
tools=[
|
||||
Tool(
|
||||
name="greet",
|
||||
|
|
@ -167,7 +170,7 @@ async def test_client_list_tools(app: MCPServer):
|
|||
"type": "object",
|
||||
},
|
||||
)
|
||||
]
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -177,6 +180,7 @@ async def test_client_call_tool(app: MCPServer):
|
|||
result = await client.call_tool("greet", {"name": "World"})
|
||||
assert result == snapshot(
|
||||
CallToolResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
content=[TextContent(text="Hello, World!")],
|
||||
structured_content={"result": "Hello, World!"},
|
||||
)
|
||||
|
|
@ -189,7 +193,8 @@ async def test_read_resource(app: MCPServer):
|
|||
result = await client.read_resource("test://resource")
|
||||
assert result == snapshot(
|
||||
ReadResourceResult(
|
||||
contents=[TextResourceContents(uri="test://resource", mime_type="text/plain", text="Test content")]
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
contents=[TextResourceContents(uri="test://resource", mime_type="text/plain", text="Test content")],
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -269,6 +274,7 @@ async def test_get_prompt(app: MCPServer):
|
|||
result = await client.get_prompt("greeting_prompt", {"name": "Alice"})
|
||||
assert result == snapshot(
|
||||
GetPromptResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
description="A greeting prompt.",
|
||||
messages=[PromptMessage(role="user", content=TextContent(text="Please greet Alice warmly."))],
|
||||
)
|
||||
|
|
@ -335,6 +341,7 @@ async def test_client_list_resources_with_params(app: MCPServer):
|
|||
result = await client.list_resources()
|
||||
assert result == snapshot(
|
||||
ListResourcesResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
resources=[
|
||||
Resource(
|
||||
name="test_resource",
|
||||
|
|
@ -342,7 +349,7 @@ async def test_client_list_resources_with_params(app: MCPServer):
|
|||
description="A test resource.",
|
||||
mime_type="text/plain",
|
||||
)
|
||||
]
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -351,7 +358,11 @@ async def test_client_list_resource_templates(app: MCPServer):
|
|||
"""Test listing resource templates with params parameter."""
|
||||
async with Client(app) as client:
|
||||
result = await client.list_resource_templates()
|
||||
assert result == snapshot(ListResourceTemplatesResult(resource_templates=[]))
|
||||
assert result == snapshot(
|
||||
ListResourceTemplatesResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}}, resource_templates=[]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def test_list_prompts(app: MCPServer):
|
||||
|
|
@ -360,13 +371,14 @@ async def test_list_prompts(app: MCPServer):
|
|||
result = await client.list_prompts()
|
||||
assert result == snapshot(
|
||||
ListPromptsResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
prompts=[
|
||||
Prompt(
|
||||
name="greeting_prompt",
|
||||
description="A greeting prompt.",
|
||||
arguments=[PromptArgument(name="name", required=True)],
|
||||
)
|
||||
]
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -376,7 +388,12 @@ async def test_complete_with_prompt_reference(simple_server: Server):
|
|||
async with Client(simple_server) as client:
|
||||
ref = types.PromptReference(type="ref/prompt", name="test_prompt")
|
||||
result = await client.complete(ref=ref, argument={"name": "arg", "value": "test"})
|
||||
assert result == snapshot(types.CompleteResult(completion=types.Completion(values=[])))
|
||||
assert result == snapshot(
|
||||
types.CompleteResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test_server", "version": ""}},
|
||||
completion=types.Completion(values=[]),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_client_with_url_initializes_streamable_http_transport():
|
||||
|
|
@ -573,6 +590,7 @@ async def test_client_auto_mode_falls_back_to_initialize_on_legacy_signal(code:
|
|||
with anyio.fail_after(5):
|
||||
async with Client(scripted_transport(), mode="auto") as client:
|
||||
assert client.protocol_version == LATEST_HANDSHAKE_VERSION
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "legacy-only"
|
||||
assert methods_seen == ["server/discover", "initialize", "notifications/initialized"]
|
||||
|
||||
|
|
@ -754,7 +772,11 @@ async def test_call_tool_auto_loop_dispatches_elicitation_then_returns_final_res
|
|||
result = await client.call_tool("greet")
|
||||
|
||||
assert result == snapshot(
|
||||
CallToolResult(content=[TextContent(text="Hello, Ada!")], structured_content={"result": "Hello, Ada!"})
|
||||
CallToolResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
content=[TextContent(text="Hello, Ada!")],
|
||||
structured_content={"result": "Hello, Ada!"},
|
||||
)
|
||||
)
|
||||
assert len(callback_params) == 1
|
||||
assert isinstance(callback_params[0], types.ElicitRequestFormParams)
|
||||
|
|
@ -800,7 +822,9 @@ async def test_call_tool_auto_loop_dispatches_sampling_then_returns_final_result
|
|||
|
||||
assert result == snapshot(
|
||||
CallToolResult(
|
||||
content=[TextContent(text="Model said: Paris")], structured_content={"result": "Model said: Paris"}
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
content=[TextContent(text="Model said: Paris")],
|
||||
structured_content={"result": "Model said: Paris"},
|
||||
)
|
||||
)
|
||||
assert len(callback_params) == 1
|
||||
|
|
@ -833,6 +857,7 @@ async def test_call_tool_auto_loop_dispatches_list_roots_then_returns_final_resu
|
|||
|
||||
assert result == snapshot(
|
||||
CallToolResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
content=[TextContent(text="Client exposed 1 root(s).")],
|
||||
structured_content={"result": "Client exposed 1 root(s)."},
|
||||
)
|
||||
|
|
@ -917,7 +942,12 @@ async def test_get_prompt_auto_loop_resolves_input_required_via_callbacks() -> N
|
|||
with anyio.fail_after(5):
|
||||
async with Client(server, mode="2026-07-28", elicitation_callback=elicitation_callback) as client:
|
||||
result = await client.get_prompt("summary")
|
||||
assert result == snapshot(GetPromptResult(messages=[PromptMessage(role="user", content=TextContent(text="ok"))]))
|
||||
assert result == snapshot(
|
||||
GetPromptResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
messages=[PromptMessage(role="user", content=TextContent(text="ok"))],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def test_read_resource_auto_loop_resolves_input_required_via_callbacks() -> None:
|
||||
|
|
@ -944,5 +974,8 @@ async def test_read_resource_auto_loop_resolves_input_required_via_callbacks() -
|
|||
async with Client(server, mode="2026-07-28", elicitation_callback=elicitation_callback) as client:
|
||||
result = await client.read_resource("memory://gated")
|
||||
assert result == snapshot(
|
||||
ReadResourceResult(contents=[TextResourceContents(uri="memory://gated", text="unlocked")])
|
||||
ReadResourceResult(
|
||||
_meta={"io.modelcontextprotocol/serverInfo": {"name": "test", "version": ""}},
|
||||
contents=[TextResourceContents(uri="memory://gated", text="unlocked")],
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue