Skip to main content
Glama
ToKiDoO

Advanced Obsidian MCP Server

by ToKiDoO

obsidian_list_files_in_dir

List files and directories in a specific Obsidian vault folder to discover content structure and locate documents.

Instructions

Lists all files and directories that exist in a specific Obsidian directory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirpathYesPath to list files from (relative to your vault root). Note that empty directories will not be returned.

Implementation Reference

  • The run_tool method implements the core tool logic: it validates the 'dirpath' argument, calls the Obsidian API to list files in the directory, and returns the results as JSON-formatted text content.
    def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
    
        if "dirpath" not in args:
            raise RuntimeError("dirpath argument missing in arguments")
    
        files = api.list_files_in_dir(args["dirpath"])
    
        return [
            TextContent(
                type="text",
                text=json.dumps(files, indent=2)
            )
        ]
  • Defines the tool's schema, including the name 'obsidian_list_files_in_dir', description, and input schema requiring a 'dirpath' string parameter.
    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"]
            }
        )
  • TOOL_MAPPING dictionary maps the tool name constant TOOL_LIST_FILES_IN_DIR ("obsidian_list_files_in_dir") to the ListFilesInDirToolHandler class. This mapping is used in register_tools() to instantiate and register the handler with the MCP server.
    TOOL_MAPPING = {
        tools.TOOL_LIST_FILES_IN_DIR: tools.ListFilesInDirToolHandler,
        tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler,
        tools.TOOL_PATCH_CONTENT: tools.PatchContentToolHandler,
        tools.TOOL_PUT_CONTENT: tools.PutContentToolHandler,
        tools.TOOL_APPEND_CONTENT: tools.AppendContentToolHandler,
        tools.TOOL_DELETE_FILE: tools.DeleteFileToolHandler,
        tools.TOOL_COMPLEX_SEARCH: tools.ComplexSearchToolHandler,
        tools.TOOL_BATCH_GET_FILES: tools.BatchGetFilesToolHandler,
        tools.TOOL_PERIODIC_NOTES: tools.PeriodicNotesToolHandler,
        tools.TOOL_RECENT_PERIODIC_NOTES: tools.RecentPeriodicNotesToolHandler,
        tools.TOOL_RECENT_CHANGES: tools.RecentChangesToolHandler,
        tools.TOOL_UNDERSTAND_VAULT: tools.UnderstandVaultToolHandler,
        tools.TOOL_GET_ACTIVE_NOTE: tools.GetActiveNoteToolHandler,
        tools.TOOL_OPEN_FILES: tools.OpenFilesToolHandler,
        tools.TOOL_LIST_COMMANDS: tools.ListCommandsToolHandler,
        tools.TOOL_EXECUTE_COMMANDS: tools.ExecuteCommandsToolHandler,
    }
  • register_tools() function instantiates handler classes from TOOL_MAPPING for selected tools (including obsidian_list_files_in_dir if not filtered out) and adds them to the tool_handlers dictionary used by list_tools() and call_tool(). Called at startup.
    def register_tools():
        """Register the selected tools with the server."""
        tools_to_include = parse_include_tools()
        
        registered_count = 0
        for tool_name in tools_to_include:
            if tool_name in TOOL_MAPPING:
                handler_class = TOOL_MAPPING[tool_name]
                handler_instance = handler_class()
                add_tool_handler(handler_instance)
                registered_count += 1
                logger.debug(f"Registered tool: {tool_name}")
        
        logger.info(f"Successfully registered {registered_count} tools")
  • Constant defining the exact tool name string "obsidian_list_files_in_dir" used throughout for registration and identification.
    TOOL_LIST_FILES_IN_DIR = "obsidian_list_files_in_dir"

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.5/5.0
Behavior3/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 core function (listing files/directories) and notes that empty directories are not returned (via schema description), but does not disclose other behavioral traits such as permissions needed, rate limits, output format, pagination, or error handling. It adds some context but leaves significant gaps for a tool with no 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 that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and scope, making it easy to parse. Every part of the sentence contributes essential information, earning its place with zero waste.

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

Completeness3/5

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

Given no annotations, no output schema, and a simple single-parameter input schema, the description provides basic completeness for a read-only listing tool. However, it lacks details on output structure (e.g., format of returned list), error conditions, or integration with sibling tools. It is minimally viable but has clear gaps in contextual information that could aid an AI agent.

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 'dirpath' fully documented in the schema (path relative to vault root, empty directories not returned). The description does not add any parameter-specific semantics beyond what the schema provides, such as format examples or edge cases. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 ('Lists') and resource ('all files and directories') with specific scope ('in a specific Obsidian directory'). It distinguishes from sibling 'obsidian_list_files_in_vault' by specifying directory-level rather than vault-wide listing, though not explicitly named. The purpose is unambiguous but could be more explicit about the sibling distinction.

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

Usage Guidelines3/5

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

The description implies usage context (directory-level listing) but does not explicitly state when to use this tool versus alternatives like 'obsidian_list_files_in_vault' or file-content tools. It provides no guidance on prerequisites, exclusions, or comparative scenarios. The context is clear but lacks explicit alternative naming or when-not-to-use advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.