Skip to content

Commit fa1e2c0

Browse files
committed
Add some missing exception XML tags
1 parent f7c35e3 commit fa1e2c0

22 files changed

+64
-10
lines changed

src/ModelContextProtocol.Core/AIContentExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ internal static AdditionalPropertiesDictionary ToAdditionalProperties(this JsonO
161161
/// This method transforms a protocol-specific <see cref="PromptMessage"/> from the Model Context Protocol
162162
/// into a standard <see cref="ChatMessage"/> object that can be used with AI client libraries.
163163
/// </remarks>
164+
/// <exception cref="ArgumentNullException"><paramref name="promptMessage"/> is <see langword="null"/>.</exception>
164165
public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
165166
{
166167
Throw.IfNull(promptMessage);
@@ -187,6 +188,7 @@ public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
187188
/// <see cref="ChatRole.Tool"/> message containing a <see cref="FunctionResultContent"/> with result as a
188189
/// serialized <see cref="JsonElement"/>.
189190
/// </remarks>
191+
/// <exception cref="ArgumentNullException"><paramref name="result"/> or <paramref name="callId"/> is <see langword="null"/>.</exception>
190192
public static ChatMessage ToChatMessage(this CallToolResult result, string callId)
191193
{
192194
Throw.IfNull(result);
@@ -207,6 +209,7 @@ public static ChatMessage ToChatMessage(this CallToolResult result, string callI
207209
/// This method transforms protocol-specific <see cref="PromptMessage"/> objects from a Model Context Protocol
208210
/// prompt result into standard <see cref="ChatMessage"/> objects that can be used with AI client libraries.
209211
/// </remarks>
212+
/// <exception cref="ArgumentNullException"><paramref name="promptResult"/> is <see langword="null"/>.</exception>
210213
public static IList<ChatMessage> ToChatMessages(this GetPromptResult promptResult)
211214
{
212215
Throw.IfNull(promptResult);
@@ -224,6 +227,7 @@ public static IList<ChatMessage> ToChatMessages(this GetPromptResult promptResul
224227
/// protocol-specific <see cref="PromptMessage"/> objects for the Model Context Protocol system.
225228
/// Only representable content items are processed.
226229
/// </remarks>
230+
/// <exception cref="ArgumentNullException"><paramref name="chatMessage"/> is <see langword="null"/>.</exception>
227231
public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage)
228232
{
229233
Throw.IfNull(chatMessage);
@@ -251,6 +255,7 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
251255
/// This method converts Model Context Protocol content types to the equivalent Microsoft.Extensions.AI
252256
/// content types, enabling seamless integration between the protocol and AI client libraries.
253257
/// </remarks>
258+
/// <exception cref="ArgumentNullException"><paramref name="content"/> is <see langword="null"/>.</exception>
254259
public static AIContent? ToAIContent(this ContentBlock content)
255260
{
256261
Throw.IfNull(content);
@@ -294,6 +299,8 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
294299
/// This method converts Model Context Protocol resource types to the equivalent Microsoft.Extensions.AI
295300
/// content types, enabling seamless integration between the protocol and AI client libraries.
296301
/// </remarks>
302+
/// <exception cref="ArgumentNullException"><paramref name="content"/> is <see langword="null"/>.</exception>
303+
/// <exception cref="NotSupportedException">The resource type is not supported.</exception>
297304
public static AIContent ToAIContent(this ResourceContents content)
298305
{
299306
Throw.IfNull(content);
@@ -325,6 +332,7 @@ public static AIContent ToAIContent(this ResourceContents content)
325332
/// preserving the type-specific conversion logic for text, images, audio, and resources.
326333
/// </para>
327334
/// </remarks>
335+
/// <exception cref="ArgumentNullException"><paramref name="contents"/> is <see langword="null"/>.</exception>
328336
public static IList<AIContent> ToAIContents(this IEnumerable<ContentBlock> contents)
329337
{
330338
Throw.IfNull(contents);
@@ -347,6 +355,7 @@ public static IList<AIContent> ToAIContents(this IEnumerable<ContentBlock> conte
347355
/// binary resources become <see cref="DataContent"/> objects.
348356
/// </para>
349357
/// </remarks>
358+
/// <exception cref="ArgumentNullException"><paramref name="contents"/> is <see langword="null"/>.</exception>
350359
public static IList<AIContent> ToAIContents(this IEnumerable<ResourceContents> contents)
351360
{
352361
Throw.IfNull(contents);
@@ -357,8 +366,11 @@ public static IList<AIContent> ToAIContents(this IEnumerable<ResourceContents> c
357366
/// <summary>Creates a new <see cref="ContentBlock"/> from the content of an <see cref="AIContent"/>.</summary>
358367
/// <param name="content">The <see cref="AIContent"/> to convert.</param>
359368
/// <returns>The created <see cref="ContentBlock"/>.</returns>
369+
/// <exception cref="ArgumentNullException"><paramref name="content"/> is <see langword="null"/>.</exception>
360370
public static ContentBlock ToContentBlock(this AIContent content)
361371
{
372+
Throw.IfNull(content);
373+
362374
ContentBlock contentBlock = content switch
363375
{
364376
TextContent textContent => new TextContentBlock

src/ModelContextProtocol.Core/Client/HttpClientTransport.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public HttpClientTransport(HttpClientTransportOptions transportOptions, ILoggerF
4141
/// <see langword="true"/> to dispose of <paramref name="httpClient"/> when the transport is disposed;
4242
/// <see langword="false"/> if the caller is retaining ownership of the <paramref name="httpClient"/>'s lifetime.
4343
/// </param>
44+
/// <exception cref="ArgumentNullException"><paramref name="transportOptions"/> or <paramref name="httpClient"/> is <see langword="null"/>.</exception>
4445
public HttpClientTransport(HttpClientTransportOptions transportOptions, HttpClient httpClient, ILoggerFactory? loggerFactory = null, bool ownsHttpClient = false)
4546
{
4647
Throw.IfNull(transportOptions);

src/ModelContextProtocol.Core/Client/McpClient.Methods.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract partial class McpClient : McpSession
2020
/// <param name="loggerFactory">A logger factory for creating loggers for clients.</param>
2121
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
2222
/// <returns>An <see cref="McpClient"/> that's connected to the specified server.</returns>
23-
/// <exception cref="ArgumentNullException"><paramref name="clientTransport"/> or <paramref name="clientOptions"/> is <see langword="null"/>.</exception>
23+
/// <exception cref="ArgumentNullException"><paramref name="clientTransport"/> is <see langword="null"/>.</exception>
2424
public static async Task<McpClient> CreateAsync(
2525
IClientTransport clientTransport,
2626
McpClientOptions? clientOptions = null,
@@ -60,7 +60,7 @@ public static async Task<McpClient> CreateAsync(
6060
/// <param name="loggerFactory">An optional logger factory for diagnostics.</param>
6161
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
6262
/// <returns>An <see cref="McpClient"/> bound to the resumed session.</returns>
63-
/// <exception cref="ArgumentNullException">Thrown when <paramref name="clientTransport"/> or <paramref name="resumeOptions"/> is <see langword="null"/>.</exception>
63+
/// <exception cref="ArgumentNullException"><paramref name="clientTransport"/>, <paramref name="resumeOptions"/>, <see cref="ResumeClientSessionOptions.ServerCapabilities"/>, or <see cref="ResumeClientSessionOptions.ServerInfo"/> is <see langword="null"/>.</exception>
6464
public static async Task<McpClient> ResumeSessionAsync(
6565
IClientTransport clientTransport,
6666
ResumeClientSessionOptions resumeOptions,
@@ -104,6 +104,7 @@ public ValueTask<PingResult> PingAsync(RequestOptions? options = null, Cancellat
104104
/// <param name="requestParams">The request parameters to send in the request.</param>
105105
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
106106
/// <returns>A task containing the ping result.</returns>
107+
/// <exception cref="ArgumentNullException"><paramref name="requestParams"/> is <see langword="null"/>.</exception>
107108
/// <exception cref="McpException">The server cannot be reached or returned an error response.</exception>
108109
public ValueTask<PingResult> PingAsync(
109110
PingRequestParams requestParams,
@@ -235,6 +236,8 @@ public ValueTask<ListPromptsResult> ListPromptsAsync(
235236
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
236237
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
237238
/// <returns>A task containing the prompt's result with content and messages.</returns>
239+
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception>
240+
/// <exception cref="ArgumentException"><paramref name="name"/> is empty or composed entirely of whitespace.</exception>
238241
public ValueTask<GetPromptResult> GetPromptAsync(
239242
string name,
240243
IReadOnlyDictionary<string, object?>? arguments = null,
@@ -391,6 +394,7 @@ public ValueTask<ListResourcesResult> ListResourcesAsync(
391394
/// <param name="uri">The URI of the resource.</param>
392395
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
393396
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
397+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
394398
public ValueTask<ReadResourceResult> ReadResourceAsync(
395399
Uri uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
396400
{
@@ -405,6 +409,8 @@ public ValueTask<ReadResourceResult> ReadResourceAsync(
405409
/// <param name="uri">The URI of the resource.</param>
406410
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
407411
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
412+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
413+
/// <exception cref="ArgumentException"><paramref name="uri"/> is empty or composed entirely of whitespace.</exception>
408414
public ValueTask<ReadResourceResult> ReadResourceAsync(
409415
string uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
410416
{
@@ -424,6 +430,8 @@ public ValueTask<ReadResourceResult> ReadResourceAsync(
424430
/// <param name="arguments">Arguments to use to format <paramref name="uriTemplate"/>.</param>
425431
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
426432
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
433+
/// <exception cref="ArgumentNullException"><paramref name="uriTemplate"/> or <paramref name="arguments"/> is <see langword="null"/>.</exception>
434+
/// <exception cref="ArgumentException"><paramref name="uriTemplate"/> is empty or composed entirely of whitespace.</exception>
427435
public ValueTask<ReadResourceResult> ReadResourceAsync(
428436
string uriTemplate, IReadOnlyDictionary<string, object?> arguments, RequestOptions? options = null, CancellationToken cancellationToken = default)
429437
{
@@ -469,6 +477,8 @@ public ValueTask<ReadResourceResult> ReadResourceAsync(
469477
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
470478
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
471479
/// <returns>A <see cref="CompleteResult"/> containing completion suggestions.</returns>
480+
/// <exception cref="ArgumentNullException"><paramref name="reference"/> or <paramref name="argumentName"/> is <see langword="null"/>.</exception>
481+
/// <exception cref="ArgumentException"><paramref name="argumentName"/> is empty or composed entirely of whitespace.</exception>
472482
public ValueTask<CompleteResult> CompleteAsync(
473483
Reference reference, string argumentName, string argumentValue,
474484
RequestOptions? options = null, CancellationToken cancellationToken = default)
@@ -514,6 +524,7 @@ public ValueTask<CompleteResult> CompleteAsync(
514524
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
515525
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
516526
/// <returns>A task that represents the asynchronous operation.</returns>
527+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
517528
public Task SubscribeToResourceAsync(Uri uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
518529
{
519530
Throw.IfNull(uri);
@@ -528,6 +539,8 @@ public Task SubscribeToResourceAsync(Uri uri, RequestOptions? options = null, Ca
528539
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
529540
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
530541
/// <returns>A task that represents the asynchronous operation.</returns>
542+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
543+
/// <exception cref="ArgumentException"><paramref name="uri"/> is empty or composed entirely of whitespace.</exception>
531544
public Task SubscribeToResourceAsync(string uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
532545
{
533546
Throw.IfNullOrWhiteSpace(uri);
@@ -569,6 +582,7 @@ public Task SubscribeToResourceAsync(
569582
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
570583
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
571584
/// <returns>A task that represents the asynchronous operation.</returns>
585+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
572586
public Task UnsubscribeFromResourceAsync(Uri uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
573587
{
574588
Throw.IfNull(uri);
@@ -583,6 +597,8 @@ public Task UnsubscribeFromResourceAsync(Uri uri, RequestOptions? options = null
583597
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
584598
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
585599
/// <returns>A task that represents the asynchronous operation.</returns>
600+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
601+
/// <exception cref="ArgumentException"><paramref name="uri"/> is empty or composed entirely of whitespace.</exception>
586602
public Task UnsubscribeFromResourceAsync(string uri, RequestOptions? options = null, CancellationToken cancellationToken = default)
587603
{
588604
Throw.IfNullOrWhiteSpace(uri);
@@ -626,6 +642,7 @@ public Task UnsubscribeFromResourceAsync(
626642
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
627643
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
628644
/// <returns>The <see cref="CallToolResult"/> from the tool execution.</returns>
645+
/// <exception cref="ArgumentNullException"><paramref name="toolName"/> is <see langword="null"/>.</exception>
629646
public ValueTask<CallToolResult> CallToolAsync(
630647
string toolName,
631648
IReadOnlyDictionary<string, object?>? arguments = null,

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public McpClientTool WithDescription(string description) =>
275275
/// </para>
276276
/// </remarks>
277277
/// <returns>A new instance of <see cref="McpClientTool"/>, configured with the provided progress instance.</returns>
278+
/// <exception cref="ArgumentNullException"><paramref name="progress"/> is <see langword="null"/>.</exception>
278279
public McpClientTool WithProgress(IProgress<ProgressNotificationValue> progress)
279280
{
280281
Throw.IfNull(progress);

src/ModelContextProtocol.Core/Client/StdioClientTransport.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public sealed partial class StdioClientTransport : IClientTransport
3939
/// </summary>
4040
/// <param name="options">Configuration options for the transport, including the command to execute, arguments, working directory, and environment variables.</param>
4141
/// <param name="loggerFactory">A logger factory for creating loggers used for diagnostic output during transport operations.</param>
42+
/// <exception cref="ArgumentNullException"><paramref name="options"/> is <see langword="null"/>.</exception>
4243
public StdioClientTransport(StdioClientTransportOptions options, ILoggerFactory? loggerFactory = null)
4344
{
4445
Throw.IfNull(options);

src/ModelContextProtocol.Core/Client/StreamClientTransport.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public sealed class StreamClientTransport : IClientTransport
2929
/// Reads from this stream will receive messages from the server.
3030
/// </param>
3131
/// <param name="loggerFactory">A logger factory for creating loggers.</param>
32+
/// <exception cref="ArgumentNullException"><paramref name="serverInput"/> or <paramref name="serverOutput"/> is <see langword="null"/>.</exception>
3233
public StreamClientTransport(
3334
Stream serverInput, Stream serverOutput, ILoggerFactory? loggerFactory = null)
3435
{

0 commit comments

Comments
 (0)