Skip to main content
Glama
pmmvr

Obsidian MCP Server

by pmmvr

browse_vault_structure

Read-only

Explore and navigate Obsidian vault directories to view folder structures, optionally including files and recursively listing nested contents for comprehensive organization.

Instructions

Browse vault directory structure.

Args:
    path: Path to browse from (defaults to vault root)
    include_files: Include files in listing (default: False, folders only)
    recursive: List nested contents recursively

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_filesNo
pathNo
recursiveNo

Implementation Reference

  • The primary MCP tool handler for 'browse_vault_structure', decorated with @mcp.tool(). Cleans input path, delegates to client.browse_vault(), separates directories and files, and returns a structured dictionary response with success/error handling.
    @mcp.tool(
        annotations={
            "title": "Browse Obsidian Vault Structure",
            "readOnlyHint": True,
            "openWorldHint": False
        }
    )
    async def browse_vault_structure(path: str = "", include_files: bool = False, recursive: bool = False) -> Dict[str, Any]:
        """
        Browse vault directory structure.
        
        Args:
            path: Path to browse from (defaults to vault root)
            include_files: Include files in listing (default: False, folders only)
            recursive: List nested contents recursively
        """
        try:
            # Remove leading/trailing quotes and whitespace 
            clean_path = path.strip().strip('"\'')
            items = await client.browse_vault(clean_path, include_files, recursive)
            
            directories = [item for item in items if item.endswith('/')]
            files = [item for item in items if not item.endswith('/')]
            
            return {
                "success": True,
                "path": clean_path,
                "include_files": include_files,
                "recursive": recursive,
                "directories": directories,
                "files": files if include_files else [],
                "total_directories": len(directories),
                "total_files": len(files) if include_files else 0,
                "total_items": len(items)
            }
        except Exception as e:
            return {
                "success": False,
                "error": f"Failed to browse vault structure for path '{path}': {str(e)}",
                "path": path,
                "include_files": include_files,
                "recursive": recursive,
                "directories": [],
                "files": [],
                "total_directories": 0,
                "total_files": 0,
                "total_items": 0
            }
  • Supporting helper method in ObsidianClient that implements the vault browsing logic, handling both shallow (non-recursive) and deep recursive traversal using list_directory(), with file inclusion filter and max_depth safety limit.
    async def browse_vault(self, base_path: str = "", include_files: bool = False, recursive: bool = False, max_depth: int = 10) -> List[str]:
        """Browse vault structure with flexible filtering options."""
        if not recursive:
            all_items = await self.list_directory(base_path)
            if not include_files:
                # Filter to only show directories (items ending with '/')
                return [item for item in all_items if item.endswith('/')]
            return all_items
        
        all_items = []
        
        async def _recursive_list(current_path: str, depth: int):
            if depth > max_depth:
                return
                
            try:
                items = await self.list_directory(current_path)
                for item in items:
                    if current_path:
                        full_path = f"{current_path}/{item}"
                    else:
                        full_path = item
                    
                    # Apply file filtering
                    if include_files or item.endswith('/'):
                        all_items.append(full_path)
                    
                    # If it's a directory, recurse into it
                    if item.endswith('/'):
                        await _recursive_list(full_path.rstrip('/'), depth + 1)
            except Exception:
                # Skip directories we can't access
                pass
        
        await _recursive_list(base_path, 0)
        return all_items
  • Low-level helper in ObsidianClient to list contents of a vault directory/path via Obsidian API endpoint.
    async def list_directory(self, path: str = "") -> List[str]:
        if path:
            # Just URL encode the path and try it directly
            encoded_path = quote(path, safe='/')
            endpoint = f"/vault/{encoded_path}/"
        else:
            endpoint = "/vault/"
        
        result = await self._request("GET", endpoint)
        return result.get("files", [])
Behavior4/5

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

Annotations already provide readOnlyHint=true and openWorldHint=false, indicating this is a safe read operation with deterministic results. The description adds valuable context about default behaviors (browsing from vault root, folders-only by default) and the recursive option, which goes beyond what annotations provide. No contradictions with annotations exist.

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 perfectly structured: a clear purpose statement followed by a bullet-point style explanation of each parameter. Every sentence earns its place, with no wasted words. The information is front-loaded with the core purpose first.

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?

For a directory browsing tool with 3 parameters, no output schema, and good annotations, the description covers the essential behavior and parameters adequately. However, it doesn't describe the return format (e.g., what structure is returned, error conditions), which would be helpful given the lack of output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description carries full burden for parameter meaning. It successfully explains all three parameters: 'path' (starting location with default), 'include_files' (files inclusion toggle with default), and 'recursive' (nested listing). This compensates well for the schema's lack of descriptions.

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 ('Browse') and resource ('vault directory structure'), making the purpose immediately understandable. It distinguishes from sibling tools like 'get_note_content' (which retrieves content) and 'search_vault' (which searches), but doesn't explicitly mention these distinctions in the description itself.

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 for exploring directory structure rather than retrieving content or searching, but doesn't provide explicit guidance on when to use this tool versus alternatives like 'search_vault'. The parameter descriptions suggest default behaviors (folders only, non-recursive), which gives some contextual hints.

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

Related 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/pmmvr/obsidian-api-mcp-server'

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