Skip to content

Conversation

@scbedd
Copy link
Contributor

@scbedd scbedd commented Nov 24, 2025

Following up original closed PR #1218 .

Hey @vukelich please take a look when you have a couple minutes? Not entirely done yet but not much more to work through.

This PR is addressing the fact that the GetArmClient() implementation in BaseAzureService ignores the recording configuration that HttpClientService doesn't. We do this by:

  • Adds a client configurator that is basically copy/pasta of HttpClientService
  • Injects a configured IHttpClientFactory into the azure mcp server utilizing said configurator.
  • Injects IHttpClientFactory into TenantService
  • Utilizes new TenantService.CreateClient() while creating the base ArmClient within BaseAzureService
  • I have verified that an AppConfig livetest can successfullly record with my code changes
  • I must be missing something with the default client from AddHttpClient(). I should be able to override the default without actually naming it right? Seems super weird that I can't. Yep I was ignorant.
  • Fix failing unit test.
  • Configure IHttpClientFactory in Azure.Fabric and Azure.Template servers so that the changes to TenantService don't melt the world. We only don't see failures because of the fact that we're not running those servers.
  • Verify unbroken fabric server

Todo:

  • I am going to Inject IHttpClientFactory into HttpClientService and utilize the _clientFactory.CreateClient() over the existing CreateClientInternal(). From there should be easy to entirely replace IHttpClientService in favor of the clientFactory created client. Very next PR. I want to unblock record/playback.
  • Accept feedback from @hallipr / @vukelich / whoever else
    • First round accepted. Need to deal with HttpClientService / the re-instantiation of the useragent string now.
    • Secound round also accepted.

…Factory injected. We now use that to create a new clienttransport for CreateArmClient within BaseAzureService. Now it's time to actually integration test this before we do any major cleanup
…AzureService. time to get this up, handle other feedback from steven, and get it merged
@scbedd scbedd self-assigned this Nov 24, 2025
Copilot AI review requested due to automatic review settings November 24, 2025 00:28
@scbedd scbedd changed the title Populate IHttpClientFactory, utilize in BaseAzureService Populate ClientFactory, utilize in BaseAzureService Nov 24, 2025
@scbedd scbedd changed the title Populate ClientFactory, utilize in BaseAzureService Populate HttpClientFactory, utilize in BaseAzureService Nov 24, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses the issue where GetArmClient() in BaseAzureService was ignoring recording configuration that HttpClientService properly handles. The solution introduces IHttpClientFactory configuration and injection throughout the codebase to ensure consistent HTTP client setup across Azure SDK calls.

Key changes:

  • Introduces HttpClientFactoryConfigurator to configure IHttpClientFactory with recording support, proxy settings, and user-agent headers
  • Updates TenantService to accept IHttpClientFactory and provide configured clients via GetClient()
  • Modifies BaseAzureService.CreateArmClientAsync() to use the configured HTTP client transport

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
core/Azure.Mcp.Core/src/Services/Http/HttpClientFactoryConfigurator.cs New configurator class that sets up IHttpClientFactory with recording handler, proxy support, and user-agent configuration
core/Azure.Mcp.Core/src/Services/Http/RecordingRedirectHandler.cs Changed visibility from internal sealed to public and fixed trailing whitespace in XML comment
core/Azure.Mcp.Core/src/Services/Azure/Tenant/TenantService.cs Added IHttpClientFactory dependency and GetClient() method to provide configured HTTP clients
core/Azure.Mcp.Core/src/Services/Azure/Tenant/ITenantService.cs Added GetClient() method to the interface
core/Azure.Mcp.Core/src/Services/Azure/BaseAzureService.cs Updated CreateArmClientAsync() to use HttpClientTransport with configured client from TenantService
servers/Azure.Mcp.Server/src/Program.cs Registered configured HTTP client factory in DI container
core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Helpers/TestHttpClientFactoryProvider.cs New test helper to create configured IHttpClientFactory for live tests
tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.LiveTests/MonitorCommandTests.cs Updated to use TestHttpClientFactoryProvider for creating TenantService instances
tools/Azure.Mcp.Tools.Marketplace/tests/Azure.Mcp.Tools.Marketplace.LiveTests/ProductListCommandTests.cs Updated to use TestHttpClientFactoryProvider and added disposal pattern for proper resource cleanup
tools/Azure.Mcp.Tools.Marketplace/tests/Azure.Mcp.Tools.Marketplace.LiveTests/ProductGetCommandTests.cs Updated to use TestHttpClientFactoryProvider and added disposal pattern for proper resource cleanup
tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.LiveTests/AppConfigCommandTests.cs Updated to use TestHttpClientFactoryProvider and added disposal pattern for proper resource cleanup

@scbedd scbedd moved this from Untriaged to In Progress in Azure MCP Server Nov 24, 2025
Copy link
Member

@vukelich vukelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick early comments to unblock. Will look more later, too.

@joshfree joshfree added this to the 2025-12 milestone Nov 25, 2025
Copy link
Member

@vukelich vukelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another dump of comments as I continue reading.

Copy link
Member

@vukelich vukelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions but all things that could be follow ups.

@scbedd scbedd merged commit 2c930f6 into microsoft:main Dec 1, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Azure MCP Server Dec 1, 2025
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Dec 8, 2025
…t#1239)

* Configure IHttpClientFactory and inject to TenantService in preparation for record/playback for any class inheriting from BaseAzureService.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants