Azure Cosmos DB MCP Server

MIT License
1

Integrations

  • Provides a backend implementation for the MCP server using .NET, connecting to Azure Cosmos DB for database operations

  • Serves as the foundation for the MCP server component, connecting to Azure Cosmos DB to read products and orders data

  • Integrates with Azure OpenAI services for text embeddings and the AI Assistant functionality that helps users find products and retrieve order information

Azure Cosmos DB MCP 클라이언트 및 서버

이 리포지토리에는 Azure Cosmos DB용 MCP 서버와 클라이언트를 만드는 방법을 보여주는 프로젝트가 포함되어 있습니다. 이 프로젝트는 두 부분으로 나뉩니다.

  • 프런트엔드 애플리케이션: 제품 카탈로그를 표시하고 사용자가 카탈로그에서 제품을 찾고 이전 주문을 확인할 수 있도록 돕는 AI 어시스턴트를 갖춘 NextJS 15 애플리케이션
  • Azure Cosmos DB NoSQL 데이터베이스에 연결되어 데이터베이스에서 제품과 주문을 읽는 역할을 하는 MCP 서버 구성 요소입니다.

Azure 아키텍처

  • 제품 카탈로그를 저장하는 Azure Cosmos DB NoSQL 데이터베이스
  • MCP 서버 구성 요소 역할을 하는 node.js 서버

참고문헌

단계별 연습

설치

애저 코스모스 DB

Azure Portal에서 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 데이터베이스와 제품 컨테이너를 만듭니다.
  • eShop 옆에 있는 "..."을 클릭하여 상황에 맞는 메뉴를 표시하고 "새 컨테이너"를 선택하여 eShop 데이터베이스에 "카트" 컨테이너를 만듭니다.

파티션 키가 "/id" 인지 확인하세요(파티션 키는 대소문자를 구분합니다)

"컨테이너 벡터 정책"을 확장하고 "벡터 임베딩 추가" 버튼을 클릭합니다.

  • 카트 컨테이너 만들기

저장 계정

  1. 제품 이미지를 저장하기 위한 저장소 계정을 생성하세요

자세한 내용은 다음 설명서를 참조하세요: https://learn.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal

**소프트웨어 필수 구성 요소 설치**

  1. Azure에서 가상 머신을 만들거나 로컬 컴퓨터를 사용하세요.
  2. https://nodejs.org/en/download 에서 node.js v22.13.1(LTS)을 설치하세요.
  3. https://code.visualstudio.com/download 에서 Visual Studio Code x64 1.97.0을 설치하세요.
  4. https://git-scm.com/downloads 에서 Git 2.47.12 x64를 설치하세요.
  5. https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-9.0.102-windows-x64-installer 에서 .NET SDK x64 v9.0.102를 설치하세요.
  6. 터미널 창을 열고 NuGet 소스를 추가하세요.

지엑스피1

  1. 필요한 경우 Windows 컴퓨터의 PowerShell 실행 정책을 변경하세요. PowerShell 창을 관리자 모드로 열고 다음 명령을 실행하세요.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  1. 필요한 경우 nuget, powershell, az cli 및 az 모듈을 설치하세요.
# install az cli winget install -e --id Microsoft.AzureCLI # install nuget and reference nuget source Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force # update to latest Powershell release (7.5 as of writing) winget install --id Microsoft.PowerShell --source winget # install az modules Install-Module -Name Az -Repository PSGallery -Force -AllowClobber
  1. 터미널 창을 열고 저장소를 복제합니다.
git clone https://github.com/patrice-truong/cosmosdb-mcp.git cd cosmosdb-mcp
  1. nextjs 폴더로 이동하여 종속성을 설치합니다.
cd cosmosdb-mcp/nextjs npm install --legacy-peer-deps
  1. 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>
  1. 테넌트 ID를 확인하세요. 다음 명령을 사용하여 테넌트 ID를 검색할 수 있습니다.
az login az account show --query tenantId -o tsv
  1. 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>" } }
  1. Azure Portal에서 앱 등록 만들기
  2. Azure Portal에서 앱 비밀 만들기
  3. 앱이 Azure Cosmos DB에 액세스할 수 있도록 허용해야 합니다. 아래 언급된 4개의 ID를 검색하여 "populate/set_rbac.ps1" 파일을 수정하세요.
