Share via


IMcpToolHandler.InvokeToolAsync Method

Definition

Invokes an MCP tool on the specified server.

public System.Threading.Tasks.Task<Microsoft.Extensions.AI.McpServerToolResultContent> InvokeToolAsync(string serverUrl, string? serverLabel, string toolName, System.Collections.Generic.IDictionary<string,object?>? arguments, System.Collections.Generic.IDictionary<string,string>? headers, string? connectionName, System.Threading.CancellationToken cancellationToken = default);
abstract member InvokeToolAsync : string * string * string * System.Collections.Generic.IDictionary<string, obj> * System.Collections.Generic.IDictionary<string, string> * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.McpServerToolResultContent>
Public Function InvokeToolAsync (serverUrl As String, serverLabel As String, toolName As String, arguments As IDictionary(Of String, Object), headers As IDictionary(Of String, String), connectionName As String, Optional cancellationToken As CancellationToken = Nothing) As Task(Of McpServerToolResultContent)

Parameters

serverUrl
String

The URL of the MCP server.

serverLabel
String

An optional label identifying the server connection.

toolName
String

The name of the tool to invoke.

arguments
IDictionary<String,Object>

Optional arguments to pass to the tool.

headers
IDictionary<String,String>

Optional headers to include in the request.

connectionName
String

An optional connection name for managed connections.

cancellationToken
CancellationToken

A token to observe cancellation.

Returns

A task representing the asynchronous operation. The result contains a McpServerToolResultContent with the tool invocation output.

Applies to