obsidian_simple_search
Search across all Obsidian vault files for documents containing specific text queries, returning relevant matches with context.
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: 100) |
Implementation Reference
- src/mcp_obsidian/tools.py:156-190 (handler)The `run_tool` method in `SearchToolHandler` class executes the obsidian_simple_search tool: validates input, calls Obsidian API search, formats results with context and match positions, and returns JSON-formatted TextContent.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) api = obsidian.Obsidian(api_key=api_key, host=obsidian_host) 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) ) ]
- src/mcp_obsidian/tools.py:134-154 (schema)The `get_tool_description` method defines the tool schema including name, description, and inputSchema for query (required string) and optional context_length (integer, default 100).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: 100)", "default": 100 } }, "required": ["query"] } )
- src/mcp_obsidian/server.py:47-47 (registration)Registers the SearchToolHandler instance by adding it to the tool_handlers dictionary via add_tool_handler.add_tool_handler(tools.SearchToolHandler())