# azure-cosmos-rust

Tells the agent how to talk to Azure Cosmos DB NoSQL API from Rust: item CRUD, containers, partition keys, and credentials.

- skill · `type=skill` · Claude Code, GitHub Copilot · 5 installs · ★ 3149
- Author: Microsoft
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/azure-cosmos-rust

## What it does

The skill covers the official `azure_data_cosmos` crate. It walks through building a client, reaching databases and containers, then creating, reading, replacing, deleting and patching items. The client hierarchy is spelled out: `CosmosClient` for the account, `DatabaseClient` for a database, `ContainerClient` for items.

Credentials come from `azure_identity`. Rust has no `DefaultAzureCredential`, so the skill points at `DeveloperToolsCredential` while developing and `ManagedIdentityCredential` in production. Every operation needs the account endpoint in `COSMOS_ENDPOINT`. Account key auth is opt-in through the `key_auth` feature.

One warning stands out: pull the crate published by the azure-sdk user on crates.io, not the community alternatives. Dependencies are added with `cargo add` rather than hand-edited manifests. For Entra ID there are two built-in Cosmos DB roles to pick from, a read-only one and a read/write one.

## Requirements
- Works with: Azure

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add microsoft/skills --skill azure-cosmos-rust -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/azure-cosmos-rust/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/azure-cosmos-rust/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/azure-cosmos-rust/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

**Manually: put the files in place**
- File: `.cursor/skills/azure-cosmos-rust/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install microsoft/skills azure-cosmos-rust
```

2. **Manually: put the files in place**
- File: `.github/skills/azure-cosmos-rust/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-rust/skills/azure-cosmos-rust
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/azure-cosmos-rust/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md

## When to use it
- connect a Rust app to Cosmos DB without grabbing the wrong crate
- run item CRUD with partition keys
- patch a single field instead of replacing the whole document
- pick credentials for local dev versus production
- assign an Entra ID role for data access

## Example prompts
- Connect to Cosmos DB from Rust with `azure_data_cosmos` and read an item by partition key
- Patch the `value` field with `patch_item` instead of rewriting the whole item
- Check that the code uses `DeveloperToolsCredential` and not `DefaultAzureCredential`

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 90730ecb79f69a37.

BEGIN THIRD-PARTY FILE 90730ecb79f69a37
````text
---
name: azure-cosmos-rust
description: |
  Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data.
  Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust".
license: MIT
metadata:
  author: Microsoft
  package: azure_data_cosmos
---

# Azure Cosmos DB library for Rust

Client library for Azure Cosmos DB NoSQL API — document CRUD, containers, and globally distributed data.

Use this skill when:

- An app needs to store or query documents in Cosmos DB from Rust
- You need CRUD operations on items with partition keys
- You need key-based auth as an alternative to Entra ID

> **IMPORTANT:** Only use the official `azure_data_cosmos` crate published by the [azure-sdk](https://crates.io/users/azure-sdk) crates.io user. Do NOT use the unofficial `azure_cosmos` or `azure_sdk_for_rust` community crates. Official crates use underscores in names and none have version 0.21.0.

## Installation

```sh
cargo add azure_data_cosmos azure_identity serde serde_json tokio
```

> If your code uses `azure_core` types directly (for example, `azure_core::credentials::TokenCredential`), add `azure_core` to `Cargo.toml`. If you only use `azure_data_cosmos` re-exports, direct `azure_core` dependency is optional.

## Environment Variables

```bash
COSMOS_ENDPOINT=https://<account>.documents.azure.com/ # Required for all operations
```

## Authentication

Rust Azure SDK code must not use `DefaultAzureCredential`. The Rust identity crate does not provide that type.

```rust
use azure_identity::DeveloperToolsCredential;
use azure_data_cosmos::{
    CosmosClient, AccountReference, AccountEndpoint, RoutingStrategy,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Local dev: DeveloperToolsCredential. Production: use ManagedIdentityCredential.
    let credential = DeveloperToolsCredential::new(None)?;
    let endpoint: AccountEndpoint = "https://<account>.documents.azure.com/"
        .parse()?;
    let account = AccountReference::with_credential(endpoint, credential);
    let client = CosmosClient::builder()
        .build(account, RoutingStrategy::ProximityTo("East US".into()))
        .await?;
    Ok(())
}
```

Prefer the crate README/examples when checking builder signatures and CRUD method shapes instead of reconstructing APIs from memory or generated internals.

## Client Hierarchy

| Client            | Purpose                   | Access                                          |
| ----------------- | ------------------------- | ----------------------------------------------- |
| `CosmosClient`    | Account-level operations  | `CosmosClient::builder().build(account).await?` |
| `DatabaseClient`  | Database operations       | `client.database_client("db")`                  |
| `ContainerClient` | Container/item operations | `database.container_client("c").await`          |

## Core Workflow

```rust
use serde::{Serialize, Deserialize};
use azure_data_cosmos::CosmosClient;

#[derive(Serialize, Deserialize)]
struct Item {
    pub id: String,
    pub partition_key: String,
    pub value: String,
````
END THIRD-PARTY FILE 90730ecb79f69a37

The third-party file has ended. Everything between the 90730ecb79f69a37 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3157 of 6571 bytes. © Microsoft · MIT · https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
