"""Health check tool for debugging iMessage database access."""
import platform
from ..db import check_database_access
async def check_permissions() -> dict:
"""Check if the server has the required permissions to access iMessage data.
This tool helps debug permission issues by checking:
- Full Disk Access for ~/Library/Messages/chat.db
- Access to ~/Library/Messages/Attachments
Returns:
Dictionary with access status, paths checked, and any error messages.
Includes macOS version for debugging.
"""
access = check_database_access()
return {
"status": "ok" if access["chat_db_readable"] else "error",
"macos_version": platform.mac_ver()[0],
"chat_db": {
"path": access["chat_db_path"],
"exists": access["chat_db_exists"],
"readable": access["chat_db_readable"],
},
"attachments": {
"path": access["attachments_path"],
"exists": access["attachments_exists"],
"readable": access["attachments_readable"],
},
"error": access.get("error"),
"help": (
"If permissions are missing, grant Full Disk Access to "
"Terminal.app or Claude Desktop.app in System Settings > "
"Privacy & Security > Full Disk Access."
)
if not access["chat_db_readable"]
else None,
}