Skip to content

TypeScript/JavaScript SDK for MonarchMoney's GraphQL API with comprehensive authentication, caching, and rate limiting

License

Notifications You must be signed in to change notification settings

keithah/monarchmoney-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MonarchMoney TypeScript SDK

npm version License: MIT Build Status Coverage

A comprehensive, production-ready TypeScript/JavaScript SDK for the MonarchMoney API with advanced context optimization for AI/MCP integrations.

πŸš€ Key Features

🎯 Context-Optimized for AI Assistants

  • 99% Response Size Reduction with intelligent verbosity levels
  • Emoji-Rich Formatting for Claude Desktop and other AI assistants
  • Smart Query Selection for optimal GraphQL usage
  • Zero Context Overflow - maintain unlimited conversation length

πŸ”§ Complete API Coverage

  • 70+ Dynamic Methods across accounts, transactions, budgets, categories
  • Full TypeScript Support with comprehensive type definitions
  • Production-Ready Authentication with MFA/TOTP support
  • Advanced Session Management with AES-256 encryption

⚑ Performance & Reliability

  • Multi-Level Caching (memory + persistent)
  • Smart Rate Limiting respects API boundaries
  • Comprehensive Error Handling with retry logic
  • Dual Package Support (CommonJS + ESM)

πŸ“¦ Installation

npm install monarchmoney

πŸƒ Quick Start

Standard Usage

import { MonarchClient } from 'monarchmoney'

const client = new MonarchClient({
  baseURL: 'https://api.monarchmoney.com',
  timeout: 30000
})

// Login with credentials and MFA
await client.login({
  email: '[email protected]',
  password: 'your-password',
  mfaSecretKey: 'your-mfa-secret' // Optional TOTP secret
})

// Get accounts with different verbosity levels
const accounts = await client.accounts.getAll({ verbosity: 'light' })
const transactions = await client.transactions.getTransactions({
  limit: 10,
  verbosity: 'ultra-light'
})

AI Assistant Integration

import { MonarchClient, ResponseFormatter } from 'monarchmoney'

const client = new MonarchClient(/* config */)
await client.login(/* credentials */)

// Get ultra-compact responses perfect for AI context
const accounts = await client.accounts.getAll({ verbosity: 'ultra-light' })
// Returns: "πŸ’° 12 accounts, Total: $145,678"

// Or format existing data for AI consumption
const formatted = ResponseFormatter.formatAccounts(rawAccounts, 'ultra-light')
const quickStats = ResponseFormatter.formatQuickStats(accounts, recentTransactions)
// Returns: "πŸ’° $52,345 β€’ ⬇️ -$3,200 β€’ πŸ“Š 14 accounts"

🎯 Context Optimization Features

Verbosity Levels

Control response detail to optimize AI context usage:

Level Use Case Characters/Item Example
ultra-light Quick overviews ~60 chars πŸ’° 5 accounts, Total: $23,456
light Moderate detail ~180 chars Account names + balances + institutions
standard Full analysis ~800 chars Complete account details + metadata

Smart Query Selection

import { getQueryForVerbosity } from 'monarchmoney'

// Automatically select optimal GraphQL query
const query = getQueryForVerbosity('accounts', 'ultra-light')
// Returns optimized query with minimal fields

Response Formatters

import { ResponseFormatter } from 'monarchmoney'

// Ultra-compact account summary
const summary = ResponseFormatter.formatAccounts(accounts, 'ultra-light')
// "πŸ’° 12 accounts, Total: $145,678"

// Quick financial overview
const overview = ResponseFormatter.formatQuickStats(accounts, transactions)
// "πŸ’° $52,345 β€’ ⬇️ -$3,200 β€’ πŸ“Š 14 accounts"

// Spending by category
const spending = ResponseFormatter.formatSpendingSummary(transactions, 5)
// "🍽️ $450 β€’ β›½ $280 β€’ πŸ›’ $380 (top 3 this month)"

πŸ“š API Documentation

Accounts API (15+ methods)

// Get accounts with verbosity control
const accounts = await client.accounts.getAll({
  includeHidden: false,
  verbosity: 'light'
})

// Get specific account details
const account = await client.accounts.getById('account-id')

// Get balance history
const history = await client.accounts.getBalanceHistory('account-id')

Transactions API (25+ methods)

