Skip to content

Commit 77871c5

Browse files
robchstephentoub
andauthored
AI seeded comments from robch and then edited by stephentoub (#238)
* AI generated `///` comment updates * Fix compilation issues * Fix incorrect XML comment structure * Update all Client comments * Update all Configuration comments * Update all Messages comments * Update all Transport comments * Update all Types comments * Update all Server comments * Undo some commenting --------- Co-authored-by: Stephen Toub <[email protected]>
1 parent 0730038 commit 77871c5

File tree

144 files changed

+4017
-1066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+4017
-1066
lines changed

src/Common/Polyfills/System/IO/TextWriterExtensions.cs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using ModelContextProtocol.Utils;
2-
using System.Runtime.InteropServices;
3-
41
namespace System.IO;
52

63
internal static class TextWriterExtensions

src/Common/Throw.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics.CodeAnalysis;
1+
using System.Diagnostics.CodeAnalysis;
22
using System.Runtime.CompilerServices;
33

44
namespace ModelContextProtocol.Utils;
@@ -38,4 +38,4 @@ private static void ThrowArgumentNullOrWhiteSpaceException(string? parameterName
3838

3939
[DoesNotReturn]
4040
private static void ThrowArgumentNullException(string? parameterName) => throw new ArgumentNullException(parameterName);
41-
}
41+
}

src/ModelContextProtocol.AspNetCore/McpEndpointRouteBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace Microsoft.AspNetCore.Builder;
1919