변하기 쉬운참조
구독 IDCosmos DB > 개요 > 구독 ID
Azure Cosmos DB 계정 이름코스모스-eastus2-nosql-2
리소스 그룹 이름Cosmos DB > 개요 > 리소스 그룹 이름
교장 ID앱 등록 개체 ID
$SubscriptionId = "<subscription-id>" # Azure subscription id $AccountName = "<cosmosdb-account-name>" # cosmos db account name $ResourceGroupName = "<resource-group-name>" # resource group name of the Cosmos DB account $PrincipalId = "<principal-id>" # object id of the app registered in Entra ID
  1. PowerShell 프롬프트를 열고 Connect-AzAccount를 실행한 후 ./set_rbac.ps1을 실행합니다.

  1. 앱(또는 가상 머신)이 저장소 계정에 액세스하도록 허용합니다.
  • Azure Portal에서 저장소 계정으로 이동하세요.
  • 메뉴에서 액세스 제어(IAM)를 선택하세요

  • "역할 할당 추가"를 클릭하세요.
  • 필터 텍스트 상자에 "Storage Blob Data Contributor"를 입력합니다.

  • "회원"을 클릭하세요
  • 애플리케이션 이름을 선택하세요

  • "선택" 버튼을 클릭하세요
  • "검토 및 할당"을 클릭하세요.

  1. 컨테이너를 만들고 "azure-storage" 폴더의 내용을 스토리지 계정에 복사합니다.

  1. dotnet build로 webapi 백엔드 프로젝트 빌드
cd webapi dotnet build

18. 보조 지역 VM(호주 동부)에서 기본 지역(미국 동부 2)의 소켓 서버의 IP 주소로 .env 파일을 수정합니다.

  1. 이 프로젝트에는 인증 기능이 내장되어 있지 않습니다. 사용자 이메일은 /nextjs/models/constants.ts에 하드코딩되어 있습니다. 데모 요구 사항에 맞게 변경하세요.

  1. 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
  1. nextjs 프런트엔드 프로젝트 빌드
cd nextjs npm run build

제품 카탈로그를 채우세요

이 섹션에서는 populate/catalog.json 파일에서 제품 카탈로그를 읽고 NoSQL 데이터베이스용 Azure Cosmos DB를 채웁니다.

  1. cosmosdb 계정 이름으로 appsettings.json을 수정하세요.
{ "CosmosDb": { "Endpoint": "https://<cosmosdb_account_name>.documents.azure.com:443/", "TenantId": "<tenant_id>", "DatabaseName": "eshop", "ProductsContainerName": "products", "OrdersContainerName": "orders", } }
  1. 터미널 창을 열고 populate 폴더로 이동한 후 az login을 실행한 다음 dotnet run을 실행합니다.

  1. Azure Cosmos DB 컨테이너가 제대로 채워졌는지 확인하세요.

데모 스크립트

데모 초기화:

  1. 개발용 컴퓨터에서 mcp 서버를 시작하세요.
cd mcp-server npx ts-node src/server.ts
  1. 프런트엔드 프로젝트 시작
  • NextJS 프런트엔드(스토어 프런트)
    • cd 넥스트js
    • npm 시작
  1. 선택적으로 명령 프롬프트를 열고 다음 명령으로 MCP 검사기를 시작합니다: npx -y @modelcontextprotocol/inspector

데모 단계:

  1. http://localhost:3002 로 이동합니다.
  2. 오른쪽 상단의 AI Assistant 아이콘을 클릭하세요
  3. "백팩에 관심이 있어요"를 입력하세요(백팩 목록이 있는 제품 새로 고침 목록)
  4. "내 주문 가져오기"를 입력하세요(주문 목록이 주문 목록으로 새로 고쳐집니다)

-
security - not tested
A
license - permissive license
-
quality - not tested

Azure Cosmos DB NoSQL 데이터베이스에 연결되는 Node.js 서버로, 사용자는 NextJS 프런트엔드 애플리케이션의 AI Assistant를 통해 제품과 주문을 쿼리할 수 있습니다.

  1. Azure 아키텍처
    1. 참고문헌
      1. 단계별 연습
        1. 설치
      2. 제품 카탈로그를 채우세요
        1. 데모 스크립트

          Related MCP Servers

          • A
            security
            A
            license
            A
            quality
            This 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 -
            16
            4
            Python
            MIT License
            • Apple
          • -
            security
            A
            license
            -
            quality
            A server that enables LLMs like Claude to interact with Azure Cosmos DB databases through natural language queries, acting as a translator between AI assistants and database systems.
            Last updated -
            JavaScript
            MIT License
          • -
            security
            F
            license
            -
            quality
            A Node.js server that processes mathematical calculations and natural language math queries through RESTful API endpoints.
            Last updated -
            JavaScript
          • A
            security
            A
            license
            A
            quality
            A server that enables LLMs (like Claude and VSCode Copilot) to interact with Azure Cosmos DB data through natural language queries, acting as a translator between AI assistants and your database.
            Last updated -
            3
            11
            1
            JavaScript
            MIT License
            • Apple

          View all related MCP servers

          ID: dtf38p20zp