Skip to content

[Onboard][Part Two] Mcp Server for Azure DocumentDB (Database)#2048

Open
xingfan-git wants to merge 25 commits intomainfrom
users/xingfan/onboardingvcoremcp_database
Open

[Onboard][Part Two] Mcp Server for Azure DocumentDB (Database)#2048
xingfan-git wants to merge 25 commits intomainfrom
users/xingfan/onboardingvcoremcp_database

Conversation

@xingfan-git
Copy link

@xingfan-git xingfan-git commented Mar 15, 2026

What does this PR do?

This PR added MCP tools for managing Azure DocumentDB (with MongoDB compatibility) database. It implements:

  • List Databases (list all databases if no dbname specified, otherwise provide certain database details)
  • GetDbStats
  • Dropdatabase

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

Documentation:

Azure DocumentDB (with MongoDB compatibility) documentation

GitHub issue number?

[MCP Server Request] DocumentDB previously known as Azure Cosmos DB for MongoDB (vCore)

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 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 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 onboards a new Azure MCP tool area for Azure DocumentDB (MongoDB vCore compatibility), adding index, diagnostics, and database-management commands, along with docs/test infrastructure and build/publishing adjustments for the MongoDB driver dependency.

Changes:

  • Added DocumentDB tool implementation (commands, options, service) for index/ops and database operations.
  • Added unit tests, live tests, and test resource deployment scripts for DocumentDB.
  • Updated Azure MCP Server registration, consolidated tool mappings, docs, changelog entries, and build info generation (trimming behavior) to accommodate MongoDB.Driver.

Reviewed changes

Copilot reviewed 53 out of 53 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.DocumentDb/tests/test-resources.bicep Deploys DocumentDB Mongo cluster + firewall rules and outputs connection details for live tests.
tools/Azure.Mcp.Tools.DocumentDb/tests/test-resources-post.ps1 Writes .testsettings.json and optionally initializes test DB/collection via mongosh.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Index/ListIndexesCommandTests.cs Unit tests for list-indexes command behavior.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Index/IndexStatsCommandTests.cs Unit tests for index-stats command behavior.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Index/DropIndexCommandTests.cs Unit tests for drop-index command behavior.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Index/CurrentOpsCommandTests.cs Unit tests for current-ops command behavior.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Index/CreateIndexCommandTests.cs Unit tests for create-index command behavior.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Database/ListDatabasesCommandTests.cs Unit tests for listing/inspecting databases.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Database/DropDatabaseCommandTests.cs Unit tests for dropping a database.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Database/DbStatsCommandTests.cs Unit tests for database stats retrieval.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Azure.Mcp.Tools.DocumentDb.UnitTests.csproj Adds new unit test project for DocumentDB tool.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.LiveTests/assets.json Recorded-test assets metadata file for live tests project.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.LiveTests/DocumentDbCommandTests.cs Live tests invoking MCP tools against deployed DocumentDB resources.
tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.LiveTests/Azure.Mcp.Tools.DocumentDb.LiveTests.csproj Adds new live test project for DocumentDB tool.
tools/Azure.Mcp.Tools.DocumentDb/src/Services/IDocumentDbService.cs Defines service contract for DocumentDB operations.
tools/Azure.Mcp.Tools.DocumentDb/src/Services/DocumentDbService.cs Implements MongoDB driver-based operations and response shaping.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/ListIndexesOptions.cs Options model for list-indexes command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/ListDatabasesOptions.cs Options model for list-databases command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/IndexStatsOptions.cs Options model for index-stats command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/DropIndexOptions.cs Options model for drop-index command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/DropDatabaseOptions.cs Options model for drop-database command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/DbStatsOptions.cs Options model for db-stats command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/CurrentOpsOptions.cs Options model for current-ops command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/CreateIndexOptions.cs Options model for create-index command.
tools/Azure.Mcp.Tools.DocumentDb/src/Options/BaseDocumentDbOptions.cs Base options containing connection-string input.
tools/Azure.Mcp.Tools.DocumentDb/src/Models/DocumentDbResponse.cs Unified service response model.
tools/Azure.Mcp.Tools.DocumentDb/src/GlobalUsings.cs Adds global using for System.CommandLine.
tools/Azure.Mcp.Tools.DocumentDb/src/DocumentDbSetup.cs Registers DocumentDB area, DI services, and command groups.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Index/ListIndexesCommand.cs MCP command wiring for listing indexes.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Index/IndexStatsCommand.cs MCP command wiring for index statistics.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Index/DropIndexCommand.cs MCP command wiring for dropping indexes.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Index/CurrentOpsCommand.cs MCP command wiring for current operations.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Index/CreateIndexCommand.cs MCP command wiring for creating indexes.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/DocumentDbOptionDefinitions.cs Central CLI option definitions for the tool.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/DocumentDbJsonContext.cs System.Text.Json source-gen context + response helpers.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/DocumentDbHelpers.cs Parsing/serialization helpers for BSON/JSON inputs.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Database/ListDatabasesCommand.cs MCP command wiring for listing/inspecting databases.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Database/DropDatabaseCommand.cs MCP command wiring for dropping databases.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/Database/DbStatsCommand.cs MCP command wiring for database stats.
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/BaseDocumentDbCommand.cs Base command wiring for shared connection-string option binding.
tools/Azure.Mcp.Tools.DocumentDb/src/Azure.Mcp.Tools.DocumentDb.csproj Adds tool project and MongoDB.Driver dependency (trim analyzer disabled).
tools/Azure.Mcp.Tools.DocumentDb/src/AssemblyInfo.cs Exposes internals to unit test assembly.
servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json Adds consolidated tool groupings mapping to new DocumentDB tools.
servers/Azure.Mcp.Server/src/Program.cs Registers DocumentDbSetup area in server startup.
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds E2E prompts for DocumentDB tools.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Documents azmcp CLI usage for DocumentDB commands.
servers/Azure.Mcp.Server/changelog-entries/1773579786664.yaml Adds changelog entry for DocumentDB database tools.
servers/Azure.Mcp.Server/changelog-entries/1773124572664.yaml Adds changelog entry for DocumentDB index tools (currently malformed).
servers/Azure.Mcp.Server/README.md Adds example prompts for DocumentDB tools.
servers/Azure.Mcp.Server/Azure.Mcp.Server.slnx Adds DocumentDB tool projects to the Azure server solution structure.
eng/scripts/New-BuildInfo.ps1 Adjusts build_info generation to disable trimming when MongoDB.Driver is detected.
Directory.Packages.props Adds central package version for MongoDB.Driver.
.github/CODEOWNERS Adds code owners for the new DocumentDB tool area.


