Repository navigation
Add Azure IoT Hub routing endpoint health and diagnostics tools - #3894
Conversation
|
Thank you for your contribution vineetkalki! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
It adds two tools despite the one-tool rule, lacks evaluator results, and has unresolved authentication-order and retry-amplification concerns.
4 open findings
What changed in this PR
Adds IoT Hub routing endpoint health and diagnostics capabilities, plus routing endpoint details in hub responses.
Changes:
- Adds two routing troubleshooting commands and supporting services/models.
- Adds recorded, unit, infrastructure, and security tests.
- Updates registration, documentation, consolidated mappings, and changelog.
| File | Description |
|---|---|
tools/Azure.Mcp.Tools.IoTHub/tests/test-resources.bicep |
Adds routing test resources. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Services/SequenceHttpMessageHandler.cs |
Adds sequential HTTP test handler. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Services/RoutingDiagnosticsHttpMessageHandler.cs |
Adds diagnostics HTTP test handler. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Services/IoTHubRoutingServiceTests.cs |
Tests routing service fundamentals. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Services/IoTHubRoutingServiceDiagnosticsTests.cs |
Tests diagnostics orchestration. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Routing/RoutingMetricEvidenceBuilderTests.cs |
Tests metric evidence construction. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Routing/RoutingEndpointMapperTests.cs |
Tests endpoint mapping. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Routing/RoutingDiagnosticsWindowTests.cs |
Tests time-window validation. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Routing/IoTHubRoutingEndpointHealthCommandTests.cs |
Tests health command behavior. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Routing/IoTHubRoutingEndpointDiagnosticsCommandTests.cs |
Tests diagnostics command behavior. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/IoTHubCommandTests.cs |
Adds recorded routing tests. |
tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/assets.json |
Updates recording assets tag. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/RoutingTargetDescriptor.cs |
Defines target metadata. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/ResolvedTarget.cs |
Models resolved targets. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/ObservationWindow.cs |
Formats metric windows. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/IoTHubService.cs |
Adds routing endpoints to hub output. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/IoTHubRoutingService.cs |
Implements routing evidence queries. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/IIoTHubRoutingService.cs |
Defines routing service contract. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/ExistenceResult.cs |
Models target existence checks. |
tools/Azure.Mcp.Tools.IoTHub/src/Services/ArmGetResult.cs |
Models raw ARM responses. |
tools/Azure.Mcp.Tools.IoTHub/src/Routing/RoutingMetricEvidenceBuilder.cs |
Builds metric evidence output. |
tools/Azure.Mcp.Tools.IoTHub/src/Routing/RoutingEndpointMapper.cs |
Maps configured endpoints. |
tools/Azure.Mcp.Tools.IoTHub/src/Routing/RoutingDiagnosticsWindow.cs |
Validates diagnostics windows. |
tools/Azure.Mcp.Tools.IoTHub/src/Routing/MetricFieldNameBuilder.cs |
Generates metric field names. |
tools/Azure.Mcp.Tools.IoTHub/src/Options/Routing/IoTHubRoutingEndpointHealthOptions.cs |
Defines health options. |
tools/Azure.Mcp.Tools.IoTHub/src/Options/Routing/IoTHubRoutingEndpointDiagnosticsOptions.cs |
Defines diagnostics options. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingTargetInfo.cs |
Models resolved target details. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingTargetEmitted.cs |
Models target metrics. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingProperties.cs |
Models routing configuration. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingObservationWindow.cs |
Models returned time windows. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingMetricEvidence.cs |
Models metric evidence. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingHubEmitted.cs |
Models hub metrics. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpoints.cs |
Models endpoint collections. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointProperties.cs |
Models non-secret endpoint properties. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointHealthSnapshot.cs |
Models health snapshots. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointHealthResult.cs |
Wraps health results. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointDiagnostics.cs |
Wraps diagnostics results. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointDiagnostic.cs |
Models endpoint diagnostics. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingEndpointDetails.cs |
Models endpoint details. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/RoutingDiagnosticError.cs |
Models partial-evidence errors. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/IoTHubProperties.cs |
Adds routing properties. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/IoTHubDescription.cs |
Adds routing endpoints to hub details. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/EndpointHealthDataListResult.cs |
Models paged health data. |
tools/Azure.Mcp.Tools.IoTHub/src/Models/EndpointHealthData.cs |
Models REST health records. |
tools/Azure.Mcp.Tools.IoTHub/src/IoTHubSetup.cs |
Registers routing service and commands. |
tools/Azure.Mcp.Tools.IoTHub/src/Commands/Routing/IoTHubRoutingEndpointHealthCommand.cs |
Implements health command. |
tools/Azure.Mcp.Tools.IoTHub/src/Commands/Routing/IoTHubRoutingEndpointDiagnosticsCommand.cs |
Implements diagnostics command. |
tools/Azure.Mcp.Tools.IoTHub/src/Commands/IoTHubValidation.cs |
Centralizes hub-name validation. |
tools/Azure.Mcp.Tools.IoTHub/src/Commands/IoTHubJsonContext.cs |
Registers routing serialization types. |
tools/Azure.Mcp.Tools.IoTHub/src/Commands/IoTHub/IoTHubGetCommand.cs |
Documents expanded hub output. |
tools/Azure.Mcp.Tools.IoTHub/src/Azure.Mcp.Tools.IoTHub.csproj |
Adds Monitor SDK dependency. |
tools/Azure.Mcp.Tools.IoTHub/cspell.yaml |
Adds routing terminology. |
servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json |
Adds consolidated tool mappings. |
servers/Azure.Mcp.Server/README.md |
Documents routing scenarios. |
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md |
Adds routing prompts. |
servers/Azure.Mcp.Server/docs/azmcp-commands.md |
Documents routing commands. |
servers/Azure.Mcp.Server/changelog-entries/vineetkalki-iothub-routing-tools.yaml |
Records new features. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Provide a current endpoint-health snapshot and historical routing evidence, including downstream resource existence and per-metric availability without inferring overall hub health. Use a dedicated routing service with cloud-aware ARM validation, SDK-default retries, bounded operations, and cancellation handling. Include command documentation, registration, unit tests, recorded tests, and routing test infrastructure. Co-authored-by: Copilot <[email protected]>
02f943c to
25ca8f8
Compare
Only retry batched target metrics individually when Azure Monitor rejects the batch with 400, the incompatible-metric case. Throttling and server errors now fail the batch after SDK retries instead of fanning out into per-metric requests that consume the operation budget. Validate each ARM request URI, including nextLink continuations, before resolving the tenant or credential so untrusted destinations fail before any authentication work. Co-authored-by: Copilot <[email protected]>
microsoft#3884 removed the static EndpointValidator overload that took an executing tool namespace, so the routing service no longer compiles against main (CS1739). Validate ARM request and nextLink URIs through IAzureService.ValidateAzureServiceEndpoint, as IoTHubDeviceService now does. Tests use AzureServiceTestHelpers so endpoint validation stays real and shared ARM clients route through the test handler. Co-authored-by: Copilot <[email protected]>
|
@microsoft-github-policy-service agree company="Microsoft" |
Key-based endpoints have no endpointUri, and IoT Hub endpoint ids are opaque GUIDs rather than ARM resource IDs. The mapper fell back to the entity path or container name as the namespace or account name, so diagnostics checked a resource that does not exist and reported an existing target as notFound. Derive the target name only from the endpoint URI host so these endpoints report an unresolved target, and use opaque ids in the mapper fixture to match service responses. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
/azp run MCP - pullrequest - live |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run mcp - pullrequest - live |
|
Commenter does not have sufficient privileges for PR 3894 in repo microsoft/mcp |
The live pipeline failed in test-resources-post.ps1 because the azure-iot CLI extension it used cannot be installed on network-isolated agents. Seed the test devices through the IoT Hub registry REST API with Microsoft Entra ID instead, and grant the test principal IoT Hub Data Contributor. Also add the identity-based Service Bus routing endpoints in the post script rather than the template. IoT Hub validates those endpoints when they are created and rejects them (IH400117) until the routing identity's Service Bus Data Sender assignment takes effect. ARM cannot wait for that, so the post script retries until it does. Co-authored-by: Copilot <[email protected]>
|
The live run failed before any test ran. The IoT Hub Fixed in ca2e181:
I validated this against a fresh deployment in a separate subscription. The template deployed, the post script configured routing and created the 3 devices, and all 4 IoT Hub live tests passed in Live mode. Could someone with write access re-run |
|
/azp run MCP - pullrequest - live |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
There are merge conflicts that need to be addressed |
Resolve the conflict in tools/Azure.Mcp.Tools.IoTHub/tests/test-resources-post.ps1 by keeping this branch's version. microsoft#3742 hardened the azure-iot CLI extension install, but this branch's post script no longer uses the extension; it creates the test devices through the IoT Hub registry REST API, which passed in the live pipeline in both stdio and HTTP modes. Co-authored-by: Copilot <[email protected]>
Hub and resource group names were interpolated into ARM resource IDs. ResourceIdentifier accepts traversal segments, and URI normalization then sent the request elsewhere: rg1/../rg2 and rg1\..\rg2 read the hub from resource group rg2, and .. escaped to the subscription scope. Reject names outside the Azure naming rules before any credential or network work. The check runs in the shared routing service path used by both routing commands, and in IoTHubService.GetIoTHub, which serves hub get and, through the hostname resolver, the device and query tools. Resource group names follow the documented rule: 1-90 letters or digits (Char.IsLetterOrDigit), underscores, hyphens, periods, or parentheses, not ending with a period. Routing targets built from the hub's endpoint configuration are reported as unresolved unless every name is a single path segment. Co-authored-by: Copilot <[email protected]>
|
KarishmaGhiya Merged The only conflict was After the merge and the resource-name fix in 584662b, |
|
/azp run MCP - pullrequest - live |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |


