fix: add graceful error handling for get_budgets API errors
All checks were successful
Build and Push Monarch MCP Docker Image / build (push) Successful in 16s

Returns informative error message when Monarch Money API fails,
which may occur if budgets are not configured in the account.
This commit is contained in:
Ben
2025-12-25 04:20:39 +00:00
parent 4a309cbfb3
commit a229537599
6 changed files with 87 additions and 4 deletions

View File

@@ -9,13 +9,14 @@ Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: mcp[cli]>=1.0.0
Requires-Dist: fastmcp>=0.4.1
Requires-Dist: monarchmoney>=0.1.15
Requires-Dist: gql<4.0,>=3.4
Requires-Dist: keyring>=24.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: starlette>=0.35.0
Requires-Dist: uvicorn>=0.27.0
Requires-Dist: pyotp>=2.9.0
# Monarch Money Custom MCP Server
@@ -49,7 +50,7 @@ docker-compose up -d
## 🔌 Connection
The server will be available at:
- **SSE Endpoint**: `http://localhost:8000/mcp/sse`
- **MCP Endpoint**: `http://localhost:8000/mcp`
- **Health Check**: `http://localhost:8000/health`
## 🛠️ Tools Included

View File

@@ -1,8 +1,9 @@
mcp[cli]>=1.0.0
fastmcp>=0.4.1
monarchmoney>=0.1.15
gql<4.0,>=3.4
keyring>=24.0.0
python-dotenv>=1.0.0
pydantic>=2.0.0
starlette>=0.35.0
uvicorn>=0.27.0
pyotp>=2.9.0

View File

@@ -110,7 +110,21 @@ async def get_transactions(
async def get_budgets(reason: Optional[str] = None) -> str:
"""Get current budget information."""
client = await get_authenticated_client()
budgets = await client.get_budgets()
try:
budgets = await client.get_budgets()
except Exception as e:
error_msg = str(e)
# Check if this is a Monarch API error about budgets not being set up
if "Something went wrong" in error_msg:
return serialize_json(
{
"error": "Budget data unavailable",
"detail": "The Monarch Money API returned an error. This may occur if budgets are not configured in your account.",
"raw_error": error_msg,
}
)
raise
# Build a category lookup from categoryGroups
category_lookup = {}