Skip to content

Support prefix in storage listing#2378

Open
alzimmermsft wants to merge 6 commits intomicrosoft:mainfrom
alzimmermsft:SupportPrefixInStorageListing
Open

Support prefix in storage listing#2378
alzimmermsft wants to merge 6 commits intomicrosoft:mainfrom
alzimmermsft:SupportPrefixInStorageListing

Conversation

@alzimmermsft
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for --prefix when listing Storage blob containers and blobs to help target listing scope.

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds --prefix support to Azure Storage listing operations so users can scope container and blob listings by name prefix.

Changes:

  • Added --prefix option wiring for storage_blob_get (blob listing) and storage_blob_container_get (container listing).
  • Updated IStorageService/StorageService listing APIs to accept a prefix parameter and pass it into Azure SDK list calls.
  • Added/updated unit tests, live tests, and command documentation to cover and describe prefix filtering.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Storage/src/Services/StorageService.cs Implements prefix filtering in Azure SDK list calls; also refactors SKU/tier validation sets.
tools/Azure.Mcp.Tools.Storage/src/Services/IStorageService.cs Extends service interface APIs with optional prefix parameter.
tools/Azure.Mcp.Tools.Storage/src/Options/StorageOptionDefinitions.cs Introduces --prefix option definitions for blob/container listing commands.
tools/Azure.Mcp.Tools.Storage/src/Options/Blob/BlobGetOptions.cs Adds Prefix to blob get options payload.
tools/Azure.Mcp.Tools.Storage/src/Options/Blob/Container/ContainerGetOptions.cs Adds Prefix to container get options payload.
tools/Azure.Mcp.Tools.Storage/src/Commands/Blob/BlobGetCommand.cs Registers/binds --prefix and forwards it to the storage service; updates description text.
tools/Azure.Mcp.Tools.Storage/src/Commands/Blob/Container/ContainerGetCommand.cs Registers/binds --prefix and forwards it to the storage service; updates description text.
tools/Azure.Mcp.Tools.Storage/src/Commands/Blob/Container/ContainerCreateCommand.cs Description formatting update.
tools/Azure.Mcp.Tools.Storage/src/Models/BlobInfo.cs Adds explicit namespace declaration.
tools/Azure.Mcp.Tools.Storage/src/Models/ContainerInfo.cs Adds explicit namespace declaration.
tools/Azure.Mcp.Tools.Storage/tests/Azure.Mcp.Tools.Storage.UnitTests/Blob/BlobGetCommandTests.cs Adds/updates unit coverage for blob get/list flows (includes prefix parsing cases).
tools/Azure.Mcp.Tools.Storage/tests/Azure.Mcp.Tools.Storage.UnitTests/Blob/Container/ContainerGetCommandTests.cs Adds/updates unit coverage for container get/list flows (includes prefix parsing cases).
tools/Azure.Mcp.Tools.Storage/tests/Azure.Mcp.Tools.Storage.UnitTests/Blob/Container/ContainerCreateCommandTests.cs Adds unit coverage for container create command.
tools/Azure.Mcp.Tools.Storage/tests/Azure.Mcp.Tools.Storage.LiveTests/StorageCommandTests.cs Adds live tests validating prefix-filtered listing for blobs and containers.
tools/Azure.Mcp.Tools.Storage/tests/Azure.Mcp.Tools.Storage.LiveTests/assets.json Updates recorded test assets tag.
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds e2e prompts for prefix-filtered listing scenarios.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Updates CLI docs to include --prefix for relevant commands.

Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix support looks clean - nice use of the SDK's native prefix: parameter. The bundled refactoring (HashSet extraction, namespace additions, description reformatting) and new test suites are welcome additions.

One behavioral note and a couple of nits inline.

@alzimmermsft alzimmermsft requested a review from a team as a code owner April 10, 2026 15:25
@alzimmermsft alzimmermsft requested a review from jongio April 10, 2026 15:28
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core prefix implementation is correct - uses the SDK's native prefix: parameter cleanly. A few things to address:

Constructor injection divergence (BlobGetCommand.cs, ContainerGetCommand.cs):
Every other command in this project resolves IStorageService from the context via context.GetService<IStorageService>() (AccountGetCommand, AccountCreateCommand, BlobUploadCommand, ContainerCreateCommand, TableListCommand). This PR switches BlobGetCommand and ContainerGetCommand to constructor injection while leaving the other five commands unchanged. Both patterns work at runtime since IStorageService is registered as a singleton, but having two patterns in the same project is confusing for contributors. The test setup also diverges - new tests pass the mock via constructor while existing tests register mocks in the service collection. I'd pick one approach and apply it consistently. If constructor injection is the direction, that's a good separate PR that converts all commands at once.

Inconsistent type qualification (StorageService.cs):
GetBlobDetails uses Storage.Models.BlobInfo (partially qualified) in its return type and list construction, but GetContainerDetails in the same file uses ContainerInfo (unqualified). Both types are in Azure.Mcp.Tools.Storage.Models and both are imported via the using directive at the top. The partial qualification is unnecessary and inconsistent - just use BlobInfo directly.

Prefix test gap (BlobGetCommandTests.cs, ContainerGetCommandTests.cs):
The prefix feature is the main deliverable of this PR, but there's no dedicated test that verifies the prefix value actually reaches the service call. The InlineData theory includes --prefix prefix cases but uses Arg.Any<string?>() for the prefix parameter, so it only verifies the command doesn't crash - not that the value is forwarded. Consider adding a test like ExecuteAsync_WithPrefix_PassesPrefixToService that passes --prefix myprefix and uses Arg.Is("myprefix") to verify the service receives it.

Minor:

  • ContainerGetCommand.cs: double blank line between the license header and the first using; blank line between namespace and class was removed. The rest of the project uses single blank line and keeps the namespace/class separator.
  • This PR bundles several unrelated changes (HashSet refactor, tenant bug fix, namespace additions, changelog script fix, description reformatting). Consider splitting out the unrelated items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants