Semantic Search MCP Server
Enables AI agents to perform semantic search over codebases by converting natural language queries into efficient search patterns like grep and ripgrep. It utilizes LLMs to verify relevance and find code snippets that traditional keyword-based searches might miss.
README
Semantic Search MCP Server
A local Model Context Protocol (MCP) server that enables AI agents to perform semantic search over codebases using natural language queries. The server converts queries into efficient text search patterns (grep/ripgrep) and verifies relevance before returning results.
Quick Setup
Installation
pip install -e .
Environment Variables
Set the following environment variables:
REPO_PATH- Path to the repository to search (defaults to current directory)SEARCHER_TYPE- Searcher implementation to use (default:sgr_gemini_flash_lite)
API Keys (choose one based on your searcher type):
- For Claude-based searchers:
CLAUDE_API_KEYorANTHROPIC_API_KEY - For Gemini-based searchers:
GOOGLE_API_KEY,GEMINI_API_KEY,AI_STUDIO, orVERTEX_AI_API_KEY - For OpenAI-based searchers:
OPENAI_API_KEY
Available Searchers
SGR (Schema-Guided Reasoning) searchers - Production-ready implementations:
sgr/sgr_gemini_flash_lite- Default, recommended (Gemini Flash Lite)sgr_gemini_flash- SGR with Gemini Flashsgr_gemini_pro- SGR with Gemini Prosgr_gpt4o- SGR with GPT-4osgr_gpt4o_mini- SGR with GPT-4o Mini
Note: Other searcher types (ripgrep_claude, agent_claude, agent_gemini_flash_lite, etc.) are experimental implementations from earlier development phases and are not recommended for production use.
Running the MCP Server
Important: The MCP server is not meant to be run directly in a terminal. It communicates via STDIO using JSON-RPC protocol and must be launched by an IDE or MCP client.
Cursor Configuration
Add to your cursor-mcp-config.json:
{
"mcpServers": {
"qure-semantic-search": {
"command": "/path/to/.venv/bin/qure-semantic-search-mcp",
"env": {
"REPO_PATH": "/path/to/your/repo"
}
}
}
}
After configuring, restart Cursor. The server will be automatically launched when you use the semantic_search tool in Cursor's AI chat.
Note: If you see JSON parsing errors when running the command directly in terminal, this is expected - the server requires an MCP client (like Cursor) to communicate with it via JSON-RPC protocol.
Evaluation
Running Evaluation
Standard mode (single run per query):
python -m eval.run_eval
Stability mode (10 runs per query to measure consistency):
python -m eval.run_eval --stability
Stability mode with custom runs (e.g., 20 runs per query):
python -m eval.run_eval --stability --runs 20
Evaluate all searchers (compares different searcher implementations):
python -m eval.run_all_searchers --stability
Additional options:
--verbose/-v- Print detailed per-query statistics--single-dataset- Use only main dataset (exclude easy dataset)--output <path>- Export results to JSON file
Datasets
The evaluation uses two datasets:
-
Main dataset (
data/dataset.jsonl) - 12 challenging examples across different codebases (Django, Gin, CodeQL, QGIS, etc.) with non-trivial queries where simple keyword matching fails. -
Easy dataset (
data/dataset_easy.jsonl) - 14 simpler examples designed for faster evaluation and testing. These queries are more straightforward but still require semantic understanding.
By default, both datasets are used together (26 queries total). Use --single-dataset to evaluate only the main dataset.
Metrics
For detailed metric definitions and mathematical proof of perfection, see METRICS_LOGIC.md.
Quick Summary:
- Precision@K = TP / (TP + FP) - Fraction of returned results that are relevant
- Recall@K = TP / (TP + FN) - Fraction of all relevant items that were returned
- F1@K = Harmonic mean of Precision and Recall
- File Discovery Rate = Files Found / Files Expected
- Substring Coverage = Substrings Found / Substrings Required
The Logic Test: If all metrics score 1.0, the solution is mathematically perfect (see proof in METRICS_LOGIC.md).
See eval/metrics.py for detailed implementations.
Performance Results
Evaluation results for sgr_gemini_flash_lite searcher (10 runs per query, 26 queries total):
Overall Performance
| Metric | Value | Stability |
|---|---|---|
| Precision@10 | 0.30 ± 0.38 | ⚠ High variance (CV=127%) |
| Recall@10 | 0.31 ± 0.41 | ⚠ High variance (CV=133%) |
| F1@10 | 0.29 ± 0.38 | ⚠ High variance (CV=130%) |
| Success Rate@10 | 0.40 ± 0.46 | ⚠ High variance (CV=114%) |
| File Discovery Rate | 0.61 ± 0.40 | ⚠ Moderate variance (CV=66%) |
| Substring Coverage | 0.35 ± 0.39 | ⚠ High variance (CV=111%) |
| Avg Latency | 20.6s ± 7.9s | Range: 9.6s - 38.3s |
| Stability Score | 73.9% | 16/26 stable queries (61.5%) |
Dataset Breakdown
Easy Dataset (14 examples)
- Precision@10: 0.40 ± 0.44
- Recall@10: 0.46 ± 0.49
- F1@10: 0.42 ± 0.45
- File Discovery Rate: 0.92 ± 0.13 ✓ (Good stability)
- Avg Latency: 15.0s ± 4.8s
- Stability Score: 85.9% ✓ (Good stability)
Main Dataset (12 examples)
- Precision@10: 0.17 ± 0.25
- Recall@10: 0.13 ± 0.18
- F1@10: 0.14 ± 0.20
- File Discovery Rate: 0.26 ± 0.30
- Avg Latency: 27.2s ± 5.3s
- Stability Score: 60.0% ⚠ (Moderate stability)
Notes
- High variance in metrics is expected due to LLM non-determinism and the complexity of semantic search queries
- File Discovery Rate shows better stability, especially on easier queries (92% success rate)
- Latency varies significantly (9-38s) depending on query complexity and codebase size
- Results are evaluated on non-trivial queries where simple keyword matching fails
Project Structure
src/- Core MCP server and searcher implementationseval/- Evaluation scripts and metricsdata/- Evaluation dataset and test repositoriesscripts/- Utility scripts for testing and debugging
Documentation
- METRICS_LOGIC.md - Mathematical justification for metric selection and proof of perfection
- KNOWN_ISSUES.md - Current limitations, known problems, and workarounds
- FUTURE_ROADMAP.md - Planned improvements and mitigation strategies
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。