Skip to main content
Glama
mhalder

Qdrant MCP Server

by mhalder

Qdrant MCP 服务器

CI codecov

一个模型上下文协议 (MCP) 服务器,通过 Qdrant 向量数据库和多种嵌入提供程序提供语义搜索功能。

功能特性

  • 零配置:与 Ollama 开箱即用 - 无需 API 密钥

  • 隐私优先:本地嵌入和向量存储 - 数据绝不会离开您的机器

  • 代码向量化:智能代码库索引,支持 AST 感知分块和语义代码搜索

  • Git 历史搜索:索引提交历史,以便对过去的更改、修复和模式进行语义搜索

  • 高级搜索:上下文搜索(代码 + Git 关联)以及跨多个存储库的联合搜索

  • 多种提供程序:Ollama(默认)、OpenAI、Cohere 和 Voyage AI

  • 混合搜索:结合语义搜索和关键词搜索以获得更好的结果

  • 语义搜索:支持元数据过滤的自然语言搜索

  • 增量索引:高效更新 - 仅重新索引已更改的文件

  • 可配置提示词:创建自定义提示词以实现引导式工作流,无需更改代码

  • 速率限制:具有指数退避功能的智能限流

  • 完整 CRUD:创建、搜索和管理集合与文档

  • 结构化日志:通过 Pino 进行 JSON 日志记录,支持可配置的日志级别

  • 灵活部署:本地运行 (stdio) 或作为远程 HTTP 服务器运行

  • API 密钥认证:连接到受保护的 Qdrant 实例(Qdrant Cloud,或带有 API 密钥的自托管实例)

Related MCP server: MCP Qdrant Server with OpenAI Embeddings

快速入门

先决条件

  • Node.js 22.x 或 24.x

  • 支持 Compose 的 Podman 或 Docker

安装

# Clone and install
git clone https://github.com/mhalder/qdrant-mcp-server.git
cd qdrant-mcp-server

# Node 22.x
npm install

# Node 24.x (requires C++20 flag for native module compilation)
CXXFLAGS='-std=c++20' npm install

# Start services (choose one)
podman compose up -d   # Using Podman
docker compose up -d   # Using Docker

# Pull the embedding model
podman exec ollama ollama pull nomic-embed-text  # Podman
docker exec ollama ollama pull nomic-embed-text  # Docker

# Build
npm run build

配置

本地设置 (stdio 传输)

claude mcp add --transport stdio qdrant -- node /path/to/qdrant-mcp-server/build/index.js

或者添加到 ~/.claude.json:

{
  "mcpServers": {
    "qdrant": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/qdrant-mcp-server/build/index.js"]
    }
  }
}

对于 Qdrant Cloud 或受保护的实例,添加 --env QDRANT_API_KEY=your-key 或在环境变量配置中设置。

尝试一下:

Create a collection called "notes" and add a document about machine learning

启用示例提示词: 将 prompts.example.json 复制到 prompts.json 并重启。使用 /prompt 列出可用提示词。

远程设置 (HTTP 传输)

⚠️ 安全警告:在生产环境中部署 HTTP 传输时:

  • 始终在具有 HTTPS 的反向代理(nginx, Caddy)后运行

  • 在代理层实现认证/授权

  • 使用防火墙限制对受信任网络的访问

  • 在没有保护的情况下,切勿直接暴露在公共互联网上

  • 考虑在代理层实现速率限制

  • 监控服务器日志以发现可疑活动

启动服务器:

TRANSPORT_MODE=http HTTP_PORT=3000 node build/index.js

选项 1:使用 claude mcp add

claude mcp add --transport http qdrant http://your-server:3000/mcp

选项 2:添加到 ~/.claude.json

{
  "mcpServers": {
    "qdrant": {
      "type": "http",
      "url": "http://your-server:3000/mcp"
    }
  }
}

使用不同的提供程序:

"env": {
  "EMBEDDING_PROVIDER": "openai",  // or "cohere", "voyage"
  "OPENAI_API_KEY": "sk-...",      // provider-specific API key
  "QDRANT_URL": "http://localhost:6333"
}

更改后请重启。

请参阅下方的 高级配置 部分了解所有选项。

