#!/usr/bin/env python3 """ Interactive Monarch Money login with MFA support. Saves session securely and provides the token for Docker environment. """ import asyncio import os import getpass import sys from pathlib import Path # Add src to sys.path sys.path.insert(0, str(Path(__file__).parent / "src")) from monarchmoney import MonarchMoney, RequireMFAException from dotenv import load_dotenv from monarch_mcp_custom.auth import save_token async def main(): load_dotenv() print("\nšŸ¦ Monarch Money - Custom MCP Setup") print("=" * 45) print("This script will help you obtain an authentication token") print("for use in your Docker .env file.\n") mm = MonarchMoney() try: email = input("Email: ") password = getpass.getpass("Password: ") try: await mm.login(email, password, use_saved_session=False, save_session=True) print("āœ… Login successful!") except RequireMFAException: print("šŸ” MFA code required") mfa_code = input("Two Factor Code: ") await mm.multi_factor_authenticate(email, password, mfa_code) print("āœ… MFA authentication successful") token = mm.token if token: print("\n" + "!" * 50) print("šŸ”‘ YOUR MONARCH_TOKEN:") print(f"\n{token}\n") print("!" * 50) print("\nCopy the token above into your .env file as:") print(f"MONARCH_TOKEN={token}") # Also save to local keyring for convenience save_token(token) print("\nāœ… Token also saved to local system keyring.") else: print("āŒ Failed to retrieve token from MonarchMoney instance.") except Exception as e: print(f"\nāŒ Setup failed: {e}") if __name__ == "__main__": asyncio.run(main())