Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading