Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
# ServiceLabel: %tools-Docker
# ServiceOwners: @conniey @microsoft/azure-mcp

# PRLabel: %tools-DocumentDb
/tools/Azure.Mcp.Tools.DocumentDb/ @xingfan-git @microsoft/azure-mcp

# ServiceLabel: %tools-DocumentDb
# ServiceOwners: @xingfan-git

# ServiceLabel: %tools-Eclipse
# ServiceOwners: @srnagar @microsoft/azure-mcp

Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.2" />
<PackageVersion Include="ModelContextProtocol" Version="1.0.0" />
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="1.0.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.2.0" />
<PackageVersion Include="MySqlConnector" Version="2.4.0" />
<PackageVersion Include="Npgsql" Version="10.0.1" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
Expand Down
11 changes: 10 additions & 1 deletion eng/scripts/New-BuildInfo.ps1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@hallipr could you review this change, as I don't know the trimmed build usage well enough and this PR is added a dependency which doesn't support trimming.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why don't we see a CI failure for this ?

Copy link
Copy Markdown
Member

@hallipr hallipr Mar 16, 2026

Choose a reason for hiding this comment

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

I think because they're disabling trimming in New-BuildInfo. We just stop trimming the server instead of failing to trim it

Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ function Get-ServerDetails {
$version.PrereleaseNumber = $BuildId
}

# Check if this server depends on MongoDB.Driver (incompatible with IL trimming)
$projectContent = Get-Content $serverProject.FullName -Raw
$hasMongoDbDependency = $projectContent -match 'tools.+Azure\..+\.csproj'

if ($hasMongoDbDependency) {
Write-Host "Server $serverName depends on DocumentDb (with MongoDB.Driver) - trimming will be disabled" -ForegroundColor Yellow
}

