@hakimelek/monarchmoney 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/cjs/client.js +923 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/endpoints.js +11 -0
- package/dist/cjs/endpoints.js.map +1 -0
- package/dist/cjs/errors.js +78 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/queries.js +466 -0
- package/dist/cjs/queries.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/client.d.ts +87 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +151 -9
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +420 -0
- package/dist/mcp.js.map +1 -0
- package/package.json +18 -7
package/README.md
CHANGED
|
@@ -117,6 +117,8 @@ All methods return **typed responses**. Hover over any method in your editor for
|
|
|
117
117
|
| `getSubscriptionDetails()` | `GetSubscriptionDetailsResponse` | Plan status (trial, premium, etc.) |
|
|
118
118
|
| `getTransactionsSummary()` | `GetTransactionsSummaryResponse` | Aggregate summary |
|
|
119
119
|
| `getTransactions(options?)` | `GetTransactionsResponse` | Transactions with full filtering |
|
|
120
|
+
| `getAllTransactions(options?)` | `Transaction[]` | All matching transactions (auto-paginates) |
|
|
121
|
+
| `getTransactionPages(options?)` | `AsyncGenerator<Transaction[]>` | Async generator yielding pages |
|
|
120
122
|
| `getTransactionCategories()` | `GetTransactionCategoriesResponse` | All categories |
|
|
121
123
|
| `getTransactionCategoryGroups()` | `GetTransactionCategoryGroupsResponse` | Category groups |
|
|
122
124
|
| `getTransactionDetails(id)` | typed response | Single transaction detail |
|
|
@@ -194,17 +196,102 @@ const mm = new MonarchMoney({
|
|
|
194
196
|
sessionFile: ".mm/mm_session.json", // session file path
|
|
195
197
|
timeout: 10, // API timeout in seconds
|
|
196
198
|
token: "pre-existing-token", // skip login
|
|
199
|
+
retry: {
|
|
200
|
+
maxRetries: 3, // retry on 429/5xx (default: 3, set 0 to disable)
|
|
201
|
+
baseDelayMs: 500, // base delay with exponential backoff + jitter
|
|
202
|
+
},
|
|
203
|
+
rateLimit: {
|
|
204
|
+
requestsPerSecond: 10, // token-bucket throttle (default: 0 = unlimited)
|
|
205
|
+
},
|
|
197
206
|
});
|
|
198
207
|
|
|
199
208
|
mm.setTimeout(30); // change timeout later
|
|
200
209
|
```
|
|
201
210
|
|
|
211
|
+
Retry automatically handles transient failures (429 Too Many Requests, 500, 502, 503, 504) with exponential backoff and jitter. The `Retry-After` header is respected on 429 responses.
|
|
212
|
+
|
|
213
|
+
## Auto-Pagination
|
|
214
|
+
|
|
215
|
+
`getTransactions()` returns a single page. For large datasets, use the auto-pagination helpers:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
// Async generator — yields one page at a time (memory-efficient)
|
|
219
|
+
for await (const page of mm.getTransactionPages({ startDate: "2025-01-01", endDate: "2025-12-31" })) {
|
|
220
|
+
for (const tx of page) {
|
|
221
|
+
console.log(tx.merchant?.name, tx.amount);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Or collect everything into a flat array
|
|
226
|
+
const all = await mm.getAllTransactions({
|
|
227
|
+
startDate: "2025-01-01",
|
|
228
|
+
endDate: "2025-12-31",
|
|
229
|
+
pageSize: 100, // transactions per page (default: 100)
|
|
230
|
+
});
|
|
231
|
+
console.log(`${all.length} total transactions`);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Both methods accept the same filter options as `getTransactions()` (date range, category, account, tags, etc.).
|
|
235
|
+
|
|
236
|
+
## Refresh Progress
|
|
237
|
+
|
|
238
|
+
Track account refresh progress with the `onProgress` callback:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
await mm.requestAccountsRefreshAndWait({
|
|
242
|
+
timeout: 300,
|
|
243
|
+
delay: 10,
|
|
244
|
+
onProgress: ({ completed, total, elapsedMs }) => {
|
|
245
|
+
console.log(`${completed}/${total} accounts refreshed (${(elapsedMs / 1000).toFixed(0)}s)`);
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## MCP Server (AI Agent Integration)
|
|
251
|
+
|
|
252
|
+
This package includes a built-in [Model Context Protocol](https://modelcontextprotocol.io) server with **30 tools**, making your Monarch Money data accessible to AI assistants like Claude Desktop, Cursor, and any MCP-compatible client.
|
|
253
|
+
|
|
254
|
+
### Setup
|
|
255
|
+
|
|
256
|
+
1. Get your Monarch Money auth token by logging in with the library (see [Authentication](#authentication)) and saving `mm.token`.
|
|
257
|
+
|
|
258
|
+
2. Add to your MCP client config (e.g. Claude Desktop `claude_desktop_config.json`):
|
|
259
|
+
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"mcpServers": {
|
|
263
|
+
"monarch-money": {
|
|
264
|
+
"command": "npx",
|
|
265
|
+
"args": ["@hakimelek/monarchmoney"],
|
|
266
|
+
"env": {
|
|
267
|
+
"MONARCH_TOKEN": "your-token-here"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Or run it directly:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
MONARCH_TOKEN=your-token npx @hakimelek/monarchmoney
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Available Tools
|
|
281
|
+
|
|
282
|
+
**Read (18 tools):** `get_accounts`, `get_account_holdings`, `get_account_history`, `get_account_type_options`, `get_recent_account_balances`, `get_aggregate_snapshots`, `get_institutions`, `get_budgets`, `get_subscription_details`, `get_transactions`, `get_transactions_summary`, `get_transaction_details`, `get_transaction_categories`, `get_transaction_category_groups`, `get_transaction_tags`, `get_cashflow`, `get_cashflow_summary`, `get_recurring_transactions`
|
|
283
|
+
|
|
284
|
+
**Write (12 tools):** `create_transaction`, `update_transaction`, `delete_transaction`, `create_manual_account`, `update_account`, `delete_account`, `refresh_accounts`, `is_refresh_complete`, `set_budget_amount`, `create_transaction_tag`, `set_transaction_tags`, `create_transaction_category`
|
|
285
|
+
|
|
286
|
+
Every tool has typed parameters with descriptions, so AI agents know exactly what arguments to pass.
|
|
287
|
+
|
|
202
288
|
## Project Structure
|
|
203
289
|
|
|
204
290
|
```
|
|
205
291
|
src/
|
|
206
292
|
index.ts — public exports
|
|
207
293
|
client.ts — MonarchMoney class with all API methods
|
|
294
|
+
mcp.ts — MCP server (30 tools for AI agents)
|
|
208
295
|
errors.ts — error classes (MonarchMoneyError hierarchy)
|
|
209
296
|
endpoints.ts — API URL constants
|
|
210
297
|
queries.ts — all GraphQL query/mutation strings
|
|
@@ -245,6 +332,47 @@ Set a password on your Monarch account at [Settings > Security](https://app.mona
|
|
|
245
332
|
|
|
246
333
|
Monarch requires email verification for new/unrecognized devices. After login, save the session token with `mm.saveSession()` or store `mm.token` — subsequent runs will reuse it without re-authenticating.
|
|
247
334
|
|
|
335
|
+
## How This Library Compares
|
|
336
|
+
|
|
337
|
+
There are several unofficial Monarch Money integrations. Here's how `@hakimelek/monarchmoney` stacks up.
|
|
338
|
+
|
|
339
|
+
### Landscape
|
|
340
|
+
|
|
341
|
+
| | **@hakimelek/monarchmoney** | **monarch-money-api** (pbassham) | **monarchmoney** (keithah) | **monarchmoney** (hammem) |
|
|
342
|
+
|---|---|---|---|---|
|
|
343
|
+
| **Platform** | Node.js / TypeScript | Node.js / JavaScript | Node.js / TypeScript | Python |
|
|
344
|
+
| **npm weekly downloads** | — | ~440 | ~130 | N/A (pip: ~103K/mo) |
|
|
345
|
+
| **Runtime deps** | **1** (speakeasy) | 5 | 7 | 3 |
|
|
346
|
+
| **TypeScript types** | Full (every response) | None | Yes | N/A |
|
|
347
|
+
| **Email OTP flow** | Yes | No | No | No |
|
|
348
|
+
| **MFA / TOTP** | Yes | Yes | Yes | Yes |
|
|
349
|
+
| **Session persistence** | Yes (0o600 perms) | Yes | Yes (AES-256) | Yes |
|
|
350
|
+
| **Interactive CLI login** | Yes | Yes | Yes | Yes |
|
|
351
|
+
| **HTTP client** | Native `fetch` | node-fetch | node-fetch + graphql-request | aiohttp |
|
|
352
|
+
| **Error hierarchy** | 4 typed exceptions | Generic throws | Generic throws | 1 exception |
|
|
353
|
+
| **Read methods** | 20 | 15 | ~20 | ~16 |
|
|
354
|
+
| **Write methods** | 14 | 9 | ~12 | ~10 |
|
|
355
|
+
| **Rate limiting** | Yes | No | Yes | No |
|
|
356
|
+
| **Retry with backoff** | Yes | No | Yes | No |
|
|
357
|
+
| **Auto-pagination** | Yes | No | No | No |
|
|
358
|
+
| **Dual CJS + ESM** | Yes | No | Yes | No |
|
|
359
|
+
| **Refresh progress events** | Yes | No | No | No |
|
|
360
|
+
| **Built-in MCP server** | Yes (30 tools) | No | No | No |
|
|
361
|
+
|
|
362
|
+
### Where this library wins
|
|
363
|
+
|
|
364
|
+
**Minimal footprint.** One runtime dependency vs 5-7 in the JS/TS alternatives. Native `fetch` means zero HTTP polyfills on Node 18+.
|
|
365
|
+
|
|
366
|
+
**Email OTP support.** Monarch now requires email verification for unrecognized devices, even when MFA is off. This is the only Node.js library that handles the full `EmailOtpRequiredException` → `submitEmailOtp()` flow. Without it, automated scripts break on first login from a new environment.
|
|
367
|
+
|
|
368
|
+
**Typed everything.** Every API response has a dedicated TypeScript interface — 50+ exported types covering accounts, transactions, holdings, cashflow, budgets, recurring items, and mutations. The `monarch-money-api` package has no types at all.
|
|
369
|
+
|
|
370
|
+
**Structured error handling.** Four distinct exception classes (`LoginFailedException`, `RequireMFAException`, `EmailOtpRequiredException`, `RequestFailedException`) with error codes and status codes. Competitors throw generic errors or strings.
|
|
371
|
+
|
|
372
|
+
**Broader write coverage.** Includes `updateTransaction()`, `setBudgetAmount()`, `uploadAccountBalanceHistory()`, `getCashflow()`, `getCashflowSummary()`, and `getRecurringTransactions()` — all missing from `monarch-money-api`.
|
|
373
|
+
|
|
374
|
+
**Clean, flat API.** One class, direct methods, no sub-objects or verbosity levels to learn. Import `MonarchMoney`, call methods, get typed results.
|
|
375
|
+
|
|
248
376
|
## Contributing
|
|
249
377
|
|
|
250
378
|
Contributions welcome. Please ensure TypeScript compiles cleanly (`npm run build`) and tests pass (`npm test`).
|