azure-cosmos-rust — скилл для Claude Code: Cosmos DB из Rust
Подсказывает агенту, как работать с Azure Cosmos DB NoSQL API из Rust: CRUD документов, контейнеры, ключи разделов и аутентификация.
npx skills add microsoft/skills --skill azure-cosmos-rust -a claude-codeЧто делает azure-cosmos-rust
Скилл описывает официальный крейт azure_data_cosmos — создание клиента, работу с базами и контейнерами, чтение, запись, замену, удаление и частичное обновление документов через patch_item. Отдельно разобрана иерархия клиентов: CosmosClient, DatabaseClient, ContainerClient.
Аутентификация идёт через azure_identity. Для локальной разработки берётся DeveloperToolsCredential, для продакшена — ManagedIdentityCredential: типа DefaultAzureCredential в Rust-крейте нет, и код с ним просто не соберётся. Нужен адрес аккаунта в переменной COSMOS_ENDPOINT. Ключевую аутентификацию включают флагом key_auth при установке крейта.
Есть предупреждение о крейтах: брать стоит только официальный azure_data_cosmos от пользователя azure-sdk на crates.io, а не сообщества. Зависимости скилл советует ставить через cargo add, а не правкой Cargo.toml руками. Для Entra ID перечислены встроенные роли Cosmos DB — читатель и участник данных.
Какие задачи решает
- подключиться к Cosmos DB из Rust и не перепутать крейт
- сделать CRUD документов с ключом раздела
- обновить одно поле документа без полной замены
- выбрать правильный тип учётных данных для локальной разработки и продакшена
- назначить роль Entra ID для доступа к данным
Примеры запросов агенту
- Подключись к Cosmos DB из Rust через
azure_data_cosmosи сделай чтение документа по ключу раздела - Замени поле
valueу документа черезpatch_item, не перезаписывая весь элемент - Проверь, что в коде используется
DeveloperToolsCredential, а неDefaultAzureCredential
Как установить azure-cosmos-rust
1Через Skills CLI (Vercel)
npx skills add microsoft/skills --skill azure-cosmos-rust -a claude-code2Вручную: положить файлы
~/.claude/skills/azure-cosmos-rust/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/azure-cosmos-rust/
Вручную: положить файлы
.agents/skills/azure-cosmos-rust/SKILL.mdДля всех проектов — ~/.agents/skills/
Вручную: положить файлы
.cursor/skills/azure-cosmos-rust/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install microsoft/skills azure-cosmos-rust2Вручную: положить файлы
.github/skills/azure-cosmos-rust/SKILL.mdКомандой платформы
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-rust/skills/azure-cosmos-rustВручную: положить файлы
.devin/skills/azure-cosmos-rust/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Claude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о azure-cosmos-rust
Как установить azure-cosmos-rust в Claude Code?
Выполните npx skills add microsoft/skills --skill azure-cosmos-rust -a claude-code. Файл скилла окажется по пути ~/.claude/skills/azure-cosmos-rust/SKILL.md.
Что делает azure-cosmos-rust?
Даёт агенту справочник по работе с Azure Cosmos DB NoSQL API из Rust: клиенты, CRUD документов, ключи разделов, аутентификация и роли доступа.
Какие крейты нужны для работы?
Официальный azure_data_cosmos и azure_identity, плюс serde, serde_json и tokio. Зависимость azure_core добавляют только при прямом импорте её типов.
Исходный текст
SKILL.md · MIT
---
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,
}
async fn crud(client: CosmosClient) -> Result<(), Box<dyn std::error::Error>> {
let container = client
.database_client("myDatabase")
.container_client("myContainer")
.await;
let item = Item {
id: "1".into(),
partition_key: "pk1".into(),
value: "hello".into(),
};
// Create
container.create_item("pk1", "1", item, None).await?;
// Read
let resp = container.read_item("pk1", "1", None).await?;
let mut item: Item = resp.into_model()?;
// Update
item.value = "updated".into();
container.replace_item("pk1", "1", item, None).await?;
// Delete
container.delete_item("pk1", "1", None).await?;
Ok(())
}
```
### Patch Item
```rust
use azure_data_cosmos::{PatchInstructions, PatchOperation};
let patch = PatchInstructions::from(vec![
PatchOperation::set("/value", serde_json::json!("patched")),
]);
let patched: Item = container
.patch_item("pk1", "1", patch, None)
.await?
.into_model()?;
println!("Patched value: {}", patched.value);
```
## Key Auth (Optional)
Enable account key authentication with the feature flag:
```sh
cargo add azure_data_cosmos --features key_auth
```
## RBAC Roles
For Entra ID auth, assign one of these built-in Cosmos DB roles:
| Role | Access |
| ------------------------------------- | ---------- |
| `Cosmos DB Built-in Data Reader` | Read-only |
| `Cosmos DB Built-in Data Contributor` | Read/write |
## Best Practices
1. **Use `cargo add` to manage dependencies, never edit `Cargo.toml` directly.** Add and remove Rust SDK dependencies with cargo commands instead of manual manifest edits.
2. **Add `azure_core` only when importing `azure_core` types directly.** If your code imports `azure_core::http::Url`, `azure_core::http::RequestContent`, or `azure_core::error::ErrorKind`, include `azure_core`; otherwise a direct dependency is optional.
3. **Use `DeveloperToolsCredential`** for local dev, **`ManagedIdentityCredential`** for production — Rust does not provide a single `DefaultAzureCredential` type
4. **Never hardcode credentials** — use environment variables or managed identity
5. **Reuse `CosmosClient`** — clients are thread-safe; create once, share across tasks
6. **Use `RoutingStrategy::ProximityTo`** — route to the nearest region for lowest latency
7. **Always specify partition key** for item operations — Cosmos DB requires it for all CRUD
8. **Run `cargo clippy -- -D warnings`** when the prompt, eval, or CI expects lint-clean output
9. **Future-proof `#[non_exhaustive]` SDK models** — when constructing SDK model/options structs, end the initializer with `..Default::default()` (add `#[allow(clippy::needless_update)]`) and use a `_` wildcard arm when matching SDK enums, so new service-added fields/variants don't break your build
## Reference Links
| Resource | Link |
| ------------- | ---------------------------------------------------------------------------------- |
| API Reference | https://docs.rs/azure_data_cosmos/latest/azure_data_cosmos |
| crates.io | https://crates.io/crates/azure_data_cosmos |
| Source Code | https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/cosmos/azure_data_cosmos |
© Microsoft · MIT · microsoft/skills