mcp-server-bm25-code-search
Use this server to perform fast, local BM25-ranked code search over an indexed codebase via SQLite FTS5, with no external dependencies. It can:
Search using natural language or code queries and return the most relevant code chunks
Tokenize Japanese/CJK text (2-gram) and split camelCase/snake_case identifiers for better matching
Boost file-path matches 3.0x over file-body matches
Set
top_k(1–100, default 5) and choose token combination modeOR/ANDReturn a structured fallback suggesting grep/glob when no results are found
Protect against context overflow by truncating output at a configurable max-byte limit safely on multibyte character boundaries
Integrate as an MCP Agent Plugin (zero-config) with VS Code, Cursor, GitHub Copilot, and supports Hermes Agent via a dedicated adapter
Incrementally update the index using
git ls-files(respecting.gitignore) andgit diff/HEAD hash tracking, typically in 0.1–0.5 secondsRun as a CLI tool with Markdown or JSON output.
Offers a Function Calling adapter for Hermes Agent to use the BM25 code search engine in non-MCP environments.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-server-bm25-code-searchsearch for getUserProfile implementation"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-server-bm25-code-search
AI コーディングエージェント(VS Code, Cursor, GitHub Copilot, ChatGPT & Codex, Kiro, Hermes Agent, OpenClaw, Grok Bot, NanoClaw 等)におけるファイル検索を高速化・低トークン化するための、Agent Plugins 規格準拠の SQLite FTS5 ローカル BM25 コード検索プラグイン & MCP サーバです。
✨ 特徴
📦 外部依存ゼロ (Python 標準ライブラリのみ)
sqlite3(FTS5) および標準ライブラリのみで構築されており、pip installなどのサードパーティ依存パッケージなしで即座に動作します。🧩 Agent Plugins (v1.0.0) 規格準拠
Agent Plugins に準拠し、公式対応クライアント(VS Code, Cursor, GitHub Copilot, ChatGPT & Codex, Kiro, Hermes Agent, OpenClaw, Grok Bot, NanoClaw)でディレクトリを指定するだけで、MCP サーバ(mcp.json)と検索ガイドスキル(skills/)をゼロコンフィグで一発認識・即時導入可能。🔤 コード識別子 & 日本語ハイブリッド対応
getUserProfile(camelCase) やsession_token(snake_case) のサブワード分割に加え、日本語技術文書の CJK 2-gram(バイグラム)トークナイズを Python 側で事前処理。FTS5 インデックスと検索クエリの両方に自動適用されます。📁 ファイルパスブースト (3.0x)
FTS5 のbm25(code_fts, 3.0, 1.0)列重み付けにより、ファイルパスとの一致を本文の一致より 3.0 倍優遇。探したいファイルへ少ない検索回数で到達できます。⚡ 高速増分更新 & Git Worktree 非干渉
git ls-filesによる.gitignore完全準拠のファイル収集と、git diff/ HEAD ハッシュトラッキングによる高速増分更新(通常編集時 0.1〜0.5秒)。インデックス.bm25_index.dbは Worktree ローカルに配置され.gitignoreで自動除外されます。🔌 MCP 2026-07-28 & Hermes 標準対応
MCP ネイティブ: 2026-07-28 仕様準拠のステートレス stdio JSON-RPC サーバ。プロンプトキャッシュ効率を高める決定論的ツールソートを実装。
Hermes Agent: MCP 非対応環境向けに薄い Function Calling アダプタ層 (
hermes_adapter.py) も標準同梱。
🛡️ コンテキスト溢れ防止 & フォールバック
出力文字制限 (--max-bytes) は UTF-8 のマルチバイト文字境界を保護して安全に切り詰め。検索結果 0 件時は grep/glob への切り替えを促す構造化フォールバックメッセージを返却します。
Related MCP server: lynx-mcp
📁 モジュール構成
mcp-server-bm25-code-search/
├── plugin.json # Agent Plugins v1.0.0 マニフェスト
├── mcp.json # Agent Plugins v1.0.0 MCP 設定
├── skills/ # Agent Skills (エージェント向け検索プロンプト・指針)
│ └── bm25-search/
│ └── SKILL.md
├── bm25_search/
│ ├── db.py # SQLite FTS5 v2 スキーマ (chunks / code_fts / triggers)
│ ├── tokenizer.py # 事前トークナイザ (camelCase / snake_case / CJK 2-gram)
│ ├── indexer.py # インデクサ (git ls-files, 80/20 チャンキング, 増分更新)
│ ├── search.py # 検索エンジン & CLI インターフェース
│ ├── mcp_server.py # MCP 2026-07-28 ステートレス stdio サーバ
│ └── hermes_adapter.py # Hermes Agent 向け Function Calling アダプタ
├── bin/
│ └── cli.js # Node.js 向け CLI / npx 起動ラッパー
├── docs/
│ ├── specification.md # 詳細仕様書
│ └── plans/ # 設計ドキュメント
└── tests/ # pytest テストスイート🚀 使い方
1. Agent Plugins としての導入 (推奨・ゼロコンフィグ)
Agent Plugins 公式対応クライアント(VS Code, Cursor, GitHub Copilot, ChatGPT & Codex, Kiro, Hermes Agent, OpenClaw, Grok Bot, NanoClaw)では、本リポジトリのディレクトリを指定またはプラグインとして読み込むだけで、MCP サーバ(mcp.json)と検索ガイドスキル(skills/)が同時に自動認識されます。
各クライアントの公式セットアップ手順:
VS Code: Agent Plugins in VS Code
Cursor: Cursor Plugins
GitHub Copilot: Copilot Agent Plugins
ChatGPT & Codex: OpenAI Plugin Developers
Kiro: Kiro Powers
Hermes Agent: Hermes Portable Plugins
OpenClaw: OpenClaw Plugin Bundles
Grok Bot: Grok Bot Automations
NanoClaw: NanoClaw Templates
2. CLI での検索実行
python bm25_search/search.py "<検索クエリ>" --top-k 5 --format markdown --max-bytes 4000主なオプション:
<query>: 検索クエリ(日本語、camelCase、snake_case 対応)--top-k: 返す検索結果の上限件数(デフォルト:5)--format: 出力形式markdownまたはjson(デフォルト:markdown)--max-bytes: 最大出力バイト数。マルチバイト文字を安全に維持して切詰(デフォルト:4000)--mode: クエリトークンの結合モードORまたはAND(デフォルト:OR)--db: 使用する SQLite インデックス DB パス(デフォルト:.bm25_index.db)
3. 個別 MCP サーバとしての起動(uvx / npx / 手動設定)
プロジェクトごとに Stdio + 自動インデックス構築で動かすため、uvx または npx で即座に起動できます。
引数未指定の場合、MCP サーバが起動されたプロジェクト(カレントディレクトリ)のコードベースを自動検出・増分インデックス(.bm25_index.db)の作成・同期を行います。
主な起動オプション
オプション | 説明 | デフォルト |
| インデックス・検索対象のプロジェクトルートディレクトリ |
|
| SQLite FTS5 インデックス DB ファイルパス |
|
| ツール呼び出し時の自動インデックス同期を無効化 | 無効 (自動同期有効) |
| stdio JSON-RPC トランスポートループを実行 | 有効 |
💡
--db指定時のプロジェクトルート自動認識:--db <パス>(例:--db /path/to/project/.bm25_index.db)を指定し、--rootを明示的に指定しなかった場合、指定された DB ファイルの親ディレクトリがプロジェクトルートとして自動認識されます。
これにより、グローバル設定やエージェント共通設定から起動する場合でも、--dbを指定するだけで対象プロジェクトのコードベースを特定し、自動インデックス同期(Auto Sync)と検索がシームレスに機能します(--rootを明示指定した場合はそちらが優先されます)。
① uvx (uv / Python) を使う場合
{
"mcpServers": {
"bm25-code-search": {
"command": "uvx",
"args": ["mcp-server-bm25-code-search"],
"alwaysAllow": ["search"]
}
}
}② npx (Node.js / npm) を使う場合
{
"mcpServers": {
"bm25-code-search": {
"command": "npx",
"args": ["-y", "mcp-server-bm25-code-search"],
"alwaysAllow": ["search"]
}
}
}③ ローカル Python での直接指定
{
"mcpServers": {
"bm25-code-search": {
"command": "python",
"args": [
"D:/path/to/mcp-server-bm25-code-search/bm25_search/mcp_server.py",
"--stdio"
],
"alwaysAllow": [
"search"
]
}
}
}④ --db で特定プロジェクトの DB を直接指定する場合
{
"mcpServers": {
"bm25-code-search": {
"command": "uvx",
"args": [
"mcp-server-bm25-code-search",
"--db",
"/path/to/my-project/.bm25_index.db"
],
"alwaysAllow": ["search"]
}
}
}※ --root を指定しなくても親ディレクトリ /path/to/my-project が自動でプロジェクトルートとして認識され、インデックスの自動同期と検索が行われます。
💡 AI エージェントに grep 連打を抑止し BM25 検索を優先させる設定 (AGENTS.md / CLAUDE.md)
AI エージェントが grep を何度もリトライしてトークンやコンテキストを無駄に消費するのを防ぐため、利用するプロジェクトの AGENTS.md や CLAUDE.md(またはシステムプロンプト)に以下の指示を追記することを推奨します。
## コード検索の指示方針
- コードベースの機能調査やコード探索を行う際は、最初に MCP ツール `search` (BM25 Code Search) を優先して使用してください。
- **Claude Code での呼び出し手順**: Claude Code では MCP ツールが Deferred Tool となるため、初回呼び出し前に必ず `ToolSearch` (`select:mcp__bm25-code-search__search`) でスキーマをロードしてから `mcp__bm25-code-search__search` を実行してください。
- `search` で結果が得られない場合、または特定のシンボル名の完全一致を直接検索する場合にのみ `grep_search` や `glob` を使用してください。4. Claude Code での設定方法(Agent Plugins 非準拠のため個別設定が必要)
Claude Code は Agent Plugins 規格に準拠していないため、リポジトリを指定するだけの自動認識(plugin.json / mcp.json のゼロコンフィグ読み込み)は行われません。代わりに、Claude Code 標準の MCP サーバ登録機能を使って個別に設定してください。
💡 Claude Code 利用時のポイント (Deferred Tool):
Claude Code はコンテキスト節約のため MCP ツールを「Deferred Tool(遅延ロード)」として扱います。初回の検索実行前に内部ツールToolSearch(select:mcp__bm25-code-search__search) でツールのスキーマをロードしてから検索が実行されます(上記のCLAUDE.md指示やスキル.claude/skills/bm25-search/SKILL.mdを配置しておくと確実に実行されます)。
方法 A: claude mcp add CLI コマンド(推奨)
プロジェクト直下で以下のいずれかを実行します(--scope project を付けるとプロジェクト直下に .mcp.json が生成され、git commit してチームで共有できます。--scope user にすると全プロジェクト共通のユーザー設定として登録されます)。
# uvx (uv / Python) を使う場合
claude mcp add bm25-code-search --scope project -- uvx mcp-server-bm25-code-search
# npx (Node.js / npm) を使う場合
claude mcp add bm25-code-search --scope project -- npx -y mcp-server-bm25-code-search
# ローカル Python を直接指定する場合(環境変数 -e も指定可能)
claude mcp add bm25-code-search --scope project -e PYTHONUTF8=1 -- python D:/path/to/mcp-server-bm25-code-search/bm25_search/mcp_server.py --stdio登録後は claude mcp list または Claude Code セッション内の /mcp コマンドで認識状況を確認できます。
方法 B: .mcp.json を直接作成
プロジェクトルートに .mcp.json を作成しても同様に登録できます(内容は上記「個別 MCP サーバとしての起動」節の JSON と同一形式です)。
{
"mcpServers": {
"bm25-code-search": {
"command": "uvx",
"args": ["mcp-server-bm25-code-search"]
}
}
}.mcp.json はプロジェクトルートに置いて git commit することで、チームメンバー間で設定を共有できます(初回読み込み時に Claude Code から承認確認が入ります)。
5. Hermes Agent アダプタの使用
MCP 非対応の Hermes Agent からは、bm25_search.hermes_adapter モジュールを利用します。
from bm25_search.hermes_adapter import hermes_function_schema, run_hermes_tool
# Hermes 用 Tool Schema の取得
schema = hermes_function_schema()
# Hermes からの Function Call 実行
response = run_hermes_tool({
"name": "bm25_search",
"arguments": {
"query": "getUserProfile",
"top_k": 5
}
})🧪 テストの実行
pytest を使ってユニットテストおよび統合テストを実行できます。
pytest tests/📄 ドキュメント
📚 参考文献・関連リンク
Agent Plugins 規格: Agent Plugins Specification (agentplugins/agent-plugins-spec) / agent-plugins.org
Agent Skills 規格: Agent Skills Specification
論文: Wang et al., "BM25 Wins at Scale: Evaluating Agentic Search over Enterprise Corpora" (2026)
https://arxiv.org/abs/2607.26497解説記事: 須藤英寿(株式会社ナレッジセンス), "BM25を使用してCodexのトークンの消費を30%抑える" (Zenn, 2026)
https://zenn.dev/knowledgesense/articles/9e55a3bb67729c
⚖️ ライセンス
本プロジェクトは MIT License の下で公開されています。
Available Tools
1 toolsearchBM25 Code SearchA
Search the indexed codebase with a SQLite FTS5 BM25 ranker. Returns the best-matching code chunks, ranked with the filepath column boosted 3.0x over the body. Works for Japanese (CJK) and camelCase/snake_case queries. When nothing matches, returns a structured zero-match fallback suggesting grep/glob.
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | How query tokens are combined. 'OR' maximises recall; 'AND' requires every token to hit. | OR |
| query | Yes | The search query. Japanese, camelCase and snake_case are all tokenised the same way the index was built. | |
| top_k | No | Maximum number of results to return. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries full responsibility for behavior disclosure. It transparently reveals the ranking boost (filepath 3.0x), the zero-match fallback structure, and special tokenization behaviors, which are non-obvious details. It could have explicitly stated read-only safety, but 'search' strongly implies it.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is three sentences, each carrying distinct information: ranking mechanism, tokenization support, and fallback behavior. It is front-loaded with the verb and resource, with no filler or redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no output schema, the description explains what is returned (best-matching code chunks) and the fallback, but doesn't detail the chunk structure or exact return format. It covers the main behaviors thoroughly for a search tool, though a bit more output detail would improve completeness.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already provides 100% coverage for all three parameters, including query tokenization and mode semantics. The description adds minor context about ranking (filepath boost) but doesn't meaningfully extend parameter understanding beyond the schema, warranting the baseline score.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool searches the indexed codebase using a SQLite FTS5 BM25 ranker, specifying the action, resource, and ranking method. It goes beyond a generic 'search' by noting the filepath boost and language tokenization, making the purpose unambiguous even without siblings.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description gives clear context on when to use the tool: codebase search with BM25 ranking, supporting CJK and camelCase/snake_case queries. It also mentions a fallback to grep/glob when no matches occur, implying alternative tools for exact/pattern search, though it doesn't explicitly state exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
With only one tool, there is no possibility of confusion or overlap between tools. The search tool has a clear, unique purpose.
The single tool is named 'search', which is a clear verb that directly matches its function. There are no conflicting naming conventions since only one exists.
The server's stated purpose is BM25 code search, and a single search tool fully fulfills this scope. One tool is not too few; it is exactly what the server needs.
The search tool covers all aspects of the domain: it ranks results, supports multiple query types, and provides a structured fallback for zero matches. There are no obvious missing operations for a code search server.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Search GitHub, npm, PyPI, StackOverflow, ArXiv from one MCP — built for coding agents.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA local, SQLite-backed code index for Claude Code, exposed over MCP, enabling targeted code retrieval without external APIs.1MIT
- AlicenseAqualityAmaintenanceA 100% local MCP server for semantic and lexical search over your code, library docs, and PDFs, featuring hybrid BM25 and dense retrieval, syntax aware chunking, and an optional code knowledge graph. It also ships a Coral integration, so you can expose your code search as SQL and join it with live data, all without anything leaving your machine.69Apache 2.0
- AlicenseAqualityCmaintenanceEnables AI coding agents to intelligently index and search codebases with sub-20ms retrieval, 8x memory compression, and cross-encoder reranking via MCP stdio.5MIT
- AlicenseNot gradedqualityAmaintenanceLocal-first code intelligence MCP server that enables coding agents to search code, inspect structure, read exact ranges, and explore Git history with explicit token budgets.23Apache 2.0
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/toaruR/mcp-server-bm25-code-search'
If you have feedback or need assistance with the MCP directory API, please join our Discord server