工具

集合管理

工具

描述

create_collection

使用指定的距离度量(余弦/欧几里得/点积)创建集合

list_collections

列出所有集合

get_collection_info

获取集合详情和统计信息

delete_collection

删除集合及所有文档

文档操作

工具

描述

add_documents

添加带有自动嵌入的文档(支持字符串/数字 ID,元数据)

semantic_search

带有可选元数据过滤的自然语言搜索

hybrid_search

结合语义和关键词 (BM25) 搜索以及 RRF 的混合搜索

delete_documents

按 ID 删除特定文档

代码向量化

工具

描述

index_codebase

索引代码库以进行支持 AST 感知分块的语义代码搜索

search_code

使用自然语言查询搜索已索引的代码库

reindex_changes

增量重新索引仅更改的文件(检测添加/修改/删除)

get_index_status

获取代码库的索引状态和统计信息

clear_index

删除代码库的所有索引数据

Git 历史

工具

描述

index_git_history

索引 Git 提交历史,以便对过去的更改和修复进行语义搜索

search_git_history

使用自然语言查询搜索已索引的 Git 历史

index_new_commits

增量索引自上次索引以来的新提交

get_git_index_status

获取存储库 Git 历史的索引状态和统计信息

clear_git_index

删除存储库的所有已索引 Git 历史数据

高级搜索

工具

描述

contextual_search

结合文件-提交关联的代码 + Git 历史搜索

federated_search

使用倒数排名融合 (RRF) 排序跨多个存储库进行搜索

资源

  • qdrant://collections - 列出所有集合

  • qdrant://collection/{name} - 集合详情

可配置提示词

创建针对您特定用例的自定义提示词,无需修改代码。提示词为常见任务提供引导式工作流。

注意:默认情况下,服务器会在项目根目录中查找 prompts.json。如果文件存在,提示词会自动加载。您可以使用 PROMPTS_CONFIG_FILE 环境变量指定自定义路径。

设置

  1. 创建提示词配置文件(例如,项目根目录下的 prompts.json):

    请参阅 prompts.example.json 获取您可以复制和自定义的示例配置。

  2. 配置服务器(可选 - 仅在需要自定义路径时需要):

如果您将 prompts.json 放在项目根目录中,则无需额外配置。要使用自定义路径:

{
  "mcpServers": {
    "qdrant": {
      "command": "node",
      "args": ["/path/to/qdrant-mcp-server/build/index.js"],
      "env": {
        "QDRANT_URL": "http://localhost:6333",
        "PROMPTS_CONFIG_FILE": "/custom/path/to/prompts.json"
      }
    }
  }
}
  1. 在 AI 助手中使用提示词:

Claude Code:

/mcp__qdrant__find_similar_docs papers "neural networks" 10

VSCode:

/mcp.qdrant.find_similar_docs papers "neural networks" 10

示例提示词

请参阅 prompts.example.json 获取现成的提示词,包括:

  • setup_rag_collection - 创建 RAG 优化集合

  • analyze_and_optimize - 集合洞察和建议

  • compare_search_strategies - 语义搜索与混合搜索对比

  • migrate_to_hybrid - 集合迁移指南

  • debug_search_quality - 排查搜索结果不佳的问题

  • build_knowledge_base - 带有元数据的结构化文档

  • index_git_history - 索引存储库提交历史以进行语义搜索

  • search_project_history - 搜索 Git 历史以了解功能实现

  • investigate_code_with_history - 通过上下文搜索深入研究代码

  • cross_repo_search - 跨多个存储库搜索模式

  • trace_feature_evolution - 跟踪功能随时间的演变

  • security_audit_search - 查找与安全相关的代码和修复

模板语法

模板使用 {{variable}} 占位符:

  • 必须提供必需参数

  • 如果未指定,可选参数将使用默认值

  • 未知变量在输出中保持原样

代码向量化

使用语义代码搜索智能地索引和搜索您的代码库。非常适合 AI 辅助开发、代码探索和理解大型代码库。

