An AI-powered assistant that lets you query and manage Azure CosmosDB databases using natural language through Microsoft 365 Copilot. This project implements a Declarative Agent that connects to CosmosDB via an MCP (Model Context Protocol) server running as an Azure Function.
CosmosDB Copilot enables you to interact with your Azure CosmosDB databases conversationally. Instead of writing code or using management tools, simply ask questions like:
- "What databases do I have?"
- "Show me all products in the electronics category"
- "List containers in my SampleDB database"
- "Update the price of item ABC123"
The agent understands your intent and executes the appropriate CosmosDB operations through secure, managed tools.
- List Databases: View all databases in your CosmosDB account
- List Containers: Explore containers within a specific database
- Query Items: Execute SQL queries against your data using natural language
- Get Items: Retrieve specific items by ID and partition key
- Update Items: Create or update documents in your containers
- Delete Items: Remove documents from your containers
This project consists of two main components:
-
MCP Server (
mcp-function/): An Azure Function that exposes CosmosDB operations as MCP tools. It uses Azure Managed Identity for secure authentication to CosmosDB. -
Declarative Agent (
appPackage/): The M365 Copilot agent configuration that integrates with the MCP server, enabling natural language interactions.
To use and deploy CosmosDB Copilot, you need:
- Azure Developer CLI (azd)
- Azure Functions Core Tools >= 4.0.7030
- Python 3.12
- An Azure CosmosDB account
- Microsoft 365 Agents Toolkit VS Code Extension version 6.0 or higher
- Microsoft 365 Copilot license
- A Microsoft 365 account for development
The MCP server needs to be deployed to Azure Functions to make it accessible to your Declarative Agent.
cd mcp-function
# Set your CosmosDB endpoint
azd env set COSMOS_ENDPOINT "https://<your-cosmosdb-account>.documents.azure.com:443/"
# Deploy to Azure
azd upThis will:
- Create an Azure resource group
- Deploy the Azure Function (Flex Consumption plan)
- Configure Application Insights for monitoring
- Set up Managed Identity for secure CosmosDB access
After deployment, note the MCP endpoint URL:
https://<function-app-name>.azurewebsites.net/runtime/webhooks/mcp/sse?code=<mcp-extension-key>
See mcp-function/README.md for detailed deployment instructions.
-
Open the project in VS Code with the Microsoft 365 Agents Toolkit extension installed
-
Sign in to your M365 developer account through the toolkit
-
Update
appPackage/ai-plugin.jsonwith your MCP server endpoint URL:"runtimes": [ { "type": "RemoteMCPServer", "spec": { "url": "https://<your-function-app>.azurewebsites.net/runtime/webhooks/mcp/sse?code=<your-key>" } } ]
-
Click "Provision" in the Agents Toolkit to create the app registration
-
Click "Start Debugging" to preview your agent in Copilot
- Open Microsoft 365 Copilot in Edge or Chrome
- Find "CosmosDB Copilot" in your available agents
- Start a conversation with prompts like:
- "List my databases"
- "What containers are in SampleDB?"
- "Show me all products where category is electronics"
- "Get item with ID ABC123 from the Products container"
| Folder/File | Description |
|---|---|
mcp-function/ |
Azure Function that implements the MCP server with CosmosDB tools. See mcp-function/README.md for details. |
appPackage/ |
Declarative Agent configuration files |
├─ declarativeAgent.json |
Agent definition with name, description, and conversation starters |
├─ ai-plugin.json |
MCP server connection, authentication, and function definitions |
├─ manifest.json |
Teams/M365 integration manifest |
├─ instruction.txt |
System prompt that defines the agent's behavior |
.vscode/ |
VS Code settings and launch configurations |
├─ mcp.json |
Local MCP server configuration for development |
env/ |
Environment files for different deployment stages |
m365agents.yml |
Defines provisioning and deployment lifecycle for the agent |
The MCP server exposes these tools that can be invoked through natural language:
| Tool | Description | Example Prompt |
|---|---|---|
list_databases |
List all databases in your CosmosDB account | "What databases do I have?" |
list_containers |
List containers in a specific database | "Show me containers in SampleDB" |
query_items |
Execute SQL queries against containers | "Find all products with price > 100" |
get_item |
Retrieve a specific item by ID and partition key | "Get item ABC123 from Products" |
update_item |
Insert or update an item (upsert) | "Add a new product with name Laptop" |
delete_item |
Delete an item by ID and partition key | "Delete item ABC123 from Products" |
For local development and testing:
-
Start Azurite (Azure Storage emulator):
docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
-
Configure your local settings in
mcp-function/src/local.settings.json:{ "Values": { "COSMOS_ENDPOINT": "https://<your-account>.documents.azure.com:443/", "AZURE_CLIENT_ID": "<your-managed-identity-client-id>" } } -
Run the function locally:
cd mcp-function/src pip install -r requirements.txt func start -
Test with MCP Inspector:
npx @modelcontextprotocol/inspector
Connect to:
http://0.0.0.0:7071/runtime/webhooks/mcp/sse
- Authentication: The MCP server uses Azure Function-level authentication with function keys
- CosmosDB Access: Uses Azure Managed Identity for secure, credential-free access to CosmosDB
- No Credentials: No database keys or secrets are stored in code or configuration files
az webapp log tail --name <function-app-name> --resource-group <resource-group>az functionapp show --name <function-app-name> --resource-group <resource-group> --query "state" -o tsv- Ensure your M365 Copilot license is active
- Verify the agent is provisioned in the Agents Toolkit
- Check that the MCP server endpoint is accessible
- Microsoft 365 Copilot Extensibility Overview
- Build Declarative Agents with Agents Toolkit
- Declarative Agents Overview
- Microsoft 365 Agents Toolkit
- Add Plugins to Declarative Agents
To remove all deployed resources:
cd mcp-function
azd downThis project is an example implementation. Feel free to fork and customize it for your specific CosmosDB use cases.
See LICENSE file for details.