fix: remove try-except blocks from MCP tools to allow auth-retry decorator to work
All checks were successful
Build and Push Monarch MCP Docker Image / build (push) Successful in 16s

This commit is contained in:
Ben
2025-12-24 21:48:34 +00:00
parent 1e8d484389
commit e462c31907

View File

@@ -41,7 +41,6 @@ def serialize_json(data: Any) -> str:
@retry_on_auth_error() @retry_on_auth_error()
async def get_accounts(reason: Optional[str] = None) -> str: async def get_accounts(reason: Optional[str] = None) -> str:
"""Get all financial accounts from Monarch Money.""" """Get all financial accounts from Monarch Money."""
try:
client = await get_authenticated_client() client = await get_authenticated_client()
accounts = await client.get_accounts() accounts = await client.get_accounts()
@@ -58,9 +57,6 @@ async def get_accounts(reason: Optional[str] = None) -> str:
account_list.append(account_info) account_list.append(account_info)
return serialize_json(account_list) return serialize_json(account_list)
except Exception as e:
logger.error(f"Failed to get accounts: {e}")
return f"Error: {str(e)}"
@mcp.tool() @mcp.tool()
@@ -76,7 +72,6 @@ async def get_transactions(
Get transactions from Monarch Money. Get transactions from Monarch Money.
Dates should be in YYYY-MM-DD format. Dates should be in YYYY-MM-DD format.
""" """
try:
client = await get_authenticated_client() client = await get_authenticated_client()
filters = {} filters = {}
if start_date: if start_date:
@@ -86,9 +81,7 @@ async def get_transactions(
if account_id: if account_id:
filters["account_id"] = account_id filters["account_id"] = account_id
transactions = await client.get_transactions( transactions = await client.get_transactions(limit=limit, offset=offset, **filters)
limit=limit, offset=offset, **filters
)
results = transactions.get("allTransactions", {}).get("results", []) results = transactions.get("allTransactions", {}).get("results", [])
formatted = [] formatted = []
@@ -107,16 +100,12 @@ async def get_transactions(
) )
return serialize_json(formatted) return serialize_json(formatted)
except Exception as e:
logger.error(f"Failed to get transactions: {e}")
return f"Error: {str(e)}"
@mcp.tool() @mcp.tool()
@retry_on_auth_error() @retry_on_auth_error()
async def get_budgets(reason: Optional[str] = None) -> str: async def get_budgets(reason: Optional[str] = None) -> str:
"""Get current budget information.""" """Get current budget information."""
try:
client = await get_authenticated_client() client = await get_authenticated_client()
budgets = await client.get_budgets() budgets = await client.get_budgets()
@@ -133,37 +122,26 @@ async def get_budgets(reason: Optional[str] = None) -> str:
) )
return serialize_json(budget_list) return serialize_json(budget_list)
except Exception as e:
logger.error(f"Failed to get budgets: {e}")
return f"Error: {str(e)}"
@mcp.tool() @mcp.tool()
@retry_on_auth_error() @retry_on_auth_error()
async def get_account_holdings(account_id: str, reason: Optional[str] = None) -> str: async def get_account_holdings(account_id: str, reason: Optional[str] = None) -> str:
"""Get investment holdings for a specific account.""" """Get investment holdings for a specific account."""
try:
client = await get_authenticated_client() client = await get_authenticated_client()
# The library expects an int for account_id # The library expects an int for account_id
holdings = await client.get_account_holdings(int(account_id)) holdings = await client.get_account_holdings(int(account_id))
return serialize_json(holdings) return serialize_json(holdings)
except Exception as e:
logger.error(f"Failed to get holdings: {e}")
return f"Error: {str(e)}"
@mcp.tool() @mcp.tool()
@retry_on_auth_error() @retry_on_auth_error()
async def refresh_accounts(reason: Optional[str] = None) -> str: async def refresh_accounts(reason: Optional[str] = None) -> str:
"""Request a refresh of account data from financial institutions.""" """Request a refresh of account data from financial institutions."""
try:
client = await get_authenticated_client() client = await get_authenticated_client()
# Request refresh for all accounts (empty list often means all in this library) # Request refresh for all accounts (empty list often means all in this library)
result = await client.request_accounts_refresh([]) result = await client.request_accounts_refresh([])
return serialize_json(result) return serialize_json(result)
except Exception as e:
logger.error(f"Failed to refresh accounts: {e}")
return f"Error: {str(e)}"
# --- Health Check Endpoint --- # --- Health Check Endpoint ---