Update content according to latest spec (#513)

* Update content according to latest spec

* Add Title to a bunch of types

* Add _meta to lots of types

* Address feedback, more cleanup, fix NAOT test failure
This commit is contained in:
Stephen Toub 2025-06-16 19:39:41 -04:00 • committed by GitHub
commit 2bcff315f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
85 changed files with 1700 additions and 853 deletions

View file

@ -9,13 +9,13 @@ namespace ModelContextProtocol.Protocol;
/// Annotations enable filtering and prioritization of content for different audiences.
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class Annotations
public sealed class Annotations
{
/// <summary>
/// Gets or sets the intended audience for this content as an array of <see cref="Role"/> values.
/// </summary>
[JsonPropertyName("audience")]
public Role[]? Audience { get; init; }
public IList<Role>? Audience { get; init; }
/// <summary>
/// Gets or sets a value indicating how important this data is for operating the server.
@ -26,4 +26,14 @@ public class Annotations
/// </remarks>
[JsonPropertyName("priority")]
public float? Priority { get; init; }
/// <summary>
/// Gets or sets the moment the resource was last modified.
/// </summary>
/// <remarks>
/// The corresponding JSON should be an ISO 8601 formatted string (e.g., \"2025-01-12T15:00:58Z\").
/// Examples: last activity timestamp in an open file, timestamp when the resource was attached, etc.
/// </remarks>
[JsonPropertyName("lastModified")]
public DateTimeOffset? LastModified { get; set; }
}

View file

@ -9,7 +9,7 @@ namespace ModelContextProtocol.Protocol;
/// This class is used when requesting completion suggestions for a particular field or parameter.
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class Argument
public sealed class Argument
{
/// <summary>
/// Gets or sets the name of the argument being completed.

View file

@ -20,7 +20,7 @@ namespace ModelContextProtocol.Protocol;
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for more details.
/// </para>
/// </remarks>
public class BlobResourceContents : ResourceContents
public sealed class BlobResourceContents : ResourceContents
{
/// <summary>
/// Gets or sets the base64-encoded string representing the binary data of the item.

View file

@ -7,10 +7,10 @@ namespace ModelContextProtocol.Protocol;
/// Represents the parameters used with a <see cref="RequestMethods.ToolsCall"/> request from a client to invoke a tool provided by the server.
/// </summary>
/// <remarks>
/// The server will respond with a <see cref="CallToolResponse"/> containing the result of the tool invocation.
/// The server will respond with a <see cref="CallToolResult"/> containing the result of the tool invocation.
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class CallToolRequestParams : RequestParams
public sealed class CallToolRequestParams : RequestParams
{
/// <summary>Gets or sets the name of the tool to invoke.</summary>
[JsonPropertyName("name")]

View file

@ -0,0 +1,48 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents the result of a <see cref="RequestMethods.ToolsCall"/> request from a client to invoke a tool provided by the server.
/// </summary>
/// <remarks>
/// <para>
/// Any errors that originate from the tool should be reported inside the result
/// object, with <see cref="IsError"/> set to true, rather than as a <see cref="JsonRpcError"/>.
/// </para>
/// <para>
/// However, any errors in finding the tool, an error indicating that the
/// server does not support tool calls, or any other exceptional conditions,
/// should be reported as an MCP error response.
/// </para>
/// <para>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public sealed class CallToolResult : Result
{
/// <summary>
/// Gets or sets the response content from the tool call.
/// </summary>
[JsonPropertyName("content")]
public IList<ContentBlock> Content { get; set; } = [];
/// <summary>
/// Gets or sets an optional JSON object representing the structured result of the tool call.
/// </summary>
[JsonPropertyName("structuredContent")]
public JsonNode? StructuredContent { get; set; }
/// <summary>
/// Gets or sets an indication of whether the tool call was unsuccessful.
/// </summary>
/// <remarks>
/// When set to <see langword="true"/>, it signifies that the tool execution failed.
/// Tool errors are reported with this property set to <see langword="true"/> and details in the <see cref="Content"/>
/// property, rather than as protocol-level errors. This allows LLMs to see that an error occurred
/// and potentially self-correct in subsequent requests.
/// </remarks>
[JsonPropertyName("isError")]
public bool IsError { get; set; }
}

View file

@ -0,0 +1,30 @@
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents a notification indicating that a request has been cancelled by the client,
/// and that any associated processing should cease immediately.
/// </summary>
/// <remarks>
/// This class is typically used in conjunction with the <see cref="NotificationMethods.CancelledNotification"/>
/// method identifier. When a client sends this notification, the server should attempt to
/// cancel any ongoing operations associated with the specified request ID.
/// </remarks>
public sealed class CancelledNotificationParams : NotificationParams
{
/// <summary>
/// Gets or sets the ID of the request to cancel.
/// </summary>
/// <remarks>
/// This must match the ID of an in-flight request that the sender wishes to cancel.
/// </remarks>
[JsonPropertyName("requestId")]
public RequestId RequestId { get; set; }
/// <summary>
/// Gets or sets an optional string describing the reason for the cancellation request.
/// </summary>
[JsonPropertyName("reason")]
public string? Reason { get; set; }
}

View file

@ -15,7 +15,7 @@ namespace ModelContextProtocol.Protocol;
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public class ClientCapabilities
public sealed class ClientCapabilities
{
/// <summary>
/// Gets or sets experimental, non-standard capabilities that the client supports.
@ -33,7 +33,7 @@ public class ClientCapabilities
/// </para>
/// </remarks>
[JsonPropertyName("experimental")]
public Dictionary<string, object>? Experimental { get; set; }
public IDictionary<string, object>? Experimental { get; set; }
/// <summary>
/// Gets or sets the client's roots capability, which are entry points for resource navigation.

View file

@ -9,7 +9,7 @@ namespace ModelContextProtocol.Protocol;
/// This context provides information that helps the server generate more relevant
/// completion suggestions, such as previously resolved variables in a template.
/// </remarks>
public class CompleteContext
public sealed class CompleteContext
{
/// <summary>
/// Gets or sets previously-resolved variables in a URI template or prompt.

View file

@ -17,7 +17,7 @@ namespace ModelContextProtocol.Protocol;
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public class CompleteRequestParams : RequestParams
public sealed class CompleteRequestParams : RequestParams
{
/// <summary>
/// Gets or sets the reference's information.

View file

@ -23,7 +23,7 @@ namespace ModelContextProtocol.Protocol;
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public class CompleteResult
public sealed class CompleteResult : Result
{
/// <summary>
/// Gets or sets the completion object containing the suggested values and pagination information.

View file

@ -8,7 +8,7 @@ namespace ModelContextProtocol.Protocol;
/// <remarks>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class Completion
public sealed class Completion
{
/// <summary>
/// Gets or sets an array of completion values (auto-suggestions) for the requested input.
@ -19,7 +19,7 @@ public class Completion
/// Per the specification, this should not exceed 100 items.
/// </remarks>
[JsonPropertyName("values")]
public string[] Values { get; set; } = [];
public IList<string> Values { get; set; } = [];
/// <summary>
/// Gets or sets the total number of completion options available.

View file

@ -20,7 +20,7 @@ namespace ModelContextProtocol.Protocol;
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public class CompletionsCapability
public sealed class CompletionsCapability
{
// Currently empty in the spec, but may be extended in the future.

View file

@ -1,92 +0,0 @@
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents content within the Model Context Protocol (MCP) that can contain text, binary data, or references to resources.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="Content"/> class is a fundamental type in the MCP that can represent different forms of content
/// based on the <see cref="Type"/> property. The main content types are:
/// </para>
/// <list type="bullet">
/// <item><description>"text" - Textual content, stored in the <see cref="Text"/> property</description></item>
/// <item><description>"image" - Image data, stored as base64 in the <see cref="Data"/> property with appropriate MIME type</description></item>
/// <item><description>"audio" - Audio data, stored as base64 in the <see cref="Data"/> property with appropriate MIME type</description></item>
/// <item><description>"resource" - Reference to a resource, accessed through the <see cref="Resource"/> property</description></item>
/// </list>
/// <para>
/// This class is used extensively throughout the MCP for representing content in messages, tool responses,
/// and other communication between clients and servers.
/// </para>
/// <para>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for more details.
/// </para>
/// </remarks>
public class Content
{
/// <summary>
/// Gets or sets the type of content.
/// </summary>
/// <remarks>
/// This determines the structure of the content object. Valid values include "image", "audio", "text", and "resource".
/// </remarks>
[JsonPropertyName("type")]
public string Type { get; set; } = "text";
/// <summary>
/// Gets or sets the text content of the message.
/// </summary>
[JsonPropertyName("text")]
public string? Text { get; set; }
/// <summary>
/// Gets or sets the base64-encoded image or audio data.
/// </summary>
[JsonPropertyName("data")]
public string? Data { get; set; }
/// <summary>
/// Gets or sets the MIME type (or "media type") of the content, specifying the format of the data.
/// </summary>
/// <remarks>
/// <para>
/// This property is used when <see cref="Type"/> is "image", "audio", or "resource", to indicate the specific format of the binary data.
/// Common values include "image/png", "image/jpeg", "audio/wav", and "audio/mp3".
/// </para>
/// <para>
/// This property is required when the <see cref="Data"/> property contains binary content,
/// as it helps clients properly interpret and render the content.
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public string? MimeType { get; set; }
/// <summary>
/// Gets or sets the resource content of the message when <see cref="Type"/> is "resource".
/// </summary>
/// <remarks>
/// <para>
/// This property is used to embed or reference resource data within a message. It's only
/// applicable when the <see cref="Type"/> property is set to "resource".
/// </para>
/// <para>
/// Resources can be either text-based (<see cref="TextResourceContents"/>) or
/// binary (<see cref="BlobResourceContents"/>), allowing for flexible data representation.
/// Each resource has a URI that can be used for identification and retrieval.
/// </para>
/// </remarks>
[JsonPropertyName("resource")]
public ResourceContents? Resource { get; set; }
/// <summary>
/// Gets or sets optional annotations for the content.
/// </summary>
/// <remarks>
/// These annotations can be used to specify the intended audience (<see cref="Role.User"/>, <see cref="Role.Assistant"/>, or both)
/// and the priority level of the content. Clients can use this information to filter or prioritize content for different roles.
/// </remarks>
[JsonPropertyName("annotations")]
public Annotations? Annotations { get; init; }
}

View file

@ -0,0 +1,456 @@
using Microsoft.Extensions.AI;
using System.ComponentModel;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents content within the Model Context Protocol (MCP).
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="ContentBlock"/> class is a fundamental type in the MCP that can represent different forms of content
/// based on the <see cref="Type"/> property. Derived types like <see cref="TextContentBlock"/>, <see cref="ImageContentBlock"/>,
/// and <see cref="EmbeddedResourceBlock"/> provide the type-specific content.
/// </para>
/// <para>
/// This class is used throughout the MCP for representing content in messages, tool responses,
/// and other communication between clients and servers.
/// </para>
/// <para>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for more details.
/// </para>
/// </remarks>
[JsonConverter(typeof(Converter))] // TODO: This converter exists due to the lack of downlevel support for AllowOutOfOrderMetadataProperties.
public abstract class ContentBlock
{
/// <summary>Prevent external derivations.</summary>
private protected ContentBlock()
{
}
/// <summary>
/// Gets or sets the type of content.
/// </summary>
/// <remarks>
/// This determines the structure of the content object. Valid values include "image", "audio", "text", "resource", and "resource_link".
/// </remarks>
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
/// <summary>
/// Gets or sets optional annotations for the content.
/// </summary>
/// <remarks>
/// These annotations can be used to specify the intended audience (<see cref="Role.User"/>, <see cref="Role.Assistant"/>, or both)
/// and the priority level of the content. Clients can use this information to filter or prioritize content for different roles.
/// </remarks>
[JsonPropertyName("annotations")]
public Annotations? Annotations { get; init; }
/// <summary>
/// Provides a <see cref="JsonConverter"/> for <see cref="ContentBlock"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class Converter : JsonConverter<ContentBlock>
{
/// <inheritdoc/>
public override ContentBlock? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
{
return null;
}
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException();
}
string? type = null;
string? text = null;
string? name = null;
string? data = null;
string? mimeType = null;
string? uri = null;
string? description = null;
long? size = null;
ResourceContents? resource = null;
Annotations? annotations = null;
JsonObject? meta = null;
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType != JsonTokenType.PropertyName)
{
continue;
}
string? propertyName = reader.GetString();
bool success = reader.Read();
Debug.Assert(success, "STJ must have buffered the entire object for us.");
switch (propertyName)
{
case "type":
type = reader.GetString();
break;
case "text":
text = reader.GetString();
break;
case "data":
data = reader.GetString();
break;
case "mimeType":
mimeType = reader.GetString();
break;
case "uri":
uri = reader.GetString();
break;
case "description":
description = reader.GetString();
break;
case "size":
size = reader.GetInt64();
break;
case "resource":
resource = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.ResourceContents);
break;
case "annotations":
annotations = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.Annotations);
break;
case "_meta":
meta = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.JsonObject);
break;
default:
break;
}
}
return type switch
{
"text" => new TextContentBlock
{
Text = text ?? throw new JsonException("Text contents must be provided for 'text' type."),
Annotations = annotations,
Meta = meta,
},
"image" => new ImageContentBlock()
{
Data = data ?? throw new JsonException("Image data must be provided for 'image' type."),
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'image' type."),
Annotations = annotations,
Meta = meta,
},
"audio" => new AudioContentBlock()
{
Data = data ?? throw new JsonException("Audio data must be provided for 'audio' type."),
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'audio' type."),
Annotations = annotations,
Meta = meta,
},
"resource" => new EmbeddedResourceBlock()
{
Resource = resource ?? throw new JsonException("Resource contents must be provided for 'resource' type."),
Annotations = annotations,
Meta = meta,
},
"resource_link" => new ResourceLinkBlock()
{
Uri = uri ?? throw new JsonException("URI must be provided for 'resource_link' type."),
Name = name ?? throw new JsonException("Name must be provided for 'resource_link' type."),
Description = description,
MimeType = mimeType,
Size = size,
Annotations = annotations,
},
_ => throw new JsonException($"Unknown content type: '{type}'"),
};
}
/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, ContentBlock value, JsonSerializerOptions options)
{
if (value is null)
{
writer.WriteNullValue();
return;
}
writer.WriteStartObject();
writer.WriteString("type", value.Type);
switch (value)
{
case TextContentBlock textContent:
writer.WriteString("text", textContent.Text);
if (textContent.Meta is not null)
{
writer.WritePropertyName("_meta");
JsonSerializer.Serialize(writer, textContent.Meta, McpJsonUtilities.JsonContext.Default.JsonObject);
}
break;
case ImageContentBlock imageContent:
writer.WriteString("data", imageContent.Data);
writer.WriteString("mimeType", imageContent.MimeType);
if (imageContent.Meta is not null)
{
writer.WritePropertyName("_meta");
JsonSerializer.Serialize(writer, imageContent.Meta, McpJsonUtilities.JsonContext.Default.JsonObject);
}
break;
case AudioContentBlock audioContent:
writer.WriteString("data", audioContent.Data);
writer.WriteString("mimeType", audioContent.MimeType);
if (audioContent.Meta is not null)
{
writer.WritePropertyName("_meta");
JsonSerializer.Serialize(writer, audioContent.Meta, McpJsonUtilities.JsonContext.Default.JsonObject);
}
break;
case EmbeddedResourceBlock embeddedResource:
writer.WritePropertyName("resource");
JsonSerializer.Serialize(writer, embeddedResource.Resource, McpJsonUtilities.JsonContext.Default.ResourceContents);
if (embeddedResource.Meta is not null)
{
writer.WritePropertyName("_meta");
JsonSerializer.Serialize(writer, embeddedResource.Meta, McpJsonUtilities.JsonContext.Default.JsonObject);
}
break;
case ResourceLinkBlock resourceLink:
writer.WriteString("uri", resourceLink.Uri);
writer.WriteString("name", resourceLink.Name);
if (resourceLink.Description is not null)
{
writer.WriteString("description", resourceLink.Description);
}
if (resourceLink.MimeType is not null)
{
writer.WriteString("mimeType", resourceLink.MimeType);
}
if (resourceLink.Size.HasValue)
{
writer.WriteNumber("size", resourceLink.Size.Value);
}
break;
}
if (value.Annotations is { } annotations)
{
writer.WritePropertyName("annotations");
JsonSerializer.Serialize(writer, annotations, McpJsonUtilities.JsonContext.Default.Annotations);
}
writer.WriteEndObject();
}
}
}
/// <summary>Represents text provided to or from an LLM.</summary>
public sealed class TextContentBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="TextContentBlock"/> class.</summary>
public TextContentBlock() => Type = "text";
/// <summary>
/// Gets or sets the text content of the message.
/// </summary>
[JsonPropertyName("text")]
public required string Text { get; set; }
/// <summary>
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
/// </summary>
/// <remarks>
/// Implementations must not make assumptions about its contents.
/// </remarks>
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }
}
/// <summary>Represents an image provided to or from an LLM.</summary>
public sealed class ImageContentBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="ImageContentBlock"/> class.</summary>
public ImageContentBlock() => Type = "image";
/// <summary>
/// Gets or sets the base64-encoded image data.
/// </summary>
[JsonPropertyName("data")]
public required string Data { get; set; }
/// <summary>
/// Gets or sets the MIME type (or "media type") of the content, specifying the format of the data.
/// </summary>
/// <remarks>
/// <para>
/// Common values include "image/png" and "image/jpeg".
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public required string MimeType { get; set; }
/// <summary>
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
/// </summary>
/// <remarks>
/// Implementations must not make assumptions about its contents.
/// </remarks>
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }
}
/// <summary>Represents audio provided to or from an LLM.</summary>
public sealed class AudioContentBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="AudioContentBlock"/> class.</summary>
public AudioContentBlock() => Type = "audio";
/// <summary>
/// Gets or sets the base64-encoded audio data.
/// </summary>
[JsonPropertyName("data")]
public required string Data { get; set; }
/// <summary>
/// Gets or sets the MIME type (or "media type") of the content, specifying the format of the data.
/// </summary>
/// <remarks>
/// <para>
/// Common values include "audio/wav" and "audio/mp3".
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public required string MimeType { get; set; }
/// <summary>
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
/// </summary>
/// <remarks>
/// Implementations must not make assumptions about its contents.
/// </remarks>
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }
}
/// <summary>Represents the contents of a resource, embedded into a prompt or tool call result.</summary>
/// <remarks>
/// It is up to the client how best to render embedded resources for the benefit of the LLM and/or the user.
/// </remarks>
public sealed class EmbeddedResourceBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary>
public EmbeddedResourceBlock() => Type = "resource";
/// <summary>
/// Gets or sets the resource content of the message when <see cref="Type"/> is "resource".
/// </summary>
/// <remarks>
/// <para>
/// Resources can be either text-based (<see cref="TextResourceContents"/>) or
/// binary (<see cref="BlobResourceContents"/>), allowing for flexible data representation.
/// Each resource has a URI that can be used for identification and retrieval.
/// </para>
/// </remarks>
[JsonPropertyName("resource")]
public required ResourceContents Resource { get; set; }
/// <summary>
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
/// </summary>
/// <remarks>
/// Implementations must not make assumptions about its contents.
/// </remarks>
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }
}
/// <summary>Represents a resource that the server is capable of reading, included in a prompt or tool call result.</summary>
/// <remarks>
/// Resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
/// </remarks>
public sealed class ResourceLinkBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary>
public ResourceLinkBlock() => Type = "resource_link";
/// <summary>
/// Gets or sets the URI of this resource.
/// </summary>
[JsonPropertyName("uri")]
public required string Uri { get; init; }
/// <summary>
/// Gets or sets a human-readable name for this resource.
/// </summary>
[JsonPropertyName("name")]
public required string Name { get; init; }
/// <summary>
/// Gets or sets a description of what this resource represents.
/// </summary>
/// <remarks>
/// <para>
/// This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a \"hint\" to the model.
/// </para>
/// <para>
/// The description should provide clear context about the resource's content, format, and purpose.
/// This helps AI models make better decisions about when to access or reference the resource.
/// </para>
/// <para>
/// Client applications can also use this description for display purposes in user interfaces
/// or to help users understand the available resources.
/// </para>
/// </remarks>
[JsonPropertyName("description")]
public string? Description { get; init; }
/// <summary>
/// Gets or sets the MIME type of this resource.
/// </summary>
/// <remarks>
/// <para>
/// <see cref="MimeType"/> specifies the format of the resource content, helping clients to properly interpret and display the data.
/// Common MIME types include "text/plain" for plain text, "application/pdf" for PDF documents,
/// "image/png" for PNG images, and "application/json" for JSON data.
/// </para>
/// <para>
/// This property may be <see langword="null"/> if the MIME type is unknown or not applicable for the resource.
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public string? MimeType { get; init; }
/// <summary>
/// Gets or sets the size of the raw resource content (before base64 encoding), in bytes, if known.
/// </summary>
/// <remarks>
/// This can be used by applications to display file sizes and estimate context window usage.
/// </remarks>
[JsonPropertyName("size")]
public long? Size { get; init; }
}

