Azure Cosmos DB MCP Server
以下是将英文翻译成中文: 基于 Node.js 的服务器,连接到 Azure Cosmos DB NoSQL 数据库,允许用户通过 NextJS 前端应用程序中的 AI 助手查询产品和订单。 Here's a slightly more nuanced translation, offering a bit more context: 一个使用 Node.js 构建的服务器,它连接到 Azure Cosmos DB NoSQL 数据库,并允许用户通过 NextJS 前端应用中的 AI 助手来查询产品和订单信息。 **Explanation of differences and why the second option might be preferred:** * **"基于" (jī yú) vs. "使用" (shǐ yòng):** While both mean "based on" or "using," "使用" (shǐ yòng) is often preferred when referring to technology or tools. It emphasizes the *use* of Node.js rather than just its foundation. * **"信息" (xìn xī):** Adding "信息" (information) after "产品和订单" (products and orders) clarifies that the user is querying *information* about these items. It's a subtle addition that improves clarity. * **"构建" (gòu jiàn):** Using "构建" (build) instead of just implying it is more accurate. Ultimately, the best translation depends on the specific context and the desired level of detail. Both are accurate, but the second option is slightly more descriptive.
README
Azure Cosmos DB MCP 客户端 & 服务器
此仓库包含一个项目,展示了如何为 Azure Cosmos DB 创建 MCP 服务器和客户端。该项目分为两个部分:
- 前端应用程序:NextJS 15 应用程序,显示产品目录,并具有 AI 助手,可帮助用户在目录中查找产品并获取过去的订单。
- MCP 服务器组件,连接到 Azure Cosmos DB NoSQL 数据库,负责从数据库读取产品和订单。

Azure 架构
- 一个 Azure Cosmos DB NoSQL 数据库,用于存储产品目录
- 一个 node.js 服务器,用作 MCP 服务器组件
参考
逐步演练
安装
Azure Cosmos DB
在 Azure 门户中,创建一个 Azure Cosmos DB for NoSQL 帐户。
- 为您的 Azure Cosmos DB 帐户指定一个唯一的名称。在本次演练的其余部分,我们将使用 cosmos-eastus2-nosql-2。

- 点击“下一步:全局分布”

- 接受默认值,然后点击“下一步:网络”

- 接受默认值,然后点击“下一步:备份策略”
- 选择“定期”备份策略
- 选择“本地冗余备份存储”

- 点击“下一步:加密”

- 点击“查看 + 创建”以开始验证

- 点击“创建”以开始创建 Azure Cosmos DB for NoSQL 帐户
对于此项目,您需要在 Azure Cosmos DB 帐户上启用向量支持。
-
在设置部分,选择“功能”,然后选择“NoSQL API 的向量搜索”
-
在打开的面板中,点击“启用”按钮

-
创建 Azure Cosmos DB eShop 数据库和 Products 容器
-
点击 eShop 旁边的“...”以显示上下文菜单,然后选择“新建容器”以在 eShop 数据库中创建“carts”容器。
确保分区键为 "/id"(分区键区分大小写)
展开“容器向量策略”,然后点击“添加向量嵌入”按钮

- 创建 carts 容器

存储帐户
- 创建一个存储帐户来存储产品图像
有关更多详细信息,请参阅文档:https://learn.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal






