-
Notifications
You must be signed in to change notification settings - Fork 436
[Onboard][Part One] Mcp Server for Azure DocumentDB (Index) #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
1edc300
1f5ff7e
2442f7d
ba35d97
08efc55
2c11d8c
383acaf
9599980
bb42d4a
2fe4f1c
6088353
c6fe9f7
225d9a3
b084426
6bd0d18
08d80c5
9e0b67d
ccea698
cdbc996
5ac4fc9
14dec4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" |
| 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" | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| "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.", | ||
|
|
||
| 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."; | ||
xingfan-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public override string Title => "Connect or disconnect DocumentDB"; | ||
|
|
||
| public override ToolMetadata Metadata => new() | ||
| { | ||
| Destructive = false, | ||
| ReadOnly = false | ||
| }; | ||
xingfan-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
xingfan-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
| } | ||
xingfan-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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}'.") | ||
xingfan-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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