View file

@ -10,7 +10,7 @@ namespace ModelContextProtocol.Protocol;
/// <remarks>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class CreateMessageRequestParams : RequestParams
public sealed class CreateMessageRequestParams : RequestParams
{
/// <summary>
/// Gets or sets an indication as to which server contexts should be included in the prompt.

View file

@ -8,13 +8,13 @@ namespace ModelContextProtocol.Protocol;
/// <remarks>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </remarks>
public class CreateMessageResult
public sealed class CreateMessageResult : Result
{
/// <summary>
/// Gets or sets the content of the message.
/// </summary>
[JsonPropertyName("content")]
public required Content Content { get; init; }
public required ContentBlock Content { get; init; }
/// <summary>
/// Gets or sets the name of the model that generated the message.

View file

@ -6,7 +6,7 @@ namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents a message issued from the server to elicit additional information from the user via the client.
/// </summary>
public class ElicitRequestParams
public sealed class ElicitRequestParams
{
/// <summary>
/// Gets or sets the message to present to the user.
@ -65,6 +65,7 @@ public class ElicitRequestParams
[JsonDerivedType(typeof(StringSchema))]
public abstract class PrimitiveSchemaDefinition
{
/// <summary>Prevent external derivations.</summary>
protected private PrimitiveSchemaDefinition()
{
}

View file

@ -6,7 +6,7 @@ namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents the client's response to an elicitation request.
/// </summary>
public class ElicitResult
public sealed class ElicitResult : Result
{
/// <summary>
/// Gets or sets the user action in response to the elicitation.
@ -34,8 +34,14 @@ public class ElicitResult
/// Gets or sets the submitted form data.
/// </summary>
/// <remarks>
/// <para>
/// This is typically omitted if the action is "cancel" or "decline".
/// </para>
/// <para>
/// Values in the dictionary should be of types <see cref="JsonValueKind.String"/>, <see cref="JsonValueKind.Number"/>,
/// <see cref="JsonValueKind.True"/>, or <see cref="JsonValueKind.False"/>.
/// </para>
/// </remarks>
[JsonPropertyName("content")]
public JsonElement? Content { get; set; }
public IDictionary<string, JsonElement>? Content { get; set; }
}

View file

@ -14,7 +14,7 @@ namespace ModelContextProtocol.Protocol;
/// during interactions. The client must set a <see cref="ElicitationHandler"/> to process these requests.
/// </para>
/// </remarks>
public class ElicitationCapability
public sealed class ElicitationCapability
{
// Currently empty in the spec, but may be extended in the future.

View file

@ -6,7 +6,7 @@ namespace ModelContextProtocol.Protocol;
/// Represents an empty result object for operations that need to indicate successful completion
/// but don't need to return any specific data.
/// </summary>
public class EmptyResult
public sealed class EmptyResult : Result
{
[JsonIgnore]
internal static EmptyResult Instance { get; } = new();

Some files were not shown because too many files have changed in this diff Show more