MCPcopy Create free account
hub / github.com/modelcontextprotocol/mcpb / list_files

Function list_files

examples/file-manager-python/server/main.py:22–47  ·  view source on GitHub ↗

List files in a directory

(path: str)

Source from the content-addressed store, hash-verified

20
21@mcp.tool()
22def 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()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…