This guide covers setting up and running the Azure Cosmos DB MCP Toolkit on your local machine for development and testing.
- Git
- Docker Desktop
- .NET 9.0 SDK
- Azure CLI (for testing with Azure resources)
git clone https://github.com/AzureCosmosDB/MCPToolKit.git
cd MCPToolKitSet bypass mode to disable authentication for local development:
$env:DEV_BYPASS_AUTH = "true"Runs the MCP server with a local Cosmos DB emulator:
docker-compose up -dThis starts:
- MCP Toolkit server on
http://localhost:8080 - Cosmos DB Emulator (if configured in docker-compose.yml)
Run the application directly with .NET:
cd src/AzureCosmosDB.MCP.Toolkit
dotnet runThe server will start on http://localhost:8080 (or port specified in launchSettings.json).
Invoke-RestMethod http://localhost:8080/api/health$body = '{"jsonrpc":"2.0","method":"tools/list","id":1}'
Invoke-RestMethod -Uri http://localhost:8080/mcp `
-Method Post `
-ContentType "application/json" `
-Body $body# Example: List databases
$body = '{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 1,
"params": {
"name": "list_databases",
"arguments": {}
}
}'
Invoke-RestMethod -Uri http://localhost:8080/mcp `
-Method Post `
-ContentType "application/json" `
-Body $bodyThe MCP server uses these environment variables for both local development and production:
For Local Development (Emulator):
COSMOS_CONNECTION_STRING- Connection string for Cosmos DB emulator- Example:
AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==; - Takes priority if set; skips Azure credential authentication
- Example:
For Cloud Production:
COSMOS_ENDPOINT- Cosmos DB account endpoint URL- Example:
https://myaccount.documents.azure.com:443/ - Uses DefaultAzureCredential (no additional configuration needed)
- Example:
The toolkit supports three types of embedding endpoints with automatic detection:
Azure AI Services (Cognitive Services):
OPENAI_ENDPOINT- https://.cognitiveservices.azure.com/- Uses DefaultAzureCredential or
OPENAI_API_KEYif set - Example:
https://my-ai-service.cognitiveservices.azure.com/
Azure AI Foundry:
OPENAI_ENDPOINT- https://.services.ai.azure.com/api/projects/- Uses DefaultAzureCredential or
OPENAI_API_KEYif set - Example:
https://my-project.services.ai.azure.com/api/projects/my-project-123
OpenAI Native API:
OPENAI_ENDPOINT- https://api.openai.com/v1- Requires:
OPENAI_API_KEY(mandatory for OpenAI) - Example:
https://api.openai.com/v1
Common Configuration:
OPENAI_API_KEY- API key for authentication (optional for Azure endpoints, required for OpenAI)- Example:
sk-...(OpenAI) or Azure API key
- Example:
OPENAI_EMBEDDING_DEPLOYMENT- Model/deployment name- Examples:
text-embedding-3-small,text-embedding-3-large,gpt-4o-mini
- Examples:
| Variable | Description | Local Example |
|---|---|---|
DEV_BYPASS_AUTH |
Bypass authentication | true |
OPENAI_EMBEDDING_DEPLOYMENT |
Embedding model name | text-embedding-3-small |
OPENAI_EMBEDDING_DIMENSIONS |
Embedding dimensions | 1536 |
ENTRA_CLIENTID |
Entra App Client ID | Yes (production) |
ENTRA_AUTHORITY |
Entra authority URL | Yes (production) |
# Cosmos DB Emulator (local)
$env:COSMOS_CONNECTION_STRING = "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"
# Choose ONE of the following embedding providers:
# Option 1: OpenAI Native API
$env:OPENAI_ENDPOINT = "https://api.openai.com/v1"
$env:OPENAI_API_KEY = "sk-your-openai-key"
$env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
# Option 2: Azure AI Services (with API key)
# $env:OPENAI_ENDPOINT = "https://my-ai-service.cognitiveservices.azure.com/"
# $env:OPENAI_API_KEY = "your-azure-key"
# $env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
# Option 3: Local/Azure AI Foundry with API key
# $env:OPENAI_ENDPOINT = "http://localhost:8000" # or Azure Foundry URL
# $env:OPENAI_API_KEY = "your-api-key"
# $env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
# Development
$env:DEV_BYPASS_AUTH = "true"# Cosmos DB (cloud)
$env:COSMOS_ENDPOINT = "https://myaccount.documents.azure.com:443/"
# Azure credentials via DefaultAzureCredential (az login)
# Choose ONE of the following embedding providers:
# Option 1: Azure AI Services (cloud) with Managed Identity
$env:OPENAI_ENDPOINT = "https://my-openai.cognitiveservices.azure.com/"
$env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
# Uses DefaultAzureCredential (Managed Identity)
# Option 2: Azure AI Foundry (cloud) with Managed Identity
# $env:OPENAI_ENDPOINT = "https://my-project.services.ai.azure.com/api/projects/my-project-123"
# $env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
# Uses DefaultAzureCredential (Managed Identity)
# Option 3: OpenAI Native API
# $env:OPENAI_ENDPOINT = "https://api.openai.com/v1"
# $env:OPENAI_API_KEY = "sk-your-openai-key"
# $env:OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"The MCP Toolkit now supports local development with the Cosmos DB emulator via connection strings, so you don't need Azure credentials for local testing.
The docker-compose.yml includes both the MCP Toolkit and Cosmos DB emulator:
docker-compose upThis automatically configures:
- Cosmos DB Emulator at
https://localhost:8081 - MCP Toolkit at
http://localhost:8080/mcp - Pre-configured connection string for emulator
Download and install from: https://aka.ms/cosmosdb-emulator
Set the connection string environment variable instead of endpoint:
$env:COSMOS_CONNECTION_STRING = "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"Or for cloud production, use:
$env:COSMOS_ENDPOINT = "https://myaccount.documents.azure.com:443/"
# Uses DefaultAzureCredential automaticallyThe connection string takes priority; if it's set, cloud credentials are not used.
- Open
AzureCosmosDB.MCP.Toolkit.sln - Set
AzureCosmosDB.MCP.Toolkitas startup project - Press F5 to start debugging
- Open the repository folder
- Install C# Dev Kit extension
- Press F5 or use "Run and Debug" panel
- Select ".NET Core Launch (web)" configuration
The application supports hot reload for development:
dotnet watch run --project src/AzureCosmosDB.MCP.ToolkitChanges to C# files will automatically trigger a rebuild and restart.
dotnet test tests/AzureCosmosDB.MCP.Toolkit.TestsIntegration tests require a running Cosmos DB instance (emulator or Azure):
# Set test environment variables
$env:COSMOS_ENDPOINT = "your-cosmos-endpoint"
$env:COSMOS_KEY = "your-cosmos-key"
# Run tests
dotnet test tests/AzureCosmosDB.MCP.Toolkit.Tests --filter "Category=Integration"# Build
docker build -t mcp-toolkit:local -f Dockerfile .
# Run
docker run -p 8080:8080 `
-e DEV_BYPASS_AUTH=true `
-e COSMOS_ENDPOINT="your-endpoint" `
mcp-toolkit:localIf port 8080 is occupied:
# Find process using port 8080
netstat -ano | findstr :8080
# Kill the process (replace PID)
taskkill /PID <process-id> /F- Ensure Cosmos DB Emulator is running
- Trust the emulator's SSL certificate:
# Export certificate from emulator # Import to Trusted Root Certification Authorities
- Or disable SSL validation (development only):
$env:COSMOS_DISABLE_SSL_VERIFICATION = "true"
- Review README.md for deployment to Azure
- Check TESTING_GUIDE.md for comprehensive testing strategies
- See Configuration for production environment setup