Skip to main content
Glama
MarkusPfundstein

MCP server for Obsidian

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

Implementation Reference

  • 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) ) ]
  • 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"] } )
  • Registers the SearchToolHandler instance by adding it to the tool_handlers dictionary via add_tool_handler.
    add_tool_handler(tools.SearchToolHandler())

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

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