Skip to main content
Glama

obsidian_list_files_in_dir

Read-onlyIdempotent

Explore and list files and directories within your Obsidian vault to navigate organized sections like Zettelkasten folders.

Instructions

List files and directories in a specific vault directory.

Use this tool to explore the contents of a specific folder, such as your
Zettelkasten directory or any other organized section of your vault.

Args:
    params (ListFilesInput): Contains:
        - dirpath (str): Relative path to directory (empty for root)

Returns:
    str: Formatted list of directories and files in the specified path
    
Example:
    For dirpath="Zettelkasten", lists all notes in your Zettelkasten folder.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler function that executes the tool: constructs API endpoint, calls ObsidianClient.get(), extracts files/directories, formats output using helper, handles errors.
    async def list_files_in_dir(params: ListFilesInput) -> str:
        """List files and directories in a specific vault directory.
        
        Use this tool to explore the contents of a specific folder, such as your
        Zettelkasten directory or any other organized section of your vault.
        
        Args:
            params (ListFilesInput): Contains:
                - dirpath (str): Relative path to directory (empty for root)
        
        Returns:
            str: Formatted list of directories and files in the specified path
            
        Example:
            For dirpath="Zettelkasten", lists all notes in your Zettelkasten folder.
        """
        try:
            endpoint = f"/vault/{params.dirpath}" if params.dirpath else "/vault/"
            result = await obsidian_client.get(endpoint)
            files = result.get("files", [])
            directories = result.get("directories", [])
            
            return format_file_list(files, directories)
            
        except ObsidianAPIError as e:
            return json.dumps({
                "error": str(e),
                "success": False
            }, indent=2)
  • Pydantic model defining input schema: optional dirpath (str, default empty for root).
    class ListFilesInput(BaseModel):
        """Input for listing files in a directory."""
        model_config = ConfigDict(str_strip_whitespace=True, extra='forbid')
        
        dirpath: Optional[str] = Field(
            default="",
            description="Relative directory path to list (empty string for vault root)",
            max_length=500
        )
  • MCP tool registration decorator specifying name and annotations (read-only, idempotent).
    @mcp.tool(
        name="obsidian_list_files_in_dir",
        annotations={
            "title": "List Files in Directory",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False
        }
    )
  • Helper function formats lists of files and directories into markdown with emojis and sections.
    def format_file_list(files: List[str], directories: List[str]) -> str:
        """Format file and directory lists for display."""
        result = []
        
        if directories:
            result.append("## Directories")
            for d in sorted(directories):
                result.append(f"- 📁 {d}/")
            result.append("")
        
        if files:
            result.append("## Files")
            for f in sorted(files):
                result.append(f"- 📄 {f}")
        
        return "\n".join(result) if result else "No files or directories found."
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, and idempotentHint=true, covering safety aspects. The description adds useful context about the scope ('specific vault directory') and example use case, though it doesn't mention rate limits or authentication needs beyond what annotations imply.

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 well-structured with purpose statement, usage guidance, parameter explanation, return value, and example - all in concise sentences that earn their place. No wasted words, and key information is front-loaded.

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

Completeness5/5

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

Given the tool's simplicity (1 parameter), comprehensive annotations, and existence of an output schema, the description provides complete context. It covers purpose, usage, parameters, returns, and examples without needing to duplicate what structured fields already provide.

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%, but the description compensates by explaining the single parameter dirpath as 'Relative path to directory (empty for root)' and providing an example. However, it doesn't add significant meaning beyond what's already implied by the parameter name and example.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 with specific verb ('List') and resource ('files and directories in a specific vault directory'), and distinguishes it from sibling tools like obsidian_list_files_in_vault by specifying directory-level listing rather than vault-wide listing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('to explore the contents of a specific folder') with concrete examples ('Zettelkasten directory or any other organized section'), but doesn't explicitly mention when not to use it or name specific alternatives from the sibling list.

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/Shepherd-Creative/obsidian-mcp'

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