Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"rohit",
"vcolin",
"vinay",
"vukelich",
"wbreza",
"xiangyan"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,

var options = BindOptions(parseResult);

// Update the UserAgentPolicy for all Azure service calls to include the transport type.
var transport = string.IsNullOrEmpty(options.Transport) ? TransportTypes.StdIo : options.Transport;
BaseAzureService.InitializeUserAgentPolicy(transport);

try
{
using var tracerProvider = AddIncomingAndOutgoingHttpSpans(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Azure.Mcp.Core.Areas.Server.Options;
/// <summary>
/// Defines the supported transport mechanisms for the Azure MCP server.
/// </summary>
internal static class TransportTypes
public static class TransportTypes
{
/// <summary>
/// Standard Input/Output transport mechanism.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Licensed under the MIT License.

using Azure.Core;
using Azure.Mcp.Core.Services.Azure.Tenant;
using Microsoft.Extensions.DependencyInjection;

namespace Azure.Mcp.Core.Services.Azure.Authentication;

/// <summary>
/// Providers instances of <see cref="TokenCredential"/> appropriate for the current environment.
/// Implementations are expected to be of <see cref="ServiceLifetime.Singleton"/>, however, in
/// multi-user enviornments using on-behalf-of downstream authentication, the implementation
/// multi-user environments using on-behalf-of downstream authentication, the implementation
/// must return credentials within the context of the user in the current execution context.
/// </summary>
/// <remarks>
Expand Down
18 changes: 15 additions & 3 deletions servers/Azure.Mcp.Server/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.Net;
using Azure.Mcp.Core.Areas.Server;
using Azure.Mcp.Core.Areas.Server.Commands;
using Azure.Mcp.Core.Areas.Server.Options;
using Azure.Mcp.Core.Commands;
using Azure.Mcp.Core.Helpers;
using Azure.Mcp.Core.Services.Azure;
using Azure.Mcp.Core.Services.Azure.ResourceGroup;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Core.Services.Azure.Tenant;
Expand All @@ -15,6 +17,7 @@
using Azure.Mcp.Core.Services.Time;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Mcp.Core.Areas;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Models.Command;
Expand Down Expand Up @@ -162,7 +165,7 @@ private static void WriteResponse(CommandResponse response)
/// <item>
/// <see cref="Main"/>'s command picking: The container used to populate instances of
/// <see cref="IBaseCommand"/> and selected by <see cref="CommandFactory"/>
/// baesd on the command line input. This container is a local variable in
/// based on the command line input. This container is a local variable in
/// <see cref="Main"/>, and it is not tied to
/// <c>Microsoft.Extensions.Hosting.IHostBuilder</c> (stdio) nor any
/// <c>Microsoft.AspNetCore.Hosting.IWebHostBuilder</c> (http).
Expand All @@ -188,7 +191,7 @@ private static void WriteResponse(CommandResponse response)
/// on <see cref="ITenantService"/> or <see cref="ICacheService"/>, both of which have
/// transport-specific implementations. This method can add the stdio-specific
/// implementation to allow the first container (used for command picking) to work,
/// but such transport-specific registrations must be overriden within
/// but such transport-specific registrations must be overridden within
/// <see cref="ServiceStartCommand.ExecuteAsync"/> with the appropriate
/// transport-specific implementation based on command line arguments.
/// </para>
Expand Down Expand Up @@ -216,7 +219,7 @@ internal static void ConfigureServices(IServiceCollection services)

// !!! WARNING !!!
// stdio-transport-specific implementations of ITenantService and ICacheService.
// The http-traport-specific implementations and configurations must be registered
// The http-transport-specific implementations and configurations must be registered
// within ServiceStartCommand.ExecuteAsync().
services.AddHttpClientServices(configureDefaults: true);
services.AddAzureTenantService();
Expand All @@ -233,6 +236,15 @@ internal static void ConfigureServices(IServiceCollection services)

internal static async Task InitializeServicesAsync(IServiceProvider serviceProvider)
{
ServiceStartOptions? options = serviceProvider.GetService<IOptions<ServiceStartOptions>>()?.Value;

if (options != null)
{
// Update the UserAgentPolicy for all Azure service calls to include the transport type.
var transport = string.IsNullOrEmpty(options.Transport) ? TransportTypes.StdIo : options.Transport;
BaseAzureService.InitializeUserAgentPolicy(transport);
}

// Perform any initialization before starting the service.
// If the initialization operation fails, do not continue because we do not want
// invalid telemetry published.
Expand Down
12 changes: 3 additions & 9 deletions servers/Fabric.Mcp.Server/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
using Azure.Mcp.Core.Commands;
using Azure.Mcp.Core.Extensions;
using Azure.Mcp.Core.Models;
using Azure.Mcp.Core.Services.Azure.ResourceGroup;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Core.Services.Azure.Tenant;
using Azure.Mcp.Core.Services.Caching;
using Azure.Mcp.Core.Services.ProcessExecution;
using Azure.Mcp.Core.Services.Telemetry;
Expand Down Expand Up @@ -97,7 +94,7 @@ private static void WriteResponse(CommandResponse response)
/// <item>
/// <see cref="Main"/>'s command picking: The container used to populate instances of
/// <see cref="IBaseCommand"/> and selected by <see cref="CommandFactory"/>
/// baesd on the command line input. This container is a local variable in
/// based on the command line input. This container is a local variable in
/// <see cref="Main"/>, and it is not tied to
/// <c>Microsoft.Extensions.Hosting.IHostBuilder</c> (stdio) nor any
/// <c>Microsoft.AspNetCore.Hosting.IWebHostBuilder</c> (http).
Expand All @@ -123,7 +120,7 @@ private static void WriteResponse(CommandResponse response)
/// on <see cref="ITenantService"/> or <see cref="ICacheService"/>, both of which have
/// transport-specific implementations. This method can add the stdio-specific
/// implementation to allow the first container (used for command picking) to work,
/// but such transport-specific registrations must be overriden within
/// but such transport-specific registrations must be overridden within
/// <see cref="ServiceStartCommand.ExecuteAsync"/> with the appropriate
/// transport-specific implementation based on command line arguments.
/// </para>
Expand All @@ -145,16 +142,13 @@ internal static void ConfigureServices(IServiceCollection services)
services.AddMemoryCache();
services.AddSingleton<IExternalProcessService, ExternalProcessService>();
services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
services.AddSingleton<IResourceGroupService, ResourceGroupService>();
services.AddSingleton<ISubscriptionService, SubscriptionService>();
services.AddSingleton<ICommandFactory, CommandFactory>();

// !!! WARNING !!!
// stdio-transport-specific implementations of ITenantService and ICacheService.
// The http-traport-specific implementations and configurations must be registered
// The http-transport-specific implementations and configurations must be registered
// within ServiceStartCommand.ExecuteAsync().
services.AddHttpClientServices();
services.AddAzureTenantService();
services.AddSingleUserCliCacheService();

foreach (var area in Areas)
Expand Down
6 changes: 3 additions & 3 deletions servers/Template.Mcp.Server/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static void WriteResponse(CommandResponse response)
/// <item>
/// <see cref="Main"/>'s command picking: The container used to populate instances of
/// <see cref="IBaseCommand"/> and selected by <see cref="CommandFactory"/>
/// baesd on the command line input. This container is a local variable in
/// based on the command line input. This container is a local variable in
/// <see cref="Main"/>, and it is not tied to
/// <c>Microsoft.Extensions.Hosting.IHostBuilder</c> (stdio) nor any
/// <c>Microsoft.AspNetCore.Hosting.IWebHostBuilder</c> (http).
Expand All @@ -117,7 +117,7 @@ private static void WriteResponse(CommandResponse response)
/// on <see cref="ITenantService"/> or <see cref="ICacheService"/>, both of which have
/// transport-specific implementations. This method can add the stdio-specific
/// implementation to allow the first container (used for command picking) to work,
/// but such transport-specific registrations must be overriden within
/// but such transport-specific registrations must be overridden within
/// <see cref="ServiceStartCommand.ExecuteAsync"/> with the appropriate
/// transport-specific implementation based on command line arguments.
/// </para>
Expand All @@ -143,7 +143,7 @@ internal static void ConfigureServices(IServiceCollection services)

// !!! WARNING !!!
// stdio-transport-specific implementations of ICacheService.
// The http-traport-specific implementations and configurations must be registered
// The http-transport-specific implementations and configurations must be registered
// within ServiceStartCommand.ExecuteAsync().
services.AddSingleUserCliCacheService();

Expand Down