tool_check_db_access
Diagnose and resolve database access issues for the macOS Messages app using the MCP server mac-messages-mcp. Ensure reliable connectivity and functionality.
Instructions
Diagnose database access issues.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mac_messages_mcp/server.py:110-120 (handler)Handler function for tool_check_db_access, registered via @mcp.tool() decorator. Delegates to check_messages_db_access helper function.@mcp.tool() def tool_check_db_access(ctx: Context) -> str: """ Diagnose database access issues. """ logger.info("Checking database access") try: return check_messages_db_access() except Exception as e: logger.error(f"Error checking database access: {str(e)}") return f"Error checking database access: {str(e)}"
- Core implementation that checks Messages database accessibility: file existence, permissions, SQLite connection, table presence, and provides diagnostic information.def check_messages_db_access() -> str: """Check if the Messages database is accessible and return detailed information.""" try: db_path = get_messages_db_path() status = [] # Check if the file exists if not os.path.exists(db_path): return f"ERROR: Messages database not found at {db_path} PLEASE TELL THE USER TO GRANT FULL DISK ACCESS TO THE TERMINAL APPLICATION(CURSOR, TERMINAL, CLAUDE, ETC.) AND RESTART THE APPLICATION. DO NOT RETRY UNTIL NEXT MESSAGE." status.append(f"Database file exists at: {db_path}") # Check file permissions try: with open(db_path, 'rb') as f: # Just try to read a byte to confirm access f.read(1) status.append("File is readable") except PermissionError: return f"ERROR: Permission denied when trying to read {db_path}. Please grant Full Disk Access permission to your terminal application. PLEASE TELL THE USER TO GRANT FULL DISK ACCESS TO THE TERMINAL APPLICATION(CURSOR, TERMINAL, CLAUDE, ETC.) AND RESTART THE APPLICATION. DO NOT RETRY UNTIL NEXT MESSAGE." except Exception as e: return f"ERROR: Unknown error reading file: {str(e)} PLEASE TELL THE USER TO GRANT FULL DISK ACCESS TO THE TERMINAL APPLICATION(CURSOR, TERMINAL, CLAUDE, ETC.) AND RESTART THE APPLICATION. DO NOT RETRY UNTIL NEXT MESSAGE." # Try to connect to the database try: conn = sqlite3.connect(db_path) status.append("Successfully connected to database") # Test a simple query cursor = conn.cursor() cursor.execute("SELECT count(*) FROM sqlite_master") count = cursor.fetchone()[0] status.append(f"Database contains {count} tables") # Check if the necessary tables exist cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name IN ('message', 'handle', 'chat')") tables = [row[0] for row in cursor.fetchall()] if 'message' in tables and 'handle' in tables: status.append("Required tables (message, handle) are present") else: status.append(f"WARNING: Some required tables are missing. Found: {', '.join(tables)}") conn.close() except sqlite3.OperationalError as e: return f"ERROR: Database connection error: {str(e)} PLEASE TELL THE USER TO GRANT FULL DISK ACCESS TO THE TERMINAL APPLICATION(CURSOR, TERMINAL, CLAUDE, ETC.) AND RESTART THE APPLICATION. DO NOT RETRY UNTIL NEXT MESSAGE." return "\n".join(status) except Exception as e: return f"ERROR: Unexpected error during database access check: {str(e)} PLEASE TELL THE USER TO GRANT FULL DISK ACCESS TO THE TERMINAL APPLICATION(CURSOR, TERMINAL, CLAUDE, ETC.) AND RESTART THE APPLICATION. DO NOT RETRY UNTIL NEXT MESSAGE."