Review JsonSourceGenerationOptions configurations#2598
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Standardizes JsonSourceGenerationOptions usage across MCP tools to produce consistent camelCase JSON and omit null-valued properties.
Changes:
- Added
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull(and camelCase naming) across multipleJsonSerializerContextimplementations. - Refactored many JSON context declarations to file-scoped/semicolon style for consistency.
- Updated several live tests to assert camelCase JSON property names and handle omitted null properties in some cases.
Reviewed changes
Copilot reviewed 99 out of 99 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Fabric.Mcp.Tools.OneLake/src/Models/OneLakeJsonContext.cs | Standardize source-gen options (camelCase + ignore nulls). |
| tools/Fabric.Mcp.Tools.OneLake/src/Models/MinimalJsonContext.cs | Standardize source-gen options (camelCase + ignore nulls). |
| tools/Fabric.Mcp.Tools.Docs/src/Commands/FabricJsonContext.cs | Add standardized source-gen options and simplify context declaration. |
| tools/Fabric.Mcp.Tools.Core/src/Models/CoreJsonContext.cs | Reorder/standardize attributes and simplify context declaration. |
| tools/Azure.Mcp.Tools.Workbooks/tests/Azure.Mcp.Tools.Workbooks.LiveTests/WorkbooksCommandTests.cs | Update assertions to use camelCase JSON properties and adjust null-handling in one case. |
| tools/Azure.Mcp.Tools.Workbooks/src/Commands/WorkbooksJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.WellArchitectedFramework/src/Commands/WellArchitectedFrameworkJsonContext.cs | Standardize source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.VirtualDesktop/src/Commands/VirtualDesktopJsonContext.cs | Standardize source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.StorageSync/src/StorageSyncJsonContext.cs | Standardize source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/SyncGroup/SyncGroupGetCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/SyncGroup/SyncGroupDeleteCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/SyncGroup/SyncGroupCreateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/StorageSyncService/StorageSyncServiceUpdateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/StorageSyncService/StorageSyncServiceGetCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/StorageSyncService/StorageSyncServiceDeleteCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/StorageSyncService/StorageSyncServiceCreateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/ServerEndpoint/ServerEndpointUpdateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/ServerEndpoint/ServerEndpointGetCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/ServerEndpoint/ServerEndpointDeleteCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/ServerEndpoint/ServerEndpointCreateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/RegisteredServer/RegisteredServerUpdateCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/RegisteredServer/RegisteredServerUnregisterCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/RegisteredServer/RegisteredServerGetCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/CloudEndpoint/CloudEndpointTriggerChangeDetectionCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/CloudEndpoint/CloudEndpointGetCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/CloudEndpoint/CloudEndpointDeleteCommand.cs | Remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.StorageSync/src/Commands/CloudEndpoint/CloudEndpointCreateCommand.cs | Use target-typed new(...) and remove per-record JsonSerializable attribute usage. |
| tools/Azure.Mcp.Tools.Storage/src/Commands/StorageJsonContext.cs | Standardize source-gen options (switch ignore condition to null) and simplify context declaration. |
| tools/Azure.Mcp.Tools.Sql/src/Commands/SqlJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.Speech/src/Commands/SpeechJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.SignalR/src/Commands/SignalRJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.ServiceFabric/tests/Azure.Mcp.Tools.ServiceFabric.LiveTests/ServiceFabricCommandTests.cs | Update assertions to use camelCase JSON properties. |
| tools/Azure.Mcp.Tools.ServiceFabric/src/Commands/ServiceFabricJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.ServiceBus/src/Commands/ServiceBusJsonContext.cs | Standardize source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.Search/src/Commands/SearchJsonContext.cs | Standardize source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.ResourceHealth/src/ResourceHealthJsonContext.cs | Standardize source-gen options (add ignore nulls) while preserving generation mode. |
| tools/Azure.Mcp.Tools.Redis/src/Commands/RedisJsonContext.cs | Switch ignore condition from default to null and keep camelCase. |
| tools/Azure.Mcp.Tools.Quota/src/Commands/QuotaJsonContext.cs | Reorder attributes and simplify context declaration; keep case-insensitive + ignore nulls. |
| tools/Azure.Mcp.Tools.Pricing/src/Commands/PricingJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.Postgres/src/Commands/PostgresJsonContext.cs | Add camelCase + ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.Policy/src/Commands/PolicyJsonContext.cs | Remove WriteIndented and standardize ignore nulls. |
| tools/Azure.Mcp.Tools.MySql/src/Commands/MySqlJsonContext.cs | Add camelCase + ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.Monitor/src/Models/Instrumentation/OnboardingJsonContext.cs | Reorder options and keep existing indentation/case-insensitive behavior. |
| tools/Azure.Mcp.Tools.Monitor/src/Commands/MonitorJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.Monitor/src/Commands/Instrumentation/MonitorInstrumentationJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.Marketplace/src/Commands/MarketplaceJsonContext.cs | Formatting + keep enum converter; add ignore nulls. |
| tools/Azure.Mcp.Tools.ManagedLustre/src/Commands/ManagedLustreJsonContext.cs | Remove WriteIndented and standardize ignore nulls. |
| tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.LiveTests/LoadTestingCommandTests.cs | Update assertions to use camelCase JSON properties. |
| tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTestingJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.Kusto/src/Commands/KustoJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.KeyVault/src/Commands/KeyVaultJsonContext.cs | Simplify context declaration; formatting-only options tweak. |
| tools/Azure.Mcp.Tools.Grafana/src/Commands/GrafanaJsonContext.cs | Switch ignore condition from default to null and keep camelCase. |
| tools/Azure.Mcp.Tools.Functions/src/Commands/FunctionsJsonContext.cs | Remove unused using; standardize options formatting. |
| tools/Azure.Mcp.Tools.FunctionApp/src/Commands/FunctionAppJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.FoundryExtensions/src/Commands/FoundryExtensionsJsonContext.cs | Switch ignore condition from default to null and keep camelCase. |
| tools/Azure.Mcp.Tools.FileShares/src/FileSharesJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.Extension/src/Commands/ExtensionJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.EventHubs/src/Commands/EventHubsJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.EventGrid/src/Commands/EventGridJsonContext.cs | Standardize options and simplify context declaration. |
| tools/Azure.Mcp.Tools.DeviceRegistry/src/Commands/DeviceRegistryJsonContext.cs | Switch ignore condition from default to null and keep camelCase. |
| tools/Azure.Mcp.Tools.Deploy/src/Commands/DeployJsonContext.cs | Reorder attributes and simplify context declaration; keep case-insensitive + ignore nulls. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CosmosJsonContext.cs | Simplify context declaration; formatting-only options tweak. |
| tools/Azure.Mcp.Tools.ContainerApps/src/Commands/ContainerAppsJsonContext.cs | Simplify context declaration; formatting-only options tweak. |
| tools/Azure.Mcp.Tools.ConfidentialLedger/src/Commands/ConfidentialLedgerJsonContext.cs | Add standardized source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.Compute/tests/Azure.Mcp.Tools.Compute.LiveTests/ComputeCommandTests.cs | Update assertions to use camelCase JSON properties. |
| tools/Azure.Mcp.Tools.Compute/src/Commands/ComputeJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.Communication/src/CommunicationJsonContext.cs | Add ignore nulls to metadata generation mode and simplify context declaration. |
| tools/Azure.Mcp.Tools.CloudArchitect/src/CloudArchitectJsonContext.cs | Add ignore nulls while keeping case-insensitive; simplify context declaration. |
| tools/Azure.Mcp.Tools.BicepSchema/src/Commands/BicepSchemaJsonContext.cs | Add standardized source-gen options and simplify context declaration. |
| tools/Azure.Mcp.Tools.AzureTerraformBestPractices/src/Commands/AzureTerraformBestPracticesJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.AzureTerraform/src/Services/AzApiExamplesJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.AzureTerraform/src/Services/AvmJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.AzureTerraform/src/Commands/AzureTerraformJsonContext.cs | Add ignore nulls and format options attribute. |
| tools/Azure.Mcp.Tools.AzureMigrate/src/Helpers/AzureMigrateSerializerContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.AzureMigrate/src/Commands/AzureMigrateJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.AzureIsv/src/Commands/Datadog/DatadogJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.AzureBestPractices/src/Commands/AzureBestPracticesJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.AzureBackup/src/Commands/AzureBackupJsonContext.cs | Switch ignore condition from default to null and simplify context declaration. |
| tools/Azure.Mcp.Tools.AzureBackup/docs/architecture.md | Update documentation snippet for source-gen options / context declaration. |
| tools/Azure.Mcp.Tools.Authorization/src/Commands/AuthorizationJsonContext.cs | Formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.ApplicationInsights/src/Commands/ApplicationInsightsJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.AppService/src/Commands/AppServiceJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensJsonContext.cs | Add ignore nulls and simplify context declaration. |
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/AppConfigJsonContext.cs | Simplify context declaration; formatting-only options tweak. |
| tools/Azure.Mcp.Tools.Aks/tests/Azure.Mcp.Tools.Aks.LiveTests/AksCommandTests.cs | Tighten value-kind assertions and adjust optional-property checks. |
| tools/Azure.Mcp.Tools.Aks/src/Commands/AksJsonContext.cs | Add standardized source-gen options (camelCase + ignore nulls). |
| tools/Azure.Mcp.Tools.Advisor/src/Commands/AdvisorJsonContext.cs | Add license header and formatting-only change to options attribute. |
| tools/Azure.Mcp.Tools.Acr/src/Commands/AcrJsonContext.cs | Simplify context declaration; formatting-only options tweak. |
| core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SerializerContext.cs | Simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Services/ServicesJsonContext.cs | Add ignore nulls and simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Models/ModelsJsonContext.cs | Add ignore nulls and simplify context declaration. |
| core/Microsoft.Mcp.Core/src/CoreJsonContext.cs | Simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Commands/JsonSourceGenerationContext.cs | Add ignore nulls and simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Areas/Server/ServerJsonContext.cs | Use JsonIgnoreCondition alias and simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Models/OAuthProtectedResourceMetadata.cs | Add standardized source-gen options and simplify context declaration. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceInfoJsonContext.cs | Add ignore nulls and simplify context declaration. |
| core/Azure.Mcp.Core/src/Areas/Subscription/Commands/SubscriptionJsonContext.cs | Add ignore nulls and simplify context declaration. |
| core/Azure.Mcp.Core/src/Areas/Group/Commands/GroupJsonContext.cs | Add ignore nulls and simplify context declaration. |
| AGENTS.md | Update documentation snippet to include ignore-nulls option. |
Comments suppressed due to low confidence (2)
tools/Azure.Mcp.Tools.Workbooks/tests/Azure.Mcp.Tools.Workbooks.LiveTests/WorkbooksCommandTests.cs:1
WorkbooksJsonContextnow ignores null properties when serializing, so ifserializedDatais null it will likely be omitted entirely (not present as"serializedData": null). This assertion can fail against real responses; update the test to accept an omittedserializedData(e.g.,TryGetProperty) or only assert presence when the value is expected to be non-null.
tools/Azure.Mcp.Tools.Storage/src/Commands/StorageJsonContext.cs:1- This changes the ignore behavior from
WhenWritingDefaulttoWhenWritingNull, which will cause default values of non-nullable value types (e.g.,0,false, empty structs) to be serialized instead of omitted. If any tool responses previously relied on default-omission for payload size or schema shape, this is a behavior change for API consumers; consider either keepingWhenWritingDefaultwhere it mattered, or ensuring optional fields are nullable (so they can still be omitted) and documenting/changelogging the output change.
vcolin7
left a comment
There was a problem hiding this comment.
The changes look good. I just left a small comment.
| [JsonSerializable(typeof(BrownfieldFindings))] | ||
| [JsonSerializable(typeof(AnalysisTemplate))] | ||
| [JsonSourceGenerationOptions( | ||
| WriteIndented = true, |
There was a problem hiding this comment.
We removed this from some places but kept it here. Is there a particular reason we'd like to keep this one around?
There was a problem hiding this comment.
I kept it as I know it returns user instructions, but we can remove it and see what happens.
|
Oh, there's something else: there are classes like It's possible we'll have to re-record for test classes modified in this PR. |
There are some model types that explicitly define their JSON property names which overrides the behavior specified in |
jongio
left a comment
There was a problem hiding this comment.
Standardization effort looks solid overall - consistent formatting, semicolon bodies, and adding DefaultIgnoreCondition everywhere. A few behavioral concerns worth confirming:
WhenWritingDefault vs WhenWritingNull - Several tools (AzureBackup, DeviceRegistry, FoundryExtensions, Grafana, Redis, Storage) changed from WhenWritingDefault to WhenWritingNull. These have different semantics: WhenWritingDefault omits default-valued fields (0, false, empty Guid), while WhenWritingNull only omits null. After this change, fields like "count": 0 and "isEnabled": false will now appear in tool responses where they were previously omitted. This is additive (not field-removing), so likely safe for MCP consumers, but worth being aware of.
Contexts gaining options for the first time - A few contexts (AppService, SignalR, AvmJsonContext, AzApiExamplesJsonContext, etc.) previously had no JsonSourceGenerationOptions. Adding CamelCase naming policy means their source-generated serializers will now produce camelCase property names. If these were already using runtime options that specified camelCase, no change. If they relied on the source-gen defaults (PascalCase), this changes output shape.
WriteIndented removal - ManagedLustre and Policy lost WriteIndented = true. Output will no longer be pretty-printed. Functionally fine, but might affect debugging readability.
| internal sealed partial class AzureBackupJsonContext : JsonSerializerContext { } | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault | ||
| )] | ||
| internal sealed partial class AzureBackupJsonContext : JsonSerializerContext; |
There was a problem hiding this comment.
The docs snippet still shows WhenWritingDefault but the actual code (AzureBackupJsonContext.cs) was changed to WhenWritingNull. Should update the docs to match.
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault | ||
| )] | ||
| internal sealed partial class AzureBackupJsonContext : JsonSerializerContext; | ||
| ``` |
There was a problem hiding this comment.
Nit: the closing )] here has 2 extra spaces of indentation ( )]) while all other files in this PR use no extra indentation on the closing bracket.
jongio
left a comment
There was a problem hiding this comment.
Checked the new commit (c794930). The architecture.md docs fix addresses my earlier WhenWritingDefault/WhenWritingNull mismatch - now consistent with the code change.
The approach of adding explicit [JsonPropertyName("PascalCase")] attributes to preserve backward compat for Compute, LoadTesting, ServiceFabric, and Workbooks is pragmatic. One concern: models like DiskInfo and TestResource now rely on per-property attributes fighting the context-level CamelCase policy. Any new property added without the attribute will silently serialize as camelCase while existing ones stay PascalCase. A brief code comment in those models would help future contributors avoid mixed output.
Minor nit from last review: architecture.md line 392 still has )] with 2 extra spaces vs the PR's standard )] formatting.
| /// <summary> | ||
| /// Gets or sets the name of the disk. | ||
| /// </summary> | ||
| [JsonPropertyName("Name")] |
There was a problem hiding this comment.
These PascalCase overrides fight the context-level CamelCase policy. Works fine today, but a new property added without [JsonPropertyName] would silently serialize as camelCase while these stay PascalCase. Consider adding a comment at the top of the class (or in the JsonContext) noting that explicit attributes are needed here to preserve backward compat.
What does this PR do?
Standardizes behaviors of
JsonSourceGenerationOptionsacross all tools.GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline