feat: add automatic re-authentication with MFA support
All checks were successful
Build and Push Monarch MCP Docker Image / build (push) Successful in 8s

Implement automatic token refresh using stored credentials and TOTP MFA secret. When an API call fails with a 401/unauthorized error, the system now transparently re-authenticates using MONARCH_EMAIL, MONARCH_PASSWORD, and MONARCH_MFA_SECRET, then retries the original request.

Changes:
- Add refresh_authentication() function in auth.py for credential-based login
- Create @retry_on_auth_error decorator to handle and retry failed auth calls
- Apply decorator to all MCP tools (get_accounts, get_transactions, etc.)
- Add MONARCH_MFA_SECRET to .env.example with documentation
- Update login_setup.py to instruct users about required env vars
- Replace PROBLEM.md with PLAN.md documenting the implementation
This commit is contained in:
Ben
2025-12-24 15:45:43 +00:00
parent 27ef7f0e1e
commit 6fc09d956f
6 changed files with 153 additions and 65 deletions

View File

@@ -2,10 +2,15 @@
# You can use MONARCH_TOKEN (recommended) OR Email/Password
MONARCH_TOKEN=
# Fallback credentials
# Credentials for automatic re-authentication (required for token refresh)
MONARCH_EMAIL=
MONARCH_PASSWORD=
# MFA Secret for TOTP-based re-authentication
# This is the secret you saved when you first set up 2FA for Monarch Money
# Required if you have MFA enabled on your Monarch account
MONARCH_MFA_SECRET=
# Server Configuration
PORT=8000
MONARCH_PORT=8070