INNER CODE UNIT · Python
list_files
existence-master/Sentient · src/server/mcp_hub/file_management/main.py:117
async def list_files(ctx: Context) -> Dict[str, Any]:
"""
Lists all files currently available in the user's temporary storage area.
"""
logger.info("Executing tool: list_files")
try:
user_id = auth.get_user_id_from_context(ctx)
# Sanitize user_id to ensure it's safe for use in a file path
safe_user_id = "".join(c for c in user_id if c.isalnum() or c in ('-', '_'))
user_dir = os.path.join(FILE_MANAGEMENT_TEMP_DIR, safe_user_id)
if not os.path.isdir(user_dir):
return {"status": "success", "result": []} # User has no files yet
files = [f for f in os.listdir(user_dir) if os.path.isfile(os.path.join(user_dir, f))]
# Return just the filenames, not the relative path
return {"status": "success", "result": files}