Repository navigation
Add Device Provisioning Service get tool #3898
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
Merged
Connie Yau (conniey)
merged 5 commits into
microsoft:main
from
khalilCodeX:feature/device-provisioning-service-get
Oct 16, 2026
+893
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
servers/Azure.Mcp.Server/changelog-entries/khalil-device-provisioning-service-get.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| changes: | ||
| - section: "Features Added" | ||
| description: "Added a read-only Azure Device Provisioning Service tool for retrieving service configuration and linked IoT Hub metadata without exposing connection strings or keys." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Spell-check overrides for this toolset/server. | ||
| # Inherits the global config at the repo root. | ||
| version: "0.2" | ||
| import: | ||
| - ../../.vscode/cspell.json | ||
| words: | ||
| - idscope | ||
| - iothubs | ||
| - provisioningserviceowner |
17 changes: 17 additions & 0 deletions
17
tools/Azure.Mcp.Tools.DeviceProvisioning/src/Azure.Mcp.Tools.DeviceProvisioning.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <IsAotCompatible>true</IsAotCompatible> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="$(AssemblyName).Tests" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.ResourceManager" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
| <PackageReference Include="ModelContextProtocol" /> | ||
| </ItemGroup> | ||
| </Project> | ||
|
|
21 changes: 21 additions & 0 deletions
21
tools/Azure.Mcp.Tools.DeviceProvisioning/src/Commands/DeviceProvisioningJsonContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Commands.Service; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.DeviceProvisioning.Commands; | ||
|
|
||
| [JsonSerializable(typeof(DeviceProvisioningProperties))] | ||
| [JsonSerializable(typeof(DeviceProvisioningServiceDescription))] | ||
| [JsonSerializable(typeof(LinkedIoTHubDescription))] | ||
| [JsonSerializable(typeof(List<LinkedIoTHubDescription>))] | ||
| [JsonSerializable(typeof(DeviceProvisioningServiceGetCommand.DeviceProvisioningServiceGetCommandResult))] | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| internal sealed partial class DeviceProvisioningJsonContext : JsonSerializerContext | ||
| { | ||
| } | ||
|
|
114 changes: 114 additions & 0 deletions
114
....Mcp.Tools.DeviceProvisioning/src/Commands/Service/DeviceProvisioningServiceGetCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Core.Commands.Subscription; | ||
| using Azure.Mcp.Core.Services.Azure.Subscription; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Models; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Options.Service; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Mcp.Core.Commands; | ||
| using Microsoft.Mcp.Core.Models.Command; | ||
|
|
||
| namespace Azure.Mcp.Tools.DeviceProvisioning.Commands.Service; | ||
|
|
||
| [CommandMetadata( | ||
| Id = "3bf66226-33b8-438b-9f71-3abe62a6bf6c", | ||
| Name = "get", | ||
| Title = "Get Device Provisioning Service", | ||
| Description = """ | ||
| Get an Azure Device Provisioning Service instance by name in a resource group. | ||
| Returns resource identity, SKU, service state, endpoints, ID scope, allocation policy, | ||
| public network access, data residency, and linked IoT Hub metadata. | ||
| Connection strings, authorization policies, and keys are not returned. | ||
| """, | ||
| OperationPlane = ToolOperationPlane.Control, | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = true, | ||
| Secret = false, | ||
| LocalRequired = false)] | ||
| public sealed class DeviceProvisioningServiceGetCommand( | ||
| ILogger<DeviceProvisioningServiceGetCommand> logger, | ||
| IDeviceProvisioningService service, | ||
| ISubscriptionResolver subscriptionResolver) | ||
| : SubscriptionCommand<DeviceProvisioningServiceGetOptions, DeviceProvisioningServiceGetCommand.DeviceProvisioningServiceGetCommandResult>(subscriptionResolver) | ||
| { | ||
| private readonly ILogger<DeviceProvisioningServiceGetCommand> _logger = logger; | ||
| private readonly IDeviceProvisioningService _service = service; | ||
|
|
||
| public override void ValidateOptions( | ||
| DeviceProvisioningServiceGetOptions options, | ||
| ValidationResult validationResult) | ||
| { | ||
| base.ValidateOptions(options, validationResult); | ||
|
|
||
| if (!IsValidServiceName(options.Service)) | ||
| { | ||
| validationResult.Errors.Add( | ||
| "--service must be 3-64 characters long, contain only letters, numbers, or hyphens, and start and end with a letter or number."); | ||
| } | ||
| } | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync( | ||
| CommandContext context, | ||
| DeviceProvisioningServiceGetOptions options, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| var provisioningService = await _service.GetService( | ||
| options.Service, | ||
| options.ResourceGroup, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| cancellationToken); | ||
|
|
||
| context.Response.Results = ResponseResult.Create( | ||
| new DeviceProvisioningServiceGetCommandResult( | ||
| provisioningService, | ||
| AreResultsTruncated: false), | ||
| DeviceProvisioningJsonContext.Default.DeviceProvisioningServiceGetCommandResult); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError( | ||
| ex, | ||
| "Error getting Device Provisioning Service '{ServiceName}' in resource group '{ResourceGroup}' and subscription '{Subscription}'.", | ||
| options.Service, | ||
| options.ResourceGroup, | ||
| options.Subscription); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| public record DeviceProvisioningServiceGetCommandResult( | ||
| DeviceProvisioningServiceDescription DeviceProvisioningService, | ||
| bool AreResultsTruncated); | ||
|
|
||
| private static bool IsValidServiceName(string value) | ||
| { | ||
| if (value.Length is < 3 or > 64 || | ||
| value[0] == '-' || | ||
| value[^1] == '-') | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| foreach (var ch in value) | ||
| { | ||
| var isAlphaNumeric = (ch >= 'a' && ch <= 'z') || | ||
| (ch >= 'A' && ch <= 'Z') || | ||
| (ch >= '0' && ch <= '9'); | ||
| if (!isAlphaNumeric && ch != '-') | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
tools/Azure.Mcp.Tools.DeviceProvisioning/src/DeviceProvisioningSetup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Tools.DeviceProvisioning.Commands.Service; | ||
| using Azure.Mcp.Tools.DeviceProvisioning.Services; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Mcp.Core.Areas; | ||
| using Microsoft.Mcp.Core.Commands; | ||
|
|
||
| namespace Azure.Mcp.Tools.DeviceProvisioning; | ||
|
|
||
| public class DeviceProvisioningSetup : IAreaSetup | ||
| { | ||
| public string Name => "deviceprovisioning"; | ||
|
|
||
| public string Title => "Manage Azure Device Provisioning Service"; | ||
|
|
||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| services.AddSingleton<IDeviceProvisioningService, DeviceProvisioningService>(); | ||
| services.AddSingleton<DeviceProvisioningServiceGetCommand>(); | ||
| } | ||
|
|
||
| public CommandGroup RegisterCommands(IServiceProvider serviceProvider) | ||
| { | ||
| var deviceProvisioning = new CommandGroup( | ||
| Name, | ||
| "Azure Device Provisioning Service operations.", | ||
| Title); | ||
|
|
||
| var service = new CommandGroup( | ||
| "service", | ||
| "Azure Device Provisioning Service resource operations."); | ||
| deviceProvisioning.AddSubGroup(service); | ||
| service.AddCommand<DeviceProvisioningServiceGetCommand>(serviceProvider); | ||
|
|
||
| return deviceProvisioning; | ||
| } | ||
| } | ||
|
|
25 changes: 25 additions & 0 deletions
25
tools/Azure.Mcp.Tools.DeviceProvisioning/src/Models/DeviceProvisioningProperties.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Tools.DeviceProvisioning.Models; | ||
|
|
||
| public class DeviceProvisioningProperties | ||
| { | ||
| public string? State { get; set; } | ||
|
|
||
| public string? ProvisioningState { get; set; } | ||
|
|
||
| public string? ServiceOperationsHostName { get; set; } | ||
|
|
||
| public string? DeviceProvisioningHostName { get; set; } | ||
|
|
||
| public string? IdScope { get; set; } | ||
|
|
||
| public string? AllocationPolicy { get; set; } | ||
|
|
||
| public string? PublicNetworkAccess { get; set; } | ||
|
|
||
| public bool? EnableDataResidency { get; set; } | ||
|
|
||
| public List<LinkedIoTHubProperties>? IotHubs { get; set; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.