-
Notifications
You must be signed in to change notification settings - Fork 296
Remove hard coded strings. Migrate to use IConfiguration #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 refactors the configuration system to use appsettings.json files with the Host.CreateApplicationBuilder pattern, moving away from manual service collection construction. The changes enable AOT-compatible configuration binding and centralize server configuration (name, prefix, display name) in appsettings.json files.
Key changes:
- Introduced
appsettings.jsonfiles for server configuration across multiple servers - Updated
AzureMcpServerConfigurationto include required properties (Prefix, Name, DisplayName) with data annotations - Refactored Program.cs files to use
Host.CreateApplicationBuilderinstead of directServiceCollectioninstantiation
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| servers/Template.Mcp.Server/src/appsettings.json | Added configuration file with server metadata |
| servers/Template.Mcp.Server/src/appsettings.Development.json | Added development logging configuration |
| servers/Template.Mcp.Server/src/Template.Mcp.Server.csproj | Added content items to copy appsettings files to output |
| servers/Template.Mcp.Server/src/Program.cs | Refactored to use Host.CreateApplicationBuilder and pass IHostEnvironment |
| servers/Fabric.Mcp.Server/src/Program.cs | Refactored to use Host.CreateApplicationBuilder and pass IHostEnvironment |
| servers/Azure.Mcp.Server/src/appsettings.json | Added configuration file with server metadata |
| servers/Azure.Mcp.Server/src/appsettings.Release.json | Added release configuration with Application Insights connection string |
| servers/Azure.Mcp.Server/src/appsettings.Development.json | Added development logging configuration with telemetry disabled |
| servers/Azure.Mcp.Server/src/Properties/launchSettings.json | Reformatted and added new "local-stdio" profile |
| servers/Azure.Mcp.Server/src/Program.cs | Refactored to use Host.CreateApplicationBuilder, added Release config loading, and host lifecycle |
| servers/Azure.Mcp.Server/src/Azure.Mcp.Server.csproj | Added conditional content items for configuration files based on build configuration |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Services/Telemetry/TelemetryServiceTests.cs | Updated test configuration instances with new required properties |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Commands/CommandFactoryTests.cs | Added server configuration setup and updated constructor calls |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Tools/UnitTests/ToolsListCommandTests.cs | Updated CommandFactory instantiation with server configuration |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/Commands/Discovery/ConsolidatedToolDiscoveryStrategyTests.cs | Updated strategy instantiation to pass required dependencies explicitly |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/CommandFactoryHelpers.cs | Added default server configuration creation in test helpers |
| core/Azure.Mcp.Core/src/Extensions/OpenTelemetryExtensions.cs | Refactored to accept IHostEnvironment, removed hardcoded connection string, added empty conditional blocks |
| core/Azure.Mcp.Core/src/Configuration/AzureMcpServerConfigurationValidator.cs | Added options validator for server configuration |
| core/Azure.Mcp.Core/src/Configuration/AzureMcpServerConfiguration.cs | Added required properties with data annotations and documentation |
| core/Azure.Mcp.Core/src/Commands/CommandFactory.cs | Updated to use server name from configuration instead of hardcoded value |
| core/Azure.Mcp.Core/src/Azure.Mcp.Core.csproj | Enabled configuration binding generator for AOT compatibility |
| core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs | Refactored to use Host.CreateApplicationBuilder pattern |
| core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs | Extracted configuration setup, moved GetServerVersion method, added ConfigureMcpServerOptions |
| core/Azure.Mcp.Core/src/Areas/Server/Commands/Discovery/ConsolidatedToolDiscoveryStrategy.cs | Updated constructor to accept required dependencies as parameters |
Comments suppressed due to low confidence (3)
core/Azure.Mcp.Core/src/Extensions/OpenTelemetryExtensions.cs:94
- Empty block without comment.
{
}
core/Azure.Mcp.Core/src/Extensions/OpenTelemetryExtensions.cs:94
- If-statement with an empty then-branch and no else-branch.
else if(hostEnvironment.IsDevelopment())
{
}
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs:54
- This assignment to mcpServerOptionsBuilder is useless, since its value is never read.
var mcpServerOptionsBuilder = services.AddOptions<McpServerOptions>();
| }); | ||
|
|
||
| } | ||
| else if(hostEnvironment.IsDevelopment()) |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after 'if' keyword. Should be else if (hostEnvironment.IsDevelopment()) to follow C# coding conventions.
| else if(hostEnvironment.IsDevelopment()) | |
| else if (hostEnvironment.IsDevelopment()) |
| await InitializeServicesAsync(host.Services); | ||
|
|
||
| // Starts any IHostedServices | ||
| await host.StartAsync(); |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting the host before invoking the command will cause the application to hang indefinitely. The host.StartAsync() call starts background services and keeps them running. This should either be removed or the application lifecycle should be refactored to properly manage the host. Consider whether hosted services are needed here, or if the host should be started only when running in HTTP mode.
| await host.StartAsync(); | |
| // await host.StartAsync(); // Removed to prevent application hang |
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Show resolved
Hide resolved
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Show resolved
Hide resolved
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Show resolved
Hide resolved
d08b719 to
1f6a28d
Compare
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,22 @@ | |||
| { | |||
| "AZURE_MCP_COLLECT_TELEMETRY": "false", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want this to be true and AZURE_MCP_ENABLE_OTLP_EXPORTER. But we don't want to have the Application Insights connection string injected.
| _logger = logger; | ||
| _rootGroup = new CommandGroup(RootCommandGroupName, "Azure MCP Server"); | ||
| _serverName = serverConfig.Value.Name; | ||
| _rootGroup = new CommandGroup(_serverName, serverConfig.Value.DisplayName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using serverConfig.Value.Prefix for CommandGroup name?
| _rootGroup = new CommandGroup(_serverName, serverConfig.Value.DisplayName); | |
| _rootGroup = new CommandGroup(serverConfig.Value.Prefix, serverConfig.Value.DisplayName); |
Won't this be changing azmcp to Azure.Mcp.Server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But maybe we should rename prefix to RootCommandName?
|
|
||
| builder.AddAzureMonitorMetricExporter(options => | ||
| { | ||
| options.ConnectionString = config.ApplicationInsightsConnectionString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does Azure Monitor do when the connection string is missing / null / empty?
Should configuration of Azure Monitor be guarded by the state of the connection string?
…ault required keywords for runtime option checks.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ecb7bc8 to
5c33b01
Compare
What does this PR do?
[Provide a clear, concise description of the changes]Related issues from migration
dotnet formatresulting in IL2026 and IL3050 despite using source generation for configuration. (See:dotnet formatraises native AOT warnings regardless of<EnableConfigurationBindingGenerator/>dotnet/sdk#45054)[Any additional context, screenshots, or information that helps reviewers]GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test prompts/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline