Skip to main content
Glama
JessiP23

Weather MCP Server

by JessiP23

search_keyword

Find specific keywords within weather data files to locate relevant meteorological information and analysis results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
keywordYes

Implementation Reference

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

Other 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/JessiP23/mcp'

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