MCP-Grep
モデル コンテキスト プロトコル (MCP) を通じて grep 機能を公開する 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インスペクター統合
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
ライセンス
マサチューセッツ工科大学