Skip to main content
Glama

search_by_property

Search for notes by frontmatter property values to quickly locate specific content based on metadata fields in your Obsidian vault.

Instructions

Search for notes by frontmatter property (metadata field)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
property_nameYes
property_valueNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary MCP tool handler for 'search_by_property'. Validates inputs, invokes the VaultSearch method, formats results as markdown list.
        name="search_by_property",
        description="Search for notes by frontmatter property (metadata field)",
    )
    async def search_by_property(property_name: str, property_value: str = "", limit: int = 50) -> str:
        """
        Search for notes by frontmatter property.
    
        Args:
            property_name: Name of the frontmatter property to search
            property_value: Optional value to match (empty to find all notes with this property)
            limit: Maximum number of results (default: 50)
    
        Returns:
            Formatted list of notes matching the property
        """
        if not property_name or not property_name.strip():
            return "Error: Property name cannot be empty"
        if limit <= 0 or limit > 1000:
            return "Error: Limit must be between 1 and 1000"
    
        context = _get_context()
    
        try:
            # Convert empty string to None for "any value" search
            value = property_value if property_value else None
            results = await context.search.search_by_property(property_name, value, limit=limit)
    
            if not results:
                if value:
                    return f"No notes found with property '{property_name}' = '{value}'"
                else:
                    return f"No notes found with property '{property_name}'"
    
            # Format results
            if value:
                output = f"Found {len(results)} note(s) with '{property_name}' = '{value}':\n\n"
            else:
                output = f"Found {len(results)} note(s) with property '{property_name}':\n\n"
    
            for i, result in enumerate(results, 1):
                output += f"{i}. **{result.name}**\n"
                output += f"   Path: `{result.path}`\n"
                if result.snippet:
                    output += f"   {result.snippet}\n"
                output += "\n"
    
            return output
    
        except Exception as e:
            logger.exception(f"Error searching by property: {property_name}")
            return f"Error searching by property: {e}"
  • Core implementation logic in VaultSearch class that scans notes, matches frontmatter properties, scores results, and returns SearchResult list.
    async def search_by_property(
        self, property_name: str, property_value: str | None = None, limit: int = 50
    ) -> list[SearchResult]:
        """
        Search for notes by frontmatter property.
    
        Args:
            property_name: Name of the frontmatter property
            property_value: Optional value to match (if None, matches any note with the property)
            limit: Maximum number of results
    
        Returns:
            List of search results
        """
        results: list[SearchResult] = []
        notes = self.vault.list_notes(limit=None)
    
        for note_meta in notes:
            if len(results) >= limit:
                break
    
            try:
                note = await self.vault.read_note(note_meta.path)
    
                if not note.frontmatter:
                    continue
    
                # Check if property exists
                if property_name not in note.frontmatter:
                    continue
    
                prop_val = note.frontmatter[property_name]
    
                # If no value specified, just match presence
                if property_value is None:
                    score = 1.0
                else:
                    # Check if value matches
                    if isinstance(prop_val, list):
                        # Check if value is in list
                        if property_value in prop_val or property_value in str(prop_val):
                            score = 2.0
                        else:
                            continue
                    elif str(prop_val).lower() == property_value.lower():
                        score = 5.0  # Exact match
                    elif property_value.lower() in str(prop_val).lower():
                        score = 2.0  # Partial match
                    else:
                        continue
    
                # Create snippet from frontmatter
                snippet = f"{property_name}: {prop_val}"
    
                results.append(
                    SearchResult(
                        path=note_meta.path, name=note_meta.name, score=score, snippet=snippet
                    )
                )
    
            except (OSError, UnicodeDecodeError) as e:
                logger.debug(f"Failed to read note {note_meta.path}: {e}")
                continue
    
        results.sort(key=lambda r: r.score, reverse=True)
        return results[:limit]
  • Dataclass defining the structure of search results used by search_by_property.
    @dataclass(slots=True, frozen=True)
    class SearchResult:
        """A search result with context (immutable)."""
    
        path: str
        name: str
        score: float
        snippet: str | None = None
        matched_tags: list[str] | None = None
  • MCP tool registration decorator specifying the tool name and description.
        name="search_by_property",
        description="Search for notes by frontmatter property (metadata field)",
    )
    async def search_by_property(property_name: str, property_value: str = "", limit: int = 50) -> str:
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits like whether it's read-only, pagination behavior, rate limits, authentication needs, or what happens with partial matches. The presence of an output schema helps but isn't mentioned.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and uses parentheses for clarification without redundancy.

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?

For a search tool with 3 parameters, 0% schema coverage, and no annotations, the description is minimal. The output schema existence reduces need to explain returns, but more context on usage, parameters, and behavior would improve completeness. It's adequate but has clear gaps.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate but only mentions 'frontmatter property (metadata field)', which loosely relates to 'property_name'. It doesn't explain the three parameters (property_name, property_value, limit), their formats, or interactions. Baseline 3 is appropriate as it adds minimal value beyond the schema.

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 verb ('search') and resource ('notes'), specifying the search criteria ('by frontmatter property/metadata field'). It distinguishes from generic 'search_notes' by focusing on frontmatter properties, but doesn't explicitly differentiate from other property-related tools like 'update_frontmatter'.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'search_notes', 'get_notes_by_tag', or 'update_frontmatter'. The description implies it's for searching by metadata fields, but doesn't specify scenarios, prerequisites, or exclusions.

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/getglad/obsidian_mcp'

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