# Get index statistics for a collection
# ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb index index stats --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

index index stats is a bit odd, should this just be index stats? index index-stats would also be more preferable to index index stats as well.

Suggested change
azmcp documentdb index index stats --connection-string <connection-string> \
azmcp documentdb index stats --connection-string <connection-string> \


# Get current DocumentDB operations
# ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb index current ops --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

If there aren't other concepts that will be put in the current grouping, current-ops would be a better command name.

Suggested change
azmcp documentdb index current ops --connection-string <connection-string> \
azmcp documentdb index current-ops --connection-string <connection-string> \


# Drop a database
# ✅ Destructive | ❌ Idempotent | ❌ OpenWorld | ❌ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb database drop database --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use database drop, we don't need the second database word. And if there are concepts under database that can also be dropped, when adding those in the future use database <resource>... drop (where ... could be sub-sub resources).

Suggested change
azmcp documentdb database drop database --connection-string <connection-string> \
azmcp documentdb database drop --connection-string <connection-string> \


# Get statistics for a database
# ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb database db stats --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
azmcp documentdb database db stats --connection-string <connection-string> \
azmcp documentdb database stats --connection-string <connection-string> \

Don't really need db as it isn't adding anything as we already know we're targeting a database from the database group.

```bash
# List all indexes on a collection
# ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb index list indexes --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
azmcp documentdb index list indexes --connection-string <connection-string> \
azmcp documentdb index list --connection-string <connection-string> \

Don't need indexes again, we already know we're targeting indexes as we're in the index group and this is a root command in that group.

Also, optionally, call this command get and make collection-name optional to allow listing many indexes or getting an individual index. This is a common pattern throughout the commands in this repo to reduce the number of tools we have.


# List all databases or inspect a single database
# ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb database list databases --connection-string <connection-string> \
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
azmcp documentdb database list databases --connection-string <connection-string> \
azmcp documentdb database get --connection-string <connection-string> \

Given this command already has db-name as optional rename it to get.

ParseResult parseResult,
CancellationToken cancellationToken)
{
DbStatsOptions? options = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

For all commands, as I see this has been repeated in this PR, call Validate and BindOptions outside the try/catch block and inline this variable declaration when calling BindOptions. Those methods shouldn't be throwing exceptions, and if they are this pattern doesn't really help anything.

}

options = BindOptions(parseResult);
var dbName = options.DbName!;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason this isn't being done when calling GetDatabaseStatsAsync? This variable isn't used anywhere else.


public override string Id => "e5f6a7b8-c9d0-4e5f-2a3b-4c5d6e7f8a9b";

public override string Name => "db_stats";
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use _ for command names, this breaks the group name contract elsewhere as _ is the delimiter between parent and child groups.

Comment on lines +45 to +64
catch (MongoCommandException ex) when (ex.Code == 26)
{
_logger.LogWarning("Database '{DatabaseName}' not found", databaseName);
return Failure(HttpStatusCode.BadRequest, $"Database '{databaseName}' not found");
}
catch (MongoCommandException ex) when (ex.CodeName == "NamespaceNotFound")
{
_logger.LogWarning("Collection '{CollectionName}' not found in database '{DatabaseName}'", collectionName, databaseName);
return Failure(HttpStatusCode.BadRequest, $"Collection '{collectionName}' not found");
}
catch (MongoAuthenticationException ex)
{
_logger.LogWarning(ex, "Unauthorized access creating index on {DatabaseName}.{CollectionName}", databaseName, collectionName);
return Failure(HttpStatusCode.Unauthorized, $"Unauthorized access: {ex.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error creating index on {DatabaseName}.{CollectionName}", databaseName, collectionName);
return Failure(HttpStatusCode.InternalServerError, $"Failed to create index: {ex.Message}");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How does Failure get handled later one? It seems these catch statements may make it more difficult to troubleshoot the underlying problem as they hide the causal exception in some cases. It may be better to remove them and just let the exception exit out and be handled further up the call stack which can send more details back to the agent / user.

@alzimmermsft alzimmermsft added the Do Not Merge Do Not Merge / WIP PRs label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge Do Not Merge / WIP PRs

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants