obsidian_list_files_in_dir
List files and directories within a specific Obsidian vault folder to manage and navigate your notes.
Instructions
Lists all files and directories that exist in a specific Obsidian directory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dirpath | Yes | Path to list files from (relative to your vault root). Note that empty directories will not be returned. |
Implementation Reference
- src/mcp_obsidian/tools.py:58-92 (handler)The ListFilesInDirToolHandler class is the core handler for the 'obsidian_list_files_in_dir' tool. It defines the tool's schema (inputSchema for 'dirpath') and implements the run_tool method, which calls the Obsidian API to list files in the specified directory and returns the JSON-formatted result.class ListFilesInDirToolHandler(ToolHandler): def __init__(self): super().__init__(TOOL_LIST_FILES_IN_DIR) def get_tool_description(self): return Tool( name=self.name, description="Lists all files and directories that exist in a specific Obsidian directory.", inputSchema={ "type": "object", "properties": { "dirpath": { "type": "string", "description": "Path to list files from (relative to your vault root). Note that empty directories will not be returned." }, }, "required": ["dirpath"] } ) def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "dirpath" not in args: raise RuntimeError("dirpath argument missing in arguments") api = obsidian.Obsidian(api_key=api_key, host=obsidian_host) files = api.list_files_in_dir(args["dirpath"]) return [ TextContent( type="text", text=json.dumps(files, indent=2) ) ]
- src/mcp_obsidian/server.py:44-44 (registration)Registers the ListFilesInDirToolHandler instance in the tool_handlers dictionary, making the 'obsidian_list_files_in_dir' tool available to the MCP server.add_tool_handler(tools.ListFilesInDirToolHandler())
- src/mcp_obsidian/obsidian.py:59-68 (helper)The Obsidian client's list_files_in_dir method performs the HTTP GET request to the Obsidian API endpoint '/vault/{dirpath}/' to retrieve the list of files and directories in the specified path.def list_files_in_dir(self, dirpath: str) -> Any: url = f"{self.get_base_url()}/vault/{dirpath}/" def call_fn(): response = requests.get(url, headers=self._get_headers(), verify=self.verify_ssl, timeout=self.timeout) response.raise_for_status() return response.json()['files'] return self._safe_call(call_fn)
- src/mcp_obsidian/tools.py:19-19 (registration)Defines the constant string for the tool name used in the handler initialization.TOOL_LIST_FILES_IN_DIR = "obsidian_list_files_in_dir"