Skip to main content
Glama

search_notes

Search your Obsidian vault by content, title, or tags to quickly find relevant notes and information across your knowledge base.

Instructions

Search the vault by content, title, tags, or all

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderNo
limitNo
queryYes
search_typeNoall

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler for the 'search_notes' MCP tool. It handles input validation, invokes the VaultSearch.search method, formats the search results into a readable string, and includes error handling.
    @mcp.tool(name="search_notes", description="Search the vault by content, title, tags, or all")
    async def search_notes(
        query: str, search_type: SearchType = "all", folder: str = "", limit: int = 20
    ) -> str:
        """
        Search for notes in the vault.
    
        Args:
            query: Search query string
            search_type: Type of search - "content", "title", "tags", or "all"
            folder: Optional folder to limit search (e.g., "Projects")
            limit: Maximum number of results (default: 20)
    
        Returns:
            Formatted list of search results with snippets
        """
        # Validate input
        if not query or not query.strip():
            return "Error: Query cannot be empty"
        if len(query) > 500:
            return "Error: Query too long"
        if limit <= 0 or limit > 1000:
            return "Error: Limit must be between 1 and 1000"
    
        context = _get_context()
    
        try:
            results = await context.search.search(
                query=query, search_type=search_type, folder=folder, limit=limit
            )
    
            if not results:
                return f"No results found for query: {query}"
    
            # Format results
            output = f"Found {len(results)} results for '{query}':\n\n"
    
            for i, result in enumerate(results, 1):
                output += f"{i}. **{result.name}**\n"
                output += f"   Path: `{result.path}`\n"
                output += f"   Score: {result.score:.1f}\n"
    
                if result.snippet:
                    output += f"   Snippet: {result.snippet}\n"
    
                if result.matched_tags:
                    output += f"   Tags: {', '.join(result.matched_tags)}\n"
    
                output += "\n"
    
            return output
    
        except VaultSecurityError as e:
            return f"Error: Security violation: {e}"
        except Exception as e:
            logger.exception("Error searching notes")
            return f"Error searching notes: {e}"
  • The @mcp.tool decorator registers the 'search_notes' function as an MCP tool with the specified name and description.
    @mcp.tool(name="search_notes", description="Search the vault by content, title, tags, or all")
  • Type definition for the search_type parameter used in the search_notes tool, defining valid literal values for search types.
    SearchType = Literal["content", "title", "tags", "all"]
  • The core search logic in VaultSearch.search method, called by the search_notes handler. Performs the actual searching based on type (content, title, tags, or all) and returns sorted SearchResult list.
    async def search(
        self, query: str, search_type: SearchType = "all", folder: str = "", limit: int = 20
    ) -> list[SearchResult]:
        """
        Search the vault.
    
        Args:
            query: Search query string
            search_type: Type of search to perform
            folder: Limit search to this folder
            limit: Maximum number of results
    
        Returns:
            List of search results sorted by relevance
        """
        logger.debug(
            f"Searching for '{query}' (type={search_type}, folder={folder}, limit={limit})"
        )
    
        if not query:
            return []
    
        if search_type == "content":
            return await self._search_in_content(query, limit, folder)
        elif search_type == "title":
            return self._search_by_title(query, limit, folder)
        elif search_type == "tags":
            return self._search_by_tags(query, limit, folder)
        else:  # "all"
            # Combine results from all search types (each with full limit to ensure enough results)
            title_results = self._search_by_title(query, limit, folder)
            tag_results = self._search_by_tags(query, limit, folder)
            content_results = await self._search_in_content(query, limit, folder)
    
            # Merge and deduplicate by path
            seen_paths = set()
            all_results = []
    
            for result in title_results + tag_results + content_results:
                if result.path not in seen_paths:
                    seen_paths.add(result.path)
                    all_results.append(result)
    
            # Sort by score and return top results up to limit
            all_results.sort(key=lambda r: r.score, reverse=True)
    
            return all_results[:limit]
  • Dataclass defining the structure of each search result returned by the search functionality.
    @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
Behavior1/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It fails to describe key behaviors: whether this is a read-only operation (implied but not stated), what the output format is (though an output schema exists), whether results are paginated or limited (the 'limit' parameter suggests limiting but not described), or any performance/rate-limiting considerations. For a search tool with zero annotation coverage, this is inadequate.

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 parallel structure ('content, title, tags, or all'). Every word earns its place, making it easy to parse quickly.

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 moderate complexity (search with 4 parameters) and no annotations, the description is incomplete. It covers the purpose and one parameter indirectly but lacks behavioral context, usage guidelines, and details on most parameters. The existence of an output schema reduces the need to describe return values, but other gaps remain. This is minimally adequate but with clear room for improvement.

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 schema provides no parameter descriptions. The description mentions searchable fields (content, title, tags, or all), which maps to the 'search_type' enum parameter, adding some semantics. However, it doesn't explain the 'query', 'folder', or 'limit' parameters, leaving three of four parameters with minimal context. The baseline is 3 because it adds value for one parameter but doesn't fully compensate for the coverage gap.

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 ('the vault'), specifying what fields can be searched (content, title, tags, or all). It distinguishes from siblings like 'list_notes' (which lists without search) and 'search_by_property' (which searches by property rather than content/title/tags). However, it doesn't explicitly mention that it searches notes specifically, though this is implied by context.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer 'search_notes' over 'list_notes' (for listing without query), 'get_notes_by_tag' (for tag-specific retrieval), or 'search_by_property' (for property-based search). There's no context about prerequisites, performance implications, or typical use cases.

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