Allows direct execution from GitHub repository using npx, with configuration instructions for connecting to various MCP clients.
Leverages Node.js runtime for server operations, requiring Node.js 18+ for execution and compatibility.
Built with TypeScript for type safety and modern JavaScript features, providing strongly-typed interfaces for database operations.
MCP CosmosDB - Azure CosmosDB MCP Server
A comprehensive Model Context Protocol (MCP) server for Azure CosmosDB database operations. This server provides 8 powerful tools for document database analysis, container discovery, and data querying through the MCP protocol.
🚀 Quick Start
Prerequisites
- Node.js 18+ and npm
- Azure CosmosDB database with connection string
- MCP-compatible client (like Claude Desktop, Cursor IDE, or any MCP client)
Installation & Configuration
Option 1: Using npx from GitHub (Recommended)
No installation needed! Just configure your MCP client to run directly from the GitHub repository:
For Claude Desktop (claude_desktop_config.json
):
For Cursor IDE (~/.cursor/mcp.json
):
Option 2: Local Development Installation
- Clone and setup:
- Configure CosmosDB connection:
Create a
.env
file with your CosmosDB credentials:
- Configure MCP client with local path:
🛠️ Available Tools
MCP CosmosDB provides 8 comprehensive tools for Azure CosmosDB operations:
1. 🗄️ List Databases - mcp_list_databases
List all databases in the CosmosDB account.
2. 📦 List Containers - mcp_list_containers
List all containers in the current database.
3. 📋 Container Information - mcp_container_info
Get detailed information about a specific container including partition key, indexing policy, and throughput settings.
4. 📊 Container Statistics - mcp_container_stats
Get statistics about a container including document count, size estimation, and partition key distribution.
5. 🔍 Execute SQL Query - mcp_execute_query
Execute SQL queries against CosmosDB containers with parameters and performance metrics.
6. 📄 Get Documents - mcp_get_documents
Retrieve documents from containers with optional filtering and partition key targeting.
7. 🎯 Get Document by ID - mcp_get_document_by_id
Retrieve a specific document by its ID and partition key.
8. 🏗️ Schema Analysis - mcp_analyze_schema
Analyze document schema structure in containers to understand data patterns.
📋 Usage Examples
Container Analysis
Querying Data
Document Operations
🔧 Environment Variables & Configuration
Required Environment Variables
Variable | Description | Example |
---|---|---|
OCONNSTRING | CosmosDB connection string from Azure Portal | AccountEndpoint=https://...;AccountKey=...; |
COSMOS_DATABASE_ID | Database ID to connect to | MyDatabase |
Optional Configuration
Variable | Description | Default |
---|---|---|
COSMOS_ENABLE_ENDPOINT_DISCOVERY | Enable automatic endpoint discovery | true |
COSMOS_MAX_RETRY_ATTEMPTS | Maximum retry attempts for requests | 9 |
COSMOS_MAX_RETRY_WAIT_TIME | Maximum retry wait time (ms) | 30000 |
COSMOS_ENABLE_CROSS_PARTITION_QUERY | Enable cross-partition queries | true |
🔧 Configuration Examples
1. 🌐 Azure CosmosDB (Production)
2. 🏠 CosmosDB Emulator (Local Development)
3. ⚙️ Advanced Configuration
🚨 Troubleshooting Common Issues
Connection Issues
- "Invalid connection string": Verify your OCONNSTRING format and ensure it contains both AccountEndpoint and AccountKey
- "Database not found": Check that COSMOS_DATABASE_ID matches an existing database
- "Request timeout": Increase COSMOS_MAX_RETRY_WAIT_TIME or check network connectivity
Query Issues
- "Cross partition query required": Set
enable_cross_partition: true
in query parameters - "Query timeout": Reduce sample sizes or add more specific filters
- "Partition key required": Specify partition_key parameter for single-partition operations
CosmosDB Emulator Setup
- Download and install Azure CosmosDB Emulator
- Start the emulator and ensure it's running on default port 8081
- Use the default emulator connection string in your configuration
- Create a database and containers for testing
🧪 Testing
Run the test suite:
Build the project:
Start in development mode:
🏗️ Architecture
Project Structure
Key Features
- ⚡ Connection Management: Efficient CosmosDB client management with retry logic
- 🛡️ Error Handling: Comprehensive error handling and validation
- 📊 Performance Metrics: Query performance tracking with request charges
- 🔧 Flexible Configuration: Environment-based configuration
- 📋 Schema Analysis: Intelligent document schema discovery
📝 Important Notes
- Container IDs: Use exact container names as they appear in CosmosDB
- Partition Keys: Required for single-document operations and optimal performance
- Cross-Partition Queries: Can be expensive; use filters when possible
- Request Charges: Monitor RU consumption through query statistics
- Connection Management: Automatic connection pooling and retry logic
- Security: Connection strings contain sensitive keys; store securely
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes and add tests
- Ensure all tests pass (
npm test
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with the Model Context Protocol SDK
- Uses @azure/cosmos for CosmosDB connectivity
- Inspired by MCPQL for SQL Server
🏷️ Tags & Keywords
Database: cosmosdb
azure-cosmosdb
nosql
document-database
database-analysis
database-tools
azure
database-management
database-operations
data-analysis
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
Use Cases: database-development
data-science
business-intelligence
database-migration
schema-documentation
performance-analysis
data-governance
database-monitoring
troubleshooting
automation
🎯 MCP CosmosDB provides comprehensive Azure CosmosDB database analysis and manipulation capabilities through the Model Context Protocol. Perfect for developers, data analysts, and anyone working with CosmosDB databases! 🚀
This server cannot be installed
A Model Context Protocol server for Azure CosmosDB database operations that provides 8 tools for document database analysis, container discovery, and data querying.
- 🚀 Quick Start
- 🛠️ Available Tools
- 1. 🗄️ List Databases - mcp_list_databases
- 2. 📦 List Containers - mcp_list_containers
- 3. 📋 Container Information - mcp_container_info
- 4. 📊 Container Statistics - mcp_container_stats
- 5. 🔍 Execute SQL Query - mcp_execute_query
- 6. 📄 Get Documents - mcp_get_documents
- 7. 🎯 Get Document by ID - mcp_get_document_by_id
- 8. 🏗️ Schema Analysis - mcp_analyze_schema
- 📋 Usage Examples
- 🔧 Environment Variables & Configuration
- 🔧 Configuration Examples
- 🚨 Troubleshooting Common Issues
- 🧪 Testing
- 🏗️ Architecture
- 📝 Important Notes
- 🤝 Contributing
- 📄 License
- 🙏 Acknowledgments
- 🏷️ Tags & Keywords
Related MCP Servers
- AsecurityAlicenseAqualityThis server implements the Model Context Protocol for seamless interaction with Azure Blob Storage and Cosmos DB, enabling automatic logging and audit tracking of operations.Last updated -165PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI assistants to interact with Azure DevOps services, allowing users to query work items with plans to support creating/updating items, managing pipelines, handling pull requests, and administering sprints and branch policies.Last updated -971PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server for querying and analyzing Azure resources at scale using Azure Resource Graph, enabling AI assistants to explore and monitor Azure infrastructure.Last updated -110TypeScriptMIT License
- -securityFlicense-qualityA Model Context Protocol server that integrates with Azure DevOps, enabling users to query work items, access backlogs, and perform various Azure DevOps operations through a standardized interface.Last updated -1Python