Class McpClientExtensions
- Namespace
- ModelContextProtocol.Client
- Assembly
- ModelContextProtocol.Core.dll
Provides extension methods for interacting with an McpClient.
public static class McpClientExtensions
- Inheritance
-
McpClientExtensions
- Inherited Members
Remarks
This class contains extension methods that simplify common operations with an MCP client, such as pinging a server, listing and working with tools, prompts, and resources, and managing subscriptions to resources.
Methods
CreateSamplingHandler(IChatClient)
Creates a sampling handler for use with SamplingHandler that will satisfy sampling requests using the specified Microsoft.Extensions.AI.IChatClient.
public static Func<CreateMessageRequestParams?, IProgress<ProgressNotificationValue>, CancellationToken, ValueTask<CreateMessageResult>> CreateSamplingHandler(this IChatClient chatClient)
Parameters
chatClient
IChatClientThe Microsoft.Extensions.AI.IChatClient with which to satisfy sampling requests.
Returns
- Func<CreateMessageRequestParams, IProgress<ProgressNotificationValue>, CancellationToken, ValueTask<CreateMessageResult>>
The created handler delegate that can be assigned to SamplingHandler.
Remarks
This method creates a function that converts MCP message requests into chat client calls, enabling an MCP client to generate text or other content using an actual AI model via the provided chat client.
The handler can process text messages, image messages, and resource messages as defined in the Model Context Protocol.
Exceptions
- ArgumentNullException
chatClient
is null.