Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

fix(mcp): shape get_account_summary payload like the other tools (#953)

Dino Constantinoue3570c05b19d
diff --git a/backend/mcp_server/tools/accounts.py b/backend/mcp_server/tools/accounts.py
index 61ea3eda..60475b95 100644
--- a/backend/mcp_server/tools/accounts.py
+++ b/backend/mcp_server/tools/accounts.py
@@ -89,9 +89,12 @@ async def get_account_summary(
)
if summary is None:
return {"error": "account not found"}
- # Normalize numeric fields.
- for k in list(summary.keys()):
- v = summary[k]
- if hasattr(v, "isoformat"):
- summary[k] = v.isoformat()
- return summary
+ return {
+ "account_id": str(summary["account_id"]),
+ "current_balance": num(summary.get("current_balance")),
+ "opening_balance": num(summary.get("opening_balance")),
+ "monthly_income": num(summary.get("monthly_income")),
+ "monthly_expenses": num(summary.get("monthly_expenses")),
+ "projected_income": num(summary.get("projected_income")),
+ "projected_expenses": num(summary.get("projected_expenses")),
+ }
diff --git a/backend/tests/test_agents_mcp_tools.py b/backend/tests/test_agents_mcp_tools.py
index 60b12858..1c6f4791 100644
--- a/backend/tests/test_agents_mcp_tools.py
+++ b/backend/tests/test_agents_mcp_tools.py
@@ -285,9 +285,27 @@ async def test_list_accounts(session: AsyncSession, ctx: CallContext, test_accou
async def test_get_account_summary(session: AsyncSession, ctx: CallContext, test_account, test_transactions):
handler = REGISTRY["get_account_summary"].handler
result = await handler(session=session, ctx=ctx, account_id=str(test_account.id))
- # Real service returns a dict with income/expense/etc. We just verify it's not an error.
assert isinstance(result, dict)
assert "error" not in result or result.get("error") is None
+ assert set(result) == {
+ "account_id",
+ "current_balance",
+ "opening_balance",
+ "monthly_income",
+ "monthly_expenses",
+ "projected_income",
+ "projected_expenses",
+ }
+ income = float(sum(t.amount for t in test_transactions if t.type == "credit"))
+ expenses = float(sum(t.amount for t in test_transactions if t.type == "debit"))
+ current_balance = float(test_account.balance)
+ assert result["account_id"] == str(test_account.id)
+ assert result["current_balance"] == pytest.approx(current_balance)
+ assert result["opening_balance"] == pytest.approx(current_balance - (income - expenses))
+ assert result["monthly_income"] == pytest.approx(income)
+ assert result["monthly_expenses"] == pytest.approx(expenses)
+ assert result["projected_income"] == pytest.approx(income)
+ assert result["projected_expenses"] == pytest.approx(expenses)
async def test_get_account_summary_unknown_account(session: AsyncSession, ctx: CallContext):