-
Notifications
You must be signed in to change notification settings - Fork 555
On boarding IoTHub toolset #3005
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
Open
jichang1
wants to merge
6
commits into
main
Choose a base branch
from
jichang/hubonboarding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e90910a
on boarding IoTHub toolset
jichang1 27f06ca
Address CR comments: Remove Unused Reference projects; align indentat…
jichang1 d00a27f
revert change to get_azure_messaging_service_details in consolidated …
jichang1 74ed768
revert change to get_azure_messaging_service_details in consolidated …
jichang1 6ebde76
Merge branch 'main' of https://github.com/microsoft/mcp into jichang/…
jichang1 820cd59
Address CodeAnalysis Error - Sort usings
jichang1 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/jichang1-add-iothub-docs-integration.yml
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 Azure IoT Hub integration updates including command docs, e2e prompts, README service coverage, consolidated tool mapping, and CODEOWNERS ownership." |
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,7 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Azure.Mcp.Tools.IoTHub.UnitTests")] | ||
| [assembly: InternalsVisibleTo("Azure.Mcp.Tools.IoTHub.LiveTests")] |
20 changes: 20 additions & 0 deletions
20
tools/Azure.Mcp.Tools.IoTHub/src/Azure.Mcp.Tools.IoTHub.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,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <IsAotCompatible>true</IsAotCompatible> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <EmbeddedResource Include="**\Resources\*.txt" /> | ||
| <EmbeddedResource Include="**\Resources\*.json" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup /> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.ResourceManager" /> | ||
| <PackageReference Include="Azure.ResourceManager.IotHub" /> | ||
|
jichang1 marked this conversation as resolved.
Outdated
|
||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
| <PackageReference Include="ModelContextProtocol" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
| </Project> | ||
71 changes: 71 additions & 0 deletions
71
tools/Azure.Mcp.Tools.IoTHub/src/Commands/IoTHub/IoTHubGetCommand.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,71 @@ | ||
| // 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.IoTHub.Models; | ||
| using Azure.Mcp.Tools.IoTHub.Options.IoTHub; | ||
| using Azure.Mcp.Tools.IoTHub.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Mcp.Core.Commands; | ||
| using Microsoft.Mcp.Core.Models.Command; | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub.Commands.IoTHub; | ||
|
|
||
| [CommandMetadata( | ||
| Id = "108daa19-5c1b-4633-9a56-d58f4da020e1", | ||
| Name = "get", | ||
| Title = "Get IoT Hub", | ||
| Description = """ | ||
| Get IoT Hub details or list IoT Hubs in a subscription. Optionally filter by resource group and IoT Hub name. | ||
| Returns each IoT Hub with id, name, location, resourceGroup, subscriptionId, sku, capacity, state, and hostName. | ||
| """, | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = true, | ||
| Secret = false, | ||
| LocalRequired = false)] | ||
| public sealed class IoTHubGetCommand( | ||
| ILogger<IoTHubGetCommand> logger, | ||
| IIoTHubService service, | ||
| ISubscriptionResolver subscriptionResolver) | ||
| : SubscriptionCommand<IoTHubGetOptions, IoTHubGetCommand.IoTHubGetCommandResult>(subscriptionResolver) | ||
| { | ||
| private readonly ILogger<IoTHubGetCommand> _logger = logger; | ||
| private readonly IIoTHubService _service = service; | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync( | ||
| CommandContext context, | ||
| IoTHubGetOptions options, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| var results = await _service.GetIoTHub( | ||
| options.Name, | ||
| options.ResourceGroup, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| options.RetryPolicy, | ||
| cancellationToken); | ||
|
|
||
| context.Response.Results = ResponseResult.Create( | ||
| new(results?.Results ?? [], results?.AreResultsTruncated ?? false), | ||
| IoTHubJsonContext.Default.IoTHubGetCommandResult); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, | ||
| "Error getting IoT Hub(s). Subscription: {Subscription}, ResourceGroup: {ResourceGroup}, Name: {Name}.", | ||
| options.Subscription, | ||
| options.ResourceGroup, | ||
| options.Name); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| public record IoTHubGetCommandResult(List<IoTHubDescription> IoTHubs, bool AreResultsTruncated); | ||
| } |
17 changes: 17 additions & 0 deletions
17
tools/Azure.Mcp.Tools.IoTHub/src/Commands/IoTHubJsonContext.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,17 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
| using Azure.Mcp.Tools.IoTHub.Commands.IoTHub; | ||
| using Azure.Mcp.Tools.IoTHub.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub.Commands; | ||
|
|
||
| [JsonSerializable(typeof(IoTHubGetCommand.IoTHubGetCommandResult))] | ||
| [JsonSerializable(typeof(IoTHubDescription))] | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| internal sealed partial class IoTHubJsonContext : JsonSerializerContext | ||
| { | ||
| } |
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,7 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| global using System; | ||
| global using System.Collections.Generic; | ||
| global using System.Threading; | ||
| global using System.Threading.Tasks; |
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,37 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Tools.IoTHub.Commands.IoTHub; | ||
| using Azure.Mcp.Tools.IoTHub.Services; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Mcp.Core.Areas; | ||
| using Microsoft.Mcp.Core.Commands; | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub; | ||
|
|
||
| public class IoTHubSetup : IAreaSetup | ||
| { | ||
| public string Name => "iothub"; | ||
|
|
||
| public string Title => "Manage Azure IoT Hub"; | ||
|
|
||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| services.AddSingleton<IIoTHubService, IoTHubService>(); | ||
| services.AddSingleton<IoTHubGetCommand>(); | ||
| } | ||
|
|
||
| public CommandGroup RegisterCommands(IServiceProvider serviceProvider) | ||
| { | ||
| var iothub = new CommandGroup(Name, | ||
| "IoT Hub operations - Commands for managing Azure IoT Hubs.", | ||
| Title); | ||
|
|
||
| var hub = new CommandGroup("hub", "IoT Hub resource operations."); | ||
| iothub.AddSubGroup(hub); | ||
|
|
||
| hub.AddCommand<IoTHubGetCommand>(serviceProvider); | ||
|
|
||
| return iothub; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
tools/Azure.Mcp.Tools.IoTHub/src/Models/IoTHubDescription.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,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub.Models; | ||
|
|
||
| public record IoTHubDescription( | ||
| string Id, | ||
| string Name, | ||
| string Location, | ||
| string ResourceGroup, | ||
| string SubscriptionId, | ||
| string Sku, | ||
| long Capacity, | ||
| string State, | ||
| string HostName); |
25 changes: 25 additions & 0 deletions
25
tools/Azure.Mcp.Tools.IoTHub/src/Options/IoTHub/IoTHubGetOptions.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. | ||
|
|
||
| using Azure.Mcp.Core.Options; | ||
| using Microsoft.Mcp.Core.Options; | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub.Options.IoTHub; | ||
|
|
||
| public class IoTHubGetOptions : ISubscriptionOption | ||
| { | ||
| [Option(Description = "The name of the IoT Hub.")] | ||
| public string? Name { get; set; } | ||
|
|
||
| [Option(Description = OptionDescriptions.ResourceGroup)] | ||
| public string? ResourceGroup { get; set; } | ||
|
|
||
| [Option(Description = OptionDescriptions.Subscription)] | ||
| public string? Subscription { get; set; } | ||
|
|
||
| [Option(Description = OptionDescriptions.Tenant)] | ||
| public string? Tenant { get; set; } | ||
|
|
||
| [OptionContainer(Prefix = "retry")] | ||
| public RetryPolicyOptions? RetryPolicy { get; set; } | ||
| } |
19 changes: 19 additions & 0 deletions
19
tools/Azure.Mcp.Tools.IoTHub/src/Services/IIoTHubService.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,19 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Tools.IoTHub.Models; | ||
| using Azure.Mcp.Core.Services.Azure; | ||
| using Microsoft.Mcp.Core.Options; | ||
|
|
||
| namespace Azure.Mcp.Tools.IoTHub.Services; | ||
|
|
||
| public interface IIoTHubService | ||
| { | ||
| Task<ResourceQueryResults<IoTHubDescription>> GetIoTHub( | ||
| string? name, | ||
| string? resourceGroup, | ||
| string subscription, | ||
| string? tenant = null, | ||
| RetryPolicyOptions? retryPolicy = null, | ||
| CancellationToken cancellationToken = default); | ||
| } |
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.