Home
Login

為 Milvus 向量資料庫提供 Model Context Protocol (MCP) 伺服器實現,實現 AI 應用與向量資料庫的無縫整合

Apache-2.0Python 146zilliztechmcp-server-milvus Last Updated: 2025-06-05

mcp-server-milvus 項目詳細介紹

項目概述

mcp-server-milvus 是由 Zilliz Tech 開發的一個開源項目,它為 Milvus 向量資料庫提供了 Model Context Protocol (MCP) 伺服器實現。該項目使得LLM應用能夠通過標準化協定無縫集成和訪問Milvus向量資料庫的功能。

核心功能特性

支援的操作工具

該MCP伺服器提供了以下核心工具:

  • milvus_text_search: 使用全文搜索功能搜索文檔

    • 參數: collection_name, query_text, limit, output_fields, drop_ratio
  • milvus_vector_search: 在集合上執行向量相似性搜索

    • 參數: collection_name, vector, vector_field, limit, output_fields, metric_type
  • milvus_query: 使用過濾表達式查詢集合

    • 參數: collection_name, filter_expr, output_fields, limit
  • milvus_list_collections: 列出資料庫中的所有集合

  • milvus_create_collection: 創建具有指定模式的新集合

    • 參數: collection_name, collection_schema, index_params
  • milvus_load_collection: 將集合加載到記憶體中進行搜索和查詢

    • 參數: collection_name, replica_number
  • milvus_release_collection: 從記憶體中釋放集合

    • 參數: collection_name
  • milvus_insert_data: 向集合中插入數據

    • 參數: collection_name, data
  • milvus_delete_entities: 基於過濾表達式從集合中刪除實體

    • 參數: collection_name, filter_expr

系統要求

  • Python 3.10 或更高版本
  • 運行中的 Milvus 實例(本地或遠端)
  • uv 工具(推薦用於運行伺服器)

安裝和配置

克隆項目

git clone https://github.com/zilliztech/mcp-server-milvus.git
cd mcp-server-milvus

直接運行伺服器

推薦的方式是使用 uv 直接運行伺服器,無需安裝:

uv run src/mcp_server_milvus/server.py --milvus-uri http://localhost:19530

或者通過設置 .env 檔案中的環境變數:

uv run src/mcp_server_milvus/server.py

支援的客戶端應用

該MCP伺服器可以與多種支援Model Context Protocol的LLM應用程式配合使用:

Claude Desktop 集成

  1. 安裝 Claude Desktop
  2. 配置 claude_desktop_config.json 檔案:
{
  "mcpServers": {
    "milvus": {
      "command": "/PATH/TO/uv",
      "args": [
        "--directory",
        "/path/to/mcp-server-milvus/src/mcp_server_milvus",
        "run",
        "server.py",
        "--milvus-uri",
        "http://localhost:19530"
      ]
    }
  }
}

Cursor 編輯器集成

Cursor 支援兩種配置方式:

方式一:通過GUI配置

  1. 進入 Cursor Settings > Features > MCP
  2. 點擊 "+ Add New MCP Server" 按鈕
  3. 填寫表單:
    • Type: 選擇 stdio
    • Name: milvus
    • Command: /PATH/TO/uv --directory /path/to/mcp-server-milvus/src/mcp_server_milvus run server.py --milvus-uri http://127.0.0.1:19530

方式二:配置文件

創建 .cursor/mcp.json 檔案:

{
  "mcpServers": {
    "milvus": {
      "command": "/PATH/TO/uv",
      "args": [
        "--directory",
        "/path/to/mcp-server-milvus/src/mcp_server_milvus",
        "run",
        "server.py",
        "--milvus-uri",
        "http://127.0.0.1:19530"
      ]
    }
  }
}

環境變數配置

  • MILVUS_URI: Milvus 伺服器 URI(可替代 --milvus-uri 參數)
  • MILVUS_TOKEN: 可選的認證令牌
  • MILVUS_DB: 資料庫名稱(默認為 "default")

使用示例

在 Claude Desktop 中的使用

用戶可以通過自然語言與 Milvus 資料庫交互:

查詢集合列表:

What are the collections I have in my Milvus DB?

搜索文檔:

Find documents in my text_collection that mention "machine learning"

在 Cursor 中的使用

創建新集合:

Create a new collection called 'articles' in Milvus with fields for title (string), content (string), and a vector field (128 dimensions)

故障排除

連接問題

  • 驗證 Milvus 實例正在運行
  • 檢查 URI 配置是否正確
  • 確保防火牆規則不會阻止連接
  • 嘗試使用 127.0.0.1 而不是 localhost

認證問題

  • 驗證 MILVUS_TOKEN 是否正確
  • 檢查 Milvus 實例是否需要認證
  • 確保具有執行操作的正確權限

技術架構

該項目基於 Python 開發,採用了現代化的開發工具鏈:

  • 使用 uv 作為包管理和運行工具
  • 遵循 MCP 標準協定規範
  • 提供完整的 Milvus 資料庫操作封裝
  • 支援多種 AI 應用客戶端

應用場景

該項目主要適用於以下場景:

  • AI 驅動的程式碼編輯器增強
  • 聊天介面的上下文增強
  • 自定義 AI 工作流構建
  • 向量資料庫與 LLM 的集成
  • 語義搜索和 RAG(檢索增強生成)應用

通過 mcp-server-milvus,開發者可以輕鬆地將 Milvus 向量資料庫的強大功能集成到各種 AI 應用中,為用戶提供更智能、更準確的交互體驗。

Star History Chart