MCP-Grep について
MCP-Grep は、システムの grep バイナリをラップして MCP サーバーとして提供する Python 製のプロジェクトです。ログやコードをLLMから直接検索したいユーザーを対象としています。
主な機能
- 01システムの grep バイナリのラップ
- 02パターン検索用の grep ツール
- 03バイナリ情報を返す grep://info リソース
- 04大文字小文字を区別しない検索とコンテキスト行
- 05固定文字列検索と再帰的なディレクトリ検索
- 06MCP Inspector による デバッグ連携
活用シーン
- 01AI アシスタントによるログファイル内のエラー検索
- 02プロジェクト内のコードスニペットの再帰的検索
- 03自然言語によるファイル検索の実行
MCP 対応
本プロジェクトは MCP サーバーであり、grep ツールと grep://info リソースを MCP クライアントに公開します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
MCP-Grep
Model Context Protocol(MCP)を通じて grep 機能を提供する grep サーバーの実装です。
インストール
Smithery 経由でインストールする
Smithery 経由で Claude Desktop 用の Grep Server を自動的にインストールするには、次の手順に従います。
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
手動インストール
pip install mcp-grep
使用方法
MCP-Grep は、MCP 対応クライアントで使用できるサーバーとして動作します。
# Start the MCP-Grep server
mcp-grep-server
# Or use the MCP Inspector for interactive debugging and testing
mcp-grep-inspector
サーバーは、次の MCP 機能を提供します。
- リソース:
grep://info- システムの grep バイナリに関する情報を返します - ツール:
grep- システムの grep バイナリを使用してファイル内のパターンを検索します
機能
- システムの grep バイナリに関する情報(パス、バージョン、対応機能)
- 正規表現を使用したファイル内のパターン検索
- 一般的な grep オプションに対応:
- 大文字と小文字を区別しない検索
- コンテキスト行(一致箇所の前後)
- 一致件数の上限
- 固定文字列による検索(正規表現を使用しない)
- ディレクトリの再帰検索
- LLM で使いやすい自然言語プロンプトの理解
- MCP Inspector によるインタラクティブなデバッグとテスト
API の使用例
MCP Python クライアントを使用する場合:
from mcp.client import MCPClient
# Connect to the MCP-Grep server
client = MCPClient()
# Get information about the grep binary
grep_info = client.get_resource("grep://info")
print(grep_info)
# Search for a pattern in files
result = client.use_tool("grep", {
"pattern": "search_pattern",
"paths": ["file.txt", "directory/"],
"ignore_case": True,
"recursive": True
})
print(result)
自然言語プロンプト
MCP-Grep は自然言語プロンプトを理解するため、LLM でより簡単に使用できます。例:
# Basic search
Search for 'error' in log.txt
# Case-insensitive search
Find all instances of 'WARNING' regardless of case in system.log
# With context lines
Search for 'exception' in error.log and show 3 lines before and after each match
# Recursive search
Find all occurrences of 'deprecated' in the src directory and its subdirectories
# Fixed string search (non-regex)
Search for the exact string '.*' in config.js
# Limited results
Show me just the first 5 occurrences of 'TODO' in the project files
# Multiple options
Find 'password' case-insensitively in all .php files, show 2 lines of context, and limit to 10 results
MCP Inspector との連携
MCP-Grep には、インタラクティブなデバッグとテストのための MCP Inspector 連携機能が含まれています。
# Start the MCP Inspector with MCP-Grep
mcp-grep-inspector
これにより、次の操作ができる Web ベースの UI が開きます。
- 利用可能なリソースとツールを確認する
- さまざまなパラメーターで grep 操作をテストする
- 書式設定された結果を表示する
- grep クエリの問題をデバッグする
開発
# Clone the repository
git clone https://github.com/erniebrodeur/mcp-grep.git
cd mcp-grep
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
ライセンス
MIT
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。