Share via


McpToolRegistrationService.AddToolServersToAgent Method

Definition

Add new MCP servers to the agent by creating a new Agent instance.

Note: Due to Microsoft.Extensions.AI framework limitations, MCP tools must be set during Agent creation. If new tools are found, this method creates a new Agent instance with all tools (existing + new) properly initialized.

public System.Threading.Tasks.Task<Microsoft.Agents.AI.AIAgent> AddToolServersToAgent(Microsoft.Extensions.AI.IChatClient chatClient, string agentInstructions, System.Collections.Generic.IList<Microsoft.Extensions.AI.AITool> initialTools, string agentUserId, Microsoft.Agents.Builder.App.UserAuth.UserAuthorization userAuthorization, string authHandlerName, Microsoft.Agents.Builder.ITurnContext turnContext, string? authToken = default);
abstract member AddToolServersToAgent : Microsoft.Extensions.AI.IChatClient * string * System.Collections.Generic.IList<Microsoft.Extensions.AI.AITool> * string * Microsoft.Agents.Builder.App.UserAuth.UserAuthorization * string * Microsoft.Agents.Builder.ITurnContext * string -> System.Threading.Tasks.Task<Microsoft.Agents.AI.AIAgent>
override this.AddToolServersToAgent : Microsoft.Extensions.AI.IChatClient * string * System.Collections.Generic.IList<Microsoft.Extensions.AI.AITool> * string * Microsoft.Agents.Builder.App.UserAuth.UserAuthorization * string * Microsoft.Agents.Builder.ITurnContext * string -> System.Threading.Tasks.Task<Microsoft.Agents.AI.AIAgent>
Public Function AddToolServersToAgent (chatClient As IChatClient, agentInstructions As String, initialTools As IList(Of AITool), agentUserId As String, userAuthorization As UserAuthorization, authHandlerName As String, turnContext As ITurnContext, Optional authToken As String = Nothing) As Task(Of AIAgent)

Parameters

chatClient
IChatClient

The configured IChatClient to use for creating the agent.

agentInstructions
String

The agent instructions.

initialTools
IList<AITool>

The existing tools to keep and add MCP tools to.

agentUserId
String

Agent User Id for the agent.

userAuthorization
UserAuthorization

User authorization information

authHandlerName
String

Authentication Handler Name for use with the UserAuthorization System

turnContext
ITurnContext

Turn context for the current request

authToken
String

Optional auth token to access the MCP servers.

Returns

New Agent instance with all MCP tools, or agent with original tools if no new servers

Implements

Applies to