安装软件先决条件
- 在 Azure 中创建一个虚拟机或使用您的本地计算机
- 从 https://nodejs.org/en/download 安装 node.js v22.13.1 (LTS)
- 从 https://code.visualstudio.com/download 安装 Visual Studio Code x64 1.97.0
- 从 https://git-scm.com/downloads 安装 Git 2.47.12 x64
- 从 https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-9.0.102-windows-x64-installer 安装 .NET SDK x64 v9.0.102
- 打开一个终端窗口并添加 nuget 源,使用以下命令:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
- 如果需要,更改 Windows 计算机的 PowerShell 执行策略。以管理员模式打开一个 Powershell 窗口并运行此命令
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- 如果需要,安装 nuget、powershell、az cli 和 az 模块
# 安装 az cli
winget install -e --id Microsoft.AzureCLI
# 安装 nuget 并引用 nuget 源
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
# 更新到最新的 Powershell 版本(撰写本文时为 7.5)
winget install --id Microsoft.PowerShell --source winget
# 安装 az 模块
Install-Module -Name Az -Repository PSGallery -Force -AllowClobber
- 打开一个终端窗口并克隆存储库:
git clone https://github.com/patrice-truong/cosmosdb-mcp.git
cd cosmosdb-mcp
- 导航到 nextjs 文件夹并安装依赖项
cd cosmosdb-mcp/nextjs
npm install --legacy-peer-deps
- 在 nextjs 文件夹中,创建并配置一个 .env 文件,其中包含以下值:
AZURE_COSMOSDB_NOSQL_ENDPOINT=https://<cosmosdb_account_name>.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
AZURE_STORAGE_ACCOUNT_NAME=<storage_account_name>
AZURE_STORAGE_CONTAINER_NAME=<container_name>
- 获取您的租户 ID。可以使用以下命令检索租户 ID:
az login
az account show --query tenantId -o tsv
- 在 webapi 文件夹中,配置 appsettings.json 文件,并将 tenant_id 替换为在上一步中获得的值:
{
"CosmosDb": {
"Endpoint": "https:/<cosmosdb_account_name>.documents.azure.com:443/",
"TenantId": "<tenant_id>",
"DatabaseName": "eshop",
"ProductsContainerName": "products",
"CartsContainerName": "carts",
"OrdersContainerName": "orders"
},
"AzureBlobStorage": {
"AccountName": "<storage_account_name>"
}
}
- 在 Azure 门户中创建一个应用程序注册
- 在 Azure 门户中创建一个应用程序密钥
- 您需要允许您的应用程序访问 Azure Cosmos DB。检索下面提到的 4 个 ID 并修改文件 "populate/set_rbac.ps1"。
| 变量 | 参考 |
|---|---|
| 订阅 ID | Cosmos DB > 概述 > 订阅 ID |
| Azure Cosmos DB 帐户名称 | cosmos-eastus2-nosql-2 |
| 资源组名称 | Cosmos DB > 概述 > 资源组名称 |
| 主体 ID | 应用程序注册对象 ID |
$SubscriptionId = "<subscription-id>" # Azure 订阅 ID
$AccountName = "<cosmosdb-account-name>" # cosmos db 帐户名称
$ResourceGroupName = "<resource-group-name>" # Cosmos DB 帐户的资源组名称
$PrincipalId = "<principal-id>" # 在 Entra ID 中注册的应用程序的对象 ID
- 打开一个 Powershell 提示符,运行 Connect-AzAccount 并执行 ./set_rbac.ps1

- 允许您的应用程序(或虚拟机)访问存储帐户
- 在 Azure 门户中,转到您的存储帐户
- 在菜单中选择“访问控制 (IAM)”

- 点击“添加角色分配”
- 在筛选器文本框中,键入“存储 Blob 数据参与者”

- 点击“成员”
- 选择您的应用程序的名称

- 点击“选择”按钮
- 点击“查看 + 分配”

- 创建一个容器并将“azure-storage”文件夹的内容复制到您的存储帐户



- 使用 dotnet build 构建 webapi 后端项目
cd webapi
dotnet build
18. 在您的辅助区域 VM(澳大利亚东部)上,使用主区域(美国东部 2)中套接字服务器的 IP 地址修改 .env 文件

- 此项目中没有内置身份验证。用户电子邮件硬编码在 /nextjs/models/constants.ts 中。根据您的演示需求进行更改

- 在 mcp-server 和 nextjs 文件夹中,将 .env.template 复制到 .env 并修改值以适合您的演示需求
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
- 构建 nextjs 前端项目
cd nextjs
npm run build

填充产品目录
在本节中,我们将从 populate/catalog.json 文件中读取产品目录并填充 Azure Cosmos DB for NoSQL 数据库
- 使用您的 cosmosdb 帐户名称修改 appsettings.json
{
"CosmosDb": {
"Endpoint": "https://<cosmosdb_account_name>.documents.azure.com:443/",
"TenantId": "<tenant_id>",
"DatabaseName": "eshop",
"ProductsContainerName": "products",
"OrdersContainerName": "orders",
}
}
- 打开一个终端窗口,导航到 populate 文件夹,执行 az login,然后执行 dotnet run

- 验证 Azure Cosmos DB 容器是否已正确填充

演示脚本
演示初始化:
- 在您的开发计算机上,启动 mcp 服务器
cd mcp-server
npx ts-node src/server.ts
- 启动前端项目
- NextJS 前端(店面)
- cd nextjs
- npm start
- (可选)打开命令提示符并使用以下命令启动 MCP 检查器: npx -y @modelcontextprotocol/inspector
演示步骤:
- 导航到 http://localhost:3002。
- 点击右上角的 AI 助手图标
- 输入“我对背包感兴趣”(产品列表刷新为背包列表)
- 输入“获取我的订单”(订单列表刷新为订单列表)

推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。