What does this PR do?
Adds two read-only Azure IoT Hub message-routing troubleshooting tools to the Azure MCP Server, building on the IoT Hub toolset from #3074 and #3180. They let an agent answer "are my routing destinations healthy?" and "why were messages to this destination failing?" from the services' own evidence, without the tools inferring conclusions.
iothub_routing_endpoint-healthazmcp iothub routing endpoint-healthendpoints: the current IoT Hub-reportedroutingEndpointsHealthsnapshot for one or all custom endpoints (endpointId,endpointName,healthStatus,lastKnownError,lastKnownErrorTime,lastSuccessfulSendAttemptTime,lastSendAttemptTime). Point in time only; no time-range options.iothub_routing_endpoint-diagnosticsazmcp iothub routing endpoint-diagnosticsobservationWindowplusendpoints: per-endpoint IoT HubRoutingDeliveries/RoutingDeliveryLatencymetrics, current target existence from ARM, and target-resource Azure Monitor metrics for Event Hubs, Service Bus queues/topics, Blob Storage containers, and Cosmos DB SQL containers. Paired--start-time/--end-time(default: previous 24 hours) and--interval(defaultPT1H, at most 720 buckets).iothub_hub_getalso returns an additiveroutingEndpointsfield listing the hub's configured custom endpoints (non-secret fields only; connection strings and keys are never deserialized).Implementation follows the existing IoT Hub toolset patterns:
IoTHubRoutingEndpointHealthCommand/IoTHubRoutingEndpointDiagnosticsCommandand their options sit underCommands/RoutingandOptions/Routing, inheritBaseIoTHubCommand, and register aroutingcommand group. Routing domain logic (endpoint mapping, metric evidence building, observation-window rules) lives insrc/Routing, mirroringsrc/Query. Result and wire models are public records and classes inModels.IIoTHubRoutingServicekeeps routing orchestration separate from the hub and device services;hub getand routing share endpoint conversion throughRoutingEndpointMapper.endpointUri; key-based Event Hubs, Service Bus, and Storage endpoints have none and report an unresolved target rather than a guessed one.routingEndpointsHealthand target existence checks use an Azure.Core pipeline over the factory-createdHttpClient(SDK-default retries, recorded-test playback). Rooted ARM paths resolve against the configured cloud's ARM endpoint, and every request andnextLinkis checked against thearmendpoint allow-list withIAzureService.ValidateAzureServiceEndpointbefore a credential is resolved, following URL validation for Postgres, Pricing, Quota, Resource Health, Search, Service Bus, Service Fabric, and Speech tools #3740 and Add URL validation for all ArmClient uses and add DNS->IP address resolution SSRF protections. #3884.rg1/../rg2can't redirect an ARM request to a different resource group. The check covers both routing tools andIoTHubService, which serveshub getand the device and query tools. Routing targets built from the hub's endpoint configuration are reported as unresolved unless each name is a single path segment.endpoint-healthisControl(IoT HubroutingEndpointsHealthARM operation).endpoint-diagnosticsisBoth: Azure Monitor metric evidence (classifiedData, as formonitor metrics query) plus current target existence read from ARM.test-resources.bicepdeploys a Service Bus namespace, queue, and topic with a routing identity.test-resources-post.ps1then adds the identity-based routing endpoints, retrying until the identity's Service Bus role takes effect, and creates the test devices over Microsoft Entra ID instead of theazure-iotCLI extension, which can't be installed on network-isolated pipeline agents. Both routing live tests are recorded.Documentation:
Validation:
dotnet test --project tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Azure.Mcp.Tools.IoTHub.Tests.csproj -c Release --filter-not-trait TestType=Live(Windows): passed, 244/244.mcp - pullrequeston the PR merge ref (build 6994390): the IoT Hub test assembly passed 248/248 on both Linux x64 and Windows x64 (the 244 unit tests plus the 4 recorded tests in playback).mcp - pullrequest - liveon ca2e181 (build 6963792): the 4 IoT Hub live tests passed in both stdio and HTTP modes.dotnet test --project tools/Azure.Mcp.Tools.IoTHub/tests/Azure.Mcp.Tools.IoTHub.Tests/Azure.Mcp.Tools.IoTHub.Tests.csproj -c Debug --filter-trait TestType=Live(Playback): passed, 4/4 (routing endpoint health, routing endpoint diagnostics, hub get, device list).test-resources.bicepandtest-resources-post.ps1in a separate subscription: passed, 4/4.dotnet test --project core/Azure.Mcp.Core/tests/Azure.Mcp.Core.Tests/Azure.Mcp.Core.Tests.csproj -c Release --filter-class Azure.Mcp.Core.Tests.Areas.Server.CommandOperationPlaneTests --filter-class *ConsolidatedToolDiscoveryStrategyTests --filter-class *ToolsListCommandTests: passed, 31/31.dotnet test --project servers/Azure.Mcp.Server/tests/Azure.Mcp.Server.Tests/Azure.Mcp.Server.Tests.csproj -c Release --filter-class *ConsolidatedToolMetadataTests: passed, 8/8.dotnet format --verify-no-changeson the IoT Hub src and test projects: passed..\eng\common\spelling\Invoke-Cspell.ps1on all changed files: passed, 0 issues in 57 files../eng/scripts/Update-AzCommandsMetadata.ps1: passed, no changes../eng/scripts/Process-PackageReadMe.ps1 -Command validate -InputReadMePath servers/Azure.Mcp.Server/README.md: passed../eng/scripts/Compile-Changelog.ps1 -ChangelogPath servers/Azure.Mcp.Server/CHANGELOG.md -DryRun: passed.dotnet run --project eng/tools/ToolDescriptionEvaluator/src -- --area iothub --server-exe <this branch's Release azmcp.exe>, with an Azure OpenAItext-embedding-3-largedeployment and the IoT Hub prompts ine2eTestPrompts.md.iothub_hub_getGet details for IoT Hub <hub_name> in resource group <resource_group_name>iotoperations_instance_get(0.558)iothub_hub_getShow IoT Hub <hub_name> in resource group <resource_group_name> for subscription <subscription_id>iothub_device_list(0.548)iothub_hub_getRetrieve IoT Hub <hub_name> metadata from resource group <resource_group_name>eventhubs_eventhub_consumergroup_get(0.501)iothub_routing_endpoint-diagnosticsShow routing endpoint diagnostics evidence for IoT Hub <hub_name> in resource group <resource_group_name>iothub_hub_get(0.627)iothub_routing_endpoint-diagnosticsGet routing endpoint diagnostics metrics for IoT Hub <hub_name> from <start_time> through <end_time>iothub_routing_endpoint-health(0.588)iothub_routing_endpoint-diagnosticsCheck whether routing endpoint <endpoint_name> on IoT Hub <hub_name> has a missing target, unavailable metrics, or observed delivery failures in the past six hoursiothub_routing_endpoint-health(0.567)iothub_routing_endpoint-diagnosticsShow which routing metrics returned no data for IoT Hub <hub_name> without assuming the hub is idle or healthyiothub_routing_endpoint-health(0.531)iothub_routing_endpoint-healthShow routing endpoint health for IoT Hub <hub_name> in resource group <resource_group_name>iothub_hub_get(0.643)iothub_routing_endpoint-healthGet the current routing endpoint health for endpoint <endpoint_name> on IoT Hub <hub_name>iothub_routing_endpoint-diagnostics(0.570)Across all 22 IoT Hub prompts, 22/22 score at least 0.4 and 16/22 rank first. The 6 that don't rank first belong to existing tools (
device show,device twin get,query run). A baseline run with upstream'shub getdescription and without the routing tools gives identical ranks and scores for those 6, so this PR doesn't change them. With the longer description, thehub getprompt scores drop by at most 0.018 and still rank first.The embedding deployment allows only Microsoft Entra ID auth because key auth is disabled by policy. The evaluator only sends an
api-keyheader, so it ran with an uncommitted local change that sends a bearer token instead. Scoring logic is unchanged.GitHub issue number?
#2917
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 PipelineInvoking 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.