You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return CallToolResult<T> from CallToolAsync<T>, use ToString and FirstOrDefault
- CallToolAsync<T> now returns CallToolResult<T> instead of T
- No longer throws on IsError; caller can inspect IsError on the result
- Use OfType<TextContentBlock>().FirstOrDefault() instead of indexing
- Use ToString() instead of ToJsonString(serializerOptions) in ToCallToolResult
- Updated tests accordingly
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy file name to clipboardExpand all lines: src/ModelContextProtocol.Core/Client/McpClient.Methods.cs
+24-29Lines changed: 24 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -915,33 +915,27 @@ public ValueTask<CallToolResult> CallToolAsync(
915
915
}
916
916
917
917
/// <summary>
918
-
/// Invokes a tool on the server and deserializes the result as a strongly-typed <typeparamref name="T"/>.
918
+
/// Invokes a tool on the server and deserializes the result as a strongly-typed <see cref="CallToolResult{T}"/>.
919
919
/// </summary>
920
920
/// <typeparam name="T">The type to deserialize the tool's structured content or text content into.</typeparam>
921
921
/// <param name="toolName">The name of the tool to call on the server.</param>
922
922
/// <param name="arguments">An optional dictionary of arguments to pass to the tool.</param>
923
923
/// <param name="progress">An optional progress reporter for server notifications.</param>
924
924
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
925
925
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
926
-
/// <returns>The deserialized result from the tool execution.</returns>
926
+
/// <returns>A <see cref="CallToolResult{T}"/> containing the deserialized content, error state, and metadata.</returns>
927
927
/// <exception cref="ArgumentNullException"><paramref name="toolName"/> is <see langword="null"/>.</exception>
928
-
/// <exception cref="McpException">
929
-
/// The request failed, the server returned an error response, or <see cref="CallToolResult.IsError"/> was <see langword="true"/>.
930
-
/// </exception>
928
+
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
931
929
/// <exception cref="JsonException">The result content could not be deserialized as <typeparamref name="T"/>.</exception>
932
930
/// <remarks>
933
931
/// <para>
934
932
/// This method calls the existing <see cref="CallToolAsync(string, IReadOnlyDictionary{string, object?}?, IProgress{ProgressNotificationValue}?, RequestOptions?, CancellationToken)"/>
935
933
/// and then deserializes the result. If the result has <see cref="CallToolResult.StructuredContent"/>, that is deserialized
936
-
/// as <typeparamref name="T"/>. Otherwise, if the result has text content, the text of the last <see cref="TextContentBlock"/>
934
+
/// as <typeparamref name="T"/>. Otherwise, if the result has text content, the text of the first <see cref="TextContentBlock"/>
937
935
/// is deserialized as <typeparamref name="T"/>.
938
936
/// </para>
939
-
/// <para>
940
-
/// If <see cref="CallToolResult.IsError"/> is <see langword="true"/>, an <see cref="McpException"/> is thrown
0 commit comments