Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
ignore_caseNo
patternYes

Implementation Reference

  • 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)
Install Server

Other Tools

Related Tools

Latest Blog Posts

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/herring101/docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server