feat(cosmos): Add container copy job commands (copyJobs API)#2098
Open
niteshvijay1995 wants to merge 2 commits intomicrosoft:mainfrom
Open
feat(cosmos): Add container copy job commands (copyJobs API)#2098niteshvijay1995 wants to merge 2 commits intomicrosoft:mainfrom
niteshvijay1995 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Add 7 new MCP commands under 'cosmos copyjob' group for managing Cosmos DB container copy jobs via the copyJobs ARM REST API (Microsoft.DocumentDB/databaseAccounts/copyJobs). Commands: - cosmos_copyjob_create: Create a new copy job - cosmos_copyjob_get: Get job status and progress - cosmos_copyjob_list: List all copy jobs on an account - cosmos_copyjob_cancel: Cancel a running/pending job - cosmos_copyjob_pause: Pause a running job - cosmos_copyjob_resume: Resume a paused job - cosmos_copyjob_complete: Complete an Online copy job Supports all 6 job types (NoSqlRUToNoSqlRU, CassandraRUToCassandraRU, MongoRUToMongoRU, MongoRUToMongoVCore, CassandraRUToAzureBlobStorage, AzureBlobStorageToCassandraRU), multi-task jobs, and Offline/Online modes. Uses direct ARM REST API calls for portability across SDK versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Cosmos tool surface area (cosmos copyjob) to manage Cosmos DB container copy jobs via the ARM Microsoft.DocumentDB/databaseAccounts/copyJobs REST API, and wires those commands into the Cosmos tool + consolidated tool mapping.
Changes:
- Introduces
ICopyJobService+CopyJobServicefor ARM copyJobs CRUD/action calls (create/get/list + cancel/pause/resume/complete). - Adds 7 new
cosmos copyjobcommands and their option models + JSON source-gen context types. - Registers the new service/commands in
CosmosSetupand maps them inconsolidated-tools.json.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Cosmos/src/Services/ICopyJobService.cs | New service interface for copy job operations. |
| tools/Azure.Mcp.Tools.Cosmos/src/Services/CopyJobService.cs | ARM REST implementation for create/get/list and action endpoints. |
| tools/Azure.Mcp.Tools.Cosmos/src/Options/CosmosOptionDefinitions.cs | Adds --job-name, --job-properties, --mode, --worker-count options. |
| tools/Azure.Mcp.Tools.Cosmos/src/Options/CopyJobOptions.cs | Base options model for copy job commands. |
| tools/Azure.Mcp.Tools.Cosmos/src/Options/CopyJobCreateOptions.cs | Create-specific options model (jobProperties, mode, workerCount). |
| tools/Azure.Mcp.Tools.Cosmos/src/CosmosSetup.cs | Registers copy job service + commands; adds copyjob command subgroup. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CosmosJsonContext.cs | Adds JSON source-gen types for copy job results. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/BaseCopyJobCommand.cs | Shared command base adding --account + --job-name. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobCreateCommand.cs | cosmos copyjob create command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobGetCommand.cs | cosmos copyjob get command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobListCommand.cs | cosmos copyjob list command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobCancelCommand.cs | cosmos copyjob cancel command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobPauseCommand.cs | cosmos copyjob pause command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobResumeCommand.cs | cosmos copyjob resume command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobCompleteCommand.cs | cosmos copyjob complete command implementation. |
| tools/Azure.Mcp.Tools.Cosmos/src/Commands/CopyJob/CopyJobResults.cs | Result record types for copy job responses. |
| servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json | Adds a consolidated tool entry mapping the 7 new commands. |
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Net; |
Comment on lines
+99
to
+104
| // Parse and validate the job properties JSON | ||
| JsonElement jobProps; | ||
| try | ||
| { | ||
| jobProps = JsonDocument.Parse(jobPropertiesJson).RootElement; | ||
| } |
Comment on lines
+133
to
+142
| var response = await client.PutAsync(url, new StringContent(body, Encoding.UTF8, "application/json"), cancellationToken); | ||
| var responseBody = await response.Content.ReadAsStringAsync(cancellationToken); | ||
|
|
||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| throw new HttpRequestException($"Failed to create copy job (HTTP {(int)response.StatusCode}): {responseBody}"); | ||
| } | ||
|
|
||
| return JsonDocument.Parse(responseBody).RootElement; | ||
| } |
Comment on lines
21
to
+33
| services.AddSingleton<ICosmosService, CosmosService>(); | ||
| services.AddSingleton<ICopyJobService, CopyJobService>(); | ||
|
|
||
| services.AddSingleton<CosmosListCommand>(); | ||
| services.AddSingleton<ItemQueryCommand>(); | ||
|
|
||
| services.AddSingleton<CopyJobCreateCommand>(); | ||
| services.AddSingleton<CopyJobGetCommand>(); | ||
| services.AddSingleton<CopyJobListCommand>(); | ||
| services.AddSingleton<CopyJobCancelCommand>(); | ||
| services.AddSingleton<CopyJobPauseCommand>(); | ||
| services.AddSingleton<CopyJobResumeCommand>(); | ||
| services.AddSingleton<CopyJobCompleteCommand>(); |
| { | ||
| var accessToken = await GetArmAccessTokenAsync(tenant, cancellationToken); | ||
|
|
||
| var client = new HttpClient(); |
Comment on lines
+200
to
+206
| var doc = JsonDocument.Parse(responseBody); | ||
| if (doc.RootElement.TryGetProperty("value", out var valueArray)) | ||
| { | ||
| foreach (var item in valueArray.EnumerateArray()) | ||
| { | ||
| jobs.Add(item.Clone()); | ||
| } |
Comment on lines
+248
to
+252
| // Some actions return empty body on success (e.g., 202 Accepted) | ||
| if (string.IsNullOrWhiteSpace(responseBody)) | ||
| { | ||
| return JsonDocument.Parse($"{{\"status\":\"{action} accepted\",\"jobName\":\"{jobName}\"}}").RootElement; | ||
| } |
Comment on lines
+70
to
+78
| private string BuildCopyJobsUrl(string accountResourceId, string? jobName = null) | ||
| { | ||
| var armEndpoint = TenantService.CloudConfiguration.ArmEnvironment.Endpoint.ToString().TrimEnd('/'); | ||
| var url = $"{armEndpoint}{accountResourceId}/copyJobs"; | ||
| if (!string.IsNullOrEmpty(jobName)) | ||
| { | ||
| url += $"/{jobName}"; | ||
| } | ||
| url += $"?api-version={ApiVersion}"; |
Comment on lines
+61
to
+65
| public const string JobNameConst = "job-name"; | ||
| public const string JobPropertiesConst = "job-properties"; | ||
| public const string ModeConst = "mode"; | ||
| public const string WorkerCountConst = "worker-count"; | ||
|
|
Comment on lines
+3534
to
+3536
| "name": "manage_azure_cosmos_copy_jobs", | ||
| "description": "Create, monitor, and manage Cosmos DB container copy jobs (same as 'az cosmosdb copy'). Supports NoSQL-to-NoSQL, Cassandra-to-Cassandra, Mongo-to-Mongo, Mongo-to-MongoVCore, Cassandra-to-AzureBlob, and AzureBlob-to-Cassandra copy job types. Multi-task jobs can copy multiple container pairs in a single operation. Supports Offline and Online modes.", | ||
| "toolMetadata": { |
…, add tests - Remove unused 'using System.Net' import - Fix all JsonDocument.Parse() leaks with 'using' + RootElement.Clone() - Replace 'new HttpClient()' with TenantService.GetClient() (IHttpClientFactory) - Use per-request HttpRequestMessage auth headers instead of DefaultRequestHeaders - URL-encode jobName in request paths via Uri.EscapeDataString - Fix fallback JSON construction using JsonSerializer instead of string interpolation - Rename option constants to match existing naming pattern (drop 'Const' suffix) - Add unit tests for CopyJob Get, Create, List, and Cancel commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add 7 new MCP commands under 'cosmos copyjob' group for managing Cosmos DB container copy jobs via the copyJobs ARM REST API (Microsoft.DocumentDB/databaseAccounts/copyJobs).
Commands:
Supports all 6 job types (NoSqlRUToNoSqlRU, CassandraRUToCassandraRU, MongoRUToMongoRU, MongoRUToMongoVCore, CassandraRUToAzureBlobStorage, AzureBlobStorageToCassandraRU), multi-task jobs, and Offline/Online modes.
Uses direct ARM REST API calls for portability across SDK versions.
What does this PR do?
[Provide a clear, concise description of the changes][Any additional context, screenshots, or information that helps reviewers]GitHub issue number?
[Link to the GitHub issue this PR addresses]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