Skip to content

Commit 6a91e80

Browse files
committed
Second batch of AI generated /// comment updates
1 parent 3dfc569 commit 6a91e80

File tree

82 files changed

+5150
-263
lines changed

Some content is hidden

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

82 files changed

+5150
-263
lines changed

src/ModelContextProtocol/AIContentExtensions.cs

Lines changed: 223 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,46 @@ namespace ModelContextProtocol;
3333
/// </remarks>
3434
public static class AIContentExtensions
3535
{
36-
/// <summary>Creates a <see cref="ChatMessage"/> from a <see cref="PromptMessage"/>.</summary>
37-
/// <param name="promptMessage">The message to convert.</param>
38-
/// <returns>The created <see cref="ChatMessage"/>.</returns>
36+
/// <summary>
37+
/// Converts a <see cref="PromptMessage"/> to a <see cref="ChatMessage"/> object.
38+
/// </summary>
39+
/// <param name="promptMessage">The prompt message to convert.</param>
40+
/// <returns>A <see cref="ChatMessage"/> object created from the prompt message.</returns>
41+
/// <remarks>
42+
/// <para>
43+
/// This method transforms a protocol-specific <see cref="PromptMessage"/> from the Model Context Protocol
44+
/// into a standard <see cref="ChatMessage"/> object that can be used with AI client libraries.
45+
/// </para>
46+
/// <para>
47+
/// The role mapping is preserved in the conversion:
48+
/// <list type="bullet">
49+
/// <item><description><see cref="Role.User"/> → <see cref="ChatRole.User"/></description></item>
50+
/// <item><description><see cref="Role.Assistant"/> → <see cref="ChatRole.Assistant"/></description></item>
51+
/// </list>
52+
/// </para>
53+
/// <para>
54+
/// The original <see cref="PromptMessage"/> object is stored in the <see cref="AIContent.RawRepresentation"/>
55+
/// property, enabling round-trip conversions if needed.
56+
/// </para>
57+
/// </remarks>
58+
/// <example>
59+
/// <code>
60+
/// // Get a prompt message from an MCP source
61+
/// PromptMessage promptMessage = new PromptMessage
62+
/// {
63+
/// Role = Role.User,
64+
/// Content = new Content { Text = "Hello, AI!", Type = "text" }
65+
/// };
66+
///
67+
/// // Convert to ChatMessage for use with AI clients
68+
/// ChatMessage chatMessage = promptMessage.ToChatMessage();
69+
///
70+
/// // Use the chat message with Microsoft.Extensions.AI
71+
/// Console.WriteLine($"{chatMessage.Role}: {chatMessage.Contents.FirstOrDefault()?.ToString()}");
72+
/// </code>
73+
/// </example>
74+
/// <seealso cref="ToChatMessages(GetPromptResult)"/>
75+
/// <seealso cref="ToPromptMessages(ChatMessage)"/>
3976
public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
4077
{
4178
Throw.IfNull(promptMessage);
@@ -131,6 +168,59 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
131168
/// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="Content"/>.</summary>
132169
/// <param name="content">The <see cref="Content"/> to convert.</param>
133170
/// <returns>The created <see cref="AIContent"/>.</returns>
171+
/// <remarks>
172+
/// <para>
173+
/// This method converts Model Context Protocol content types to the equivalent Microsoft.Extensions.AI
174+
/// content types, enabling seamless integration between the protocol and AI client libraries.
175+
/// </para>
176+
/// <para>
177+
/// The conversion follows these rules:
178+
/// <list type="bullet">
179+
/// <item><description>When <see cref="Content.Type"/> is "image" or "audio" with data → <see cref="DataContent"/> with base64-decoded data and preserved MIME type</description></item>
180+
/// <item><description>When <see cref="Content.Resource"/> is not null → Uses <see cref="ToAIContent(ResourceContents)"/> for the resource</description></item>
181+
/// <item><description>Otherwise → <see cref="TextContent"/> using the text content</description></item>
182+
/// </list>
183+
/// </para>
184+
/// <para>
185+
/// The original <see cref="Content"/> object is stored in the <see cref="AIContent.RawRepresentation"/>
186+
/// property, enabling round-trip conversions if needed.
187+
/// </para>
188+
/// </remarks>
189+
/// <example>
190+
/// <code>
191+
/// // Convert a Content with text to AIContent
192+
/// var textContent = new Content
193+
/// {
194+
/// Text = "Hello, world!",
195+
/// Type = "text"
196+
/// };
197+
/// AIContent aiContent = textContent.ToAIContent();
198+
///
199+
/// // Convert a Content with image data to AIContent
200+
/// var imageContent = new Content
201+
/// {
202+
/// Type = "image",
203+
/// MimeType = "image/png",
204+
/// Data = Convert.ToBase64String(imageBytes)
205+
/// };
206+
/// AIContent aiImageContent = imageContent.ToAIContent();
207+
///
208+
/// // Convert a Content with a resource to AIContent
209+
/// var resourceContent = new Content
210+
/// {
211+
/// Type = "resource",
212+
/// Resource = new TextResourceContents
213+
/// {
214+
/// Uri = "resource://document.txt",
215+
/// Text = "This is a resource text"
216+
/// }
217+
/// };
218+
/// AIContent aiResourceContent = resourceContent.ToAIContent();
219+
/// </code>
220+
/// </example>
221+
/// <seealso cref="ToAIContent(ResourceContents)"/>
222+
/// <seealso cref="DataContent"/>
223+
/// <seealso cref="TextContent"/>
134224
public static AIContent ToAIContent(this Content content)
135225
{
136226
Throw.IfNull(content);
@@ -157,6 +247,65 @@ public static AIContent ToAIContent(this Content content)
157247
/// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="ResourceContents"/>.</summary>
158248
/// <param name="content">The <see cref="ResourceContents"/> to convert.</param>
159249
/// <returns>The created <see cref="AIContent"/>.</returns>
250+
/// <remarks>
251+
/// <para>
252+
/// This method converts Model Context Protocol resource types to the equivalent Microsoft.Extensions.AI
253+
/// content types, enabling seamless integration between the protocol and AI client libraries.
254+
/// </para>
255+
/// <para>
256+
/// The conversion follows these rules:
257+
/// <list type="bullet">
258+
/// <item><description><see cref="BlobResourceContents"/> → <see cref="DataContent"/> with base64-decoded data and preserved MIME type</description></item>
259+
/// <item><description><see cref="TextResourceContents"/> → <see cref="TextContent"/> with the text preserved</description></item>
260+
/// </list>
261+
/// </para>
262+
/// <para>
263+
/// The URI of the resource is preserved in the <see cref="AIContent.AdditionalProperties"/> dictionary
264+
/// with the key "uri", allowing applications to maintain resource identifiers.
265+
/// </para>
266+
/// <para>
267+
/// The original <see cref="ResourceContents"/> object is stored in the <see cref="AIContent.RawRepresentation"/>
268+
/// property, enabling round-trip conversions if needed.
269+
/// </para>
270+
/// </remarks>
271+
/// <example>
272+
/// <code>
273+
/// // Convert a TextResourceContents to AIContent
274+
/// var textResource = new TextResourceContents
275+
/// {
276+
/// Uri = "resource://document.txt",
277+
/// MimeType = "text/plain",
278+
/// Text = "This is a text resource"
279+
/// };
280+
/// AIContent textContent = textResource.ToAIContent();
281+
///
282+
/// // Use the converted content with Microsoft.Extensions.AI client
283+
/// await aiClient.GenerateTextAsync(new TextGenerationOptions
284+
/// {
285+
/// Messages = [
286+
/// new ChatMessage
287+
/// {
288+
/// Role = ChatRole.User,
289+
/// Contents = [textContent]
290+
/// }
291+
/// ]
292+
/// });
293+
///
294+
/// // Convert a BlobResourceContents to AIContent
295+
/// var blobResource = new BlobResourceContents
296+
/// {
297+
/// Uri = "resource://image.png",
298+
/// MimeType = "image/png",
299+
/// Blob = Convert.ToBase64String(imageBytes)
300+
/// };
301+
/// AIContent imageContent = blobResource.ToAIContent();
302+
/// </code>
303+
/// </example>
304+
/// <exception cref="NotSupportedException">Thrown when the resource type is not supported.</exception>
305+
/// <seealso cref="BlobResourceContents"/>
306+
/// <seealso cref="TextResourceContents"/>
307+
/// <seealso cref="DataContent"/>
308+
/// <seealso cref="TextContent"/>
160309
public static AIContent ToAIContent(this ResourceContents content)
161310
{
162311
Throw.IfNull(content);
@@ -177,6 +326,40 @@ public static AIContent ToAIContent(this ResourceContents content)
177326
/// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="Content"/>.</summary>
178327
/// <param name="contents">The <see cref="Content"/> instances to convert.</param>
179328
/// <returns>The created <see cref="AIContent"/> instances.</returns>
329+
/// <remarks>
330+
/// <para>
331+
/// This method converts a collection of Model Context Protocol content objects into a collection of
332+
/// Microsoft.Extensions.AI content objects. It's useful when working with multiple content items, such as
333+
/// when processing the contents of a message or response.
334+
/// </para>
335+
/// <para>
336+
/// Each <see cref="Content"/> object is converted using <see cref="ToAIContent(Content)"/>,
337+
/// preserving the type-specific conversion logic for text, images, audio, and resources.
338+
/// </para>
339+
/// </remarks>
340+
/// <example>
341+
/// <code>
342+
/// // Get Content objects from a source
343+
/// IEnumerable&lt;Content&gt; contents = someResponse.Contents;
344+
///
345+
/// // Convert all Content objects to AIContent objects
346+
/// IList&lt;AIContent&gt; aiContents = contents.ToAIContents();
347+
///
348+
/// // Use the converted contents
349+
/// foreach (var content in aiContents)
350+
/// {
351+
/// if (content is TextContent textContent)
352+
/// {
353+
/// Console.WriteLine($"Text content: {textContent.Text}");
354+
/// }
355+
/// else if (content is DataContent dataContent)
356+
/// {
357+
/// Console.WriteLine($"Binary content: {dataContent.MediaType}, {dataContent.Data.Length} bytes");
358+
/// }
359+
/// }
360+
/// </code>
361+
/// </example>
362+
/// <seealso cref="ToAIContent(Content)"/>
180363
public static IList<AIContent> ToAIContents(this IEnumerable<Content> contents)
181364
{
182365
Throw.IfNull(contents);
@@ -186,7 +369,43 @@ public static IList<AIContent> ToAIContents(this IEnumerable<Content> contents)
186369

187370
/// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="ResourceContents"/>.</summary>
188371
/// <param name="contents">The <see cref="ResourceContents"/> instances to convert.</param>
189-
/// <returns>The created <see cref="AIContent"/> instances.</returns>
372+
/// <returns>A list of <see cref="AIContent"/> objects created from the resource contents.</returns>
373+
/// <remarks>
374+
/// <para>
375+
/// This method converts a collection of Model Context Protocol resource objects into a collection of
376+
/// Microsoft.Extensions.AI content objects. It's useful when working with multiple resources, such as
377+
/// when processing the contents of a <see cref="ReadResourceResult"/>.
378+
/// </para>
379+
/// <para>
380+
/// Each <see cref="ResourceContents"/> object is converted using <see cref="ToAIContent(ResourceContents)"/>,
381+
/// preserving the type-specific conversion logic: text resources become <see cref="TextContent"/> objects and
382+
/// binary resources become <see cref="DataContent"/> objects.
383+
/// </para>
384+
/// </remarks>
385+
/// <example>
386+
/// <code>
387+
/// // Get resources from a read resource result
388+
/// ReadResourceResult result = await client.ReadResourceAsync("resource://folder");
389+
///
390+
/// // Convert all resources to AIContent objects
391+
/// IList&lt;AIContent&gt; aiContents = result.Contents.ToAIContents();
392+
///
393+
/// // Use the converted contents
394+
/// foreach (var content in aiContents)
395+
/// {
396+
/// if (content is TextContent textContent)
397+
/// {
398+
/// Console.WriteLine($"Text content: {textContent.Text}");
399+
/// }
400+
/// else if (content is DataContent dataContent)
401+
/// {
402+
/// Console.WriteLine($"Binary content: {dataContent.MediaType}, {dataContent.Data.Length} bytes");
403+
/// }
404+
/// }
405+
/// </code>
406+
/// </example>
407+
/// <seealso cref="ToAIContent(ResourceContents)"/>
408+
/// <seealso cref="ReadResourceResult.Contents"/>
190409
public static IList<AIContent> ToAIContents(this IEnumerable<ResourceContents> contents)
191410
{
192411
Throw.IfNull(contents);

src/ModelContextProtocol/Client/IMcpClient.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,35 @@ public interface IMcpClient : IMcpEndpoint
5353
/// <summary>
5454
/// Gets the implementation information of the connected server.
5555
/// </summary>
56+
/// <remarks>
57+
/// <para>
58+
/// This property provides identification details about the connected server, including its name and version.
59+
/// It is populated during the initialization handshake and is available after a successful connection.
60+
/// </para>
61+
/// <para>
62+
/// This information can be useful for logging, debugging, compatibility checks, and displaying server
63+
/// information to users.
64+
/// </para>
65+
/// <para>
66+
/// The property will throw an InvalidOperationException if accessed before a successful connection is established.
67+
/// </para>
68+
/// <para>
69+
/// Example usage:
70+
/// <code>
71+
/// // Connect to the server
72+
/// await mcpClient.ConnectAsync(cancellationToken);
73+
///
74+
/// // Access server information
75+
/// Console.WriteLine($"Connected to {mcpClient.ServerInfo.Name} version {mcpClient.ServerInfo.Version}");
76+
///
77+
/// // Use server information for version compatibility checks
78+
/// if (Version.TryParse(mcpClient.ServerInfo.Version, out var version) &amp;&amp; version.Major >= 2)
79+
/// {
80+
/// // Use features only available in version 2.0+
81+
/// }
82+
/// </code>
83+
/// </para>
84+
/// </remarks>
5685
Implementation ServerInfo { get; }
5786

5887
/// <summary>

0 commit comments

Comments
 (0)