# Calculate VSIX version based on server version
$vsixVersion = $null
$vsixIsPrerelease = $false
Expand Down Expand Up @@ -473,7 +481,8 @@ function Get-ServerDetails {
architecture = $arch
extension = $os.extension
native = $false
trimmed = $true
# Disable trimming for servers with MongoDB.Driver dependency (uses extensive reflection)
trimmed = !$hasMongoDbDependency
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions servers/Azure.Mcp.Server/Azure.Mcp.Server.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
<Project Path="../../tools/Azure.Mcp.Tools.Deploy/tests/Azure.Mcp.Tools.Deploy.LiveTests/Azure.Mcp.Tools.Deploy.LiveTests.csproj" />
<Project Path="../../tools/Azure.Mcp.Tools.Deploy/tests/Azure.Mcp.Tools.Deploy.UnitTests/Azure.Mcp.Tools.Deploy.UnitTests.csproj" />
</Folder>
<Folder Name="/tools/Azure.Mcp.Tools.DocumentDb/" />
<Folder Name="/tools/Azure.Mcp.Tools.DocumentDb/src/">
<Project Path="../../tools/Azure.Mcp.Tools.DocumentDb/src/Azure.Mcp.Tools.DocumentDb.csproj" />
</Folder>
<Folder Name="/tools/Azure.Mcp.Tools.DocumentDb/tests/">
<Project Path="../../tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.LiveTests/Azure.Mcp.Tools.DocumentDb.LiveTests.csproj" />
<Project Path="../../tools/Azure.Mcp.Tools.DocumentDb/tests/Azure.Mcp.Tools.DocumentDb.UnitTests/Azure.Mcp.Tools.DocumentDb.UnitTests.csproj" />
</Folder>
<Folder Name="/tools/Azure.Mcp.Tools.EventGrid/" />
<Folder Name="/tools/Azure.Mcp.Tools.EventGrid/src/">
<Project Path="../../tools/Azure.Mcp.Tools.EventGrid/src/Azure.Mcp.Tools.EventGrid.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions servers/Azure.Mcp.Server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The Azure MCP Server updates automatically by default whenever a new release com
- prompt_optimize: Optimize a prompt for a specific model
- Added `eng/scripts/Preflight.ps1` developer CI preflight check script with format, spelling, build, tool metadata, README validation, unit test, and AOT analysis steps. [[#1893](https://github.com/microsoft/mcp/pull/1893)]
- Added tools for web app diagnostics. [[#1907](https://github.com/microsoft/mcp/pull/1907)]
- Added DocumentDB tools for managing Azure DocumentDB (with MongoDB compatibility) connection: [[#1968](https://github.com/microsoft/mcp/pull/1968)]
- **Connection** tools (3): Connect, Disconnect, GetConnectionStatus

### Breaking Changes

Expand Down
5 changes: 5 additions & 0 deletions servers/Azure.Mcp.Server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ Example prompts that generate Azure CLI commands:
* "Get Azure Data Explorer databases in cluster 'mycluster'"
* "Sample 10 rows from table 'StormEvents' in Azure Data Explorer database 'db1'"

### 🗄️ Azure DocumentDB (with MongoDB compatibility)

* "Connect to/Disconnect from my DocumentDB instance"
* "Show me the DocumentDB connection status"

### 📣 Azure Event Grid

* "List all Event Grid topics in subscription 'my-subscription'"
Expand Down
3 changes: 3 additions & 0 deletions servers/Azure.Mcp.Server/changelog-entries/1773035723557.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changes:
- section: "Features Added"
description: "Added DocumentDB tools for managing Azure DocumentDB (with MongoDB compatibility) connection"
3 changes: 3 additions & 0 deletions servers/Azure.Mcp.Server/changelog-entries/1773043407868.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changes:
- section: "Features Added"
description: "MCP tools for managing Azure DocumentDB (with MongoDB compatibility) connection"
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

There are two duplicate changelog YAML entries (1773043407868.yaml and 1773035723557.yaml) that both describe the same feature: "MCP tools for managing Azure DocumentDB connection". Only one entry should exist for a single PR. The duplicate should be removed to avoid generating duplicate entries in CHANGELOG.md.

Copilot uses AI. Check for mistakes.
20 changes: 20 additions & 0 deletions servers/Azure.Mcp.Server/docs/azmcp-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,26 @@ azmcp deploy plan get --workspace-folder <workspace-folder> \
[--azd-iac-options <azd-iac-options>]
```

### Azure DocumentDB (with MongoDB compatibility) Operations

```bash
# Connection Management

# Connect to an Azure Cosmos DB for MongoDB (vCore) instance
# ❌ Destructive | ❌ Idempotent | ✅ OpenWorld | ❌ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb connection toggle --action connect --connection-string <connection-string> \
[--test-connection <true|false>]

# Disconnect from the current DocumentDB instance
# ❌ Destructive | ❌ Idempotent | ✅ OpenWorld | ❌ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb connection toggle --action disconnect


# Get the current DocumentDB connection status and details
# ❌ Destructive | ❌ Idempotent | ✅ OpenWorld | ✅ ReadOnly | ❌ Secret | ❌ LocalRequired
azmcp documentdb connection get connection status
```

### Azure Event Grid Operations

```bash
Expand Down
9 changes: 9 additions & 0 deletions servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ This file contains prompts used for end-to-end testing to ensure each tool is in
| deploy_pipeline_guidance_get | How can I create a CI/CD pipeline to deploy this app to Azure? |
| deploy_plan_get | Create a plan to deploy this application to azure |

## Azure DocumentDB (with MongoDB compatibility)

| Tool Name | Test Prompt |
|:----------|:----------|
| documentdb_connection_toggle | Connect to my DocumentDB instance using <connection-string> |
| documentdb_connection_toggle | Close the DocumentDB connection |
| documentdb_connection_get_connection_status | Show me the DocumentDB connection status |
| documentdb_connection_get_connection_status | Is DocumentDB connected? |

## Azure Event Grid

| Tool Name | Test Prompt |
Expand Down
1 change: 1 addition & 0 deletions servers/Azure.Mcp.Server/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private static IAreaSetup[] RegisterAreas()
new Azure.Mcp.Tools.AzureMigrate.AzureMigrateSetup(),
new Azure.Mcp.Tools.AzureTerraformBestPractices.AzureTerraformBestPracticesSetup(),
new Azure.Mcp.Tools.Deploy.DeploySetup(),
new Azure.Mcp.Tools.DocumentDb.DocumentDbSetup(),
new Azure.Mcp.Tools.EventGrid.EventGridSetup(),
new Azure.Mcp.Tools.Acr.AcrSetup(),
new Azure.Mcp.Tools.Advisor.AdvisorSetup(),
Expand Down
66 changes: 66 additions & 0 deletions servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,72 @@
"cosmos_database_container_item_query"
]
},
{
"name": "get_azure_database_connection_status",
"description": "Check whether there is an active Azure DocumentDB session and return the current connection state plus masked connection details for Azure Cosmos DB for MongoDB (vCore).",
"toolMetadata": {
"destructive": {
"value": false,
"description": "This tool performs only additive updates without deleting or modifying existing resources."
},
"idempotent": {
"value": false,
"description": "Running this operation multiple times with the same arguments may have additional effects or produce different results."
},
"openWorld": {
"value": true,
"description": "This tool may interact with an unpredictable or dynamic set of entities (like web search)."
},
"readOnly": {
"value": true,
"description": "This tool only performs read operations without modifying any state or data."
},
"secret": {
"value": false,
"description": "This tool does not handle sensitive or secret information."
},
"localRequired": {
"value": false,
"description": "This tool is available in both local and remote server modes."
}
},
"mappedToolList": [
"documentdb_connection_get_connection_status"
]
},
{
"name": "manage_azure_documentdb_connections",
"description": "Open, connect, switch, close, or disconnect Azure DocumentDB sessions. Use a connection string to start or change the active Azure Cosmos DB for MongoDB (vCore) session before subsequent DocumentDB operations.",
"toolMetadata": {
"destructive": {
"value": false,
"description": "This tool performs only additive updates without deleting or modifying existing resources."
},
"idempotent": {
"value": false,
"description": "Running this operation multiple times with the same arguments may have additional effects or produce different results."
},
"openWorld": {
"value": true,
"description": "This tool may interact with an unpredictable or dynamic set of entities (like web search)."
},
"readOnly": {
"value": false,
"description": "This tool may modify its environment and perform write operations (create, update, delete)."
},
"secret": {
"value": false,
"description": "This tool does not handle sensitive or secret information."
},
Comment on lines +239 to +242
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The manage_azure_documentdb_connections consolidated tool entry has "secret": { "value": false } with description "This tool does not handle sensitive or secret information." However, this tool accepts a connection string as input, which typically contains credentials (username and password). The secret flag should be true to signal that this tool handles sensitive data.

Copilot uses AI. Check for mistakes.
"localRequired": {
"value": false,
"description": "This tool is available in both local and remote server modes."
}
},
"mappedToolList": [
"documentdb_connection_toggle"
]
},
{
"name": "create_azure_sql_databases_and_servers",
"description": "Create new Azure SQL databases and SQL servers with configurable performance tiers and settings.",
Expand Down
6 changes: 6 additions & 0 deletions tools/Azure.Mcp.Tools.DocumentDb/src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Azure.Mcp.Tools.DocumentDb.UnitTests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsAotCompatible>true</IsAotCompatible>
<!-- Disable trim analyzer warnings for MongoDB.Driver which uses extensive reflection -->
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\Resources\*.txt" />
<EmbeddedResource Include="**\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.ResourceManager" />
<PackageReference Include="MongoDB.Driver" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="ModelContextProtocol" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Azure.Mcp.Core.Commands;
using Azure.Mcp.Tools.DocumentDb.Options;

namespace Azure.Mcp.Tools.DocumentDb.Commands;

public abstract class BaseDocumentDbCommand<
[DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TOptions>
: GlobalCommand<TOptions> where TOptions : BaseDocumentDbOptions, new()
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.CommandLine;
using Azure.Mcp.Core.Commands;
using Azure.Mcp.Core.Extensions;
using Azure.Mcp.Tools.DocumentDb.Options;
using Azure.Mcp.Tools.DocumentDb.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;

namespace Azure.Mcp.Tools.DocumentDb.Commands.Connection;

public sealed class ConnectionToggleCommand(ILogger<ConnectionToggleCommand> logger)
: BaseDocumentDbCommand<ConnectionToggleOptions>()
{
private const string ConnectAction = "connect";
private const string DisconnectAction = "disconnect";

private readonly ILogger<ConnectionToggleCommand> _logger = logger;

public override string Id => "a1b2c3d4-e5f6-4a1b-8c9d-0e1f2a3b4c5d";

public override string Name => "toggle";

public override string Description => "Open, connect, switch, close, or disconnect the active Azure DocumentDB session for Azure Cosmos DB for MongoDB (vCore). Use this when the user wants to connect with a connection string, reconnect to a different cluster, or end the current DocumentDB session before running database commands.";

public override string Title => "Connect or disconnect DocumentDB";

public override ToolMetadata Metadata => new()
{
Destructive = false,
ReadOnly = false
};

protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(DocumentDbOptionDefinitions.Action);
command.Options.Add(DocumentDbOptionDefinitions.ConnectionString);
command.Options.Add(DocumentDbOptionDefinitions.TestConnection);
command.Validators.Add(commandResult =>
{
var action = commandResult.GetValueOrDefault(DocumentDbOptionDefinitions.Action);
var connectionString = commandResult.GetValueOrDefault(DocumentDbOptionDefinitions.ConnectionString);

if (string.Equals(action, ConnectAction, StringComparison.OrdinalIgnoreCase)
&& string.IsNullOrWhiteSpace(connectionString))
{
commandResult.AddError($"Missing Required option: {DocumentDbOptionDefinitions.ConnectionString.Name}");
}
});
}

protected override ConnectionToggleOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.Action = parseResult.GetValueOrDefault<string>(DocumentDbOptionDefinitions.Action.Name);
options.ConnectionString = parseResult.GetValueOrDefault<string>(DocumentDbOptionDefinitions.ConnectionString.Name);
options.TestConnection = parseResult.GetValueOrDefault<bool>(DocumentDbOptionDefinitions.TestConnection.Name);
return options;
}

public override async Task<CommandResponse> ExecuteAsync(
CommandContext context,
ParseResult parseResult,
CancellationToken cancellationToken)
{
var options = BindOptions(parseResult);

try
{
if (!Validate(parseResult.CommandResult, context.Response).IsValid)
{
return context.Response;
}

var service = context.GetService<IDocumentDbService>();

var result = options.Action switch
{
ConnectAction => await service.ConnectAsync(options.ConnectionString!, options.TestConnection, cancellationToken),
DisconnectAction => await service.DisconnectAsync(cancellationToken),
_ => throw new InvalidOperationException($"Unsupported connection action '{options.Action}'.")
};

DocumentDbResponseHelper.ProcessResponse(context, result);

return context.Response;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to execute DocumentDB connection action {Action}", options.Action);
HandleException(context, ex);
return context.Response;
}
}
}
Loading
Loading