diff --git a/src/Tooling/Extensions/AzureAIFoundry/Services/IMcpToolRegistrationService.cs b/src/Tooling/Extensions/AzureAIFoundry/Services/IMcpToolRegistrationService.cs index bda8d035..78772067 100644 --- a/src/Tooling/Extensions/AzureAIFoundry/Services/IMcpToolRegistrationService.cs +++ b/src/Tooling/Extensions/AzureAIFoundry/Services/IMcpToolRegistrationService.cs @@ -21,12 +21,14 @@ public interface IMcpToolRegistrationService /// This is the primary method that customers should use in orchestrators with full authentication context. /// /// The PersistentAgentsClient instance. + /// The ID of the agent instance. /// User authorization context. /// Authentication Handler Name for use with the UserAuthorization System /// Turn context for the conversation. /// Optional auth token to access the MCP servers. Task AddToolServersToAgentAsync( PersistentAgentsClient agentClient, + string agentInstanceId, UserAuthorization userAuthorization, string authHandlerName, ITurnContext turnContext, diff --git a/src/Tooling/Extensions/AzureAIFoundry/Services/McpToolRegistrationService.cs b/src/Tooling/Extensions/AzureAIFoundry/Services/McpToolRegistrationService.cs index 4625c0c9..5fe3152d 100644 --- a/src/Tooling/Extensions/AzureAIFoundry/Services/McpToolRegistrationService.cs +++ b/src/Tooling/Extensions/AzureAIFoundry/Services/McpToolRegistrationService.cs @@ -92,9 +92,19 @@ public void AddToolServersToAgent( } } - /// + /// + /// Add new MCP servers to the agent by updating the PersistentAgentsClient asynchronously. + /// + /// PersistentAgentsClient instance for the agent. + /// The ID of the agent instance. + /// User authorization information. + /// The name of the authentication handler. + /// Turn context for the current request. + /// Authentication token for MCP server access. + /// public async Task AddToolServersToAgentAsync( PersistentAgentsClient agentClient, + string agentInstanceId, UserAuthorization userAuthorization, string authHandlerName, ITurnContext turnContext, @@ -110,15 +120,13 @@ public async Task AddToolServersToAgentAsync( authToken = await AgenticAuthenticationService.GetAgenticUserTokenAsync(userAuthorization, authHandlerName, turnContext, _configuration).ConfigureAwait(false); } - var agenticAppId = turnContext.Activity.Recipient.AgenticAppId; - try { // Perform the (potentially async) work in a dedicated task to keep this synchronous signature. - var (toolDefinitions, toolResources) = GetMcpToolDefinitionsAndResourcesAsync(agenticAppId, authToken ?? string.Empty, turnContext).GetAwaiter().GetResult(); + var (toolDefinitions, toolResources) = GetMcpToolDefinitionsAndResourcesAsync(agentInstanceId, authToken ?? string.Empty, turnContext).GetAwaiter().GetResult(); agentClient.Administration.UpdateAgent( - agenticAppId, + agentInstanceId, tools: toolDefinitions, toolResources: toolResources); @@ -126,7 +134,7 @@ public async Task AddToolServersToAgentAsync( } catch (Exception ex) { - _logger.LogError(ex, "Unhandled failure during MCP tool registration workflow for agent user {agenticAppId}", agenticAppId); + _logger.LogError(ex, "Unhandled failure during MCP tool registration workflow for agent user {agentInstanceId}", agentInstanceId); throw; } }