List files in a directory
(path: str)
| 20 | |
| 21 | @mcp.tool() |
| 22 | def list_files(path: str) -> str: |
| 23 | """List files in a directory""" |
| 24 | path_obj = Path(path) |
| 25 | |
| 26 | if not path_obj.exists(): |
| 27 | return f"Directory not found: {path}" |
| 28 | |
| 29 | if not path_obj.is_dir(): |
| 30 | return f"Path is not a directory: {path}" |
| 31 | |
| 32 | try: |
| 33 | files = [] |
| 34 | for item in path_obj.iterdir(): |
| 35 | file_type = "directory" if item.is_dir() else "file" |
| 36 | files.append(f"{item.name} ({file_type})") |
| 37 | |
| 38 | if not files: |
| 39 | return f"Directory is empty: {path}" |
| 40 | |
| 41 | file_list = "\n".join(files) |
| 42 | return f"Files in {path}:\n{file_list}" |
| 43 | |
| 44 | except PermissionError: |
| 45 | return f"Permission denied accessing: {path}" |
| 46 | except Exception as e: |
| 47 | return f"Error listing directory: {str(e)}" |
| 48 | |
| 49 | |
| 50 | @mcp.tool() |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…