qdrant-mcp-ollama
qdrant-mcp-ollama
一个用于 Qdrant 向量数据库的 Model Context Protocol (MCP) 服务器,使用 Ollama 提供 GPU 加速的嵌入 功能。
为什么不用官方的 mcp-server-qdrant?
官方 Qdrant MCP 服务器 使用 FastEmbed 进行嵌入,但它存在以下问题:
仅依赖 CPU 运行 — 在处理大型代码库时速度较慢,无法充分利用现代 GPU
使用小模型(
all-MiniLM-L6-v2,384 维)— 嵌入质量较低本地模式下存在单进程锁 — 同一时间只能有一个 MCP 客户端访问数据库
本服务器可以解决以上三个问题:
官方 |
| |
嵌入引擎 | FastEmbed(CPU) | Ollama(GPU) |
默认模型 | all-MiniLM-L6-v2(384 维,80MB) | bge-m3(1024 维,1.2GB) |
并发访问 | 否(本地模式) | 是(Qdrant 服务器) |
模型灵活性 | 仅 FastEmbed 模型 | 任意 Ollama 嵌入模型 |
Related MCP server: Claude Context MCP
架构
┌──────────────┐ ┌────────────────────┐ ┌─────────────┐
│ MCP Client │────>│ qdrant-mcp-ollama │────>│ Ollama │
│ (Claude Code, │ │ (server.py) │ │ (GPU) │
│ Kilo Code, │<────│ │ └─────────────┘
│ Cursor, etc) │ └────────┬───────────┘
└──────────────┘ │
v
┌────────────────────┐
│ Qdrant Server │
│ (Docker, :6333) │
│ Storage: local │
│ disk / cloud │
└────────────────────┘前置要求
快速开始
1. 在 Ollama 中拉取嵌入模型
ollama pull bge-m32. 启动 Qdrant 服务器
docker run -d --name qdrant-server \
-p 6333:6333 -p 6334:6334 \
-v qdrant-storage:/qdrant/storage \
--restart unless-stopped \
qdrant/qdrant:latest3. 运行 MCP 服务器
# No install needed — uv downloads dependencies on-the-fly:
QDRANT_URL="http://localhost:6333" \
EMBEDDING_MODEL="bge-m3" \
uv run --with fastmcp --with qdrant-client --with httpx python server.py4. 嵌入一个代码库
uv run --with qdrant-client --with httpx python embed_codebase.py \
/path/to/your/project my-project --preset python5. 在 MCP 客户端中搜索
配置完成后(详情见下文),向你的 AI 助手提问:
“搜索代码库中的认证逻辑”
它将使用 qdrant_find 工具返回语义相关的代码片段。
设置 Qdrant 服务器
方案 A:Docker(推荐)
将数据存储在指定驱动器上(例如 Windows 下的 E:):
# Create storage directories
mkdir -p E:/qdrant-storage E:/qdrant-snapshots
# Start Qdrant with persistent storage
docker run -d --name qdrant-server \
-p 6333:6333 -p 6334:6334 \
-v E:/qdrant-storage:/qdrant/storage \
-v E:/qdrant-snapshots:/qdrant/snapshots \
--restart unless-stopped \
qdrant/qdrant:latest在 Linux/macOS 上:
docker run -d --name qdrant-server \
-p 6333:6333 -p 6334:6334 \
-v ~/qdrant-storage:/qdrant/storage \
--restart unless-stopped \
qdrant/qdrant:latest--restart unless-stopped 标志可确保 Qdrant 随 Docker Desktop 自动启动。
验证它是否正在运行:
docker ps --filter name=qdrant-server
# Or open http://localhost:6333/dashboard in your browser方案 B:Qdrant Cloud
在 cloud.qdrant.io 注册,获取你的 URL 和 API 密钥。然后设置:
QDRANT_URL="https://your-cluster.cloud.qdrant.io:6333"
QDRANT_API_KEY="your-api-key"注意:
QDRANT_API_KEY环境变量会自动传递给 Qdrant 客户端。
嵌入代码库
embed_codebase.py 脚本会扫描一个目录,将源文件分块,并通过 Ollama 将它们批量嵌入 Qdrant。
基本用法
uv run --with qdrant-client --with httpx python embed_codebase.py <directory> <collection-name>使用扩展名预设
# Python project
python embed_codebase.py ./my-api api-backend --preset python
# Full-stack web project
python embed_codebase.py ./my-app frontend --preset web
# R / bioinformatics project
python embed_codebase.py ./analysis bio-analysis --preset r
# Everything
python embed_codebase.py ./mono-repo all-code --preset all自定义扩展名
python embed_codebase.py ./project my-collection --extensions .py .sql .sh .yaml可用预设
预设 | 扩展名 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 所有常见源码扩展名 |
如果没有提供 --preset 或 --extensions,脚本会自动检测文件类型。
所有选项
usage: embed_codebase.py <directory> <collection> [options]
positional arguments:
directory Path to the codebase directory
collection Qdrant collection name
options:
--extensions EXT [EXT ...] File extensions to include (e.g. .py .ts)
--preset PRESET Use a preset group of extensions
--model MODEL Ollama embedding model (default: bge-m3)
--qdrant-url URL Qdrant server URL (default: http://localhost:6333)
--ollama-url URL Ollama server URL (default: http://localhost:11434)
--chunk-size N Max lines per chunk (default: 80)
--chunk-overlap N Overlap lines between chunks (default: 10)
--batch-size N Upload batch size for Qdrant (default: 500)
--append Append to existing collection instead of replacing追加模式
默认情况下,重新运行脚本会替换现有集合。使用 --append 可向现有集合追加数据:
# First embed
python embed_codebase.py ./src main-code --preset typescript
# Add more files later
python embed_codebase.py ./docs main-code --extensions .md --append多代码库用法
为每个代码库使用独立的集合,以保持搜索范围聚焦和相关:
# Project A
python embed_codebase.py ~/projects/api-server api-server --preset python
# Project B
python embed_codebase.py ~/projects/web-app web-app --preset web
# Project C
python embed_codebase.py ~/projects/data-pipeline data-pipeline --preset python配置 MCP 服务器时:
不设置
COLLECTION_NAME:必须在每次查询时指定集合名称。这适合一个 MCP 服务器服务于多个项目的情况。设置
COLLECTION_NAME:将自动使用默认集合。如果 MCP 客户端支持项目级配置,请为每个项目单独设置。
配置 Claude Code
添加 MCP 服务器
claude mcp add qdrant -s user \
-e QDRANT_URL="http://localhost:6333" \
-e OLLAMA_URL="http://localhost:11434" \
-e EMBEDDING_MODEL="bge-m3" \
-- uv run --with fastmcp --with qdrant-client --with httpx \
python /path/to/qdrant-mcp-ollama/server.py将 /path/to/qdrant-mcp-ollama/ 替换为你克隆此仓库的实际路径。
使用默认集合
如果你主要在一个项目上工作:
claude mcp add qdrant -s user \
-e QDRANT_URL="http://localhost:6333" \
-e OLLAMA_URL="http://localhost:11434" \
-e EMBEDDING_MODEL="bge-m3" \
-e COLLECTION_NAME="my-project" \
-- uv run --with fastmcp --with qdrant-client --with httpx \
python /path/to/qdrant-mcp-ollama/server.py验证
claude mcp list
# Should show: qdrant: ... ✓ Connected
claude mcp get qdrant
# Shows full configuration details在 Claude Code 中使用
配置完成后,Claude Code 可以使用以下工具:
qdrant_store— 存储信息:“在 Qdrant 中存储此认证模式”qdrant_find— 搜索:“查找与数据库迁移有关的代码”
对于多代码库设置(无默认集合),请指定集合名称:
“在
api-server集合中搜索限流逻辑”
配置 Kilo Code(VS Code 扩展)
Kilo Code 是一个内置 MCP 支持的 VS Code 扩展。
方案 1:手动配置 MCP
在 VS Code 中打开 Kilo Code 设置
导航到 MCP 服务器配置
添加新服务器:
字段 名称 | 值 |
Name |
|
Command |
|
Arguments |
|
设置环境变量:
变量 变量 | 值 |
|
|
|
|
|
|
| 你的项目的集合名称(例如 |
方案 2:VS Code settings.json
添加到你的 VS Code settings.json 中(Ctrl+Shift+P > Preferences: Open User Settings (JSON)):
{
"kilocode.mcpServers": {
"qdrant": {
"command": "uv",
"args": [
"run", "--with", "fastmcp", "--with", "qdrant-client", "--with", "httpx",
"python", "/path/to/qdrant-mcp-ollama/server.py"
],
"env": {
"QDRANT_URL": "http://localhost:6333",
"OLLAMA_URL": "http://localhost:11434",
"EMBEDDING_MODEL": "bge-m3",
"COLLECTION_NAME": "my-project"
}
}
}
}按项目配置 Kilo Code
对于多代码库设置,请在项目范围(而非全局)内配置 Kilo Code,并为项目指定 COLLECTION_NAME。这样每个工作区只会搜索自己的代码库。
配置其他 MCP 客户端
Cursor / Windsurf
为了支持远程客户端,请使用 SSE 传输方式运行服务器:
QDRANT_URL="http://localhost:6333" \
OLLAMA_URL="http://localhost:11434" \
EMBEDDING_MODEL="bge-m3" \
FASTMCP_PORT=8000 \
uv run --with fastmcp --with qdrant-client --with httpx \
python server.py --transport sse然后在 Cursor/Windsurf 的 MCP 设置中连接:http://localhost:8000/sse
通用 MCP 客户端(stdio)
默认传输方式为 stdio。任何支持 stdio 的 MCP 客户端都可以通过运行以下命令来使用本服务器:
uv run --with fastmcp --with qdrant-client --with httpx python server.py配置参考
MCP 服务器环境变量
字段 字段 | 描述 | 默认值 |
| Qdrant 服务器 URL |
|
| Qdrant Cloud 的 API 密钥 | None |
| Ollama 服务器 URL |
|
| Ollama 嵌入模型名称 |
|
| 默认集合(为空时必须在每次调用中指定) | (空) |
选择嵌入模型
以下所有模型均可通过 ollama pull <model> 获取:
模型 | 维度 | 大小 | 速度 | 质量 | 适用场景 |
| 1024 | 1.2 GB | 中等 | 高 | 通用、多语言 |
| 768 | 274 MB | 快 | 良好 | 轻量、面向英文 |
| 1024 | 670 MB | 中等 | 高 | 英文、高质量 |
| 1024 | 1.2 GB | 中等 | 非常高 | 英文、最佳质量 |
| 384 | 46 MB | 极快 | 一般 | 资源占用最小 |
建议: 从 bge-m3 开始。它能很好地处理代码,支持多语言内容(任意语言的注释),并且兼顾质量与速度。
重要: 用于索引集合的嵌入模型必须与用于查询的模型匹配。如果你使用不同的模型重新嵌入,请删除并重新创建集合。
GPU 利用率
更大的模型会占用更多 GPU 资源。如果你的 GPU 利用率不高:
从
nomic-embed-text(274 MB)切换到bge-m3(1.2 GB)或更大的模型嵌入脚本会将所有文本一次性发送到单个批次中,以最大化 GPU 利用率
对于单个查询(通过
qdrant_find),GPU 峰值是短暂且正常的 — 嵌入单个查询只需要毫秒级的时间
查看 GPU 使用情况:nvidia-smi(NVIDIA)或 rocm-smi(AMD)
MCP 工具
qdrant_store
在 Qdrant 数据库中存储信息。
参数 | 类型 | 必填 | 描述 |
| string | 是 | 用于存储和可搜索的文本 |
| string | 如果没有默认集合 | Target collection |
| dict | 否 | 可选元数据 |
qdrant_find
使用语义相似度搜索相关信息。
参数 | 类型 | 必填 | 描述 |
| string | 是 | 自然语言搜索查询 |
| string | 如果没有默认集合 | 要搜索的集合 |
| int | 否 | 返回的最大结果数(默认值:5) |
故障排除
“Connection closed” / MCP 服务器无法启动
Ollama 是否正在运行? 使用
ollama list检查。如有需要,运行ollama serve启动它。是否已拉取嵌入模型? 运行
ollama pull bge-m3。Qdrant 是否正在运行? 使用
docker ps --filter name=qdrant-server检查。
“Collection does not exist”
集合由嵌入脚本创建,或在首次调用 qdrant_store 时创建。可以这样做:
先运行
embed_codebase.py为你的代码库建立索引或通过
qdrant_store存储内容,以自动创建集合
维度不匹配错误
这种情况发生在集合创建的嵌入模型与你查询所用模型不一致时。解决方法:
删除集合:访问
http://localhost:6333/dashboard使用正确的模型重新嵌入
确保 MCP 服务器配置中的
EMBEDDING_MODEL与你用于嵌入的模型一致
“存储文件夹已被另一个实例访问”
该错误来自 官方 mcp-server-qdrant 使用本地模式(QDRANT_LOCAL_PATH)时的情况。本项目通过 URL 连接 Qdrant 服务器来避免此问题。请确保你没有同时运行两个指向同一本地路径的服务器。
嵌入速度慢 / GPU 利用率低
使用更大的模型:
bge-m3(1.2 GB)而不是nomic-embed-text(274 MB)嵌入脚本会一次将所有文本放在一个批次中发送——如果你有成千上万个分块,这样可以最大化 GPU 使用
对于非常大的代码库(10,000 个以上文件),建议按目录拆分为多次运行
许可证
Apache License 2.0 — 参见 LICENSE。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables semantic code search across codebases using Qdrant vector database and OpenAI embeddings, allowing users to find code by meaning rather than just keywords through natural language queries.2MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to index and search codebases using semantic search powered by multiple embedding providers (OpenAI, VoyageAI, Gemini, Ollama) and vector database storage.
- FlicenseNot gradedqualityDmaintenanceEnables semantic code search across multi-language codebases using natural language queries, integrated with Qdrant vector database for fast, cached retrieval.1
- AlicenseNot gradedqualityFmaintenanceIndexes codebases into Qdrant for semantic search, enabling AI assistants to find relevant code by meaning without re-exploring the repo.MIT
Related MCP Connectors
Connect AI assistants to your GitHub-hosted Obsidian vault to seamlessly access, search, and analy…
Search your knowledge bases from any AI assistant using hybrid RAG.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/michal7kw/qdrant-mcp-ollama'
If you have feedback or need assistance with the MCP directory API, please join our Discord server