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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_filesystem/server.py:283-295 (handler)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)}"
- mcp_filesystem/server.py:48-83 (helper)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