Skip to main content
Glama
safurrier

MCP Filesystem Server

list_allowed_directories

Retrieve accessible directories for secure file operations in the MCP Filesystem Server.

Instructions

Returns the list of directories that this server is allowed to access.

Args:
    ctx: MCP context

Returns:
    List of allowed directories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function decorated with @mcp.tool(), which implements the tool logic by retrieving allowed directories from shared components and formatting them for output. This also serves as the registration point.
    @mcp.tool()
    async def list_allowed_directories(ctx: Context) -> str:
        """Returns the list of directories that this server is allowed to access.
    
        Args:
            ctx: MCP context
    
        Returns:
            List of allowed directories
        """
        components = get_components()
        allowed_dirs = components["allowed_dirs"]
        return f"Allowed directories:\n{os.linesep.join(allowed_dirs)}"
  • Helper function that initializes and caches shared components, including the 'allowed_dirs' list used by the tool handler.
    def get_components() -> Dict[str, Any]:
        """Initialize and return shared components.
    
        Returns cached components if already initialized.
    
        Returns:
            Dictionary with initialized components
        """
        # Return cached components if available
        if _components_cache:
            return _components_cache
    
        # Initialize components
        allowed_dirs_typed: List[Union[str, Path]] = get_allowed_dirs()
        validator = PathValidator(allowed_dirs_typed)
        operations = FileOperations(validator)
        advanced = AdvancedFileOperations(validator, operations)
        grep = GrepTools(validator)
    
        # Store in cache
        _components = {
            "validator": validator,
            "operations": operations,
            "advanced": advanced,
            "grep": grep,
            "allowed_dirs": validator.get_allowed_dirs(),
        }
    
        # Update cache
        _components_cache.update(_components)
    
        logger.info(
            f"Initialized filesystem components with allowed directories: {validator.get_allowed_dirs()}"
        )
    
        return _components

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/safurrier/mcp-filesystem'

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