Skip to content

Conversation

@anuchandy
Copy link
Member

What does this PR do?

[Provide a clear, concise description of the changes]

The .NET DI container prefers DisposeAsync() during shutdown, pr Implement IAsyncDisposable in CosmosService. Following https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync

Fixes: #1148

[Any additional context, screenshots, or information that helps reviewers]

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
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • 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 using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • 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 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 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
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

This PR implements IAsyncDisposable in CosmosService to fix an anti-pattern where the Dispose() method was implemented as async void, which prevented callers from awaiting the disposal operation. The implementation follows the Microsoft async disposal pattern guidelines for sealed classes.

Changes:

  • Added IAsyncDisposable to the ICosmosService interface and CosmosService class
  • Replaced the async void Dispose(bool disposing) method with a proper DisposeAsyncCore() implementation
  • Added DisposeAsync() method that properly implements the async disposal pattern
  • Modified synchronous Dispose() to call the async core method synchronously

Reviewed changes

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

File Description
tools/Azure.Mcp.Tools.Cosmos/src/Services/ICosmosService.cs Added IAsyncDisposable interface to ICosmosService
tools/Azure.Mcp.Tools.Cosmos/src/Services/CosmosService.cs Implemented async disposal pattern with DisposeAsyncCore(), DisposeAsync(), and updated Dispose() methods; marked class as sealed
servers/Azure.Mcp.Server/changelog-entries/1768937539777.yaml Added changelog entry documenting the bug fix

@joshfree joshfree moved this from Untriaged to Not Started in Azure MCP Server Jan 20, 2026
@joshfree joshfree added this to the 2026-01 milestone Jan 20, 2026
@joshfree joshfree moved this from Not Started to In Progress in Azure MCP Server Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[BUG] ICosmosService should implement IAsyncDisposable instead of IDisposable

2 participants