grep_docs
Search documents using grep with regular expression patterns. Optionally ignore case to broaden results.
Instructions
ドキュメント内をgrepで検索
Args:
pattern: 検索パターン(正規表現対応)
ignore_case: 大文字小文字を無視するか(デフォルト: True)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | ||
| ignore_case | No |
Implementation Reference
- src/mcp_server_docs/server.py:44-51 (handler)MCP tool handler for grep_docs: accepts a regex pattern and ignore_case flag, delegates to DocumentManager.grep_search()
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) - src/mcp_server_docs/server.py:43-44 (registration)Registration of grep_docs as an MCP tool via FastMCP's @mcp.tool() decorator
@mcp.tool() async def grep_docs(pattern: str, ignore_case: bool = True) -> str: - Helper method grep_search in DocumentManager: performs regex search across all loaded documents, returns formatted results with file:line:preview format, limited to 100 results
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) - src/mcp_server_docs/server.py:44-50 (schema)Type annotations define the input schema: pattern (str) is required, ignore_case (bool, default True) is optional. Returns a string.
async def grep_docs(pattern: str, ignore_case: bool = True) -> str: """ドキュメント内をgrepで検索 Args: pattern: 検索パターン(正規表現対応) ignore_case: 大文字小文字を無視するか(デフォルト: True) """