Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static IServiceCollection AddAzureMcpServer(this IServiceCollection servi
services.AddSingleton<SingleProxyToolLoader>();
services.AddSingleton<CompositeToolLoader>();
services.AddSingleton<ServerToolLoader>();
services.AddSingleton<NamespaceToolLoader>();

// Register server discovery strategies
services.AddSingleton<CommandGroupDiscoveryStrategy>();
Expand All @@ -85,7 +86,7 @@ public static IServiceCollection AddAzureMcpServer(this IServiceCollection servi
services.AddSingleton<IMcpRuntime, McpRuntime>();

// Register MCP discovery strategies based on proxy mode
if (serviceStartOptions.Mode == ModeTypes.SingleToolProxy || serviceStartOptions.Mode == ModeTypes.NamespaceProxy)
if (serviceStartOptions.Mode == ModeTypes.SingleToolProxy)
{
services.AddSingleton<IMcpDiscoveryStrategy>(sp =>
{
Expand All @@ -99,6 +100,10 @@ public static IServiceCollection AddAzureMcpServer(this IServiceCollection servi
return new CompositeDiscoveryStrategy(discoveryStrategies, logger);
});
}
else if (serviceStartOptions.Mode == ModeTypes.NamespaceProxy)
{
services.AddSingleton<IMcpDiscoveryStrategy, RegistryDiscoveryStrategy>();
}

// Configure tool loading based on mode
if (serviceStartOptions.Mode == ModeTypes.SingleToolProxy)
Expand All @@ -112,7 +117,14 @@ public static IServiceCollection AddAzureMcpServer(this IServiceCollection servi
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
var toolLoaders = new List<IToolLoader>
{
sp.GetRequiredService<ServerToolLoader>(),
// ServerToolLoader with RegistryDiscoveryStrategy creates proxy tools for external MCP servers.
new ServerToolLoader(
sp.GetRequiredService<RegistryDiscoveryStrategy>(),
sp.GetRequiredService<IOptions<ToolLoaderOptions>>(),
loggerFactory.CreateLogger<ServerToolLoader>()
),
// NamespaceToolLoader enables direct in-process execution for tools in Azure namespaces
sp.GetRequiredService<NamespaceToolLoader>(),
};

// Always add utility commands (subscription, group) in namespace mode
Expand Down
Loading