SuperAPI AI Directory

hledger-mcp

Read and optionally write local hledger journals for double-entry plain text accounting.

Open website

About this tool

Purpose

hledger-mcp is a local MCP server that provides AI assistants (MCP clients) with direct access to HLedger accounting data and functionality. HLedger is a plain-text double-entry accounting tool, and this server lets AI applications query account balances, generate financial reports, add new entries, and analyze accounting data through a standardized protocol.

Main Capabilities

The server provides the following tool categories:

Core Accounting

  • Accounts: List and query account names and structure
  • Balance: Generate balance reports with extensive customization options
  • Register: View transaction registers and posting details
  • Print: Output journal entries and transactions

Financial Statements

  • Balance Sheet: Generate a balance sheet
  • Balance Sheet Equity: Balance sheet with equity details
  • Income Statement: Profit and loss statement
  • Cash Flow: Cash flow analysis and reporting
  • Stats: Statistical analysis of journal data
  • Activity: Account activity and transaction frequency analysis
  • Payees: List and analyze transaction payees
  • Descriptions: Transaction description analysis
  • Tags: Query and analyze transaction tags
  • Notes: List unique transaction notes and memo fields
  • Files: List the data files used by hledger

Resource Integration Automatically registers the main journal as well as every file reported by hledger files as MCP resources, so clients can browse and retrieve the source ledgers.

Journal Updates (Write Tools)

  • Add Transaction: Append a validated new journal entry, with dry-run support
  • Find Entry: Locate the complete transaction matching any hledger query (including file and line metadata)
  • Remove Entry: Safely delete a transaction via exact text and location, with dry-run support
  • Replace Entry: Replace an existing transaction with new content after validation
  • Import Transactions: Safely bulk-import entries from an external journal file or other supported formats
  • Close Books: Generate closing/opening, retained earnings, or assertion transactions and safely append them
  • Rewrite Transactions: Use hledger's rewrite command to add synthetic postings to matching entries

Web UI

  • Start Web: Start hledger web in the specified mode without blocking the MCP server (requires the optional hledger-web executable)
  • List/Stop Web Instances: Enumerate all web servers started during the session, and gracefully terminate one or all of them

Read-only MCP sessions always run the web interface in view mode; write-enabled sessions default to add permission unless allow: "edit" is explicitly requested.

Usage

Prerequisites

  • HLedger must be installed and accessible in the system PATH (install from hledger.org, verify with hledger --version)
  • Node.js v18 or higher

Claude Desktop Configuration

Install via the .mcpb file: Get the .mcpb file from releases; this is the simplest installation method.

Install via NPM: Add the configuration to the Claude Desktop configuration file.

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json

Replace /path/to/your/master.journal with the actual HLedger journal file path. Using master.journal is recommended, because the tool supports any other files included via HLedger's existing include syntax.

Write behavior can be toggled via optional flags:

  • --read-only: Completely disables the add-transaction tool; all write attempts return an error
  • --skip-backup: Prevents the server from creating a .bak file before appending to an existing journal

Flags can appear before or after the journal path, and both default to false. It is recommended to first enable --read-only, until you are familiar with the tool.

Environment Variable Configuration

  • HLEDGER_READ_ONLY: set to true to force read-only mode
  • HLEDGER_SKIP_BACKUP: set to true to disable automatic .bak backups
  • HLEDGER_EXECUTABLE_PATH: (optional) absolute path to a specific hledger binary; overrides auto-detection if it is not in PATH
  • HLEDGER_WEB_EXECUTABLE_PATH: (optional) absolute path to a standalone hledger web binary

CLI arguments take precedence over environment variables.

Other MCP Clients The server communicates over stdio and expects the journal file path as the first argument.

Write Tool Notes

  • hledger_add_transaction: accepts structured postings, validates with hledger check, then appends a new transaction. Enable dryRun to preview without writing
  • hledger_remove_entry: removes a transaction by exact text and position, re-validates with hledger check, and honors optional backups
  • hledger_replace_entry: replaces an existing entry with new content, keeps spacing tidy, and performs validation before committing
  • hledger_import: wraps hledger import, running the command against a temporary copy of the journal. Provide one or more dataFiles (journal, csv, etc.) and an optional rulesFile; set dryRun to inspect the diff before committing. A successful import creates a timestamped .bak file unless --skip-backup is in effect
  • hledger_rewrite: runs hledger rewrite on a temporary copy, and you can specify one or more addPostings directives for matching transactions. Use dryRun to preview the diff only, or diff: true to include patch output while applying the changes
  • hledger_close: generates closing/opening assertions, retained earnings, or clopen transactions via hledger close. Use dryRun to preview the generated entries, then atomically append once satisfied (optional backup)

All write tools include a dryRun parameter so you can try them out before writing.

Web Tool Notes

  • hledger_web: starts the hledger web UI/API on an idle port unless a port/socket is specified. The response includes an instanceId that can be used to track or terminate the server later
  • hledger_web_list: returns metadata for each active web instance started by this MCP session (PID, command, base URL, access mode, etc.)
  • hledger_web_stop: stops a selected instance by instanceId, pid, or port, or stops all with all=true. You can optionally specify a shutdown signal (default SIGTERM) and timeout

Example Queries Once configured, you can ask Claude natural-language questions about your financial data:

  • "What's my current account balance?"
  • "Show me a balance sheet for last quarter"
  • "What were my expenses in the food category last month?"
  • "Generate an income statement for 2024"
  • "Who are my top payees by transaction volume?"
  • "Show me cash flow for the past 6 months"

Tool Parameters Most tools support common HLedger options:

  • Date ranges: --begin, --end, --period
  • Output formats: txt, csv, json, html
  • Account filtering: pattern matching and regular expression support
  • Calculation modes: historical, cumulative, change analysis
  • Display options: flat vs tree view, sorting, percentages

Use Cases

Suitable for users doing plain-text double-entry bookkeeping with HLedger who want to query account balances, generate financial reports, analyze transaction data, or safely add, modify, and import journal entries through an AI assistant in natural language. Also suitable for scenarios that need to integrate accounting data into MCP-compatible AI applications.

Limitations

  • Requires HLedger to be installed in advance and available in PATHAccess
  • Requires Node.js v18 or later
  • Web UI functionality requires the optional hledger-web executable; not all hledger installations include this binary
  • Write operations create a .bak backup file by default, unless --skip-backup is used
  • It is recommended to enable --read-only mode on first use

Troubleshooting

  • "hledger CLI is not installed": Ensure HLedger is installed and in PATH. The CLI path will attempt to automatically locate it in common locations; if that does not work, set the HLEDGER_EXECUTABLE_PATH environment variable
  • "hledger web command is failing": Not all hledger instances include the hledger-web binary, and some installation methods (such as .mcpb) make it difficult to find. It is recommended to first install it or locate the current installation path, then set the environment variable
  • "Journal file path is required": The server requires the journal file path as an argument; check the configuration to ensure it is included and valid
  • Claude Desktop connection issues: Verify that the journal file path is correct and accessible; check that the configuration file syntax is valid JSON; restart Claude Desktop after configuration changes

License

MIT License (see LICENSE). See CONTRIBUTING.md for setup instructions, coding standards, and tips for testing and debugging changes locally.