Audit protocol types (#892)

This commit is contained in:
Mackinnon Buck 2025-11-04 18:41:10 -05:00 • committed by GitHub
commit 121929da36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
63 changed files with 262 additions and 168 deletions

View file

@ -250,6 +250,7 @@ internal sealed class StreamableHttpHandler(
{
var jsonRpcError = new JsonRpcError
{
Id = default,
Error = new()
{
Code = errorCode,

View file

@ -226,6 +226,7 @@ public static class AIContentExtensions
{
Blob = dataContent.Base64Data.ToString(),
MimeType = dataContent.MediaType,
Uri = string.Empty,
}
},

View file

@ -15,7 +15,7 @@ public sealed class Annotations
/// Gets or sets the intended audience for this content as an array of <see cref="Role"/> values.
/// </summary>
[JsonPropertyName("audience")]
public IList<Role>? Audience { get; init; }
public IList<Role>? Audience { get; set; }
/// <summary>
/// Gets or sets a value indicating how important this data is for operating the server.
@ -25,7 +25,7 @@ public sealed class Annotations
/// 1 represents highest priority.
/// </remarks>
[JsonPropertyName("priority")]
public float? Priority { get; init; }
public float? Priority { get; set; }
/// <summary>
/// Gets or sets the moment the resource was last modified.

View file

@ -15,7 +15,7 @@ public sealed class Argument
/// Gets or sets the name of the argument being completed.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
public required string Name { get; set; }
/// <summary>
/// Gets or sets the current partial text value for which completion suggestions are requested.
@ -25,5 +25,5 @@ public sealed class Argument
/// options should be generated.
/// </remarks>
[JsonPropertyName("value")]
public string Value { get; set; } = string.Empty;
}
public required string Value { get; set; }
}

View file

@ -26,5 +26,5 @@ public sealed class BlobResourceContents : ResourceContents
/// Gets or sets the base64-encoded string representing the binary data of the item.
/// </summary>
[JsonPropertyName("blob")]
public string Blob { get; set; } = string.Empty;
}
public required string Blob { get; set; }
}

View file

@ -14,7 +14,7 @@ public sealed class CallToolRequestParams : RequestParams
{
/// <summary>Gets or sets the name of the tool to invoke.</summary>
[JsonPropertyName("name")]
public required string Name { get; init; }
public required string Name { get; set; }
/// <summary>
/// Gets or sets optional arguments to pass to the tool when invoking it on the server.
@ -24,5 +24,5 @@ public sealed class CallToolRequestParams : RequestParams
/// a parameter name and its corresponding argument value.
/// </remarks>
[JsonPropertyName("arguments")]
public IReadOnlyDictionary<string, JsonElement>? Arguments { get; init; }
public IDictionary<string, JsonElement>? Arguments { get; set; }
}

View file

@ -20,7 +20,7 @@ public sealed class CancelledNotificationParams : NotificationParams
/// This must match the ID of an in-flight request that the sender wishes to cancel.
/// </remarks>
[JsonPropertyName("requestId")]
public RequestId RequestId { get; set; }
public required RequestId RequestId { get; set; }
/// <summary>
/// Gets or sets an optional string describing the reason for the cancellation request.

View file

@ -15,5 +15,5 @@ public sealed class CompleteContext
/// Gets or sets previously-resolved variables in a URI template or prompt.
/// </summary>
[JsonPropertyName("arguments")]
public IDictionary<string, string>? Arguments { get; init; }
public IDictionary<string, string>? Arguments { get; set; }
}

View file

@ -23,18 +23,18 @@ public sealed class CompleteRequestParams : RequestParams
/// Gets or sets the reference's information.
/// </summary>
[JsonPropertyName("ref")]
public required Reference Ref { get; init; }
public required Reference Ref { get; set; }
/// <summary>
/// Gets or sets the argument information for the completion request, specifying what is being completed
/// and the current partial input.
/// </summary>
[JsonPropertyName("argument")]
public required Argument Argument { get; init; }
public required Argument Argument { get; set; }
/// <summary>
/// Gets or sets additional, optional context for completions.
/// </summary>
[JsonPropertyName("context")]
public CompleteContext? Context { get; init; }
public CompleteContext? Context { get; set; }
}

View file

