diff --git a/mcp_codebase.py b/mcp_codebase.py index a70661a..311a869 100644 --- a/mcp_codebase.py +++ b/mcp_codebase.py @@ -2041,10 +2041,10 @@ def find_brace_block_end(lines: List[str], start_idx: int) -> Optional[int]: # ----------------------------- @mcp.tool() def health_check() -> str: - """What it does – Quick JSON status of the RAG server (ready, indexed path, chunk count, age). -When to use – Before any other query, to confirm the index is current. -When not to use – After you already know the server is healthy; it adds no value. -Example – health_check() → { "status":"ready","total_chunks":11234,"index_age_hours":4.7 }""" + """What it does - Quick JSON status of the RAG server (ready, indexed path, chunk count, age). +When to use - Before any other query, to confirm the index is current. +When not to use - After you already know the server is healthy; it adds no value. +Example - health_check() → { "status":"ready","total_chunks":11234,"index_age_hours":4.7 }""" try: with _startup_lock: status = { @@ -2081,11 +2081,11 @@ Example – health_check() → { "status":"ready","total_chunks":11234,"index_ag @mcp.tool() def search_codebase(query: str, top_k: int = 5, rerank: bool = True) -> str: - """What it does – Hybrid RAG search that returns semantically ranked snippets with file/line info from natural language queries. -When to use – For open‑ended questions or unknown patterns (“how does auth work?”). Natural language and verbose queries ONLY. -When not to use – For a single symbol or exact phrase; use find_code_references then read instead to avoid a large result set. + """What it does - Hybrid RAG search that returns semantically ranked snippets with file/line info from natural language queries. +When to use - For open-ended questions or unknown patterns (“how does auth work?”). Natural language and verbose queries ONLY. +When not to use - For a single symbol or exact phrase; use find_code_references then read instead to avoid a large result set. Rerank false is good enough for 65% of searches and is VERY fast, rerank true is much slower but good enough for 95% of searches. Best to use rerank true if rerank false didn't quite help enough. -Example – search_codebase("user authentication python", top_k=5, rerank=True) → 5 relevant snippets.""" +Example - search_codebase("user authentication python", top_k=5, rerank=True) → 5 relevant snippets.""" try: hy = hybrid_search(query, k=max(top_k, RERANK_TOP_N)) @@ -2189,10 +2189,10 @@ def _format_toon_results(results: List[Dict], query: str, result_type: str) -> s @mcp.tool() def find_code_references(symbol: str, top_k: int = 20) -> str: - """What it does – Fast, unranked lookup of all file/line occurrences of a symbol. -When to use – After identifying a symbol in a search hit, or when you need every use of a class/method. -When not to use – When you need context‑rich code; use read_file_lines_tool after getting the locations. -Example – find_code_references("AuthService") → list of references.""" + """What it does - Fast, unranked lookup of all file/line occurrences of a symbol. +When to use - After identifying a symbol in a search hit, or when you need every use of a class/method. +When not to use - When you need context-rich code; use read_file_lines_tool after getting the locations. +Example - find_code_references("AuthService") → list of references.""" matches = search_symbol(symbol, CODEBASE_PATH) if not matches: @@ -2240,24 +2240,24 @@ def _format_reference_results(results: List[Dict], symbol: str) -> str: @mcp.tool() def read_file_lines_tool(path: str, start: int = 1, end: Optional[int] = None) -> str: - """What it does – Reads a requested line range and auto‑expands to include surrounding context (function body, docstring, comments). -When to use – To inspect a specific hit from find_code_references or a snippet from search_codebase. -When not to use – For browsing the entire file or unrelated sections; use search_codebase first to pinpoint relevant parts. -Example – read_file_lines_tool("src/auth/login.py", start=45, end=60) → full function with context. + """What it does - Reads a requested line range and auto-expands to include surrounding context (function body, docstring, comments). +When to use - To inspect a specific hit from find_code_references or a snippet from search_codebase. +When not to use - For browsing the entire file or unrelated sections; use search_codebase first to pinpoint relevant parts. +Example - read_file_lines_tool("src/auth/login.py", start=45, end=60) → full function with context. Note: This tool treats / as '/home/popertots/Crussell/' so adjust paths accordingly""" return EnhancedToon.file_content_results(read_file_lines(path, start, end), path) @mcp.tool() def init_repo(git_url: str) -> str: - """What it does – Initialise the RAG stack with a brand‑new Git repository or update an existing one. + """What it does - Initialise the RAG stack with a brand-new Git repository or update an existing one. The function will: 1. Clone the repo if it does not already exist locally, 2. Pull the latest changes if it does, 3. Reset the global `CODEBASE_PATH` to the local clone, 4. Remove any stale index artefacts, - 5. Re‑build the vector/BM25 indexes with the same lock‑protected flow used by `rebuild_index`, - 6. Return a human‑readable status message. + 5. Re-build the vector/BM25 indexes with the same lock-protected flow used by `rebuild_index`, + 6. Return a human-readable status message. Next steps: • Call `health_check` to confirm that the server is ready. @@ -2314,7 +2314,7 @@ def init_repo(git_url: str) -> str: except Exception as e: logger.warning(f"Could not delete {artefact_path}: {e}") - # ----- 5. Re‑build the index (protected by the startup lock) ------------ + # ----- 5. Re-build the index (protected by the startup lock) ------------ try: rebuild_index() except Exception as e: @@ -2335,10 +2335,10 @@ def init_repo(git_url: str) -> str: @mcp.tool() def rebuild_index() -> str: - """What it does – Re‑creates all embeddings, BM25, and metadata indexes after major code changes. -When to use – When the codebase has been pulled or refactored and you suspect stale search results, and only after explicit instruction to do so. -When not to use – On every query; it’s expensive and unnecessary if the index is already up‑to‑date. -Example – rebuild_index() → '✅ Index rebuilt (13.2 s); 11,234 chunks'""" + """What it does - Re-creates all embeddings, BM25, and metadata indexes after major code changes. +When to use - When the codebase has been pulled or refactored and you suspect stale search results, and only after explicit instruction to do so. +When not to use - On every query; it’s expensive and unnecessary if the index is already up-to-date. +Example - rebuild_index() → '✅ Index rebuilt (13.2 s); 11,234 chunks'""" with _startup_lock: try: # Clear LRU caches