Skip to main content
Glama
ToKiDoO

Advanced Obsidian MCP Server

by ToKiDoO

obsidian_simple_search

Search across all files in an Obsidian vault to find documents matching a specific text query, with customizable context length for results. Ideal for quick and targeted text retrieval.

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
NameRequiredDescriptionDefault
context_lengthNoHow much context to return around the matching string (default: 300)
queryYesText to a simple search for in the vault.

Implementation Reference

  • SearchToolHandler class implements the core logic for the 'obsidian_simple_search' tool, including tool description/schema and the run_tool method that performs the search via api.search and formats results.
    class SearchToolHandler(ToolHandler): def __init__(self): super().__init__(TOOL_SIMPLE_SEARCH) 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"] } ) 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) ) ]
  • TOOL_MAPPING dictionary maps the tool name 'obsidian_simple_search' (TOOL_SIMPLE_SEARCH) to its SearchToolHandler class for registration.
    tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler,
  • register_tools function instantiates the handler for 'obsidian_simple_search' (if included) from TOOL_MAPPING and adds it to tool_handlers for MCP server registration.
    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")
  • Obsidian API client's search method that makes the HTTP POST request to Obsidian's /search/simple/ endpoint, which is called by the tool handler.
    def search(self, query: str, context_length: int = 300) -> Any: url = f"{self.get_base_url()}/search/simple/" params = { 'query': query, 'contextLength': context_length } def call_fn(): response = requests.post(url, headers=self._get_headers(), params=params, verify=self.verify_ssl, timeout=self.timeout) response.raise_for_status() return response.json() return self._safe_call(call_fn)
  • Constant defining the tool name 'obsidian_simple_search' used throughout the code.
    TOOL_SIMPLE_SEARCH = "obsidian_simple_search"

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/ToKiDoO/mcp-obsidian-advanced'

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