obsidian_simple_search
Search across all files in your Obsidian vault to find documents containing specific text queries, returning relevant context around matches.
Instructions
Simple search for documents matching a specified text query across all files in the vault. Use this tool when you want to do a simple text search
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Text to a simple search for in the vault. | |
| context_length | No | How much context to return around the matching string (default: 300) |
Implementation Reference
- The run_tool method in SearchToolHandler class that implements the core logic of the obsidian_simple_search tool: validates input, calls the Obsidian API search, formats the results with context and match positions, and returns as JSON.def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "query" not in args: raise RuntimeError("query argument missing in arguments") context_length = args.get("context_length", 100) results = api.search(args["query"], context_length) formatted_results = [] for result in results: formatted_matches = [] for match in result.get('matches', []): context = match.get('context', '') match_pos = match.get('match', {}) start = match_pos.get('start', 0) end = match_pos.get('end', 0) formatted_matches.append({ 'context': context, 'match_position': {'start': start, 'end': end} }) formatted_results.append({ 'filename': result.get('filename', ''), 'score': result.get('score', 0), 'matches': formatted_matches }) return [ TextContent( type="text", text=json.dumps(formatted_results, indent=2) ) ]
- The get_tool_description method defining the input schema and description for the obsidian_simple_search tool.def get_tool_description(self): return Tool( name=self.name, description="""Simple search for documents matching a specified text query across all files in the vault. Use this tool when you want to do a simple text search""", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "Text to a simple search for in the vault." }, "context_length": { "type": "integer", "description": "How much context to return around the matching string (default: 300)", "default": 300 } }, "required": ["query"] } )
- src/mcp_obsidian_advanced/server.py:26-43 (registration)TOOL_MAPPING dictionary maps the tool name 'obsidian_simple_search' (via tools.TOOL_SIMPLE_SEARCH) to its handler class SearchToolHandler, used in register_tools() to instantiate and register the tool with the MCP server.TOOL_MAPPING = { tools.TOOL_LIST_FILES_IN_DIR: tools.ListFilesInDirToolHandler, tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler, tools.TOOL_PATCH_CONTENT: tools.PatchContentToolHandler, tools.TOOL_PUT_CONTENT: tools.PutContentToolHandler, tools.TOOL_APPEND_CONTENT: tools.AppendContentToolHandler, tools.TOOL_DELETE_FILE: tools.DeleteFileToolHandler, tools.TOOL_COMPLEX_SEARCH: tools.ComplexSearchToolHandler, tools.TOOL_BATCH_GET_FILES: tools.BatchGetFilesToolHandler, tools.TOOL_PERIODIC_NOTES: tools.PeriodicNotesToolHandler, tools.TOOL_RECENT_PERIODIC_NOTES: tools.RecentPeriodicNotesToolHandler, tools.TOOL_RECENT_CHANGES: tools.RecentChangesToolHandler, tools.TOOL_UNDERSTAND_VAULT: tools.UnderstandVaultToolHandler, tools.TOOL_GET_ACTIVE_NOTE: tools.GetActiveNoteToolHandler, tools.TOOL_OPEN_FILES: tools.OpenFilesToolHandler, tools.TOOL_LIST_COMMANDS: tools.ListCommandsToolHandler, tools.TOOL_EXECUTE_COMMANDS: tools.ExecuteCommandsToolHandler, }
- src/mcp_obsidian_advanced/server.py:95-108 (registration)register_tools() function instantiates handlers from TOOL_MAPPING (conditionally based on INCLUDE_TOOLS env var) and adds them to tool_handlers dict, making them available via @app.list_tools() and @app.call_tool().def register_tools(): """Register the selected tools with the server.""" tools_to_include = parse_include_tools() registered_count = 0 for tool_name in tools_to_include: if tool_name in TOOL_MAPPING: handler_class = TOOL_MAPPING[tool_name] handler_instance = handler_class() add_tool_handler(handler_instance) registered_count += 1 logger.debug(f"Registered tool: {tool_name}") logger.info(f"Successfully registered {registered_count} tools")
- SearchToolHandler class definition and __init__ that sets the tool name to 'obsidian_simple_search'.class SearchToolHandler(ToolHandler): def __init__(self): super().__init__(TOOL_SIMPLE_SEARCH)