Skip to content

Commit fc571e2

Browse files
committed
Fix structured output backwards compatibility for string literals
1 parent 0cf449e commit fc571e2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,13 @@ public override async ValueTask<CallToolResult> InvokeAsync(
257257
Content = [],
258258
StructuredContent = structuredContent,
259259
},
260-
260+
261261
string text => new()
262262
{
263-
Content = [new TextContentBlock { Text = text }],
263+
// If there is structuredOutput we must stringify it, as the MCP specification requires Content to be for backwards compatibility
264+
// but otherwise not differ
265+
Content = [new TextContentBlock { Text = structuredContent == null ? text :
266+
JsonSerializer.Serialize(result, AIFunction.JsonSerializerOptions.GetTypeInfo(typeof(object)))}],
264267
StructuredContent = structuredContent,
265268
},
266269

0 commit comments

Comments
 (0)