Skip to main content
Glama
ToKiDoO

Advanced Obsidian MCP Server

by ToKiDoO

obsidian_complex_search

Perform advanced searches in Obsidian vaults using JsonLogic queries with pattern matching to find documents by tags, content, or file paths.

Instructions

Complex search for documents using a JsonLogic query. Supports standard JsonLogic operators plus 'glob' and 'regexp' for pattern matching. Results must be non-falsy.

       Use this tool when you want to do a complex search, e.g. for all documents with certain tags etc.
       ALWAYS follow query syntax in examples.

       Examples
        1. Match all markdown files
        {"glob": ["*.md", {"var": "path"}]}

        2. Match all markdown files with 1221 substring inside them
        {
          "and": [
            { "glob": ["*.md", {"var": "path"}] },
            { "regexp": [".*1221.*", {"var": "content"}] }
          ]
        }

        3. Match all markdown files in Work folder containing name Keaton
        {
          "and": [
            { "glob": ["*.md", {"var": "path"}] },
            { "regexp": [".*Work.*", {"var": "path"}] },
            { "regexp": ["Keaton", {"var": "content"}] }
          ]
        }
       

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesJsonLogic query object. ALWAYS follow query syntax in examples. Example 1: {"glob": ["*.md", {"var": "path"}]} matches all markdown files Example 2: {"and": [{"glob": ["*.md", {"var": "path"}]}, {"regexp": [".*1221.*", {"var": "content"}]}]} matches all markdown files with 1221 substring inside them Example 3: {"and": [{"glob": ["*.md", {"var": "path"}]}, {"regexp": [".*Work.*", {"var": "path"}]}, {"regexp": ["Keaton", {"var": "content"}]}]} matches all markdown files in Work folder containing name Keaton

Implementation Reference

  • The run_tool method of ComplexSearchToolHandler that executes the obsidian_complex_search tool by invoking api.search_json with the JsonLogic query argument and returning the results as formatted JSON.
    def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
        if "query" not in args:
            raise RuntimeError("query argument missing in arguments")
    
        results = api.search_json(args.get("query", ""))
    
        return [
            TextContent(
                type="text",
                text=json.dumps(results, indent=2)
            )
        ]
  • The get_tool_description method of ComplexSearchToolHandler providing the tool schema, description, and input validation for the JsonLogic query.
    def get_tool_description(self):
        return Tool(
            name=self.name,
            description="""Complex search for documents using a JsonLogic query. 
            Supports standard JsonLogic operators plus 'glob' and 'regexp' for pattern matching. Results must be non-falsy.
    
            Use this tool when you want to do a complex search, e.g. for all documents with certain tags etc.
            ALWAYS follow query syntax in examples.
    
            Examples
             1. Match all markdown files
             {"glob": ["*.md", {"var": "path"}]}
    
             2. Match all markdown files with 1221 substring inside them
             {
               "and": [
                 { "glob": ["*.md", {"var": "path"}] },
                 { "regexp": [".*1221.*", {"var": "content"}] }
               ]
             }
    
             3. Match all markdown files in Work folder containing name Keaton
             {
               "and": [
                 { "glob": ["*.md", {"var": "path"}] },
                 { "regexp": [".*Work.*", {"var": "path"}] },
                 { "regexp": ["Keaton", {"var": "content"}] }
               ]
             }
            """,
            inputSchema={
                "type": "object",
                "properties": {
                    "query": {
                        "type": "object",
                        "description": "JsonLogic query object. ALWAYS follow query syntax in examples. \
                             Example 1: {\"glob\": [\"*.md\", {\"var\": \"path\"}]} matches all markdown files \
                             Example 2: {\"and\": [{\"glob\": [\"*.md\", {\"var\": \"path\"}]}, {\"regexp\": [\".*1221.*\", {\"var\": \"content\"}]}]} matches all markdown files with 1221 substring inside them \
                             Example 3: {\"and\": [{\"glob\": [\"*.md\", {\"var\": \"path\"}]}, {\"regexp\": [\".*Work.*\", {\"var\": \"path\"}]}, {\"regexp\": [\"Keaton\", {\"var\": \"content\"}]}]} matches all markdown files in Work folder containing name Keaton \
                         "
                    }
                },
                "required": ["query"]
            }
        )
  • TOOL_MAPPING dictionary entry mapping TOOL_COMPLEX_SEARCH ("obsidian_complex_search") to ComplexSearchToolHandler class for tool registration.
    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,
    }
  • The Obsidian API client's search_json method, which sends the JsonLogic query via POST to the /search/ endpoint and returns the search results. This is the core implementation delegated to by the tool handler.
    def search_json(self, query: dict) -> Any:
        url = f"{self.get_base_url()}/search/"
        
        headers = self._get_headers() | {
            'Content-Type': 'application/vnd.olrapi.jsonlogic+json'
        }
        
        def call_fn():
            response = requests.post(url, headers=headers, json=query, verify=self.verify_ssl, timeout=self.timeout)
            response.raise_for_status()
            return response.json()
    
        return self._safe_call(call_fn)
  • The register_tools function that instantiates handlers from TOOL_MAPPING (including ComplexSearchToolHandler for obsidian_complex_search) and adds them to the tool_handlers dictionary used by list_tools and call_tool.
    """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")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool 'Supports standard JsonLogic operators plus 'glob' and 'regexp' for pattern matching' and that 'Results must be non-falsy,' adding useful behavioral context. However, it doesn't cover aspects like performance implications, error handling, or result format details, leaving gaps for a mutation-like search operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately front-loaded with key information, but includes extensive examples that, while helpful, make it lengthy. Every sentence adds value, but the structure could be more streamlined by integrating examples more succinctly or moving some details to the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (involving JsonLogic queries with nested objects) and lack of annotations and output schema, the description is moderately complete. It covers purpose, usage, and parameter semantics with examples, but doesn't fully address behavioral aspects like result formatting or error cases, leaving room for improvement in contextual coverage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds value by explaining that the query uses 'JsonLogic operators plus 'glob' and 'regexp' for pattern matching' and provides multiple examples that illustrate syntax and usage, enhancing understanding beyond the schema's technical documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs 'complex search for documents using a JsonLogic query,' which specifies the verb (search) and resource (documents) with the method (JsonLogic). It distinguishes from sibling 'obsidian_simple_search' by emphasizing complexity, but doesn't explicitly contrast their capabilities beyond naming.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance: 'Use this tool when you want to do a complex search, e.g. for all documents with certain tags etc.' This gives clear context for when to use it, though it doesn't explicitly mention when not to use it or name alternatives like 'obsidian_simple_search' as direct comparisons.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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