@ -1,6 +1,7 @@
using Microsoft.Extensions.AI;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
@ -33,13 +34,13 @@ public abstract class ContentBlock
}
/// <summary>
/// Gets or sets the type of content.
/// When overridden in a derived class, gets 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;
public abstract string Type { get; }
/// <summary>
/// Gets or sets optional annotations for the content.
@ -49,7 +50,7 @@ public abstract class ContentBlock
/// 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; }
public Annotations? Annotations { get; set; }
/// <summary>
/// Provides a <see cref="JsonConverter"/> for <see cref="ContentBlock"/>.
@ -276,8 +277,8 @@ public abstract class ContentBlock
/// <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";
/// <inheritdoc/>
public override string Type => "text";
/// <summary>
/// Gets or sets the text content of the message.
@ -298,8 +299,8 @@ public sealed class TextContentBlock : ContentBlock
/// <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";
/// <inheritdoc/>
public override string Type => "image";
/// <summary>
/// Gets or sets the base64-encoded image data.
@ -331,8 +332,8 @@ public sealed class ImageContentBlock : ContentBlock
/// <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";
/// <inheritdoc/>
public override string Type => "audio";
/// <summary>
/// Gets or sets the base64-encoded audio data.
@ -367,8 +368,8 @@ public sealed class AudioContentBlock : ContentBlock
/// </remarks>
public sealed class EmbeddedResourceBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary>
public EmbeddedResourceBlock() => Type = "resource";
/// <inheritdoc/>
public override string Type => "resource";
/// <summary>
/// Gets or sets the resource content of the message when <see cref="Type"/> is "resource".
@ -399,20 +400,21 @@ public sealed class EmbeddedResourceBlock : ContentBlock
/// </remarks>
public sealed class ResourceLinkBlock : ContentBlock
{
/// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary>
public ResourceLinkBlock() => Type = "resource_link";
/// <inheritdoc/>
public override string Type => "resource_link";
/// <summary>
/// Gets or sets the URI of this resource.
/// </summary>
[JsonPropertyName("uri")]
public required string Uri { get; init; }
[StringSyntax(StringSyntaxAttribute.Uri)]
public required string Uri { get; set; }
/// <summary>
/// Gets or sets a human-readable name for this resource.
/// </summary>
[JsonPropertyName("name")]
public required string Name { get; init; }
public required string Name { get; set; }
/// <summary>
/// Gets or sets a description of what this resource represents.
@ -431,7 +433,7 @@ public sealed class ResourceLinkBlock : ContentBlock
/// </para>
/// </remarks>
[JsonPropertyName("description")]
public string? Description { get; init; }
public string? Description { get; set; }
/// <summary>
/// Gets or sets the MIME type of this resource.
@ -447,7 +449,7 @@ public sealed class ResourceLinkBlock : ContentBlock
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public string? MimeType { get; init; }
public string? MimeType { get; set; }
/// <summary>
/// Gets or sets the size of the raw resource content (before base64 encoding), in bytes, if known.
@ -456,5 +458,5 @@ public sealed class ResourceLinkBlock : ContentBlock
/// This can be used by applications to display file sizes and estimate context window usage.
/// </remarks>
[JsonPropertyName("size")]
public long? Size { get; init; }
}
public long? Size { get; set; }
}

View file

