This commit is contained in:
parent
3a6f2996cd
commit
837ef904f8
1 changed files with 1757 additions and 567 deletions
|
|
@ -3,7 +3,7 @@
|
|||
import re
|
||||
|
||||
import pytest
|
||||
from mcp_types import DiscoverResult, Implementation, ServerCapabilities
|
||||
from mcp_types import SERVER_INFO_META_KEY, DiscoverResult, Implementation, ServerCapabilities
|
||||
|
||||
from docs_src.protocol_versions import tutorial001, tutorial002, tutorial003, tutorial004
|
||||
from mcp import Client
|
||||
|
|
@ -16,6 +16,7 @@ async def test_auto_lands_on_the_modern_version() -> None:
|
|||
"""tutorial001: the default `mode="auto"` probes `server/discover` and adopts the result."""
|
||||
async with Client(tutorial001.mcp) as client:
|
||||
assert client.protocol_version == "2026-07-28"
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "Bookshop"
|
||||
assert client.session.discover_result is not None
|
||||
assert client.session.initialize_result is None
|
||||
|
|
@ -25,18 +26,18 @@ async def test_legacy_forces_the_initialize_handshake() -> None:
|
|||
"""tutorial002: `mode="legacy"` runs `initialize` against the very same server."""
|
||||
async with Client(tutorial002.mcp, mode="legacy") as client:
|
||||
assert client.protocol_version == "2025-11-25"
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "Bookshop"
|
||||
assert client.session.initialize_result is not None
|
||||
assert client.session.discover_result is None
|
||||
|
||||
|
||||
async def test_version_pin_sends_nothing_and_knows_nothing() -> None:
|
||||
"""tutorial003: a pin adopts the version locally; `server_info` and capabilities are blank."""
|
||||
"""tutorial003: a pin adopts the version locally; `server_info` is None and capabilities are blank."""
|
||||
async with Client(tutorial003.mcp, mode="2026-07-28") as client:
|
||||
assert client.protocol_version == "2026-07-28"
|
||||
assert client.server_info == Implementation(name="", version="")
|
||||
# The `!!! check` fence is the literal `print(client.server_info)` output.
|
||||
assert str(client.server_info) == "name='' title=None version='' description=None website_url=None icons=None"
|
||||
# The `!!! check` fence is the literal `print(client.server_info)` output: None.
|
||||
assert client.server_info is None
|
||||
assert client.server_capabilities == ServerCapabilities()
|
||||
result = await client.call_tool("search_books", {"query": "dune"})
|
||||
assert result.structured_content == {"result": "Found 3 books matching 'dune'."}
|
||||
|
|
@ -63,6 +64,7 @@ async def test_prior_discover_round_trips() -> None:
|
|||
|
||||
async with Client(tutorial004.mcp, mode="2026-07-28", prior_discover=saved) as client:
|
||||
assert client.protocol_version == "2026-07-28"
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "Bookshop"
|
||||
assert client.server_capabilities.tools is not None
|
||||
|
||||
|
|
@ -77,6 +79,7 @@ async def test_discover_result_survives_json() -> None:
|
|||
assert restored == saved
|
||||
|
||||
async with Client(tutorial004.mcp, mode="2026-07-28", prior_discover=restored) as client:
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "Bookshop"
|
||||
|
||||
|
||||
|
|
@ -85,9 +88,14 @@ async def test_prior_discover_is_ignored_unless_mode_is_a_pin() -> None:
|
|||
stale = DiscoverResult(
|
||||
supported_versions=["2026-07-28"],
|
||||
capabilities=ServerCapabilities(),
|
||||
server_info=Implementation(name="Stale", version="0.0.0"),
|
||||
_meta={
|
||||
SERVER_INFO_META_KEY: Implementation(name="Stale", version="0.0.0").model_dump(
|
||||
by_alias=True, mode="json", exclude_none=True
|
||||
)
|
||||
},
|
||||
)
|
||||
async with Client(tutorial004.mcp, prior_discover=stale) as client:
|
||||
assert client.server_info is not None
|
||||
assert client.server_info.name == "Bookshop"
|
||||
async with Client(tutorial004.mcp, mode="legacy", prior_discover=stale) as client:
|
||||
assert client.session.discover_result is None
|
||||
|
|
|
|||
Loading…
Reference in a new issue