Skip to main content
Glama
libra850
by libra850

search_files

Search files and directories within an Obsidian vault using path and pattern parameters to locate specific content.

Instructions

Obsidianボルト内のファイルとディレクトリを検索します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchPathNo検索を開始するパス(vault相対パス、省略時はルート)
patternNo検索パターン(ファイル名の一部、省略時は全て)

Implementation Reference

  • Core implementation of the search_files tool handler. Recursively traverses directories from the specified searchPath, matches file/directory names against the pattern, collects results with relative paths and types, sorts directories first then alphabetically.
    async searchFiles(searchPath: string = '', pattern: string = ''): Promise<{ path: string; type: 'file' | 'directory' }[]> {
      const basePath = path.join(this.config.vaultPath, searchPath);
      
      if (!FileUtils.validatePath(this.config.vaultPath, searchPath)) {
        throw new Error('無効なパスです');
      }
      
      const results: { path: string; type: 'file' | 'directory' }[] = [];
      
      const processDirectory = async (dirPath: string, relativePath: string = '') => {
        try {
          const entries = await fs.readdir(dirPath, { withFileTypes: true });
          
          for (const entry of entries) {
            const fullPath = path.join(dirPath, entry.name);
            const entryRelativePath = path.join(relativePath, entry.name);
            
            if (entry.isDirectory()) {
              if (!pattern || entry.name.includes(pattern)) {
                results.push({ path: entryRelativePath, type: 'directory' });
              }
              await processDirectory(fullPath, entryRelativePath);
            } else if (entry.isFile()) {
              if (!pattern || entry.name.includes(pattern)) {
                results.push({ path: entryRelativePath, type: 'file' });
              }
            }
          }
        } catch (error) {
          // ディレクトリ読み込みエラーは無視
        }
      };
      
      await processDirectory(basePath, searchPath);
      
      return results.sort((a, b) => {
        if (a.type !== b.type) {
          return a.type === 'directory' ? -1 : 1;
        }
        return a.path.localeCompare(b.path);
      });
    }
  • src/server.ts:146-164 (registration)
    Registration of the search_files tool in the MCP server's list_tools handler, defining the tool name, description, and input schema for parameters searchPath and pattern.
    {
      name: 'search_files',
      description: 'Obsidianボルト内のファイルとディレクトリを検索します',
      inputSchema: {
        type: 'object',
        properties: {
          searchPath: {
            type: 'string',
            description: '検索を開始するパス(vault相対パス、省略時はルート)',
            default: '',
          },
          pattern: {
            type: 'string',
            description: '検索パターン(ファイル名の一部、省略時は全て)',
            default: '',
          },
        },
      },
    },
  • Dispatch handler in the MCP server's CallToolRequestSchema that invokes the ObsidianHandler.searchFiles method with parsed arguments and formats the JSON response.
    case 'search_files':
      const searchResults = await this.obsidianHandler.searchFiles(
        (args.searchPath as string) || '',
        (args.pattern as string) || ''
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(searchResults, null, 2),
          },
        ],
      };
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool searches but doesn't disclose behavioral traits like whether it's read-only, how results are returned (e.g., list format, pagination), error handling, or performance implications (e.g., speed on large vaults). This is inadequate for a search tool with zero annotation coverage.

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 in Japanese that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, with every part contributing to understanding the purpose.

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 the complexity of a search tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the search returns (e.g., file paths, metadata), how results are structured, or any limitations (e.g., case sensitivity, regex support). This leaves significant gaps for an agent to use the tool effectively.

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?

The description adds no parameter semantics beyond what the input schema provides. With 100% schema description coverage, the schema fully documents both parameters (searchPath and pattern), including defaults and meanings. The baseline score of 3 reflects that the schema does the heavy lifting, and the description doesn't compensate or add value.

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's purpose: 'search files and directories in Obsidian vault' (verb+resource). It's specific about the scope (Obsidian vault) but doesn't differentiate from sibling tools like 'find_broken_links' or 'list_tags' which also involve searching or listing operations in the same 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 prerequisites, exclusions, or compare it to siblings like 'list_templates' or 'analyze_backlinks', leaving the agent to infer usage based on tool names alone.

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

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