Skip to content

Commit 8f318f5

Browse files
committed
Implementing annotated tool call
1 parent cab54dd commit 8f318f5

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

samples/EverythingServer/Tools/AnnotatedMessageTool.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ModelContextProtocol.Server;
1+
using ModelContextProtocol.Protocol.Types;
2+
using ModelContextProtocol.Server;
23
using System.ComponentModel;
34

45
namespace EverythingServer.Tools;
@@ -14,8 +15,42 @@ public enum MessageType
1415
}
1516

1617
[McpServerTool(Name = "annotatedMessage"), Description("Generates an annotated message")]
17-
public static IEnumerable<string> AnnotatedMessage(MessageType messageType, bool includeImage = true)
18+
public static IEnumerable<Content> AnnotatedMessage(MessageType messageType, bool includeImage = true)
1819
{
19-
throw new NotSupportedException("Unable to write annotations to the output.");
20+
List<Content> contents = messageType switch
21+
{
22+
MessageType.Error => [new()
23+
{
24+
Type = "text",
25+
Text = "Error: Operation failed",
26+
Annotations = new() { Audience = [Role.User, Role.Assistant], Priority = 1.0f }
27+
}],
28+
MessageType.Success => [new()
29+
{
30+
Type = "text",
31+
Text = "Operation completed successfully",
32+
Annotations = new() { Audience = [Role.User], Priority = 0.7f }
33+
}],
34+
MessageType.Debug => [new()
35+
{
36+
Type = "text",
37+
Text = "Debug: Cache hit ratio 0.95, latency 150ms",
38+
Annotations = new() { Audience = [Role.Assistant], Priority = 0.3f }
39+
}],
40+
_ => throw new ArgumentOutOfRangeException(nameof(messageType), messageType, null)
41+
};
42+
43+
if (includeImage)
44+
{
45+
contents.Add(new()
46+
{
47+
Type = "image",
48+
Data = TinyImageTool.MCP_TINY_IMAGE.Split(",").Last(),
49+
MimeType = "image/png",
50+
Annotations = new() { Audience = [Role.User], Priority = 0.5f }
51+
});
52+
}
53+
54+
return contents;
2055
}
2156
}

0 commit comments

Comments
 (0)