Skip to main content
Glama

search_vault

Find specific content within your Obsidian vault by entering a search query to locate relevant notes and information.

Instructions

Search for content in the Obsidian vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • Input schema and description for the search_vault tool, registered in the list_tools handler.
      name: 'search_vault',
      description: 'Search for content in the Obsidian vault',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query',
          },
        },
        required: ['query'],
      },
    },
    {
  • src/index.ts:1395-1396 (registration)
    Registration of the search_vault tool handler in the CallToolRequestSchema switch statement.
      return await this.handleSearchVault(request.params.arguments);
    case 'delete_note':
  • Entry point handler for the search_vault tool. Validates arguments and calls the core searchVault method.
    private async handleSearchVault(args: any) {
      if (!args?.query) {
        throw new Error('Search query is required');
      }
      
      const results = await this.searchVault(args.query);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results, null, 2),
          },
        ],
      };
    }
  • Core implementation of vault search logic. Uses Obsidian search API if available, otherwise performs full-text search across all vault files with filename and content matching.
    private async searchVault(query: string): Promise<any[]> {
      // Search vault
      
      try {
        // First try using the Obsidian API
        const apiUrl = `/search?query=${encodeURIComponent(query)}`;
        // Search API call
        const response = await this.api.get(apiUrl);
        // API response received
        // API data received
        // Check if API returns results directly or wrapped in {results: ...}
        const results = response.data.results || response.data || [];
        // Search results processed
        return results;
      } catch (error) {
        console.warn('API request failed, falling back to simple search:', error);
        
        // Fallback to simple search if API fails
        const files = await this.listVaultFiles();
        // Fallback search files
        // Files list processed
        const results = [];
        
        for (const file of files) {
          try {
            // Check file for matches
            const lowerQuery = query.toLowerCase();
            const lowerFileName = file.toLowerCase();
            let matchedByName = false;
            let matchedByContent = false;
            
            // Check if filename contains the query
            if (lowerFileName.includes(lowerQuery)) {
              matchedByName = true;
              // Filename match found
            }
            
            // Check if content contains the query (only for text files)
            let content = '';
            try {
              content = await this.readNote(file);
              // Read file content
              // Content preview processed
              if (typeof content === 'string' && content.toLowerCase().includes(lowerQuery)) {
                matchedByContent = true;
                // Content match found
              }
            } catch (readError) {
              // Could not read file for content search
              // For binary files that can't be read as text, only use filename matching
            }
            
            // Add to results if matched by name or content
            if (matchedByName || matchedByContent) {
              const matchType = matchedByName ? 'filename' : 'content';
              const lineMatch = matchedByContent && typeof content === 'string' 
                ? content.split('\n').findIndex(line => line.toLowerCase().includes(lowerQuery))
                : -1;
                
              results.push({
                path: file,
                score: matchedByName ? 2 : 1, // Higher score for filename matches
                matches: [{ 
                  line: lineMatch,
                  type: matchType 
                }],
              });
              
              // Match found in file
            } else {
              // No match found
            }
          } catch (error) {
            // Skip file due to error
          }
        }
        
        return results;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Search') but doesn't describe what the search returns (e.g., file names, content snippets, metadata), how results are formatted, or any limitations (e.g., search scope, performance). This leaves significant gaps for a tool with no output schema.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded for quick understanding.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It doesn't explain what 'content' means (e.g., files, text, metadata), the search behavior (e.g., full-text, fuzzy), or the return format, making it inadequate for a search tool in a complex vault system.

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 100%, with the single parameter 'query' documented in the schema. The description adds no additional meaning beyond implying a search operation, so it meets the baseline of 3 where the schema does the heavy lifting.

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 ('content in the Obsidian vault'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'list_notes' or 'notes_insight' that might also involve finding content, so it doesn't reach the highest clarity level.

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 like 'list_notes' or 'notes_insight'. There's no mention of prerequisites, context, or exclusions, leaving the agent with minimal usage direction.

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

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