search_keyword
Find specific keywords within weather data files to locate relevant meteorological information and analysis results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| keyword | Yes |
Implementation Reference
- tool/logic.py:5-23 (handler)The core handler function for the 'search_keyword' MCP tool. Decorated with @mcp.tool() for automatic registration and schema inference. Implements keyword search in a file using regex (case-insensitive whole-word matches), counting occurrences, extracting matching lines, and sentence contexts.
@mcp.tool() def search_keyword(file_path: str, keyword: str) -> dict: path = Path(file_path) if not path.is_file(): return {"file_path": file_path, "keyword": keyword, "matches_found": 0, "lines": [], "contexts": []} pattern = re.compile(rf"\b{re.escape(keyword)}\b", flags=re.IGNORECASE) try: text = path.read_text(encoding="utf-8") except OSError: return {"file_path": file_path, "keyword": keyword, "matches_found": 0, "lines": [], "contexts": []} total = len(pattern.findall(text)) lines = [ln.rstrip("\n") for ln in text.splitlines() if pattern.search(ln)] sentences = re.split(r"(?<=[.!?])\s+", text) contexts = [s.strip() for s in sentences if pattern.search(s)] return {"file_path": file_path, "keyword": keyword, "matches_found": total, "lines": lines, "contexts": contexts}