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"

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/ToKiDoO/mcp-obsidian-advanced'

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