-
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 all 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 |
|---|---|---|
|
|
@@ -170,6 +170,53 @@ function CheckVariable($name) { | |
| return $value | ||
| } | ||
|
|
||
| function Test-ProjectUsesMongoDbDriver { | ||
| param( | ||
| [string] $ProjectPath | ||
| ) | ||
|
|
||
| if (!(Test-Path $ProjectPath)) { | ||
| return $false | ||
| } | ||
|
|
||
| $projectContent = Get-Content $ProjectPath -Raw | ||
| return $projectContent -match '<PackageReference\s+Include="MongoDB\.Driver"' | ||
| } | ||
|
|
||
| function Test-ServerHasMongoDbDependency { | ||
| param( | ||
| [System.IO.FileInfo] $ServerProject | ||
| ) | ||
|
|
||
| $serverProjectDirectory = Split-Path $ServerProject.FullName -Parent | ||
| $serverProjectContent = Get-Content $ServerProject.FullName -Raw | ||
| $projectReferenceMatches = [regex]::Matches($serverProjectContent, '<ProjectReference\s+Include="([^"]+)"') | ||
|
|
||
| foreach ($projectReferenceMatch in $projectReferenceMatches) { | ||
| $projectReference = $projectReferenceMatch.Groups[1].Value | ||
| if (-not $projectReference) { | ||
| continue | ||
| } | ||
|
|
||
| $expandedReference = $projectReference.Replace('$(RepoRoot)', $RepoRoot) | ||
| $expandedReference = $expandedReference.Replace('$(MSBuildThisFileDirectory)', "$serverProjectDirectory/") | ||
| $expandedReference = $expandedReference.Replace('\', '/') | ||
|
|
||
| if (-not [System.IO.Path]::IsPathRooted($expandedReference)) { | ||
| $expandedReference = (Join-Path $serverProjectDirectory $expandedReference).Replace('\', '/') | ||
| } | ||
|
|
||
| $referencedProjects = @(Get-ChildItem -Path $expandedReference -File -ErrorAction SilentlyContinue) | ||
| foreach ($referencedProject in $referencedProjects) { | ||
| if (Test-ProjectUsesMongoDbDriver -ProjectPath $referencedProject.FullName) { | ||
| return $true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $false | ||
| } | ||
|
|
||
| $windowsPool = CheckVariable 'WINDOWSPOOL' | ||
| $linuxPool = CheckVariable 'LINUXPOOL' | ||
| $linuxArm64Pool = CheckVariable 'LINUXARM64POOL' | ||
|
|
@@ -387,6 +434,13 @@ function Get-ServerDetails { | |
| $version.PrereleaseNumber = $BuildId | ||
| } | ||
|
|
||
| # Check if this server depends on MongoDB.Driver (incompatible with IL trimming) | ||
| $hasMongoDbDependency = Test-ServerHasMongoDbDependency -ServerProject $serverProject | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a odd place to put this test. If we know a server shouldn't be trimmed, we should just add a property to the project file like |
||
|
|
||
| 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 | ||
|
|
@@ -473,7 +527,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 | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -498,7 +553,7 @@ function Get-ServerDetails { | |
| architecture = $additionalPlatform.architecture | ||
| extension = $os.extension | ||
| native = $additionalPlatform.native | ||
| trimmed = $additionalPlatform.trimmed | ||
| trimmed = $additionalPlatform.trimmed -and !$hasMongoDbDependency | ||
| specialPurpose = $additionalPlatform.specialPurpose | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| pr: 1968 | ||
| changes: | ||
| - section: "Features Added" | ||
| description: "Added mcp tools for managing Azure DocumentDB (with MongoDB compatibility) index" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,75 @@ | |
| "cosmos_database_container_item_query" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "inspect_azure_documentdb_indexes_and_diagnostics", | ||
| "description": "Inspect Azure DocumentDB collection indexes, index statistics, and current operations by supplying a connection string for each request.", | ||
| "toolMetadata": { | ||
| "destructive": { | ||
| "value": false, | ||
| "description": "This tool performs only additive updates without deleting or modifying existing resources." | ||
| }, | ||
| "idempotent": { | ||
| "value": true, | ||
| "description": "Running this operation multiple times with the same arguments produces the same result without additional effects." | ||
| }, | ||
| "openWorld": { | ||
| "value": false, | ||
| "description": "This tool's domain of interaction is closed and well-defined, limited to a specific set of entities (like memory access)." | ||
| }, | ||
| "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_index_list_indexes", | ||
| "documentdb_index_index_stats", | ||
| "documentdb_index_current_ops" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "manage_azure_documentdb_indexes", | ||
| "description": "Create or drop indexes in Azure DocumentDB collections by supplying a connection string for each request.", | ||
| "toolMetadata": { | ||
| "destructive": { | ||
| "value": true, | ||
| "description": "This tool may delete or modify existing resources in its environment." | ||
| }, | ||
| "idempotent": { | ||
| "value": false, | ||
| "description": "Running this operation multiple times with the same arguments may have additional effects or produce different results." | ||
| }, | ||
| "openWorld": { | ||
| "value": false, | ||
| "description": "This tool's domain of interaction is closed and well-defined, limited to a specific set of entities (like memory access)." | ||
| }, | ||
| "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_index_create_index", | ||
| "documentdb_index_drop_index" | ||
| ] | ||
| }, | ||
| { | ||
| "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,29 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.CommandLine; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Azure.Mcp.Core.Commands; | ||
| using Azure.Mcp.Core.Extensions; | ||
| 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() | ||
| { | ||
| protected override void RegisterOptions(Command command) | ||
| { | ||
| base.RegisterOptions(command); | ||
| command.Options.Add(DocumentDbOptionDefinitions.ConnectionString); | ||
| } | ||
|
|
||
| protected override TOptions BindOptions(ParseResult parseResult) | ||
| { | ||
| return new TOptions | ||
| { | ||
| ConnectionString = parseResult.GetValueOrDefault<string>(DocumentDbOptionDefinitions.ConnectionString.Name) | ||
| }; | ||
| } | ||
| } |
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