Add tools support to sampling (#976)

This commit is contained in:
Stephen Toub 2025-11-20 09:52:23 -05:00 • committed by GitHub
commit 15139cc569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,7 +18,7 @@ public class McpServerExtensionsTests
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await server.SampleAsync(
new CreateMessageRequestParams
{
Messages = [new SamplingMessage { Role = Role.User, Content = new TextContentBlock { Text = "hi" } }],
Messages = [new SamplingMessage { Role = Role.User, Content = [new TextContentBlock { Text = "hi" }] }],
MaxTokens = 1000
},
TestContext.Current.CancellationToken));
@ -80,7 +80,7 @@ public class McpServerExtensionsTests
var resultPayload = new CreateMessageResult
{
Content = new TextContentBlock { Text = "resp" },
Content = [new TextContentBlock { Text = "resp" }],
Model = "test-model",
Role = Role.Assistant,
StopReason = "endTurn",
@ -101,13 +101,13 @@ public class McpServerExtensionsTests
var result = await server.SampleAsync(new CreateMessageRequestParams
{
Messages = [new SamplingMessage { Role = Role.User, Content = new TextContentBlock { Text = "hi" } }],
Messages = [new SamplingMessage { Role = Role.User, Content = [new TextContentBlock { Text = "hi" }] }],
MaxTokens = 1000
}, TestContext.Current.CancellationToken);
Assert.Equal("test-model", result.Model);
Assert.Equal(Role.Assistant, result.Role);
Assert.Equal("resp", Assert.IsType<TextContentBlock>(result.Content).Text);
Assert.Equal("resp", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
mockServer.Verify(s => s.SendRequestAsync(It.IsAny<JsonRpcRequest>(), It.IsAny<CancellationToken>()), Times.Once);
}
@ -118,7 +118,7 @@ public class McpServerExtensionsTests
var resultPayload = new CreateMessageResult
{
Content = new TextContentBlock { Text = "resp" },
Content = [new TextContentBlock { Text = "resp" }],
Model = "test-model",
Role = Role.Assistant,
StopReason = "endTurn",