Fix monitor_healthmodels_entity_get HTTP 400 error#2896
Conversation
The control-plane GET that resolves the health model dataplane endpoint used the unsupported Microsoft.CloudHealth api-version 2023-10-01-preview, which ARM rejects with HTTP 400 (Bad Request). The data-plane request URL was also malformed: it concatenated the dataplane endpoint with the path without a separator and did not URL-encode the entity name. - Use supported api-version 2025-05-01-preview for the control-plane call. - Join the dataplane endpoint and path with a single '/' (trimming any trailing slash) and URL-encode the entity name. - Add MonitorHealthModelServiceTests covering URL construction and api-version. Fixes #2247 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes monitor_healthmodels_entity_get failing with HTTP 400 (Bad Request) by updating the Monitor Health Models control-plane api-version to a currently supported value and correcting dataplane URL construction so entity history requests are valid.
Changes:
- Updated
Microsoft.CloudHealthcontrol-plane api-version to2025-05-01-previewwhen resolving the health model dataplane endpoint. - Corrected dataplane entity history URL construction by normalizing the endpoint, inserting the missing path separator, and URL-encoding the entity name.
- Added unit tests to prevent regressions for api-version selection, endpoint trailing-slash handling, and entity encoding.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.Tests/HealthModels/MonitorHealthModelServiceTests.cs | Adds focused tests verifying the fixed control-plane api-version and correct dataplane URL formation/encoding. |
| tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorHealthModelService.cs | Updates api-version and fixes entity history URL construction to prevent malformed requests. |
| servers/Azure.Mcp.Server/changelog-entries/jairmyree-fix-healthmodels-entity-get.yaml | Documents the bug fix in the server changelog entries. |
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot The tests should be follow the updated test model. Since the changes impact the monitor_healthmodels_entity_get command the tests should be placed in EntityGetHealthCommandTests.cs |
Moved the dataplane URL / control-plane api-version regression tests into Note: I couldn't run |
|
@copilot Redo the tests following the test structure of the repository. Unit tests should go within EntityGetHealthCommandTests and live recorded tests should go within MonitorCommandTests |
…ive recorded in MonitorCommandTests
Done. Restored Note: I couldn't build/run locally — the |
Summary
monitor_healthmodels_entity_getreturnedHTTP 400 (Bad Request)for every entity health query.Root cause
MonitorHealthModelServiceresolved the health model's dataplane endpoint withMicrosoft.CloudHealthapi-version2023-10-01-preview. That version is no longer supported by the resource provider (the published versions are2025-05-01-preview,2026-01-01-preview,2026-05-01-preview), so ARM rejected the request with400 (Bad Request). The failingEnsureSuccessStatusCode()produced exactly theHttpRequestExceptionmessage shown in the issue.$"{dataplaneEndpoint}api/entities/{entity}/history"— no/separator between the endpoint host and the path, and the entity name was not URL-encoded.Changes
2025-05-01-previewfor the control-plane call./from the endpoint, joining with/api/entities/..., and URL-encoding the entity name (matching the documented dataplane contract).EntityGetHealthCommandTests.cs, and live recorded integration tests formonitor_healthmodels_entity_get(a positive entity-health query plus invalid-input validation) were added toMonitorCommandTests.cs. The separateMonitorHealthModelServiceTests.cswas removed.Validation
dotnet build tools/Azure.Mcp.Tools.Monitor/src— succeeds, 0 warnings.cspellclean on changed files.Compile-Changelog.ps1 -DryRun.Invoking Livetests
Copilot submitted PRs are not trustworthy by default. Users with
writeaccess to the repo need to validate the contents of this PR before leaving a comment with the text/azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.