diff --git a/src/ModelContextProtocol/Client/McpClientExtensions.cs b/src/ModelContextProtocol/Client/McpClientExtensions.cs
index 513fc8c05..01d5f1969 100644
--- a/src/ModelContextProtocol/Client/McpClientExtensions.cs
+++ b/src/ModelContextProtocol/Client/McpClientExtensions.cs
@@ -779,7 +779,7 @@ public static Task UnsubscribeFromResourceAsync(this IMcpClient client, Uri uri,
}
///
- /// Invokes a tool on the server
+ /// Invokes a tool on the server.
///
/// The client instance used to communicate with the MCP server.
/// The name of the tool to call on the server..
diff --git a/src/ModelContextProtocol/Client/McpClientTool.cs b/src/ModelContextProtocol/Client/McpClientTool.cs
index 759b9f9cf..91a0d8ab9 100644
--- a/src/ModelContextProtocol/Client/McpClientTool.cs
+++ b/src/ModelContextProtocol/Client/McpClientTool.cs
@@ -86,10 +86,53 @@ internal McpClientTool(
protected async override ValueTask InvokeCoreAsync(
AIFunctionArguments arguments, CancellationToken cancellationToken)
{
- CallToolResponse result = await _client.CallToolAsync(ProtocolTool.Name, arguments, _progress, JsonSerializerOptions, cancellationToken: cancellationToken).ConfigureAwait(false);
+ CallToolResponse result = await CallAsync(arguments, _progress, JsonSerializerOptions, cancellationToken).ConfigureAwait(false);
return JsonSerializer.SerializeToElement(result, McpJsonUtilities.JsonContext.Default.CallToolResponse);
}
+ ///
+ /// Invokes the tool on the server.
+ ///
+ /// An optional dictionary of arguments to pass to the tool. Each key represents a parameter name,
+ /// and its associated value represents the argument value.
+ ///
+ ///
+ /// An optional to have progress notifications reported to it. Setting this to a non-
+ /// value will result in a progress token being included in the call, and any resulting progress notifications during the operation
+ /// routed to this instance.
+ ///
+ ///
+ /// The JSON serialization options governing argument serialization. If , the default serialization options will be used.
+ ///
+ /// The to monitor for cancellation requests. The default is .
+ ///
+ /// A task containing the from the tool execution. The response includes
+ /// the tool's output content, which may be structured data, text, or an error message.
+ ///
+ ///
+ /// The base method is overridden to invoke this method.
+ /// The only difference in behavior is will serialize the resulting "/>
+ /// such that the returned is a containing the serialized .
+ /// This method is intended to be called directly by user code, whereas the base
+ /// is intended to be used polymorphically via the base class, typically as part of an operation.
+ ///
+ /// The server could not find the requested tool, or the server encountered an error while processing the request.
+ ///
+ ///
+ /// var result = await tool.CallAsync(
+ /// new Dictionary<string, object?>
+ /// {
+ /// ["message"] = "Hello MCP!"
+ /// });
+ ///
+ ///
+ public Task CallAsync(
+ IReadOnlyDictionary? arguments = null,
+ IProgress? progress = null,
+ JsonSerializerOptions? serializerOptions = null,
+ CancellationToken cancellationToken = default) =>
+ _client.CallToolAsync(ProtocolTool.Name, arguments, progress, serializerOptions, cancellationToken);
+
///
/// Creates a new instance of the tool but modified to return the specified name from its property.
///
@@ -114,10 +157,8 @@ internal McpClientTool(
/// the value returned from this instance's .
///
///
- public McpClientTool WithName(string name)
- {
- return new McpClientTool(_client, ProtocolTool, JsonSerializerOptions, name, _description, _progress);
- }
+ public McpClientTool WithName(string name) =>
+ new McpClientTool(_client, ProtocolTool, JsonSerializerOptions, name, _description, _progress);
///
/// Creates a new instance of the tool but modified to return the specified description from its property.
@@ -140,10 +181,8 @@ public McpClientTool WithName(string name)
///
///
/// A new instance of with the provided description.
- public McpClientTool WithDescription(string description)
- {
- return new McpClientTool(_client, ProtocolTool, JsonSerializerOptions, _name, description, _progress);
- }
+ public McpClientTool WithDescription(string description) =>
+ new McpClientTool(_client, ProtocolTool, JsonSerializerOptions, _name, description, _progress);
///
/// Creates a new instance of the tool but modified to report progress via the specified .