search_notes
Find specific text within your Markdown notes using full-text search to quickly locate relevant information across your note collection.
Instructions
Search for text within notes
Args: query: Search query
Returns: List of notes containing the query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- notes_server.py:109-143 (handler)The handler function for the 'search_notes' tool. It searches all Markdown notes in the notes directory for the given query (case-insensitive full content match first, then line-level context for display). Returns formatted list of matches with title and context snippet, or 'No matches found' message.def search_notes(query: str) -> str: """ Search for text within notes Args: query: Search query Returns: List of notes containing the query """ ensure_notes_dir() results = [] query_lower = query.lower() for filename in os.listdir(NOTES_DIR): if filename.endswith('.md'): filepath = os.path.join(NOTES_DIR, filename) with open(filepath, "r", encoding="utf-8") as f: content = f.read() if query_lower in content.lower(): title_match = re.search(r'^# (.+)$', content, re.MULTILINE) title = title_match.group(1) if title_match else filename lines = content.split('\n') for i, line in enumerate(lines): if query_lower in line.lower(): context = line[:100] + "..." if len(line) > 100 else line results.append(f"- [{filename}] {title}\n → {context}") break if not results: return f"No matches found for '{query}'" return "\n\n".join(results)
- notes_server.py:108-108 (registration)The @mcp.tool() decorator registers the search_notes function as an MCP tool.@mcp.tool()
- notes_server.py:110-118 (schema)The docstring provides the tool schema: input parameter 'query' (str), output str describing matching notes.""" Search for text within notes Args: query: Search query Returns: List of notes containing the query """