diff --git a/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs b/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs index 664ede5a..2f9286af 100644 --- a/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs +++ b/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs @@ -257,10 +257,13 @@ public override async ValueTask InvokeAsync( Content = [], StructuredContent = structuredContent, }, - + string text => new() { - Content = [new TextContentBlock { Text = text }], + // If there is structuredOutput we must return that in stringified form, + // as required for backward compatibility by the MCP specification. + Content = [new TextContentBlock { Text = structuredContent == null ? text : + JsonSerializer.Serialize(structuredContent, AIFunction.JsonSerializerOptions.GetTypeInfo(typeof(object)))}], StructuredContent = structuredContent, },