[Onboard][Part Two] Mcp Server for Azure DocumentDB (Database)#2048
[Onboard][Part Two] Mcp Server for Azure DocumentDB (Database)#2048xingfan-git wants to merge 25 commits intomainfrom
Conversation
There was a problem hiding this comment.
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. |
tools/Azure.Mcp.Tools.DocumentDb/src/Commands/DocumentDbOptionDefinitions.cs
Show resolved
Hide resolved
…/github.com/microsoft/mcp into users/xingfan/onboardingvcoremcp_database
|
|
||
| # Get index statistics for a collection | ||
| # ❌ Destructive | ✅ Idempotent | ❌ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired | ||
| azmcp documentdb index index stats --connection-string <connection-string> \ |
There was a problem hiding this comment.
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.
| 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> \ |
There was a problem hiding this comment.
If there aren't other concepts that will be put in the current grouping, current-ops would be a better command name.
| 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> \ |
There was a problem hiding this comment.
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).
| 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> \ |
There was a problem hiding this comment.
| 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> \ |
There was a problem hiding this comment.
| 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> \ |
There was a problem hiding this comment.
| 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; |
There was a problem hiding this comment.
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!; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Don't use _ for command names, this breaks the group name contract elsewhere as _ is the delimiter between parent and child groups.
| 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}"); | ||
| } |
There was a problem hiding this comment.
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.
What does this PR do?
This PR added MCP tools for managing Azure DocumentDB (with MongoDB compatibility) database. It implements:
dbnamespecified, otherwise provide certain database details)[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
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabel/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline