Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CustomContent.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
7
9{
14 {
19 : base()
20 {
21 }
22
26 public CustomContent(McpRole[]? Audience, double? Priority, DateTime? LastModified,
27 Dictionary<string, object>? MetaData)
29 {
30 }
31
35 public override Type[] Encodes => new Type[]
36 {
37 typeof(CustomEncoding)
38 };
39
43 public override bool IsStructuredContent => false;
44
51 public override Task<Dictionary<string, object>> Encode(object Content)
52 {
53 Dictionary<string, object> Result = new Dictionary<string, object>();
54 CustomEncoding Encoded = (CustomEncoding)Content;
55
56 if (Encoded.ContentType.StartsWith("text/plain", StringComparison.InvariantCultureIgnoreCase))
57 {
58 Result["type"] = "text";
59 Result["text"] = Strings.GetString(Encoded.Encoded, Encoding.UTF8);
60 }
61 else if (Encoded.ContentType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))
62 {
63 Result["type"] = "image";
64 Result["mimeType"] = Encoded.ContentType;
65 Result["data"] = Convert.ToBase64String(Encoded.Encoded);
66 }
67 else if (Encoded.ContentType.StartsWith("audio/", StringComparison.InvariantCultureIgnoreCase))
68 {
69 Result["type"] = "audio";
70 Result["mimeType"] = Encoded.ContentType;
71 Result["data"] = Convert.ToBase64String(Encoded.Encoded);
72 }
73 else
74 {
75 Result["type"] = "resource";
76 Result["resource"] = new Dictionary<string, object>()
77 {
78 { "uri", Encoded.Uri?.OriginalString ?? string.Empty },
79 { "mimeType", Encoded.ContentType },
80 { "blob", Convert.ToBase64String(Encoded.Encoded) }
81 };
82 }
83
84 this.Annotate(Result);
85
86 return Task.FromResult(Result);
87 }
88 }
89}
A custom encoded object.
Uri Uri
Optional original URI of content.
string ContentType
Internet Content-Type of encoded object.
DateTime? LastModified
The moment the resource was last modified, as an ISO 8601 formatted string.
Definition: Annotations.cs:61
double? Priority
Describes how important this data is for operating the server.
Definition: Annotations.cs:53
McpRole?[] Audience
Describes who the intended audience of this object or data is.
Definition: Annotations.cs:44
Abstract base class for an MCP Content Block.
Definition: ContentBlock.cs:11
override void Annotate(Dictionary< string, object > Object)
Annotates an object.
Definition: ContentBlock.cs:57
CustomContent(McpRole[]? Audience, double? Priority, DateTime? LastModified, Dictionary< string, object >? MetaData)
Custom Content Block
override Type[] Encodes
What types the content block encodes.
override bool IsStructuredContent
If the content block is encoded as structured content.
override Task< Dictionary< string, object > > Encode(object Content)
Encodes a content block, given the content to encode and available annotations and meta-data.
Static class managing binary representations of strings.
Definition: Strings.cs:10
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Definition: Strings.cs:148
McpRole
Identifies a Role in a Model Context Protocol (MCP) context.
Definition: McpRole.cs:7