@ -19,7 +19,7 @@ public sealed class CreateMessageRequestParams : RequestParams
/// The client may ignore this request.
/// </remarks>
[JsonPropertyName("includeContext")]
public ContextInclusion? IncludeContext { get; init; }
public ContextInclusion? IncludeContext { get; set; }
/// <summary>
/// Gets or sets the maximum number of tokens to generate in the LLM response, as requested by the server.
@ -29,13 +29,13 @@ public sealed class CreateMessageRequestParams : RequestParams
/// response length and computation time. The client may choose to sample fewer tokens than requested.
/// </remarks>
[JsonPropertyName("maxTokens")]
public int? MaxTokens { get; init; }
public required int MaxTokens { get; set; }
/// <summary>
/// Gets or sets the messages requested by the server to be included in the prompt.
/// </summary>
[JsonPropertyName("messages")]
public required IReadOnlyList<SamplingMessage> Messages { get; init; }
public IList<SamplingMessage> Messages { get; set; } = [];
/// <summary>
/// Gets or sets optional metadata to pass through to the LLM provider.
@ -46,7 +46,7 @@ public sealed class CreateMessageRequestParams : RequestParams
/// that are specific to certain AI models or providers.
/// </remarks>
[JsonPropertyName("metadata")]
public JsonElement? Metadata { get; init; }
public JsonElement? Metadata { get; set; }
/// <summary>
/// Gets or sets the server's preferences for which model to select.
@ -66,7 +66,7 @@ public sealed class CreateMessageRequestParams : RequestParams
/// </para>
/// </remarks>
[JsonPropertyName("modelPreferences")]
public ModelPreferences? ModelPreferences { get; init; }
public ModelPreferences? ModelPreferences { get; set; }
/// <summary>
/// Gets or sets optional sequences of characters that signal the LLM to stop generating text when encountered.
@ -84,7 +84,7 @@ public sealed class CreateMessageRequestParams : RequestParams
/// </para>
/// </remarks>
[JsonPropertyName("stopSequences")]
public IReadOnlyList<string>? StopSequences { get; init; }
public IList<string>? StopSequences { get; set; }
/// <summary>
/// Gets or sets an optional system prompt the server wants to use for sampling.
@ -93,11 +93,11 @@ public sealed class CreateMessageRequestParams : RequestParams
/// The client may modify or omit this prompt.
/// </remarks>
[JsonPropertyName("systemPrompt")]
public string? SystemPrompt { get; init; }
public string? SystemPrompt { get; set; }
/// <summary>
/// Gets or sets the temperature to use for sampling, as requested by the server.
/// </summary>
[JsonPropertyName("temperature")]
public float? Temperature { get; init; }
public float? Temperature { get; set; }
}

View file

@ -14,7 +14,7 @@ public sealed class CreateMessageResult : Result
/// Gets or sets the content of the message.
/// </summary>
[JsonPropertyName("content")]
public required ContentBlock Content { get; init; }
public required ContentBlock Content { get; set; }
/// <summary>
/// Gets or sets the name of the model that generated the message.
@ -29,7 +29,7 @@ public sealed class CreateMessageResult : Result
/// </para>
/// </remarks>
[JsonPropertyName("model")]
public required string Model { get; init; }
public required string Model { get; set; }
/// <summary>
/// Gets or sets the reason why message generation (sampling) stopped, if known.
@ -43,11 +43,11 @@ public sealed class CreateMessageResult : Result
/// </list>
/// </remarks>
[JsonPropertyName("stopReason")]
public string? StopReason { get; init; }
public string? StopReason { get; set; }
/// <summary>
/// Gets or sets the role of the user who generated the message.
/// </summary>
[JsonPropertyName("role")]
public required Role Role { get; init; }
public required Role Role { get; set; }
}

View file

@ -15,7 +15,7 @@ public sealed class ElicitRequestParams
/// Gets or sets the message to present to the user.
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;
public required string Message { get; set; }
/// <summary>
/// Gets or sets the requested schema.

View file

@ -67,6 +67,25 @@ public sealed class ElicitResult<T> : Result
/// <summary>
/// Gets or sets the user action in response to the elicitation.
/// </summary>
/// <value>
/// Defaults to "cancel" if not explicitly set.
/// </value>
/// <remarks>
/// <list type="bullet">
/// <item>
/// <term>"accept"</term>
/// <description>User submitted the form/confirmed the action</description>
/// </item>
/// <item>
/// <term>"decline"</term>
/// <description>User explicitly declined the action</description>
/// </item>
/// <item>
/// <term>"cancel"</term>
/// <description>User dismissed without making an explicit choice (default)</description>
/// </item>
/// </list>
/// </remarks>
public string Action { get; set; } = "cancel";
/// <summary>

View file

@ -16,7 +16,7 @@ public sealed class GetPromptRequestParams : RequestParams
/// Gets or sets the name of the prompt.
/// </summary>
[JsonPropertyName("name")]
public required string Name { get; init; }
public required string Name { get; set; }
/// <summary>
/// Gets or sets arguments to use for templating the prompt when retrieving it from the server.
@ -27,5 +27,5 @@ public sealed class GetPromptRequestParams : RequestParams
/// choose to use these arguments in any way it deems appropriate to generate the prompt.
/// </remarks>
[JsonPropertyName("arguments")]
public IReadOnlyDictionary<string, JsonElement>? Arguments { get; init; }
public IDictionary<string, JsonElement>? Arguments { get; set; }
}

View file

