@@ -1415,6 +1415,61 @@ await transport.SendMessageAsync(
14151415 await runTask ;
14161416 }
14171417
1418+ [ Fact ]
1419+ public async Task Call_Tool_Result_With_Annotated_Content_Serializes ( )
1420+ {
1421+ await using var transport = new TestServerTransport ( ) ;
1422+ var options = CreateOptions ( new ServerCapabilities { Tools = new ( ) } ) ;
1423+ options . Handlers . CallToolHandler = ( request , ct ) => new ValueTask < CallToolResult > ( new CallToolResult
1424+ {
1425+ Content =
1426+ [
1427+ new TextContentBlock { Text = "x" , Annotations = new Annotations { Audience = [ Role . User ] , Priority = 0.5f } } ,
1428+ new ResourceLinkBlock
1429+ {
1430+ Uri = "https://example.com/x" ,
1431+ Name = "x" ,
1432+ Icons = [ new Icon { Source = "https://example.com/icon.png" } ] ,
1433+ Annotations = new Annotations { Audience = [ Role . Assistant ] } ,
1434+ } ,
1435+ ] ,
1436+ } ) ;
1437+ options . Handlers . ListToolsHandler = ( request , ct ) => throw new NotImplementedException ( ) ;
1438+
1439+ await using var server = McpServer . Create ( transport , options , LoggerFactory ) ;
1440+ var runTask = server . RunAsync ( TestContext . Current . CancellationToken ) ;
1441+
1442+ var reply = new TaskCompletionSource < JsonRpcMessageWithId > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1443+ transport . OnMessageSent = message =>
1444+ {
1445+ if ( message is JsonRpcResponse or JsonRpcError )
1446+ {
1447+ reply . TrySetResult ( ( JsonRpcMessageWithId ) message ) ;
1448+ }
1449+ } ;
1450+
1451+ await transport . SendMessageAsync (
1452+ new JsonRpcRequest
1453+ {
1454+ Method = RequestMethods . ToolsCall ,
1455+ Id = new RequestId ( 1 ) ,
1456+ Params = JsonNode . Parse ( """{"name":"annotated"}""" ) ,
1457+ } ,
1458+ TestContext . Current . CancellationToken ) ;
1459+
1460+ var response = Assert . IsType < JsonRpcResponse > ( await reply . Task . WaitAsync ( TestConstants . DefaultTimeout , TestContext . Current . CancellationToken ) ) ;
1461+ var content = response . Result ? [ "content" ] ? . AsArray ( ) ;
1462+ Assert . NotNull ( content ) ;
1463+ Assert . Equal ( 2 , content . Count ) ;
1464+ Assert . Equal ( "user" , content [ 0 ] ? [ "annotations" ] ? [ "audience" ] ? [ 0 ] ? . GetValue < string > ( ) ) ;
1465+ Assert . Equal ( 0.5 , content [ 0 ] ? [ "annotations" ] ? [ "priority" ] ? . GetValue < double > ( ) ) ;
1466+ Assert . Equal ( "assistant" , content [ 1 ] ? [ "annotations" ] ? [ "audience" ] ? [ 0 ] ? . GetValue < string > ( ) ) ;
1467+ Assert . Equal ( "https://example.com/icon.png" , content [ 1 ] ? [ "icons" ] ? [ 0 ] ? [ "src" ] ? . GetValue < string > ( ) ) ;
1468+
1469+ await transport . DisposeAsync ( ) ;
1470+ await runTask ;
1471+ }
1472+
14181473 private async Task Can_Handle_Requests ( ServerCapabilities ? serverCapabilities , string method , Action < McpServerOptions > ? configureOptions , Action < McpServer , JsonNode ? > assertResult )
14191474 {
14201475 await using var transport = new TestServerTransport ( ) ;
0 commit comments