Skip to main content
Glama

search_files

Search files and directories within an Obsidian vault using path-based queries and filename patterns to locate specific content.

Instructions

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

Input Schema

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

Implementation Reference

  • The core implementation of the search_files tool handler. It recursively traverses the directory tree starting from the specified searchPath within the Obsidian vault, filters entries by the pattern in their names, collects relative paths with types, and returns them sorted (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)
    Registers the 'search_files' tool in the MCP server's tool list, providing name, description, and input schema.
    { name: 'search_files', description: 'Obsidianボルト内のファイルとディレクトリを検索します', inputSchema: { type: 'object', properties: { searchPath: { type: 'string', description: '検索を開始するパス(vault相対パス、省略時はルート)', default: '', }, pattern: { type: 'string', description: '検索パターン(ファイル名の一部、省略時は全て)', default: '', }, }, }, },
  • src/server.ts:316-328 (registration)
    Handles incoming calls to the 'search_files' tool in the MCP server request handler, delegating execution to ObsidianHandler.searchFiles and formatting the 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), }, ], };

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