This Node.js-based MCP (Model Context Protocol) server connects to Azure Cosmos DB, providing an interface for AI applications to retrieve product and order data. It acts as a backend component for applications that need to access structured data from Cosmos DB through the MCP protocol.
You'll need to have the following installed:
Create a new Azure Cosmos DB for NoSQL account in the Azure portal
Enable vector search support:
Create the necessary containers:
$SubscriptionId = "<subscription-id>"
$AccountName = "<cosmosdb-account-name>"
$ResourceGroupName = "<resource-group-name>"
$PrincipalId = "<principal-id>"
# Run set_rbac.ps1 script to configure proper permissions
git clone https://github.com/patrice-truong/cosmosdb-mcp.git
cd cosmosdb-mcp
cd mcp-server
npm install --legacy-peer-deps
.env
file:AZURE_COSMOSDB_NOSQL_ENDPOINT=https://<cosmosdb_account>.documents.azure.com:443/
AZURE_COSMOSDB_NOSQL_DATABASE=eshop
AZURE_COSMOSDB_NOSQL_PRODUCTS_CONTAINER=products
AZURE_COSMOSDB_NOSQL_CARTS_CONTAINER=carts
AZURE_COSMOSDB_NOSQL_ORDERS_CONTAINER=orders
NEXT_PUBLIC_AZURE_TENANT_ID=<tenant_id>
NEXT_PUBLIC_AZURE_CLIENT_ID=<client_id>
NEXT_PUBLIC_AZURE_CLIENT_SECRET=<client_secret>
NEXT_PUBLIC_AZURE_STORAGE_ACCOUNT_NAME=<storage_account_name>
NEXT_PUBLIC_AZURE_STORAGE_CONTAINER_NAME=img
AZURE_OPENAI_ENDPOINT=https://<azure_openai_account>.openai.azure.com/
AZURE_OPENAI_API_KEY=<azure_openai_key>
AZURE_OPENAI_EMBEDDING_MODEL=text-embedding-3-small
AZURE_OPENAI_API_VERSION=2024-05-01-preview
cd mcp-server
npx ts-node src/server.ts
The server will start listening for MCP connections.
Before using the server, you need to populate your Cosmos DB with sample data:
cd populate
appsettings.json
file with your Cosmos DB credentials:{
"CosmosDb": {
"Endpoint": "https://<cosmosdb_account_name>.documents.azure.com:443/",
"TenantId": "<tenant_id>",
"DatabaseName": "eshop",
"ProductsContainerName": "products",
"OrdersContainerName": "orders"
}
}
dotnet run
This will populate your database with sample products from the catalog.json
file.
For debugging and testing your MCP server, you can use the MCP Inspector:
npx -y @modelcontextprotocol/inspector
This tool helps you verify that your MCP server is correctly handling requests and returning the expected data.
To connect a client application to your MCP server:
Once the server is running, clients can make MCP requests to:
The server handles these requests by querying the Cosmos DB and returning the results formatted according to the MCP protocol.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.