Skip to content

Commit 5d9ec73

Browse files
authored
[MCP] Fixed issue with deserialization of prompt settings (#9085)
1 parent 576c72b commit 5d9ec73

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

src/All.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
<Project Path="HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/HotChocolate.Fusion.Adapters.OpenApi.csproj" />
195195
</Folder>
196196
<Folder Name="/HotChocolate/Adapters/test/">
197+
<Project Path="HotChocolate/Adapters/test/Adapters.Mcp.Core.Tests/HotChocolate.Adapters.Mcp.Core.Tests.csproj" />
197198
<Project Path="HotChocolate/Adapters/test/Adapters.Mcp.Packaging.Tests/HotChocolate.Adapters.Mcp.Packaging.Tests.csproj" />
198199
<Project Path="HotChocolate/Adapters/test/Adapters.Mcp.Tests/HotChocolate.Adapters.Mcp.Tests.csproj" />
199200
<Project Path="HotChocolate/Adapters/test/Adapters.OpenApi.Packaging.Tests/HotChocolate.Adapters.OpenApi.Packaging.Tests.csproj" />

src/HotChocolate/Adapters/Adapters.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</Folder>
1616
<Folder Name="/test/" />
1717
<Folder Name="/test/Adapters.Mcp.Tests/">
18+
<Project Path="test\Adapters.Mcp.Core.Tests\HotChocolate.Adapters.Mcp.Core.Tests.csproj" />
1819
<Project Path="test\Adapters.Mcp.Packaging.Tests\HotChocolate.Adapters.Mcp.Packaging.Tests.csproj" />
1920
<Project Path="test\Adapters.Mcp.Tests\HotChocolate.Adapters.Mcp.Tests.csproj" />
2021
</Folder>

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Serialization/McpSettingsSerializerContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ namespace HotChocolate.Adapters.Mcp.Serialization;
66
[JsonSerializable(typeof(McpToolSettingsDto))]
77
[JsonSourceGenerationOptions(
88
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
9-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
9+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
10+
AllowOutOfOrderMetadataProperties = true)]
1011
internal partial class McpSettingsSerializerContext : JsonSerializerContext;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Xunit2.Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />
3+
4+
<PropertyGroup>
5+
<AssemblyName>HotChocolate.Adapters.Mcp.Core.Tests</AssemblyName>
6+
<RootNamespace>HotChocolate.Adapters.Mcp.Core</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\src\Adapters.Mcp.Core\HotChocolate.Adapters.Mcp.Core.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Text.Json;
2+
using HotChocolate.Adapters.Mcp.Serialization;
3+
4+
namespace HotChocolate.Adapters.Mcp.Core.Serialization;
5+
6+
public sealed class McpPromptSettingsSerializerTests
7+
{
8+
[Fact]
9+
public void Parse_WithPolymorphicMessages_ShouldSucceed()
10+
{
11+
// arrange
12+
var document =
13+
JsonDocument.Parse(
14+
"""
15+
{
16+
"messages": [
17+
{
18+
"role": "user",
19+
"content": {
20+
"text": "Get the person",
21+
"type": "text"
22+
}
23+
}
24+
]
25+
}
26+
""");
27+
28+
// act
29+
var settings = McpPromptSettingsSerializer.Parse(document);
30+
31+
// assert
32+
var message = Assert.Single(settings.Messages);
33+
Assert.Equal("user", message.Role);
34+
var content = Assert.IsType<McpPromptSettingsTextContentDto>(message.Content);
35+
Assert.Equal("Get the person", content.Text);
36+
}
37+
}

0 commit comments

Comments
 (0)