JUHE API Marketplace
hendrickcastro avatar
MCP Server

MCP CosmosDB

A Model Context Protocol server for Azure CosmosDB database operations that provides 8 tools for document database analysis, container discovery, and data querying.

1
GitHub Stars
3/10/2026
Last Updated
MCP Server Configuration
1{
2 "name": "mcp-cosmosdb",
3 "command": "npx",
4 "args": [
5 "-y",
6 "hendrickcastro/MCPCosmosDB"
7 ],
8 "env": {
9 "OCONNSTRING": "AccountEndpoint=https://your-cosmos-account.documents.azure.com: 443/;AccountKey=your-account-key-here;",
10 "COSMOS_DATABASE_ID": "your-database-name"
11 }
12}
JSON12 lines
  1. Home
  2. MCP Servers
  3. MCPCosmosDB

README Documentation

MCP CosmosDB - Azure CosmosDB MCP Server

A comprehensive Model Context Protocol (MCP) server for Azure CosmosDB database operations. This server provides 13 powerful tools for document database analysis, container discovery, data querying, and CRUD operations through the MCP protocol.

โœจ Features

  • ๐Ÿ”— Multi-Connection Support: Manage multiple CosmosDB accounts/databases from a single MCP instance
  • ๐Ÿ”’ Security First: Write operations disabled by default
  • โšก High Performance: Connection caching and optimized queries
  • ๐Ÿ“Š 13 Tools: Complete set of database operations

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Azure CosmosDB database with connection string
  • MCP-compatible client (Claude Desktop, Cursor IDE, etc.)

โš™๏ธ Configuration

Configuration Priority

The server supports three configuration methods (in order of priority):

PriorityMethodEnvironment VariableDescription
1๏ธโƒฃExternal FileCOSMOS_CONNECTIONS_FILEPath to JSON file with connections array
2๏ธโƒฃJSON StringCOSMOS_CONNECTIONSInline JSON array of connections
3๏ธโƒฃSingle ConnectionCOSMOS_CONNECTION_STRING + COSMOS_DATABASE_IDLegacy single connection mode

๐Ÿ”’ Security Configuration

VariableDescriptionDefault
DB_ALLOW_MODIFICATIONSEnable/disable write operations (create, update, delete, upsert)false

โš ๏ธ IMPORTANT: By default, all write operations are DISABLED for safety. Set DB_ALLOW_MODIFICATIONS=true only when you need to perform write operations.


๐Ÿ“ฆ Installation Options

Option 1: Multi-Connection with External File (Recommended) โœ…

Create a connections file (e.g., cosmos-connections.json):

[
  {
    "id": "production",
    "connectionString": "AccountEndpoint=https://myapp-prod.documents.azure.com:443/;AccountKey=...;",
    "databaseId": "ProductionDB",
    "allowModifications": false,
    "description": "Production database (read-only)"
  },
  {
    "id": "development",
    "connectionString": "AccountEndpoint=https://myapp-dev.documents.azure.com:443/;AccountKey=...;",
    "databaseId": "DevDB",
    "allowModifications": true,
    "description": "Development database"
  },
  {
    "id": "analytics",
    "connectionString": "AccountEndpoint=https://analytics.documents.azure.com:443/;AccountKey=...;",
    "databaseId": "AnalyticsDB",
    "allowModifications": false,
    "description": "Analytics database"
  }
]

Configure your MCP client:

{
  "mcpServers": {
    "cosmosdb": {
      "command": "npx",
      "args": ["-y", "mcpcosmosdb@latest"],
      "env": {
        "COSMOS_CONNECTIONS_FILE": "/path/to/cosmos-connections.json"
      }
    }
  }
}

Option 2: Multi-Connection with Inline JSON

{
  "mcpServers": {
    "cosmosdb": {
      "command": "npx",
      "args": ["-y", "mcpcosmosdb@latest"],
      "env": {
        "COSMOS_CONNECTIONS": "[{\"id\":\"prod\",\"connectionString\":\"AccountEndpoint=https://...\",\"databaseId\":\"ProdDB\",\"allowModifications\":false},{\"id\":\"dev\",\"connectionString\":\"AccountEndpoint=https://...\",\"databaseId\":\"DevDB\",\"allowModifications\":true}]"
      }
    }
  }
}

