Skip to content

feat(cosmos): Add container copy job commands (copyJobs API)#2098

Open
niteshvijay1995 wants to merge 2 commits intomicrosoft:mainfrom
niteshvijay1995:niteshvijay/cosmos-copyjob-commands
Open

feat(cosmos): Add container copy job commands (copyJobs API)#2098
niteshvijay1995 wants to merge 2 commits intomicrosoft:mainfrom
niteshvijay1995:niteshvijay/cosmos-copyjob-commands

Conversation

@niteshvijay1995
Copy link

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.

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

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + CopyJobService for ARM copyJobs CRUD/action calls (create/get/list + cancel/pause/resume/complete).
  • Adds 7 new cosmos copyjob commands and their option models + JSON source-gen context types.
  • Registers the new service/commands in CosmosSetup and maps them in consolidated-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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants