Client-side 2026-07-28 support: .discover()/.adopt() + Client(mode=); request-metadata green (#2950)

This commit is contained in:
Max 2026-06-25 16:09:23 +02:00 • committed by GitHub
commit f226d00d0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2533 additions and 993 deletions

View file

@ -9,13 +9,17 @@ pytestmark = pytest.mark.anyio
async def test_progress_token_zero_first_call():
"""Test that progress notifications work when progress_token is 0 on first call."""
"""Regression: progress reporting must not be gated on a falsy token.
# Create mock session with progress notification tracking
Issue #176: the original Context.report_progress treated token 0 as "no token" and
silently dropped progress. Context now delegates unconditionally to
ServerSession.report_progress (which calls DispatchContext.progress, whose JSONRPC
implementation gates on `is None`, not truthiness), so a request whose meta carries
a 0-valued token still emits all three reports.
"""
mock_session = AsyncMock()
mock_session.send_progress_notification = AsyncMock()
mock_session.report_progress = AsyncMock()
# Create request context with progress token 0
request_context = ServerRequestContext(
request_id="test-request",
session=mock_session,
@ -25,22 +29,14 @@ async def test_progress_token_zero_first_call():
protocol_version="2025-11-25",
)
# Create context with our mocks
ctx = Context(request_context=request_context, mcp_server=MagicMock())
# Test progress reporting
await ctx.report_progress(0, 10) # First call with 0
await ctx.report_progress(5, 10) # Middle progress
await ctx.report_progress(10, 10) # Complete
await ctx.report_progress(0, 10)
await ctx.report_progress(5, 10)
await ctx.report_progress(10, 10)
# Verify progress notifications
assert mock_session.send_progress_notification.call_count == 3, "All progress notifications should be sent"
mock_session.send_progress_notification.assert_any_call(
progress_token=0, progress=0.0, total=10.0, message=None, related_request_id="test-request"
)
mock_session.send_progress_notification.assert_any_call(
progress_token=0, progress=5.0, total=10.0, message=None, related_request_id="test-request"
)
mock_session.send_progress_notification.assert_any_call(
progress_token=0, progress=10.0, total=10.0, message=None, related_request_id="test-request"
)
assert mock_session.report_progress.await_args_list == [
((0, 10, None),),
((5, 10, None),),
((10, 10, None),),
]

View file

@ -4,8 +4,8 @@ import pytest
from mcp.server.lowlevel import NotificationOptions, Server
from mcp.server.models import InitializationOptions
from mcp.shared.message import SessionMessage
from mcp.shared.version import LATEST_HANDSHAKE_VERSION
from mcp.types import (
LATEST_PROTOCOL_VERSION,
ClientCapabilities,
Implementation,
InitializeRequestParams,
@ -59,7 +59,7 @@ async def test_request_id_match() -> None:
id="init-1",
method="initialize",
params=InitializeRequestParams(
protocol_version=LATEST_PROTOCOL_VERSION,
protocol_version=LATEST_HANDSHAKE_VERSION,
capabilities=ClientCapabilities(),
client_info=Implementation(name="test-client", version="1.0.0"),
).model_dump(by_alias=True, exclude_none=True),

View file

@ -9,7 +9,8 @@ import pytest
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from mcp.types import LATEST_PROTOCOL_VERSION, InitializeResult
from mcp.shared.version import LATEST_HANDSHAKE_VERSION
from mcp.types import InitializeResult
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test") # pragma: no cover
@ -32,7 +33,7 @@ async def test_initialize_succeeds_and_shutdown_returns_after_the_server_exits_m
"jsonrpc": "2.0",
"id": request["id"],
"result": {{
"protocolVersion": {json.dumps(LATEST_PROTOCOL_VERSION)},
"protocolVersion": {json.dumps(LATEST_HANDSHAKE_VERSION)},
"capabilities": {{}},
"serverInfo": {{"name": "test-server", "version": "1.0"}}
}}