Option 3: Single Connection (Legacy)

Read-Only Mode (Default - Safe):

{
  "mcpServers": {
    "cosmosdb": {
      "command": "npx",
      "args": ["-y", "mcpcosmosdb@latest"],
      "env": {
        "COSMOS_CONNECTION_STRING": "AccountEndpoint=https://your-cosmos-account.documents.azure.com:443/;AccountKey=your-account-key-here;",
        "COSMOS_DATABASE_ID": "your-database-name"
      }
    }
  }
}

With Write Operations Enabled:

{
  "mcpServers": {
    "cosmosdb": {
      "command": "npx",
      "args": ["-y", "mcpcosmosdb@latest"],
      "env": {
        "COSMOS_CONNECTION_STRING": "AccountEndpoint=https://your-cosmos-account.documents.azure.com:443/;AccountKey=your-account-key-here;",
        "COSMOS_DATABASE_ID": "your-database-name",
        "DB_ALLOW_MODIFICATIONS": "true"
      }
    }
  }
}

Option 4: NPX from GitHub

{
  "mcpServers": {
    "cosmosdb": {
      "command": "npx",
      "args": ["-y", "hendrickcastro/MCPCosmosDB"],
      "env": {
        "COSMOS_CONNECTION_STRING": "AccountEndpoint=https://...;AccountKey=...;",
        "COSMOS_DATABASE_ID": "your-database-name"
      }
    }
  }
}

Option 5: Local Development

git clone https://github.com/hendrickcastro/MCPCosmosDB.git
cd MCPCosmosDB
npm install && npm run build
{
  "mcpServers": {
    "cosmosdb": {
      "command": "node",
      "args": ["path/to/MCPCosmosDB/dist/server.js"],
      "env": {
        "COSMOS_CONNECTIONS_FILE": "/path/to/cosmos-connections.json"
      }
    }
  }
}

๐Ÿ› ๏ธ Available Tools (13 Total)

๐Ÿ”— Connection Management

ToolDescription
mcp_list_connectionsList all configured connections with their status

๐Ÿ“– Read Operations (Always Available)

ToolDescription
mcp_list_databasesList all databases in the CosmosDB account
mcp_list_containersList all containers in the current database
mcp_get_container_definitionGet detailed container configuration (partition key, indexing policy, throughput)
mcp_get_container_statsGet container statistics (document count, size, partition distribution)
mcp_cosmos_queryExecute SQL queries with parameters and performance metrics
mcp_get_documentsRetrieve documents with optional filtering
mcp_get_document_by_idGet a specific document by ID and partition key
mcp_analyze_schemaAnalyze document schema structure in containers

โœ๏ธ Write Operations (Require allowModifications: true)

ToolDescription
mcp_create_documentCreate a new document in a container
mcp_update_documentUpdate (replace) an existing document
mcp_delete_documentDelete a document from a container
mcp_upsert_documentCreate or update a document (upsert operation)

๐Ÿ›ก๏ธ Security Note: Write operations are blocked by default. Set allowModifications: true in the connection config or DB_ALLOW_MODIFICATIONS=true for single connection mode.


๐Ÿ“‹ Usage Examples

Multi-Connection Usage

// List all available connections
const connections = await mcp_list_connections();
// Returns: { connections: [{id: "prod", databaseId: "ProdDB", isConnected: true}, ...] }

// Query specific connection using connection_id
const prodData = await mcp_cosmos_query({
  connection_id: "production",
  container_id: "users",
  query: "SELECT TOP 10 c.id, c.name FROM c ORDER BY c._ts DESC"
});

const devData = await mcp_cosmos_query({
  connection_id: "development",
  container_id: "users",
  query: "SELECT TOP 10 c.id, c.name FROM c ORDER BY c._ts DESC"
});

Container Analysis

// List all containers (uses default connection if connection_id not specified)
const containers = await mcp_list_containers({
  connection_id: "production"
});

// Get container definition
const containerDef = await mcp_get_container_definition({ 
  connection_id: "production",
  container_id: "users" 
});

// Get container statistics
const stats = await mcp_get_container_stats({ 
  connection_id: "production",
  container_id: "users",
  sample_size: 1000
});