功能特性

  • AST 感知分块:使用 tree-sitter 在函数/类边界进行智能代码拆分

  • 多语言支持:35+ 种文件类型,包括 TypeScript、Python、Java、Go、Rust、C++ 等

  • 增量更新:仅重新索引已更改的文件以实现快速更新

  • 智能忽略模式:遵循 .gitignore、.dockerignore 和自定义 .contextignore 文件

  • 语义搜索:使用自然语言查询查找相关代码

  • 元数据过滤:按文件类型、路径模式或语言进行过滤

  • 本地优先:所有处理都在本地进行 - 您的代码绝不会离开您的机器

快速入门

1. 索引您的代码库:

# Via Claude Code MCP tool
/mcp__qdrant__index_codebase /path/to/your/project

2. 搜索您的代码:

# Natural language search
/mcp__qdrant__search_code /path/to/your/project "authentication middleware"

# Filter by file type
/mcp__qdrant__search_code /path/to/your/project "database schema" --fileTypes .ts,.js

# Filter by path pattern
/mcp__qdrant__search_code /path/to/your/project "API endpoints" --pathPattern src/api/**

3. 更改后更新:

# Incrementally re-index only changed files
/mcp__qdrant__reindex_changes /path/to/your/project

使用示例

索引 TypeScript 项目

// The MCP tool automatically:
// 1. Scans all .ts, .tsx, .js, .jsx files
// 2. Respects .gitignore patterns (skips node_modules, dist, etc.)
// 3. Chunks code at function/class boundaries
// 4. Generates embeddings using your configured provider
// 5. Stores in Qdrant with metadata (file path, line numbers, language)

index_codebase({
  path: "/workspace/my-app",
  forceReindex: false, // Set to true to re-index from scratch
});

// Output:
// ✓ Indexed 247 files (1,823 chunks) in 45.2s

搜索身份验证代码

search_code({
  path: "/workspace/my-app",
  query: "how does user authentication work?",
  limit: 5,
});

// Results include file path, line numbers, and code snippets:
// [
//   {
//     filePath: "src/auth/middleware.ts",
//     startLine: 15,
//     endLine: 42,
//     content: "export async function authenticateUser(req: Request) { ... }",
//     score: 0.89,
//     language: "typescript"
//   },
//   ...
// ]

使用过滤器搜索

// Only search TypeScript files
search_code({
  path: "/workspace/my-app",
  query: "error handling patterns",
  fileTypes: [".ts", ".tsx"],
  limit: 10,
});

// Only search in specific directories
search_code({
  path: "/workspace/my-app",
  query: "API route handlers",
  pathPattern: "src/api/**",
  limit: 10,
});

增量重新索引

// After making changes to your codebase
reindex_changes({
  path: "/workspace/my-app",
});

// Output:
// ✓ Updated: +3 files added, ~5 files modified, -1 files deleted
// ✓ Chunks: +47 added, -23 deleted in 8.3s

检查索引状态

get_index_status({
  path: "/workspace/my-app",
});

// Output:
// {
//   status: "indexed",      // "not_indexed" | "indexing" | "indexed"
//   isIndexed: true,        // deprecated: use status instead
//   collectionName: "code_a3f8d2e1",
//   chunksCount: 1823,
//   filesCount: 247,
//   lastUpdated: "2025-01-30T10:15:00Z",
//   languages: ["typescript", "javascript", "json"]
// }

支持的语言

编程语言(35+ 种文件类型):

  • Web:TypeScript, JavaScript, Vue, Svelte

  • 后端:Python, Java, Go, Rust, Ruby, PHP

  • 系统:C, C++, C#

  • 移动端:Swift, Kotlin, Dart

  • 函数式:Scala, Clojure, Haskell, OCaml

  • 脚本:Bash, Shell, Fish

  • 数据:SQL, GraphQL, Protocol Buffers

  • 配置:JSON, YAML, TOML, XML, Markdown

请参阅 配置 获取完整列表和自定义选项。

自定义忽略模式

在项目根目录中创建 .contextignore 文件以指定要忽略的其他模式:

# .contextignore
**/test/**
**/*.test.ts
**/*.spec.ts
**/fixtures/**
**/mocks/**
**/__tests__/**

最佳实践

  1. 一次索引,增量更新:使用 index_codebase 进行初始索引,然后使用 reindex_changes 进行更新

  2. 使用过滤器:使用 fileTypes 和 pathPattern 缩小搜索范围以获得更好的结果

  3. 有意义的查询:使用描述您正在寻找的内容的自然语言(例如,“database connection pooling” 而不是 “db”)

  4. 先检查状态:在搜索之前使用 get_index_status 验证代码库是否已索引

  5. 本地嵌入:使用 Ollama(默认)以保持一切本地化和私密

性能

在现代笔记本电脑(Apple M1/M2 或类似设备)上的典型性能:

代码库大小

文件数

索引时间

搜索延迟

小型 (10k LOC)

50

~10s

<100ms

中型 (100k LOC)

500

~2min

<200ms

大型 (500k LOC)

2,500

~10min

<500ms

注意:索引时间因嵌入提供程序而异。Ollama(本地)在初始索引时速度最快。

Git 历史搜索

使用自然语言索引和搜索存储库的 Git 提交历史。非常适合查找过去的修复、理解更改模式以及从以前的工作中学习。

功能特性

  • 语义提交搜索:通过用自然语言描述您要查找的内容来查找提交

  • Conventional Commit 分类:自动对提交进行分类(feat, fix, refactor 等)

  • 增量更新:仅索引新提交以实现高效更新

  • 丰富的过滤:按提交类型、作者或日期范围进行过滤

  • 元数据提取:包括已更改的文件、插入/删除内容以及完整的提交上下文

快速入门

1. 索引存储库的 Git 历史:

# Via Claude Code MCP tool
/mcp__qdrant__index_git_history /path/to/your/repo

2. 搜索相关提交:

# Natural language search
/mcp__qdrant__search_git_history /path/to/your/repo "fix authentication bug"

# Filter by commit type
/mcp__qdrant__search_git_history /path/to/your/repo "database optimization" --commitTypes fix,perf

# Filter by author
/mcp__qdrant__search_git_history /path/to/your/repo "API changes" --authors "john@example.com"

3. 保持索引最新:

# Incrementally index only new commits
/mcp__qdrant__index_new_commits /path/to/your/repo

用例

  • 查找类似修复:“之前 auth 中的空指针问题是如何修复的?”

  • 理解模式:“对数据库层做了哪些重构?”

  • 从历史中学习:“向我展示 API 端点实现的示例”

  • 代码考古:“去年对支付系统做了哪些更改?”

高级搜索

结合代码和 Git 历史搜索以更深入地了解代码库。需要先使用 index_codebase 和 index_git_history 索引存储库。

  • 上下文搜索:结合文件-提交关联的代码 + Git 历史查询

  • 联合搜索:使用 RRF 排序跨多个存储库进行搜索

请参阅 高级搜索示例 获取详细用法、工作流和场景。

示例

请参阅 examples/ 目录获取详细指南:

高级配置

环境变量

核心配置

变量

描述

默认值

TRANSPORT_MODE

"stdio" 或 "http"

stdio

HTTP_PORT

HTTP 传输端口

3000

HTTP_REQUEST_TIMEOUT_MS

HTTP 传输的请求超时 (ms)

300000

EMBEDDING_PROVIDER

"ollama", "openai", "cohere", "voyage"

ollama

QDRANT_URL

Qdrant 服务器 URL

http://localhost:6333

QDRANT_API_KEY

Qdrant 认证 API 密钥

-

LOG_LEVEL

日志级别 (fatal/error/warn/info/debug/trace/silent)

info

PROMPTS_CONFIG_FILE

提示词配置 JSON 的路径

prompts.json

嵌入配置

变量

描述

默认值

EMBEDDING_MODEL

模型名称

提供程序特定

`

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Provides RAG capabilities for semantic document search using Qdrant vector database and Ollama/OpenAI embeddings, allowing users to add, search, list, and delete documentation with metadata support.
    16 npm
    16
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables storing and retrieving information using semantic search with Qdrant vector database. Acts as a memory layer for LLMs to persistently store and semantically search through information and metadata.
    Apache 2.0
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables semantic search and retrieval-augmented generation (RAG) using Qdrant vector database. Supports indexing documents from URLs and local directories, with flexible embedding options using Ollama or OpenAI.
    2
    -