-
Notifications
You must be signed in to change notification settings - Fork 467
[Azure MCP] New command: Eventhubs namespace get #105
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
jairmyree
merged 36 commits into
microsoft:main
from
jairmyree:eventhubs_namespaces-list
Sep 29, 2025
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a704e80
Rebasing EventHubs Namespace List Command
jairmyree 5e04724
Live tests passing
jairmyree a522534
Updating test-resources-post and adding e2e prompt
jairmyree d2b391e
Updating Namespace List to Namespace Get
jairmyree 145ab5a
updating test-resources-post
jairmyree 04e4466
Updating test to reflect tool consolidation
jairmyree f103655
Updates to PR based on feedback
jairmyree 6dc75ca
EventHubs namespace get command update. Now supports getting metadata…
jairmyree b46760f
Update namespace get command to not take id parameter
jairmyree a03e420
Correcting EventHubs to Event Hubs in documentation
jairmyree 8015a23
Additional Updates
jairmyree 28bdcc3
Remove unused imports
jairmyree 8a6d752
Changes to EventHubsService
jairmyree 141d09d
dotnet format
jairmyree a5109b9
Remove the dependency on Azure.ResourceManager.EventHubs due to use A…
ArthurMa1978 623049c
Update tools/Azure.Mcp.Tools.EventHubs/src/EventHubsSetup.cs
jairmyree 87b5424
Updates from PR comments
jairmyree 9885f19
Updates from PR comments
jairmyree 49ee954
Updates from PR comments
jairmyree 31358e1
Updates from PR comments
jairmyree 2bce69a
Fixing test error
jairmyree d7d849b
Fixing live test error
jairmyree e4de163
Update tools/Azure.Mcp.Tools.EventHubs/src/Commands/Namespace/Namespa…
jairmyree 513a2ba
Update tools/Azure.Mcp.Tools.EventHubs/src/Commands/Namespace/Namespa…
jairmyree 14175c7
Update tools/Azure.Mcp.Tools.EventHubs/src/Commands/Namespace/Namespa…
jairmyree 1e79fa0
Update tools/Azure.Mcp.Tools.EventHubs/src/Services/EventHubsService.cs
jairmyree 209abb5
Update tools/Azure.Mcp.Tools.EventHubs/tests/Azure.Mcp.Tools.EventHub…
jairmyree 9cf4a3c
Update tools/Azure.Mcp.Tools.EventHubs/tests/Azure.Mcp.Tools.EventHub…
jairmyree 7f6aa9e
Updates to PR based on feedback fron Alan and Connie
jairmyree a0c4def
Update tools/Azure.Mcp.Tools.EventHubs/src/Options/BaseEventHubsOptio…
jairmyree 6bffa87
additional PR updates
jairmyree a172503
Updates to fix test failures
jairmyree 075f97a
Update tools/Azure.Mcp.Tools.EventHubs/tests/Azure.Mcp.Tools.EventHub…
jairmyree efb33d1
Update tools/Azure.Mcp.Tools.EventHubs/src/Services/EventHubsService.cs
jairmyree 39d7fa9
Rmoving empty file
jairmyree 3e12ced
Update validation pattern
jairmyree 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
| 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.EventHubs.UnitTests")] | ||
| [assembly: InternalsVisibleTo("Azure.Mcp.Tools.EventHubs.LiveTests")] |
13 changes: 13 additions & 0 deletions
13
tools/Azure.Mcp.Tools.EventHubs/src/Azure.Mcp.Tools.EventHubs.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,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <IsAotCompatible>true</IsAotCompatible> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
| <PackageReference Include="ModelContextProtocol" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
| </Project> |
13 changes: 13 additions & 0 deletions
13
tools/Azure.Mcp.Tools.EventHubs/src/Commands/BaseEventHubsCommand.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,13 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Azure.Mcp.Core.Commands; | ||
| using Azure.Mcp.Core.Commands.Subscription; | ||
| using Azure.Mcp.Tools.EventHubs.Options; | ||
|
|
||
| namespace Azure.Mcp.Tools.EventHubs.Commands; | ||
|
|
||
| public abstract class BaseEventHubsCommand< | ||
| [DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TOptions> | ||
| : SubscriptionCommand<TOptions> where TOptions : BaseEventHubsOptions, new(); |
19 changes: 19 additions & 0 deletions
19
tools/Azure.Mcp.Tools.EventHubs/src/Commands/EventHubsJsonContext.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 System.Text.Json.Serialization; | ||
| using Azure.Mcp.Tools.EventHubs.Commands.Namespace; | ||
| using Azure.Mcp.Tools.EventHubs.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.EventHubs.Commands; | ||
|
|
||
| [JsonSerializable(typeof(EventHubsNamespaceData))] | ||
| [JsonSerializable(typeof(EventHubsNamespaceSku))] | ||
| [JsonSerializable(typeof(Models.Namespace))] | ||
| [JsonSerializable(typeof(NamespaceGetCommand.NamespaceGetCommandResult))] | ||
| [JsonSerializable(typeof(NamespaceGetCommand.NamespacesGetCommandResult))] | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| WriteIndented = true, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| internal partial class EventHubsJsonContext : JsonSerializerContext; |
143 changes: 143 additions & 0 deletions
143
tools/Azure.Mcp.Tools.EventHubs/src/Commands/Namespace/NamespaceGetCommand.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,143 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Net; | ||
| using Azure.Mcp.Core.Commands; | ||
| using Azure.Mcp.Core.Extensions; | ||
| using Azure.Mcp.Core.Models.Option; | ||
| using Azure.Mcp.Tools.EventHubs.Options; | ||
| using Azure.Mcp.Tools.EventHubs.Options.Namespace; | ||
| using Azure.Mcp.Tools.EventHubs.Services; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Azure.Mcp.Tools.EventHubs.Commands.Namespace; | ||
|
|
||
| public sealed class NamespaceGetCommand(ILogger<NamespaceGetCommand> logger) | ||
| : BaseEventHubsCommand<NamespaceGetOptions> | ||
| { | ||
| private const string CommandTitle = "Get Event Hubs Namespaces"; | ||
|
|
||
| private readonly ILogger<NamespaceGetCommand> _logger = logger; | ||
|
|
||
| public override string Name => "get"; | ||
|
|
||
| public override string Description => | ||
| """ | ||
| Get Event Hubs namespaces from Azure. This command supports three modes of operation: | ||
| 1. List all Event Hubs namespaces in a subscription (when no --resource-group is provided) | ||
| 2. List all Event Hubs namespaces in a specific resource group (when only --resource-group is provided) | ||
| 3. Get a single namespace by name (using --namespace with --resource-group) | ||
|
|
||
| When retrieving a single namespace, detailed information including SKU, settings, and metadata | ||
| is returned. When listing namespaces, the same detailed information is returned for all | ||
| namespaces in the specified scope. | ||
|
|
||
| The --resource-group parameter is optional for listing operations but required when getting a specific namespace. | ||
| """; | ||
|
|
||
| public override string Title => CommandTitle; | ||
|
|
||
| public override ToolMetadata Metadata => new() | ||
| { | ||
| OpenWorld = false, | ||
| Destructive = false, // Safe read-only operation | ||
| Idempotent = true, // Same parameters produce same results | ||
| ReadOnly = true, // Only reads data, no modifications | ||
| Secret = false, // Returns non-sensitive information | ||
| LocalRequired = false // Pure cloud API calls | ||
| }; | ||
|
|
||
| protected override void RegisterOptions(Command command) | ||
| { | ||
| base.RegisterOptions(command); | ||
| command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional()); | ||
| command.Options.Add(EventHubsOptionDefinitions.NamespaceName.AsOptional()); | ||
| command.Validators.Add(commandResult => | ||
| { | ||
| var namespaceName = commandResult.GetValueOrDefault<string>(EventHubsOptionDefinitions.NamespaceName.Name); | ||
| var resourceGroup = commandResult.GetValueOrDefault<string>(OptionDefinitions.Common.ResourceGroup.Name); | ||
|
|
||
| if (!string.IsNullOrEmpty(namespaceName) && string.IsNullOrEmpty(resourceGroup)) | ||
| { | ||
| commandResult.AddError("When specifying a namespace name, a resource group must also be provided."); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| protected override NamespaceGetOptions BindOptions(ParseResult parseResult) | ||
| { | ||
| var options = base.BindOptions(parseResult); | ||
| options.ResourceGroup ??= parseResult.GetValueOrDefault<string>(OptionDefinitions.Common.ResourceGroup.Name); | ||
| options.NamespaceName = parseResult.GetValueOrDefault<string>(EventHubsOptionDefinitions.NamespaceName.Name); | ||
| return options; | ||
| } | ||
|
|
||
|
jairmyree marked this conversation as resolved.
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult) | ||
| { | ||
| if (!Validate(parseResult.CommandResult, context.Response).IsValid) | ||
| { | ||
| return context.Response; | ||
| } | ||
|
|
||
| var options = BindOptions(parseResult); | ||
|
|
||
| try | ||
| { | ||
| var eventHubsService = context.GetService<IEventHubsService>(); | ||
|
|
||
| // Determine if this is a single namespace request or list request | ||
| bool isSingleNamespaceRequest = !string.IsNullOrEmpty(options.NamespaceName); | ||
|
|
||
| if (isSingleNamespaceRequest) | ||
| { | ||
| // Get single namespace with detailed information | ||
| var namespaceDetails = await eventHubsService.GetNamespaceAsync( | ||
| options.NamespaceName!, | ||
| options.ResourceGroup!, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| options.RetryPolicy); | ||
|
|
||
| context.Response.Results = namespaceDetails != null | ||
| ? ResponseResult.Create(new(namespaceDetails), EventHubsJsonContext.Default.NamespaceGetCommandResult) | ||
| : null; | ||
| } | ||
| else | ||
| { | ||
| var namespaces = await eventHubsService.GetNamespacesAsync( | ||
| options.ResourceGroup, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| options.RetryPolicy); | ||
|
|
||
| context.Response.Results = ResponseResult.Create(new(namespaces ?? []), EventHubsJsonContext.Default.NamespacesGetCommandResult); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "Error getting Event Hubs namespaces"); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| protected override string GetErrorMessage(Exception ex) => ex switch | ||
| { | ||
| KeyNotFoundException => $"Event Hubs namespace not found. Verify the namespace name, resource group, and that you have access.", | ||
| Identity.AuthenticationFailedException authEx => | ||
| "Authentication failed. Please ensure your Azure credentials are properly configured and have not expired.", | ||
| RequestFailedException reqEx when reqEx.Status == 403 => | ||
| "Access denied. Please ensure you have sufficient permissions to get Event Hubs namespaces in the specified resource group.", | ||
| RequestFailedException reqEx when reqEx.Status == 404 => | ||
| "The specified resource group or subscription was not found. Please verify the resource group name and subscription.", | ||
| ArgumentException argEx when argEx.ParamName == "resourceGroup" => | ||
| "Invalid resource group name. Please provide a valid resource group name.", | ||
| ArgumentException argEx when argEx.ParamName == "subscription" => | ||
| "Invalid subscription. Please provide a valid subscription ID or name.", | ||
| _ => base.GetErrorMessage(ex) | ||
| }; | ||
|
|
||
| internal record NamespacesGetCommandResult(List<Models.Namespace> Namespaces); | ||
| internal record NamespaceGetCommandResult(Models.Namespace Namespace); | ||
| } | ||
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.