Querying Data

โš ๏ธ IMPORTANT: Always use TOP N and specify fields. NEVER use SELECT * - it causes timeouts and high RU consumption in large containers.

// โœ… CORRECT: Using TOP and specific fields
const result = await mcp_cosmos_query({
  connection_id: "production",
  container_id: "products",
  query: "SELECT TOP 50 c.id, c.name, c.price FROM c WHERE c.category = @category",
  parameters: { category: "electronics" }
});

// โŒ WRONG: SELECT * without TOP (will timeout on large containers)
// query: "SELECT * FROM c WHERE c.category = @category"

// Get documents with simple filters
const documents = await mcp_get_documents({
  connection_id: "production",
  container_id: "orders",
  filter_conditions: { status: "completed" },
  order_by: "_ts",
  order_direction: "DESC",
  limit: 100
});

Document Operations

// Get specific document by ID
const document = await mcp_get_document_by_id({
  connection_id: "production",
  container_id: "users",
  document_id: "user-123",
  partition_key: "user-123"
});

// Analyze schema
const schema = await mcp_analyze_schema({
  connection_id: "production",
  container_id: "products",
  sample_size: 500
});

CRUD Operations (Requires allowModifications: true)

// Create a new document
const created = await mcp_create_document({
  connection_id: "development",  // Use a connection with write access
  container_id: "users",
  document: {
    id: "user-456",
    email: "user@example.com",
    name: "John Doe",
    status: "active"
  },
  partition_key: "user-456"
});

// Update a document (full replacement)
const updated = await mcp_update_document({
  connection_id: "development",
  container_id: "users",
  document_id: "user-456",
  document: {
    id: "user-456",
    email: "newemail@example.com",
    name: "John Doe",
    status: "inactive"
  },
  partition_key: "user-456"
});

// Upsert a document (create or update)
const upserted = await mcp_upsert_document({
  connection_id: "development",
  container_id: "users",
  document: {
    id: "user-789",
    email: "another@example.com",
    name: "Jane Doe"
  },
  partition_key: "user-789"
});

// Delete a document
const deleted = await mcp_delete_document({
  connection_id: "development",
  container_id: "users",
  document_id: "user-456",
  partition_key: "user-456"
});

๐Ÿ”ง Connection File Schema

interface ConnectionConfig {
  id: string;                    // Unique identifier for the connection
  connectionString: string;      // CosmosDB connection string
  databaseId: string;            // Database ID to connect to
  allowModifications?: boolean;  // Enable write operations (default: false)
  description?: string;          // Optional description
}

Example cosmos-connections.json:

[
  {
    "id": "athlete",
    "connectionString": "AccountEndpoint=https://dbsqlcosmosathlete.documents.azure.com:443/;AccountKey=...;",
    "databaseId": "data",
    "allowModifications": false,
    "description": "Athlete data"
  },
  {
    "id": "events",
    "connectionString": "AccountEndpoint=https://dbsqlcosmosevents.documents.azure.com:443/;AccountKey=...;",
    "databaseId": "events",
    "allowModifications": false,
    "description": "Events data"
  }
]

๐Ÿšจ Troubleshooting

Connection Issues:

  • Invalid connection string: Verify connection string format includes AccountEndpoint and AccountKey
  • Database not found: Check databaseId matches existing database
  • Request timeout: Increase COSMOS_MAX_RETRY_WAIT_TIME or check network

Query Issues:

  • Query timeout: Use TOP N to limit results, specify only needed fields, avoid SELECT *
  • Cross partition query required: Set enable_cross_partition: true in query parameters
  • Partition key required: Specify partition_key for single-partition operations

Multi-Connection Issues:

  • Connection not found: Use mcp_list_connections to see available connection IDs
  • Wrong database: Verify the connection_id parameter points to the correct connection

Write Operation Blocked:

  • Error: "Database modifications are disabled": Set allowModifications: true in connection config or DB_ALLOW_MODIFICATIONS=true
  • This is a safety feature - write operations are disabled by default

CosmosDB Emulator:

  1. Install Azure CosmosDB Emulator
  2. Start emulator on port 8081
  3. Use default emulator connection string
  4. Create database and containers for testing

