Skip to main content
Glama
MarkusPfundstein

MCP server for Obsidian

obsidian_complex_search

Search Obsidian documents using JsonLogic queries with glob and regex operators to find files by path, content, tags, and patterns.

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 ComplexSearchToolHandler class defines the tool handler, including __init__ setting the tool name, get_tool_description providing schema and description, and run_tool executing the search via Obsidian API.
    class ComplexSearchToolHandler(ToolHandler):
       def __init__(self):
           super().__init__("obsidian_complex_search")
    
       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"]
               }
           )
    
       def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
           if "query" not in args:
               raise RuntimeError("query argument missing in arguments")
    
           api = obsidian.Obsidian(api_key=api_key, host=obsidian_host)
           results = api.search_json(args.get("query", ""))
    
           return [
               TextContent(
                   type="text",
                   text=json.dumps(results, indent=2)
               )
           ]
  • Registers the ComplexSearchToolHandler instance in the tool_handlers dictionary via add_tool_handler.
    add_tool_handler(tools.ComplexSearchToolHandler())
  • The search_json method in Obsidian class performs the actual JSON logic search by posting the query to the Obsidian API endpoint /search/.
    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)
Behavior4/5

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

With no annotations provided, the description carries full burden. It effectively discloses key behavioral traits: it's a read-only search operation (implied by 'search'), supports JsonLogic with extensions ('glob' and 'regexp'), and specifies that 'Results must be non-falsy.' It doesn't mention pagination, rate limits, or authentication needs, but covers core functionality well.

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

Conciseness4/5

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

The description is well-structured with clear sections: purpose, usage guidelines, and examples. It's appropriately sized for a complex tool, though the examples are lengthy. Every sentence adds value, but it could be more front-loaded by moving the usage guidance closer to the beginning.

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

Completeness4/5

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

Given the tool's complexity (JsonLogic queries, pattern matching), no annotations, and no output schema, the description does a good job. It explains the query language, provides examples, and specifies result requirements. However, it doesn't describe the output format (e.g., what fields are returned), which is a gap since there's no output schema.

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 significant value beyond the schema by explaining the JsonLogic operators ('standard JsonLogic operators plus 'glob' and 'regexp' for pattern matching'), providing three detailed examples with explanations, and emphasizing 'ALWAYS follow query syntax in examples.' This compensates for the schema's technical nature.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Complex search for documents using a JsonLogic query.' It specifies the resource (documents) and method (JsonLogic query), and distinguishes it from sibling 'obsidian_simple_search' by emphasizing complexity and additional operators like 'glob' and 'regexp'.

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.' It distinguishes from simpler alternatives by naming the use case, though it doesn't explicitly list when NOT to use it or name all alternatives.

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

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