Skip to content

Commit 11e43eb

Browse files
Copilotstephentoub
andcommitted
Add missing exception documentation to McpSession, McpClient, and McpServer public APIs
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 4385805 commit 11e43eb

7 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public McpClientPrompt(McpClient client, Prompt prompt)
7777
/// <param name="serializerOptions">The serialization options governing argument serialization.</param>
7878
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
7979
/// <returns>A <see cref="ValueTask"/> containing the prompt's result with content and messages.</returns>
80+
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
8081
/// <remarks>
8182
/// <para>
8283
/// This method sends a request to the MCP server to execute this prompt with the provided arguments.

src/ModelContextProtocol.Core/Client/McpClientResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public McpClientResource(McpClient client, Resource resource)
7676
/// </summary>
7777
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
7878
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource's result with content and messages.</returns>
79+
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
7980
/// <remarks>
8081
/// <para>
8182
/// This is a convenience method that internally calls <see cref="McpClient.ReadResourceAsync(string, RequestOptions, CancellationToken)"/>.

src/ModelContextProtocol.Core/Client/McpClientResourceTemplate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public McpClientResourceTemplate(McpClient client, ResourceTemplate resourceTemp
8080
/// </param>
8181
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
8282
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource template's result with content and messages.</returns>
83+
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
8384
public ValueTask<ReadResourceResult> ReadAsync(
8485
IReadOnlyDictionary<string, object?> arguments,
8586
CancellationToken cancellationToken = default) =>

src/ModelContextProtocol.Core/McpSession.Methods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public abstract partial class McpSession : IAsyncDisposable
1818
/// <param name="serializerOptions">The options governing request serialization.</param>
1919
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
2020
/// <returns>A task that represents the asynchronous operation. The task result contains the deserialized result.</returns>
21+
/// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception>
22+
/// <exception cref="ArgumentException"><paramref name="method"/> is empty or composed entirely of whitespace.</exception>
23+
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
2124
public ValueTask<TResult> SendRequestAsync<TParameters, TResult>(
2225
string method,
2326
TParameters parameters,

src/ModelContextProtocol.Core/McpSession.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public abstract partial class McpSession : IAsyncDisposable
8686
/// <param name="method">The notification method.</param>
8787
/// <param name="handler">The handler to be invoked.</param>
8888
/// <returns>An <see cref="IDisposable"/> that will remove the registered handler when disposed.</returns>
89+
/// <exception cref="ArgumentNullException"><paramref name="method"/> or <paramref name="handler"/> is <see langword="null"/>.</exception>
90+
/// <exception cref="ArgumentException"><paramref name="method"/> is empty or composed entirely of whitespace.</exception>
8991
public abstract IAsyncDisposable RegisterNotificationHandler(string method, Func<JsonRpcNotification, CancellationToken, ValueTask> handler);
9092

9193
/// <inheritdoc/>

src/ModelContextProtocol.Core/Server/McpServer.Methods.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static McpServer Create(
5252
/// <returns>A task containing the sampling result from the client.</returns>
5353
/// <exception cref="ArgumentNullException"><paramref name="requestParams"/> is <see langword="null"/>.</exception>
5454
/// <exception cref="InvalidOperationException">The client does not support sampling.</exception>
55+
/// <exception cref="McpException">The request failed or the client returned an error response.</exception>
5556
public ValueTask<CreateMessageResult> SampleAsync(
5657
CreateMessageRequestParams requestParams,
5758
CancellationToken cancellationToken = default)
@@ -76,6 +77,7 @@ public ValueTask<CreateMessageResult> SampleAsync(
7677
/// <returns>A task containing the chat response from the model.</returns>
7778
/// <exception cref="ArgumentNullException"><paramref name="messages"/> is <see langword="null"/>.</exception>
7879
/// <exception cref="InvalidOperationException">The client does not support sampling.</exception>
80+
/// <exception cref="McpException">The request failed or the client returned an error response.</exception>
7981
public async Task<ChatResponse> SampleAsync(
8082
IEnumerable<ChatMessage> messages, ChatOptions? chatOptions = default, CancellationToken cancellationToken = default)
8183
{
@@ -222,6 +224,7 @@ public ILoggerProvider AsClientLoggerProvider() =>
222224
/// <returns>A task containing the list of roots exposed by the client.</returns>
223225
/// <exception cref="ArgumentNullException"><paramref name="requestParams"/> is <see langword="null"/>.</exception>
224226
/// <exception cref="InvalidOperationException">The client does not support roots.</exception>
227+
/// <exception cref="McpException">The request failed or the client returned an error response.</exception>
225228
public ValueTask<ListRootsResult> RequestRootsAsync(
226229
ListRootsRequestParams requestParams,
227230
CancellationToken cancellationToken = default)
@@ -245,6 +248,7 @@ public ValueTask<ListRootsResult> RequestRootsAsync(
245248
/// <returns>A task containing the elicitation result.</returns>
246249
/// <exception cref="ArgumentNullException"><paramref name="requestParams"/> is <see langword="null"/>.</exception>
247250
/// <exception cref="InvalidOperationException">The client does not support elicitation.</exception>
251+
/// <exception cref="McpException">The request failed or the client returned an error response.</exception>
248252
public ValueTask<ElicitResult> ElicitAsync(
249253
ElicitRequestParams requestParams,
250254
CancellationToken cancellationToken = default)
@@ -272,6 +276,7 @@ public ValueTask<ElicitResult> ElicitAsync(
272276
/// <exception cref="ArgumentNullException"><paramref name="message"/> is <see langword="null"/>.</exception>
273277
/// <exception cref="ArgumentException"><paramref name="message"/> is empty or composed entirely of whitespace.</exception>
274278
/// <exception cref="InvalidOperationException">The client does not support elicitation.</exception>
279+
/// <exception cref="McpException">The request failed or the client returned an error response.</exception>
275280
/// <remarks>
276281
/// Elicitation uses a constrained subset of JSON Schema and only supports strings, numbers/integers, booleans and string enums.
277282
/// Unsupported member types are ignored when constructing the schema.

0 commit comments

Comments
 (0)