get_accounts
Retrieve all financial accounts from Monarch Money using the MCP server for integration or analysis purposes.
Instructions
Get all financial accounts from Monarch Money.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/monarch_mcp_server/server.py:154-183 (handler)The MCP tool handler for 'get_accounts'. Fetches accounts asynchronously from the MonarchMoney client, formats the data into a structured JSON list including id, name, type, balance, institution, and active status, and handles errors.@mcp.tool() def get_accounts() -> str: """Get all financial accounts from Monarch Money.""" try: async def _get_accounts(): client = await get_monarch_client() return await client.get_accounts() accounts = run_async(_get_accounts()) # Format accounts for display account_list = [] for account in accounts.get("accounts", []): account_info = { "id": account.get("id"), "name": account.get("displayName") or account.get("name"), "type": (account.get("type") or {}).get("name"), "balance": account.get("currentBalance"), "institution": (account.get("institution") or {}).get("name"), "is_active": account.get("isActive") if "isActive" in account else not account.get("deactivatedAt"), } account_list.append(account_info) return json.dumps(account_list, indent=2, default=str) except Exception as e: logger.error(f"Failed to get accounts: {e}") return f"Error getting accounts: {str(e)}"
- Helper function that provides the authenticated MonarchMoney client instance used by get_accounts, handling secure session retrieval or login with environment credentials.async def get_monarch_client() -> MonarchMoney: """Get or create MonarchMoney client instance using secure session storage.""" # Try to get authenticated client from secure session client = secure_session.get_authenticated_client() if client is not None: logger.info("✅ Using authenticated client from secure keyring storage") return client # If no secure session, try environment credentials email = os.getenv("MONARCH_EMAIL") password = os.getenv("MONARCH_PASSWORD") if email and password: try: client = MonarchMoney() await client.login(email, password) logger.info( "Successfully logged into Monarch Money with environment credentials" ) # Save the session securely secure_session.save_authenticated_session(client) return client except Exception as e: logger.error(f"Failed to login to Monarch Money: {e}") raise raise RuntimeError("🔐 Authentication needed! Run: python login_setup.py")
- Utility helper to execute async coroutines synchronously from the sync MCP tool context, used by get_accounts.def run_async(coro): """Run async function in a new thread with its own event loop.""" def _run(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) try: return loop.run_until_complete(coro) finally: loop.close() with ThreadPoolExecutor() as executor: future = executor.submit(_run) return future.result()
- src/monarch_mcp_server/server.py:154-154 (registration)The @mcp.tool() decorator registers the get_accounts function as an MCP tool.@mcp.tool()