csharp-sdk/samples/EverythingServer/Tools/AnnotatedMessageTool.cs
Copilot 80b1ad21d7
Use ReadOnlyMemory<byte> for binary data to eliminate UTF-16 transcoding (#1070)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Co-authored-by: Eric StJohn <ericstj@microsoft.com>
2026-02-19 14:08:05 -08:00

53 lines
1.7 KiB
C#

using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Text;
namespace EverythingServer.Tools;
[McpServerToolType]
public class AnnotatedMessageTool
{
public enum MessageType
{
Error,
Success,
Debug,
}
[McpServerTool(Name = "annotatedMessage"), Description("Generates an annotated message")]
public static IEnumerable<ContentBlock> AnnotatedMessage(MessageType messageType, bool includeImage = true)
{
List<ContentBlock> contents = messageType switch
{
MessageType.Error => [new TextContentBlock
{
Text = "Error: Operation failed",
Annotations = new() { Audience = [Role.User, Role.Assistant], Priority = 1.0f }
}],
MessageType.Success => [new TextContentBlock
{
Text = "Operation completed successfully",
Annotations = new() { Audience = [Role.User], Priority = 0.7f }
}],
MessageType.Debug => [new TextContentBlock
{
Text = "Debug: Cache hit ratio 0.95, latency 150ms",
Annotations = new() { Audience = [Role.Assistant], Priority = 0.3f }
}],
_ => throw new ArgumentOutOfRangeException(nameof(messageType), messageType, null)
};
if (includeImage)
{
contents.Add(new ImageContentBlock
{
Data = Encoding.UTF8.GetBytes(TinyImageTool.MCP_TINY_IMAGE.Split(",").Last()),
MimeType = "image/png",
Annotations = new() { Audience = [Role.User], Priority = 0.5f }
});
}
return contents;
}
}