PluginWorks in Claude CodeCurrent
Azure cosmos db assistant
Expert assistant for Azure Cosmos DB — data modeling, query optimization, performance tuning, and best practices.
0
Try it
See what this would do for you. No sign-up needed.
Install in Claude Code
Run these in Claude Code, in order. The first adds the marketplace, the second installs the plugin.
Step 1
/plugin marketplace add anthropics/claude-plugins-official
Step 2
/plugin install azure-cosmos-db-assistant@claude-plugins-official
Review commands before running them. Promptu never runs code on your machine or pushes changes to your repo.
What's inside
1 skill
- cosmosdb-best-practices
3 commands
- cosmos-review
- cosmos-setup
- generate-skills
1 agent
Security scan
Passed
Promptu's text scan of the files it could read didn't match any known risky patterns. It doesn't run the plugin, and a clean scan doesn't mean the plugin is safe.
Automated pattern check of 8 file(s) found nothing risky. Not a full audit.
Details
# Azure Cosmos DB Plugin for Claude Code
The Azure Cosmos DB plugin for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) gives Claude deep expertise in Azure Cosmos DB best practices, data modeling, query optimization, and SDK usage — ready to use immediately after install with no configuration required.
## Install
Install from the official Anthropic marketplace:
```
/plugin install azure-cosmos-db-assistant@claude-plugins-official
/reload-plugins
```
> **Note:** Earlier versions of this plugin used the namespace `/azure-cosmosdb:*`.
> The plugin now uses `/azure-cosmos-db-assistant:*` to align with the official marketplace entry and improve discoverability.
## Works Out of the Box
This plugin installs cleanly with **no required environment variables, no external services, and no auto-running binaries**. All skills, the expert agent, and commands are available immediately.
## What's Included
- **Skills** — 73 best-practice rules across 10 categories covering data modeling, partition key design, query optimization, SDK patterns, indexing, throughput, global distribution, monitoring, design patterns, and vector search — sourced from the [cosmosdb-agent-kit](https://github.com/AzureCosmosDB/cosmosdb-agent-kit)
- **Agent** — A specialized Cosmos DB expert agent for in-depth guidance
- **Commands** — Code review and skill regeneration commands
## Optional: MCP Toolkit Integration
For users who want to connect Claude Code to a **live Azure Cosmos DB account**, the optional [Azure Cosmos DB MCP Toolkit](https://github.com/AzureCosmosDB/MCPToolKit) integration adds database operations, schema discovery, and vector search. This requires a separate deployment and is **not required** for the plugin to function.
See [SETUP.md](SETUP.md) for full integration instructions.
## Getting Started
After installing the plugin, try these in Claude Code:
### Commands
```
/azure-cosmos-db-assistant:cosmos-review # Review your code for Cosmos DB best practices
/azure-cosmos-db-assistant:generate-skills # Regenerate skills from upstream agent-kit
/azure-cosmos-db-assistant:cosmos-setup # Configure optional MCP Toolkit connection
```
### Agent
```
/agents cosmosdb-expert
```
### Example Questions
- "Review my Cosmos DB data model for this application"
- "What partition key should I use for a multi-tenant SaaS app?"
- "Optimize this Cosmos DB query for lower RU cost"
- "Should I embed or reference this related data?"
- "Review my Cosmos DB code for best practices"
- "How do I set up vector search in Cosmos DB for RAG?"
## Project Structure
```
cosmosdb-claude-code-plugin/
├── .claude-plugin/
│ └── plugin.json # Plugin manifest
├── .mcp.example.json # Example MCP config (copy to .mcp.json to activate)
├── agents/
│ └── cosmosdb-expert.md # Specialized Cosmos DB expert agent
├── commands/
│ ├── cosmos-setup.md # Optional MCP Toolkit setup command
│ ├── cosmos-review.md # Code review command
│ └── generate-skills.md # Regenerate skills from agent-kit
├── skills/
│ └── cosmosdb-best-practices/
│ ├── SKILL.md # Skill manifest and rule index
│ └── rules/ # 73 individual best-practice rule files
│ ├── model-*.md # Data modeling (11 rules)
│ ├── partition-*.md # Partition key design (7 rules)
│ ├── query-*.md # Query optimization (6 rules)
│ ├── sdk-*.md # SDK best practices (19 rules)
│ ├── index-*.md # Indexing strategies (5 rules)
│ ├── throughput-*.md # Throughput & scaling (5 rules)
│ ├── global-*.md # Global distribution (6 rules)
│ ├── monitoring-*.md # Monitoring & diagnostics (5 rules)
│ ├── pattern-*.md # Design patterns (3 rules)
│ └── vector-*.md # Vector search (6 rules)
├── assets/
│ └── logo.svg # Plugin logo
├── SETUP.md # Optional MCP Toolkit integration guide
├── LICENSE
└── README.md
```
## Keeping Skills Up to Date
Skills are derived from the [AzureCosmosDB/cosmosdb-agent-kit](https://github.com/AzureCosmosDB/cosmosdb-agent-kit).
To regenerate skills after the upstream agent-kit updates:
```
/azure-cosmos-db-assistant:generate-skills
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch: `git checkout -b feature/my-feature`
3. Commit your changes: `git commit -m 'feat: add my feature'`
4. Push to the branch: `git push origin feature/my-feature`
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## skills/cosmosdb-best-practices/SKILL.md
---
name: cosmosdb-best-practices
license: MIT
description: |
Azure Cosmos DB performance optimization and best practices guidelines for NoSQL,
partitioning, queries, SDK usage, and vector search. Use when writing, reviewing,
or refactoring code that interacts with Azure Cosmos DB, designing data models,
optimizing queries, or implementing high-performance database operations.
metadata:
author: cosmosdb-agent-kit
version: "1.0.0"
---
# Azure Cosmos DB Best Practices
Comprehensive performance optimization guide for Azure Cosmos DB applications, containing
73+ rules across 10 categories, prioritized by impact to guide automated
refactoring and code generation.
73 individual rule files are in the [rules/](./rules/) directory, one file per rule,
synced from the [AzureCosmosDB/cosmosdb-agent-kit](https://github.com/AzureCosmosDB/cosmosdb-agent-kit).
Load only the relevant rule file(s) when answering a question — do NOT load all files at once.
Run `/azure-cosmos-db-assistant:generate-skills` to sync with the latest rules from the agent-kit.
## When to Apply
Reference these guidelines when:
- Designing data models for Cosmos DB
- Choosing partition keys
- Writing or optimizing queries
- Implementing SDK patterns
- Reviewing code for performance issues
- Configuring throughput and scaling
- Building globally distributed applications
- Implementing vector search and RAG patterns
## Rule Index
Rules are grouped by category prefix. For a given question, load files matching
the relevant prefix (e.g., `model-*.md` for data modeling, `sdk-*.md` for SDK usage).
See [rules/_sections.md](rules/_sections.md) for category descriptions.
### 1. Data Modeling — CRITICAL (prefix: `model-`)
- [model-embed-related.md](rules/model-embed-related.md) — Embed related data retrieved together
- [model-reference-large.md](rules/model-reference-large.md) — Reference data when items grow large
- [model-avoid-2mb-limit.md](rules/model-avoid-2mb-limit.md) — Keep items well under 2MB limit
- [model-id-constraints.md](rules/model-id-constraints.md) — Follow ID value length and character constraints
- [model-nesting-depth.md](rules/model-nesting-depth.md) — Stay within 128-level nesting depth limit
- [model-numeric-precision.md](rules/model-numeric-precision.md) — Understand IEEE 754 numeric precision limits
- [model-denormalize-reads.md](rules/model-denormalize-reads.md) — Denormalize for read-heavy workloads
- [model-schema-versioning.md](rules/model-schema-versioning.md) — Version your document schemas
- [model-type-discriminator.md](rules/model-type-discriminator.md) — Use type discriminators for polymorphic data
- [model-json-serialization.md](rules/model-json-serialization.md) — Handle JSON serialization correctly
- [model-relationship-references.md](rules/model-relationship-references.md) — Use ID references with transient hydration
### 2. Partition Key Design — CRITICAL (prefix: `partition-`)
- [partition-high-cardinality.md](rules/partition-high-cardinality.md) — Choose high-cardinality partition keys
- [partition-avoid-hotspots.md](rules/partition-avoid-hotspots.md) — Distribute writes evenly
- [partition-hierarchical.md](rules/partition-hierarchical.md) — Use hierarchical partition keys for flexibility
- [partition-query-patterns.md](rules/partition-query-patterns.md) — Align partition key with query patterns
- [partition-synthetic-keys.md](rules/partition-synthetic-keys.md) — Create synthetic keys when needed
- [partition-key-length.md](rules/partition-key-length.md) — Respect partition key value length limits
- [partition-20gb-limit.md](rules/partition-20gb-limit.md) — Plan for 20GB logical partition limit
### 3. Query Optimization — HIGH (prefix: `query-`)
- [query-avoid-cross-partition.md](rules/query-avoid-cross-partition.md) — Minimize cross-partition queries
- [query-use-projections.md](rules/query-use-projections.md) — Project only needed fields
- [query-pagination.md](rules/query-pagination.md) — Use continuation tokens for pagination
- [query-avoid-scans.md](rules/query-avoid-scans.md) — Avoid full container scans
- [query-parameterize.md](rules/query-parameterize.md) — Use parameterized queries
- [query-order-filters.md](rules/query-order-filters.md) — Order filters by selectivity
### 4. SDK Best Practices — HIGH (prefix: `sdk-`)
- [sdk-singleton-client.md](rules/sdk-singleton-client.md) — Reuse CosmosClient as singleton
- [sdk-async-api.md](rules/sdk-async-api.md) — Use async APIs for throughput
- [sdk-retry-429.md](rules/sdk-retry-429.md) — Handle 429s with retry-after
- [sdk-connection-mode.md](rules/sdk-connection-mode.md) — Use Direct mode for production
- [sdk-preferred-regions.md](rules/sdk-preferred-regions.md) — Configure preferred regions
- [sdk-excluded-regions.md](rules/sdk-excluded-regions.md) — Exclude regions experiencing issues
- [sdk-availability-strategy.md](rules/sdk-availability-strategy.md) — Configure availability strategy for resilience
- [sdk-circuit-breaker.md](rules/sdk-circuit-breaker.md) — Use circuit breaker for fault tolerance
- [sdk-diagnostics.md](rules/sdk-diagnostics.md) — Log diagnostics for troubleshooting
- [sdk-serialization-enums.md](rules/sdk-serialization-enums.md) — Serialize enums as strings not integers
- [sdk-emulator-ssl.md](rules/sdk-emulator-ssl.md) — Configure SSL and connection mode for Cosmos DB Emulator
- [sdk-etag-concurrency.md](rules/sdk-etag-concurrency.md) — Use ETags for optimistic concurrency
- [sdk-java-content-response.md](rules/sdk-java-content-response.md) — Enable content response on write operations (Java)
- [sdk-java-cosmos-config.md](rules/sdk-java-cosmos-config.md) — Configure Cosmos DB in Spring Boot with dependent beans
- [sdk-java-spring-boot-versions.md](rules/sdk-java-spring-boot-versions.md) — Match Java version to Spring Boot requirements
- [sdk-local-dev-config.md](rules/sdk-local-dev-config.md) — Configure local development to avoid cloud conflicts
- [sdk-newtonsoft-dependency.md](rules/sdk-newtonsoft-dependency.md) — Explicitly reference Newtonsoft.Json package (.NET)
- [sdk-spring-data-annotations.md](rules/sdk-spring-data-annotations.md) — Annotate entities for Spring Data Cosmos
- [sdk-spring-data-repository.md](rules/sdk-spring-data-repository.md) — Use CosmosRepository correctly
### 5. Indexing Strategies — MEDIUM-HIGH (prefix: `index-`)
- [index-exclude-unused.md](rules/index-exclude-unused.md) — Exclude paths never queried
- [index-composite.md](rules/index-composite.md) — Use composite indexes for ORDER BY
- [index-spatial.md](rules/index-spatial.md) — Add spatial indexes for geo queries
- [index-range-vs-hash.md](rules/index-range-vs-hash.md) — Choose appropriate index types
- [index-lazy-consistent.md](rules/index-lazy-consistent.md) — Understand indexing modes
### 6. Throughput & Scaling — MEDIUM (prefix: `throughput-`)
- [throughput-autoscale.md](rules/throughput-autoscale.md) — Use autoscale for variable workloads
- [throughput-right-size.md](rules/throughput-right-size.md) — Right-size provisioned throughput
- [throughput-serverless.md](rules/throughput-serverless.md) — Consider serverless for dev/test
- [throughput-burst.md](rules/throughput-burst.md) — Understand burst capacity
- [throughput-container-vs-database.md](rules/throughput-container-vs-database.md) — Choose allocation level wisely
### 7. Global Distribution — MEDIUM (prefix: `global-`)
- [global-multi-region.md](rules/global-multi-region.md) — Configure multi-region writes
- [global-consistency.md](rules/global-consistency.md) — Choose appropriate consistency level
- [global-conflict-resolution.md](rules/global-conflict-resolution.md) — Implement conflict resolution
- [global-failover.md](rules/global-failover.md) — Configure automatic failover
- [global-read-regions.md](rules/global-read-regions.md) — Add read regions near users
- [global-zone-redundancy.md](rules/global-zone-redundancy.md) — Enable zone redundancy for HA
### 8. Monitoring & Diagnostics — LOW-MEDIUM (prefix: `monitoring-`)
- [monitoring-ru-consumption.md](rules/monitoring-ru-consumption.md) — Track RU consumption
- [monitoring-latency.md](rules/monitoring-latency.md) — Monitor P99 latency
- [monitoring-throttling.md](rules/monitoring-throttling.md) — Alert on throttling
- [monitoring-azure-monitor.md](rules/monitoring-azure-monitor.md) — Integrate Azure Monitor
- [monitoring-diagnostic-logs.md](rules/monitoring-diagnostic-logs.md) — Enable diagnostic logging
### 9. Design Patterns — HIGH (prefix: `pattern-`)
- [pattern-change-feed-materialized-views.md](rules/pattern-change-feed-materialized-views.md) — Use Change Feed for materialized views
- [pattern-efficient-ranking.md](rules/pattern-efficient-ranking.md) — Use count-based or cached approaches for ranking
- [pattern-service-layer-relationships.md](rules/pattern-service-layer-relationships.md) — Use a service layer to hydrate document references
### 10. Vector Search — HIGH (prefix: `vector-`)
- [vector-enable-feature.md](rules/vector-enable-feature.md) — Enable vector search feature on account
- [vector-embedding-policy.md](rules/vector-embedding-policy.md) — Define vector embedding policy on container
- [vector-index-type.md](rules/vector-index-type.md) — Configure vector indexes (QuantizedFlat or DiskANN)
- [vector-distance-query.md](rules/vector-distance-query.md) — Use VectorDistance() for similarity search
- [vector-normalize-embeddings.md](rules/vector-normalize-embeddings.md) — Normalize embeddings for cosine similarity
- [vector-repository-pattern.md](rules/vector-repository-pattern.md) — Implement repository pattern for vector search
## How to Use
Each rule is a separate file under [rules/](./rules/). When answering a Cosmos DB question,
read only the relevant rule file(s) based on the prefix matching the topic:
- Data modeling question → read `rules/model-*.md` files
- Partition key question → read `rules/partition-*.md` files
- SDK/client question → read `rules/sdk-*.md` files
- etc.
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Source: [AzureCosmosDB/cosmosdb-agent-kit](https://github.com/AzureCosmosDB/cosmosdb-agent-kit/tree/main/skills/cosmosdb-best-practices/rules)
## commands/cosmos-review.md
---
description: Review code for Azure Cosmos DB best practices and suggest optimizations
---
# Cosmos DB Code Review
Review the user's code against Azure Cosmos DB best practices. Use the cosmosdb-best-practices skill as your reference.
## Review Checklist (in priority order)
### CRITICAL
- [ ] Data model design (embedding vs referencing, document size)
- [ ] Partition key choice (cardinality, query alignment, hot partitions)
- [ ] CosmosClient lifecycle (singleton pattern)
### HIGH
- [ ] Query optimization (cross-partition, projections, pagination)
- [ ] SDK patterns (async, connection mode, retry configuration)
- [ ] Concurrency control (ETags for read-modify-write)
- [ ] Design patterns (Change Feed, materialized views)
### MEDIUM
- [ ] Indexing strategy (exclude unused paths, composite indexes)
- [ ] Throughput configuration (autoscale vs fixed, right-sizing)
- [ ] Global distribution (preferred regions, consistency level)
### LOW-MEDIUM
- [ ] Monitoring (diagnostics logging, RU tracking, alerts)
## Output Format
For each finding:
1. **Rule**: Which best practice rule applies
2. **Severity**: CRITICAL / HIGH / MEDIUM / LOW
3. **Current code**: What the code does now
4. **Issue**: Why it's problematic (with RU/latency/scalability impact)
5. **Fix**: Corrected code example
$ARGUMENTS
## commands/cosmos-setup.md
---
description: Set up the optional Azure Cosmos DB MCP Toolkit connection for live database operations
---
# Cosmos DB MCP Setup
Help the user configure the optional Azure Cosmos DB MCP Toolkit connection.
This enables live database operations (queries, schema discovery, vector search)
but is not required — the plugin's skills, agent, and commands work without it.
For detailed instructions, see [SETUP.md](../SETUP.md).
## Steps
1. **Check prerequisites:**
- Ask if they have an Azure Cosmos DB account. If not, direct them to: https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-portal
- Ask if they have deployed the MCP Toolkit. If not, direct them to: https://github.com/AzureCosmosDB/MCPToolKit#quick-start
2. **Get connection details:**
- Ask for their deployed MCP Toolkit URL (from `deployment-info.json` in the MCPToolKit output)
- Ask for their Entra App Client ID (also from `deployment-info.json`)
- Help them get a JWT token by running:
```
az login
az account get-access-token --resource "YOUR-ENTRA-APP-CLIENT-ID" --query accessToken -o tsv
```
- The `--resource` value is the Entra App Client ID from the MCPToolKit deployment output
3. **Set environment variables:**
- Guide them to set `COSMOSDB_MCP_SERVER_URL` to their toolkit URL
- Guide them to set `COSMOSDB_MCP_JWT_TOKEN` to their JWT token
- Note: JWT tokens expire after ~1 hour and need to be refreshed
4. **Create MCP config:**
- Guide them to copy `.mcp.example.json` to `.mcp.json` in their project root
- The config references the environment variables set above
5. **Verify connection:**
- Restart Claude Code after adding `.mcp.json`
- Try listing databases using the MCP tools
- If connection fails, refer to troubleshooting in [SETUP.md](../SETUP.md)
$ARGUMENTS
## commands/generate-skills.md
---
description: Regenerate best-practice skills from the upstream cosmosdb-agent-kit repository
---
# Sync Cosmos DB Best Practices Rules
Fetch the latest individual rule files from the [AzureCosmosDB/cosmosdb-agent-kit](https://github.com/AzureCosmosDB/cosmosdb-agent-kit) repository and update the local rule files.
## Steps
1. Fetch the file listing from the GitHub API:
`https://api.github.com/repos/AzureCosmosDB/cosmosdb-agent-kit/contents/skills/cosmosdb-best-practices/rules`
2. For each `.md` file returned, download it from:
`https://raw.githubusercontent.com/AzureCosmosDB/cosmosdb-agent-kit/main/skills/cosmosdb-best-practices/rules/{filename}`
3. Save each file to:
`skills/cosmosdb-best-practices/rules/{filename}`
4. Compare files before and after. Report:
- New rules added
- Existing rules updated (content changed)
- Rules removed upstream (exist locally but not in API response)
5. Update `skills/cosmosdb-best-practices/SKILL.md`:
- Add any new rules to the appropriate category in the Rule Index section
- Remove any rules that were deleted upstream
- Update the total rule count in the description
6. Report a summary of what changed.
## Notes
- The source of truth is: `https://github.com/AzureCosmosDB/cosmosdb-agent-kit/tree/main/skills/cosmosdb-best-practices/rules`
- Rules are individual markdown files named by `{prefix}-{topic}.md` (e.g., `model-embed-related.md`, `sdk-singleton-client.md`)
- The prefix determines the category: `model-` → Data Modeling, `partition-` → Partition Key, `query-` → Query Optimization, `sdk-` → SDK, `index-` → Indexing, `throughput-` → Throughput, `global-` → Global Distribution, `monitoring-` → Monitoring, `pattern-` → Design Patterns, `vector-` → Vector Search
- Files starting with `_` (like `_sections.md`, `_template.md`) are metadata, not rules
$ARGUMENTS