2020
/// <summary>
21-
/// Extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.
21+
/// Provides extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.
2222
/// </summary>
2323
public static class McpEndpointRouteBuilderExtensions
2424
{

src/ModelContextProtocol/AIContentExtensions.cs

+68-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.AI;
1+
using Microsoft.Extensions.AI;
22
using ModelContextProtocol.Protocol.Types;
33
using ModelContextProtocol.Utils;
44
using ModelContextProtocol.Utils.Json;
@@ -7,12 +7,24 @@
77

88
namespace ModelContextProtocol;
99

10-
/// <summary>Provides helpers for conversions related to <see cref="AIContent"/>.</summary>
10+
/// <summary>
11+
/// Provides extension methods for converting between Model Context Protocol (MCP) types and Microsoft.Extensions.AI types.
12+
/// </summary>
13+
/// <remarks>
14+
/// This class serves as an adapter layer between Model Context Protocol (MCP) types and the <see cref="AIContent"/> model types
15+
/// from the Microsoft.Extensions.AI namespace.
16+
/// </remarks>
1117
public static class AIContentExtensions
1218
{
13-
/// <summary>Creates a <see cref="ChatMessage"/> from a <see cref="PromptMessage"/>.</summary>
14-
/// <param name="promptMessage">The message to convert.</param>
15-
/// <returns>The created <see cref="ChatMessage"/>.</returns>
19+
/// <summary>
20+
/// Converts a <see cref="PromptMessage"/> to a <see cref="ChatMessage"/> object.
21+
/// </summary>
22+
/// <param name="promptMessage">The prompt message to convert.</param>
23+
/// <returns>A <see cref="ChatMessage"/> object created from the prompt message.</returns>
24+
/// <remarks>
25+
/// This method transforms a protocol-specific <see cref="PromptMessage"/> from the Model Context Protocol
26+
/// into a standard <see cref="ChatMessage"/> object that can be used with AI client libraries.
27+
/// </remarks>
1628
public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
1729
{
1830
Throw.IfNull(promptMessage);
@@ -25,19 +37,32 @@ public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
2537
};
2638
}
2739

28-
/// <summary>Creates <see cref="ChatMessage"/>s from a <see cref="GetPromptResult"/>.</summary>
29-
/// <param name="promptResult">The messages to convert.</param>
30-
/// <returns>The created <see cref="ChatMessage"/>.</returns>
40+
/// <summary>
41+
/// Converts a <see cref="GetPromptResult"/> to a list of <see cref="ChatMessage"/> objects.
42+
/// </summary>
43+
/// <param name="promptResult">The prompt result containing messages to convert.</param>
44+
/// <returns>A list of <see cref="ChatMessage"/> objects created from the prompt messages.</returns>
45+
/// <remarks>
46+
/// This method transforms protocol-specific <see cref="PromptMessage"/> objects from a Model Context Protocol
47+
/// prompt result into standard <see cref="ChatMessage"/> objects that can be used with AI client libraries.
48+
/// </remarks>
3149
public static IList<ChatMessage> ToChatMessages(this GetPromptResult promptResult)
3250
{
3351
Throw.IfNull(promptResult);
3452

3553
return promptResult.Messages.Select(m => m.ToChatMessage()).ToList();
3654
}
3755

38-
/// <summary>Gets <see cref="PromptMessage"/> instances for the specified <see cref="ChatMessage"/>.</summary>
39-
/// <param name="chatMessage">The message for which to extract its contents as <see cref="PromptMessage"/> instances.</param>
40-
/// <returns>The converted content.</returns>
56+
/// <summary>
57+
/// Converts a <see cref="ChatMessage"/> to a list of <see cref="PromptMessage"/> objects.
58+
/// </summary>
59+
/// <param name="chatMessage">The chat message to convert.</param>
60+
/// <returns>A list of <see cref="PromptMessage"/> objects created from the chat message's contents.</returns>
61+
/// <remarks>
62+
/// This method transforms standard <see cref="ChatMessage"/> objects used with AI client libraries into
63+
/// protocol-specific <see cref="PromptMessage"/> objects for the Model Context Protocol system.
64+
/// Only representable content items are processed.
65+
/// </remarks>
4166
public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage)
4267
{
4368
Throw.IfNull(chatMessage);
@@ -59,6 +84,10 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
5984
/// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="Content"/>.</summary>
6085
/// <param name="content">The <see cref="Content"/> to convert.</param>
6186
/// <returns>The created <see cref="AIContent"/>.</returns>
87+
/// <remarks>
88+
/// This method converts Model Context Protocol content types to the equivalent Microsoft.Extensions.AI
89+
/// content types, enabling seamless integration between the protocol and AI client libraries.
90+
/// </remarks>
6291
public static AIContent ToAIContent(this Content content)
6392
{
6493
Throw.IfNull(content);
@@ -85,6 +114,10 @@ public static AIContent ToAIContent(this Content content)
85114
/// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="ResourceContents"/>.</summary>
86115
/// <param name="content">The <see cref="ResourceContents"/> to convert.</param>
87116
/// <returns>The created <see cref="AIContent"/>.</returns>
117+
/// <remarks>
118+
/// This method converts Model Context Protocol resource types to the equivalent Microsoft.Extensions.AI
119+
/// content types, enabling seamless integration between the protocol and AI client libraries.
120+
/// </remarks>
88121
public static AIContent ToAIContent(this ResourceContents content)
89122
{
90123
Throw.IfNull(content);
@@ -105,6 +138,17 @@ public static AIContent ToAIContent(this ResourceContents content)
105138
/// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="Content"/>.</summary>
106139
/// <param name="contents">The <see cref="Content"/> instances to convert.</param>
107140
/// <returns>The created <see cref="AIContent"/> instances.</returns>
141+
/// <remarks>
142+
/// <para>
143+
/// This method converts a collection of Model Context Protocol content objects into a collection of
144+
/// Microsoft.Extensions.AI content objects. It's useful when working with multiple content items, such as
145+
/// when processing the contents of a message or response.
146+
/// </para>
147+
/// <para>
148+
/// Each <see cref="Content"/> object is converted using <see cref="ToAIContent(Content)"/>,
149+
/// preserving the type-specific conversion logic for text, images, audio, and resources.
150+
/// </para>
151+
/// </remarks>
108152
public static IList<AIContent> ToAIContents(this IEnumerable<Content> contents)
109153
{
110154
Throw.IfNull(contents);
@@ -114,7 +158,19 @@ public static IList<AIContent> ToAIContents(this IEnumerable<Content> contents)
114158

115159
/// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="ResourceContents"/>.</summary>
116160
/// <param name="contents">The <see cref="ResourceContents"/> instances to convert.</param>
117-
/// <returns>The created <see cref="AIContent"/> instances.</returns>
161+
/// <returns>A list of <see cref="AIContent"/> objects created from the resource contents.</returns>
162+
/// <remarks>
163+
/// <para>
164+
/// This method converts a collection of Model Context Protocol resource objects into a collection of
165+
/// Microsoft.Extensions.AI content objects. It's useful when working with multiple resources, such as
166+
/// when processing the contents of a <see cref="ReadResourceResult"/>.
167+
/// </para>
168+
/// <para>
169+
/// Each <see cref="ResourceContents"/> object is converted using <see cref="ToAIContent(ResourceContents)"/>,
170+
/// preserving the type-specific conversion logic: text resources become <see cref="TextContent"/> objects and
171+
/// binary resources become <see cref="DataContent"/> objects.
172+
/// </para>
173+
/// </remarks>
118174
public static IList<AIContent> ToAIContents(this IEnumerable<ResourceContents> contents)
119175
{
120176
Throw.IfNull(contents);
+21-2
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1-
using ModelContextProtocol.Protocol.Types;
1+
using ModelContextProtocol.Protocol.Types;
22

33
namespace ModelContextProtocol.Client;
44

55
/// <summary>
6-
/// Represents an instance of an MCP client connecting to a specific server.
6+
/// Represents an instance of a Model Context Protocol (MCP) client that connects to and communicates with an MCP server.
77
/// </summary>
88
public interface IMcpClient : IMcpEndpoint
99
{
1010
/// <summary>
1111
/// Gets the capabilities supported by the connected server.
1212
/// </summary>
13+
/// <exception cref="InvalidOperationException">The client is not connected.</exception>
1314
ServerCapabilities ServerCapabilities { get; }
1415

1516
/// <summary>
1617
/// Gets the implementation information of the connected server.
1718
/// </summary>
19+
/// <remarks>
20+
/// <para>
21+
/// This property provides identification details about the connected server, including its name and version.
22+
/// It is populated during the initialization handshake and is available after a successful connection.
23+
/// </para>
24+
/// <para>
25+
/// This information can be useful for logging, debugging, compatibility checks, and displaying server
26+
/// information to users.
27+
/// </para>
28+
/// </remarks>
29+
/// <exception cref="InvalidOperationException">The client is not connected.</exception>
1830
Implementation ServerInfo { get; }
1931

2032
/// <summary>
2133
/// Gets any instructions describing how to use the connected server and its features.
2234
/// </summary>
2335
/// <remarks>
36+
/// <para>
37+
/// This property contains instructions provided by the server during initialization that explain
38+
/// how to effectively use its capabilities. These instructions can include details about available
39+
/// tools, expected input formats, limitations, or any other helpful information.
40+
/// </para>
41+
/// <para>
2442
/// This can be used by clients to improve an LLM's understanding of available tools, prompts, and resources.
2543
/// It can be thought of like a "hint" to the model and may be added to a system prompt.
44+
/// </para>
2645
/// </remarks>
2746
string? ServerInstructions { get; }
2847
}

src/ModelContextProtocol/Client/McpClient.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
22
using ModelContextProtocol.Logging;
33
using ModelContextProtocol.Protocol.Messages;
44
using ModelContextProtocol.Protocol.Transport;
@@ -96,6 +96,9 @@ public McpClient(IClientTransport clientTransport, McpClientOptions? options, IL
9696
/// <inheritdoc/>
9797
public override string EndpointName { get; }
9898

99+
/// <summary>
100+
/// Asynchronously connects to an MCP server, establishes the transport connection, and completes the initialization handshake.
101+
/// </summary>
99102
public async Task ConnectAsync(CancellationToken cancellationToken = default)
100103
{
101104
_connectCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
@@ -185,4 +188,4 @@ public override async ValueTask DisposeUnsynchronizedAsync()
185188
}
186189
}
187190
}
188-
}
191+
}

0 commit comments

Comments
 (0)