@ -46,7 +46,7 @@ public sealed class Icon
/// </para>
/// </remarks>
[JsonPropertyName("src")]
public required string Source { get; init; }
public required string Source { get; set; }
/// <summary>
/// Gets or sets the optional MIME type of the icon.
@ -56,7 +56,7 @@ public sealed class Icon
/// Common values include "image/png", "image/jpeg", "image/svg+xml", and "image/webp".
/// </remarks>
[JsonPropertyName("mimeType")]
public string? MimeType { get; init; }
public string? MimeType { get; set; }
/// <summary>
/// Gets or sets the optional size specifications for the icon.
@ -71,7 +71,7 @@ public sealed class Icon
/// </para>
/// </remarks>
[JsonPropertyName("sizes")]
public IList<string>? Sizes { get; init; }
public IList<string>? Sizes { get; set; }
/// <summary>
/// Gets or sets the optional theme for this icon.
@ -81,5 +81,5 @@ public sealed class Icon
/// Used to specify which UI theme the icon is designed for.
/// </remarks>
[JsonPropertyName("theme")]
public string? Theme { get; init; }
}
public string? Theme { get; set; }
}

View file

@ -38,7 +38,7 @@ public sealed class InitializeRequestParams : RequestParams
/// </para>
/// </remarks>
[JsonPropertyName("protocolVersion")]
public required string ProtocolVersion { get; init; }
public required string ProtocolVersion { get; set; }
/// <summary>
/// Gets or sets the client's capabilities.
@ -47,7 +47,7 @@ public sealed class InitializeRequestParams : RequestParams
/// Capabilities define the features the client supports, such as "sampling" or "roots".
/// </remarks>
[JsonPropertyName("capabilities")]
public ClientCapabilities? Capabilities { get; init; }
public required ClientCapabilities Capabilities { get; set; }
/// <summary>
/// Gets or sets information about the client implementation, including its name and version.
@ -57,5 +57,5 @@ public sealed class InitializeRequestParams : RequestParams
/// Servers may use this information for logging, debugging, or compatibility checks.
/// </remarks>
[JsonPropertyName("clientInfo")]
public required Implementation ClientInfo { get; init; }
public required Implementation ClientInfo { get; set; }
}

View file

@ -38,7 +38,7 @@ public sealed class InitializeResult : Result
/// </para>
/// </remarks>
[JsonPropertyName("protocolVersion")]
public required string ProtocolVersion { get; init; }
public required string ProtocolVersion { get; set; }
/// <summary>
/// Gets or sets the server's capabilities.
@ -48,7 +48,7 @@ public sealed class InitializeResult : Result
/// and other protocol-specific functionality.
/// </remarks>
[JsonPropertyName("capabilities")]
public required ServerCapabilities Capabilities { get; init; }
public required ServerCapabilities Capabilities { get; set; }
/// <summary>
/// Gets or sets information about the server implementation, including its name and version.
@ -58,7 +58,7 @@ public sealed class InitializeResult : Result
/// Clients may use this information for logging, debugging, or compatibility checks.
/// </remarks>
[JsonPropertyName("serverInfo")]
public required Implementation ServerInfo { get; init; }
public required Implementation ServerInfo { get; set; }
/// <summary>
/// Gets or sets optional instructions for using the server and its features.
@ -75,5 +75,5 @@ public sealed class InitializeResult : Result
/// </para>
/// </remarks>
[JsonPropertyName("instructions")]
public string? Instructions { get; init; }
public string? Instructions { get; set; }
}

View file

@ -23,5 +23,5 @@ public sealed class JsonRpcError : JsonRpcMessageWithId
/// message, and optional additional data
/// </summary>
[JsonPropertyName("error")]
public required JsonRpcErrorDetail Error { get; init; }
public required JsonRpcErrorDetail Error { get; set; }
}

View file

@ -17,7 +17,7 @@ public sealed class JsonRpcErrorDetail
/// Gets an integer error code according to the JSON-RPC specification.
/// </summary>
[JsonPropertyName("code")]
public required int Code { get; init; }
public required int Code { get; set; }
/// <summary>
/// Gets a short description of the error.
@ -28,7 +28,7 @@ public sealed class JsonRpcErrorDetail
/// in the JSON-RPC 2.0 specification.
/// </remarks>
[JsonPropertyName("message")]
public required string Message { get; init; }
public required string Message { get; set; }
/// <summary>
/// Gets optional additional error data.
@ -40,5 +40,5 @@ public sealed class JsonRpcErrorDetail
/// the error condition.
/// </remarks>
[JsonPropertyName("data")]
public object? Data { get; init; }
}
public object? Data { get; set; }
}

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