diff --git a/src/ModelContextProtocol.Core/McpJsonUtilities.cs b/src/ModelContextProtocol.Core/McpJsonUtilities.cs index b193bb8de..0fe393503 100644 --- a/src/ModelContextProtocol.Core/McpJsonUtilities.cs +++ b/src/ModelContextProtocol.Core/McpJsonUtilities.cs @@ -193,6 +193,7 @@ internal static bool IsValidToolOutputSchema(JsonElement element) => // Other MCP Types [JsonSerializable(typeof(IDictionary))] [JsonSerializable(typeof(IReadOnlyDictionary))] + [JsonSerializable(typeof(List))] [JsonSerializable(typeof(ProgressToken))] [JsonSerializable(typeof(JsonElement))] [JsonSerializable(typeof(Implementation))] diff --git a/tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs b/tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs index 708cd9361..c8183c410 100644 --- a/tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs +++ b/tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs @@ -41,6 +41,24 @@ throw new Exception($"Unexpected result: {result}"); } +var join = tools.FirstOrDefault(t => t.Name == "Join"); +if (join is null) +{ + throw new Exception("Expected the Join tool."); +} + +result = await join.InvokeAsync(new() { ["items"] = new List { "one", "two" } }); +if (result is null || !result.ToString()!.Contains("Joined: one,two")) +{ + throw new Exception($"Unexpected populated array result: {result}"); +} + +result = await join.InvokeAsync(new() { ["items"] = new List() }); +if (result is null || !result.ToString()!.Contains("Joined: ")) +{ + throw new Exception($"Unexpected empty array result: {result}"); +} + Console.WriteLine("Success!"); [McpServerToolType] @@ -49,4 +67,7 @@ internal sealed class AotTools [McpServerTool(Name = "Echo")] [McpAppUi(ResourceUri = "ui://aot/echo")] public static string Echo(string arg) => $"Echo: {arg}"; + + [McpServerTool(Name = "Join")] + public static string Join(string[] items) => $"Joined: {string.Join(',', items)}"; }