-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMcpToolResultFormatterTests.cs
More file actions
49 lines (41 loc) · 1.45 KB
/
McpToolResultFormatterTests.cs
File metadata and controls
49 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Text.Json;
using EssentialCSharp.Chat.Common.Services;
using ModelContextProtocol.Protocol;
namespace EssentialCSharp.Chat.Tests;
public class McpToolResultFormatterTests
{
[Test]
public async Task GetModelInput_PrefersStructuredContent_WhenAvailable()
{
JsonElement structuredContent = JsonSerializer.SerializeToElement(new
{
diagnostic = "CS8600",
relevantSections = Array.Empty<object>()
});
CallToolResult toolResult = new()
{
Content =
[
new TextContentBlock { Text = "# Book Help for: CS8600" },
new TextContentBlock { Text = "{\"diagnostic\":\"CS8600\"}" }
],
StructuredContent = structuredContent
};
string modelInput = McpToolResultFormatter.GetModelInput(toolResult);
await Assert.That(modelInput).IsEqualTo(structuredContent.GetRawText());
}
[Test]
public async Task GetModelInput_FallsBackToFirstTextBlock_WhenStructuredContentIsMissing()
{
CallToolResult toolResult = new()
{
Content =
[
new TextContentBlock { Text = "# Readable content" },
new TextContentBlock { Text = "{\"json\":\"fallback\"}" }
]
};
string modelInput = McpToolResultFormatter.GetModelInput(toolResult);
await Assert.That(modelInput).IsEqualTo("# Readable content");
}
}