๐Ÿงช Development

npm test          # Run tests
npm run build     # Build project
npm start         # Development mode

๐Ÿ—๏ธ Architecture

Project Structure:

src/
โ”œโ”€โ”€ tools/                    # Tool implementations
โ”‚   โ”œโ”€โ”€ containerAnalysis.ts  # Container operations
โ”‚   โ”œโ”€โ”€ dataOperations.ts     # Data queries & CRUD
โ”‚   โ””โ”€โ”€ types.ts              # Type definitions
โ”œโ”€โ”€ db.ts                     # CosmosDB connection & multi-connection management
โ”œโ”€โ”€ server.ts                 # MCP server setup
โ””โ”€โ”€ tools.ts                  # Tool definitions

Key Features:

  • โšก Connection caching and pooling
  • ๐Ÿ”— Multi-connection management
  • ๐Ÿ›ก๏ธ Comprehensive error handling
  • ๐Ÿ”’ Write operation protection per connection
  • ๐Ÿ“Š Performance metrics and request charges
  • ๐Ÿ”ง Flexible configuration options
  • ๐Ÿ“‹ Intelligent schema analysis

๐Ÿ“ Important Notes

  • Query Best Practices: Always use TOP N and specify fields - never use SELECT *
  • Container IDs: Use exact names as in CosmosDB
  • Partition Keys: Required for optimal performance and CRUD operations
  • Cross-Partition Queries: Can be expensive; use filters
  • Request Charges: Monitor RU consumption
  • Security: Store connection strings securely (use external file)
  • Write Protection: Enable only for connections that need it

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/name)
  3. Make changes and add tests
  4. Ensure tests pass (npm test)
  5. Commit changes (git commit -m 'Add feature')
  6. Push and open Pull Request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿท๏ธ Tags & Keywords

Database: cosmosdb azure-cosmosdb nosql document-database database-analysis database-tools azure database-management database-operations data-analysis multi-database

MCP & AI: model-context-protocol mcp-server mcp-tools ai-tools claude-desktop cursor-ide anthropic llm-integration ai-database intelligent-database

Technology: typescript nodejs npm-package cli-tool database-client nosql-client database-sdk rest-api json-api database-connector

Features: container-analysis document-operations sql-queries schema-analysis query-execution database-search data-exploration database-insights partition-management throughput-analysis crud-operations document-crud multi-connection

Use Cases: database-development data-science business-intelligence database-migration schema-documentation performance-analysis data-governance database-monitoring troubleshooting automation

๐Ÿ™ Acknowledgments

  • Model Context Protocol SDK
  • @azure/cosmos
  • Inspired by MCPQL

๐ŸŽฏ MCP CosmosDB provides comprehensive Azure CosmosDB database analysis through the Model Context Protocol. Perfect for developers and data analysts working with CosmosDB! ๐Ÿš€

Quick Install

Quick Actions

View on GitHubView All Servers

Key Features

Model Context Protocol
Secure Communication
Real-time Updates
Open Source

Boost your projects with Wisdom Gate LLM API

Supporting GPT-5, Claude-4, DeepSeek v3, Gemini and more.

Enjoy a free trial and save 20%+ compared to official pricing.

Learn More
JUHE API Marketplace

Accelerate development, innovate faster, and transform your business with our comprehensive API ecosystem.

JUHE API VS

  • vs. RapidAPI
  • vs. API Layer
  • API Platforms 2025
  • API Marketplaces 2025
  • Best Alternatives to RapidAPI

For Developers

  • Console
  • Collections
  • Documentation
  • MCP Servers
  • Free APIs
  • Temp Mail Demo

Product

  • Browse APIs
  • Suggest an API
  • Wisdom Gate LLM
  • Global SMS Messaging
  • Temp Mail API

Company

  • What's New
  • Welcome
  • About Us
  • Contact Support
  • Terms of Service
  • Privacy Policy
Featured on Startup FameFeatured on Twelve ToolsFazier badgeJuheAPI Marketplace - Connect smarter, beyond APIs | Product Huntai tools code.marketDang.aiFeatured on ShowMeBestAI
Copyright ยฉ 2026 JUHEDATA HK LIMITED - All rights reserved