// Get transactions with smart filtering
const transactions = await client.transactions.getTransactions({
  limit: 50,
  startDate: '2024-01-01',
  endDate: '2024-01-31',
  verbosity: 'ultra-light'
})

// Smart search with natural language
const amazonCharges = await client.transactions.smartQuery({
  query: "last 5 Amazon charges over $50"
})

Budgets API (12+ methods)

// Get budget data
const budgets = await client.budgets.getBudgets({
  startDate: '2024-01-01',
  endDate: '2024-01-31'
})

// Get budget performance
const performance = await client.budgets.getBudgetSummary()

Categories & Insights APIs

// Get all categories
const categories = await client.categories.getCategories()

// Get financial insights
const insights = await client.insights.getNetWorthHistory()

// Get cashflow analysis
const cashflow = await client.cashflow.getCashflowSummary()

βš™οΈ Configuration

Client Configuration

const client = new MonarchClient({
  baseURL: 'https://api.monarchmoney.com',
  timeout: 30000,
  retries: 3,
  retryDelay: 1000,
  rateLimit: {
    requestsPerSecond: 10,
    burstSize: 20
  },
  cache: {
    enabled: true,
    ttl: 300000, // 5 minutes
    maxSize: 1000
  }
})

Authentication Options

// Basic login
await client.login({
  email: '[email protected]',
  password: 'your-password'
})

// Login with MFA/TOTP
await client.login({
  email: '[email protected]',
  password: 'your-password',
  mfaSecretKey: 'YOUR_TOTP_SECRET_KEY'
})

// Interactive login (prompts for credentials)
await client.interactiveLogin()

🎨 MCP Integration Example

Perfect for Claude Desktop and other Model Context Protocol integrations:

// MCP Tool Implementation
async function getAccountsSummary(verbosity = 'ultra-light') {
  const accounts = await client.accounts.getAll({ verbosity })

  // Returns context-optimized response:
  // "πŸ’° 12 accounts, Total: $145,678"
  return accounts
}

async function smartTransactionSearch(query: string) {
  const result = await client.transactions.smartQuery({ query })

  // Natural language to optimized GraphQL:
  // "last 3 Amazon charges" β†’ targeted GraphQL query
  return ResponseFormatter.formatTransactions(result.transactions, 'light', query)
}

πŸ§ͺ Testing & Coverage

Comprehensive test suite with 92%+ coverage on optimization features:

npm test              # Run all tests
npm run test:unit     # Run unit tests
npm run test:coverage # Run with coverage report
npm run test:integration # Integration tests (requires credentials)

Test Coverage:

  • ResponseFormatter: 98% statement, 83% branch coverage
  • Operations: 83% statement, 100% function coverage
  • 37 comprehensive tests covering all optimization features

πŸ“Š Performance Metrics

Response Size Optimization

  • Ultra-light: 99% reduction vs standard
  • Light: 85% reduction vs standard
  • Standard: Full API response

AI Context Benefits

  • Unlimited conversations - no context overflow
  • Sub-100ms formatting even with 1000+ accounts
  • Professional emoji formatting for Claude Desktop
  • Smart GraphQL selection minimizes API payload

πŸš€ CI/CD Pipeline

Automated testing across Node.js versions with:

  • Unit Tests: 37 tests covering optimization features
  • Performance Tests: Response time and size validation
  • Security Audits: Dependency vulnerability scanning
  • Integration Tests: Real API validation (when credentials provided)
  • Coverage Enforcement: 90%+ coverage requirements

πŸ› οΈ Development

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Run linting
npm run lint

# Run type checking
npm run type-check

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ˆ Project Stats

  • 70+ API Methods - Complete MonarchMoney coverage
  • 99% Context Reduction - Ultra-compact AI responses
  • 3 Verbosity Levels - Flexible detail control
  • 92%+ Test Coverage - Production-ready reliability
  • Zero Dependencies - Minimal attack surface
  • Claude Desktop Ready - Perfect MCP integration

Transform your financial data into AI-friendly insights πŸ’°πŸ€–

Perfect for Claude Desktop, MCP servers, and other AI assistant integrations requiring optimized context usage.# CI Test

About

TypeScript/JavaScript SDK for MonarchMoney's GraphQL API with comprehensive authentication, caching, and rate limiting

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •