grep_docs
Search documents using regex patterns with case-insensitive options enabled by default. Integrates with the Docs-MCP server for efficient document retrieval and analysis.
Instructions
ドキュメント内をgrepで検索
Args:
pattern: 検索パターン(正規表現対応)
ignore_case: 大文字小文字を無視するか(デフォルト: True)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ignore_case | No | ||
| pattern | Yes |
Input Schema (JSON Schema)
{
"properties": {
"ignore_case": {
"default": true,
"title": "Ignore Case",
"type": "boolean"
},
"pattern": {
"title": "Pattern",
"type": "string"
}
},
"required": [
"pattern"
],
"title": "grep_docsArguments",
"type": "object"
}
Implementation Reference
- src/mcp_server_docs/server.py:43-51 (handler)MCP tool handler for 'grep_docs'. Registers the tool via @mcp.tool() decorator and delegates execution to DocumentManager.grep_search method.@mcp.tool() async def grep_docs(pattern: str, ignore_case: bool = True) -> str: """ドキュメント内をgrepで検索 Args: pattern: 検索パターン(正規表現対応) ignore_case: 大文字小文字を無視するか(デフォルト: True) """ return doc_manager.grep_search(pattern, ignore_case)
- Core implementation of the grep search functionality. Compiles the regex pattern, searches all loaded documents line-by-line, collects matches with file path and line number, limits to 100 results, and formats the output.def grep_search(self, pattern: str, ignore_case: bool = True) -> str: """正規表現でドキュメントを検索""" try: flags = re.IGNORECASE if ignore_case else 0 regex = re.compile(pattern, flags) except re.error as e: return f"Error: Invalid regex pattern: {e}" results = [] for doc_path, content in sorted(self.docs_content.items()): lines = content.split("\n") for i, line in enumerate(lines, 1): if regex.search(line): line_preview = line.strip() if len(line_preview) > 120: line_preview = line_preview[:117] + "..." results.append(f"{doc_path}:{i}: {line_preview}") if not results: return "No matches found" # 結果が多すぎる場合は制限 if len(results) > 100: total = len(results) results = results[:100] results.append(f"\n... and {total - 100} more matches") return "\n".join(results)