From 69eb00bcfc20bd8d1e17b7ca980980d6afd2fd5c Mon Sep 17 00:00:00 2001 From: Girish Konda Date: Thu, 22 Oct 2026 12:05:44 -0700 Subject: [PATCH] Apply the test discovery timeouts to Sampling_Stdio #1943 and #1946 give stdio test_server clients an unbounded server/discover probe when a test passes no options, and leave options a test passes unchanged. Sampling_Stdio passes options for its sampling handler without pinning a protocol version, so its test_server case still used the 5-second probe and could fall back to initialize while the discover answer was on its way; the server then rejects initialize. Start its test_server options from TestMcpClient.CreateOptions(), as CONTRIBUTING.md asks; the everything server keeps the default probe. --- .../ClientIntegrationTests.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs b/tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs index d01f40a6f..4f0d478b9 100644 --- a/tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs +++ b/tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs @@ -375,24 +375,21 @@ public async Task Complete_Stdio_PromptReference(string clientId) [MemberData(nameof(GetClients))] public async Task Sampling_Stdio(string clientId) { - // Set up the sampling handler + // Set up the sampling handler. Like the fixture's default options, only test_server gets the test discovery + // timeouts; the everything server keeps the default probe. int samplingHandlerCalls = 0; - await using var client = await _fixture.CreateClientAsync(clientId, new() + var clientOptions = clientId == "test_server" ? TestMcpClient.CreateOptions() : new McpClientOptions(); + clientOptions.Handlers.SamplingHandler = async (_, _, _) => { - Handlers = new() + samplingHandlerCalls++; + return new CreateMessageResult { - SamplingHandler = async (_, _, _) => - { - samplingHandlerCalls++; - return new CreateMessageResult - { - Model = "test-model", - Role = Role.Assistant, - Content = [new TextContentBlock { Text = "Test response" }], - }; - } - } - }); + Model = "test-model", + Role = Role.Assistant, + Content = [new TextContentBlock { Text = "Test response" }], + }; + }; + await using var client = await _fixture.CreateClientAsync(clientId, clientOptions); // Call the server's trigger-sampling-request tool which should trigger our sampling handler var result = await client.CallToolAsync(