A Model Context Protocol (MCP) server that provides AI assistants (MCP Clients) with direct access to HLedger accounting data and functionality. This server enables AI applications to query account balances, generate financial reports, add new entires, and analyze accounting data through a standardized protocol. It has support for most hledger cli commands, the ability to fetch an traverse !includ
Add this skill
npx mdskills install iiAtlas/hledger-mcpComprehensive financial reporting MCP with extensive HLedger integration, write controls, and web UI support
1# HLedger MCP Server2345A Model Context Protocol (MCP) server that provides AI assistants (MCP Clients) with direct access to [HLedger](https://hledger.org/) accounting data and functionality. This server enables AI applications to query account balances, generate financial reports, add new entires, and analyze accounting data through a standardized protocol.67It has support for most `hledger` cli commands, the ability to fetch an traverse `!include`'d journal files, and a safe `--read-only` mode. I hope you find it useful!89Published on npm as [@iiatlas/hledger-mcp](https://www.npmjs.com/package/@iiatlas/hledger-mcp), and available as an installable `.mcpb` file from [releases](https://github.com/iiAtlas/hledger-mcp/releases).1011   121314## Features1516The HLedger MCP server provides comprehensive access to HLedger's financial reporting capabilities through the following tools:1718### Core Accounting1920- **Accounts** - List and query account names and structures21- **Balance** - Generate balance reports with extensive customization options22- **Register** - View transaction registers and posting details23- **Print** - Output journal entries and transactions2425### Financial Reports2627- **Balance Sheet** - Generate balance sheet reports28- **Balance Sheet Equity** - Balance sheet reports with equity details29- **Income Statement** - Profit & loss statements30- **Cash Flow** - Cash flow analysis and reports3132### Data Analysis3334- **Stats** - Statistical analysis of journal data35- **Activity** - Account activity and transaction frequency analysis36- **Payees** - List and analyze transaction payees37- **Descriptions** - Transaction description analysis38- **Tags** - Query and analyze transaction tags39- **Notes** - List unique transaction notes and memo fields40- **Files** - List data files used by hledger4142### Resource Integration4344- Automatically registers the primary journal and every file reported by `hledger files` as MCP resources so clients can browse and retrieve the source ledgers4546### Journal Updates4748- **Add Transaction** - Append new, validated journal entries with optional dry-run support49- **Find Entry** - Locate complete transactions (with file and line metadata) matching any hledger query50- **Remove Entry** - Delete a transaction safely using its exact text and location, with optional dry-run51- **Replace Entry** - Swap an existing transaction for new content after validating the change52- **Import Transactions** - Safely ingest batches of entries from external journal files or other supported formats53- **Close Books** - Generate closing/opening, retain-earnings, or assertion transactions and append them safely54- **Rewrite Transactions** - Add synthesized postings to matching entries using hledger's rewrite command5556### Web Interface5758You can open up the hledger web UI directly within the MCP server!5960- **Start Web** - Launches `hledger web` in the requested mode without blocking the MCP server61 - _Requires the optional `hledger-web` executable_. If your `hledger` binary does not recognize the `web` command, install `hledger-web` (often a separate package) or point the MCP server at an executable built with web support.62 - Set `HLEDGER_WEB_EXECUTABLE_PATH` to force the MCP server to use a dedicated binary (such as `hledger-web`) for launching the web interface.63- **List/Stop Web Instances** - Enumerate all running web servers started during the session, gracefully terminate one or all6465Read-only MCP sessions always run the web interface in `view` mode, while write-enabled sessions default to `add` permissions unless `allow: "edit"` is requested explicitly.6667## Demo6869A general summary:70717273Querying and adding new entries:74757677Create artifacts from the journal data:787980## Prerequisites8182- **HLedger** must be installed and accessible in your system PATH83 - Install from [hledger.org](https://hledger.org/)84 - Verify installation: `hledger --version`85- **Node.js** v18 or higher8687## Usage8889### Claude Desktop Configuration9091### Installing the .mcpb file9293The easiest way to install the extension is through the `.mcpb` file provided on [releases](https://github.com/iiAtlas/hledger-mcp/releases). If you prefer npm, you can use the method below.9495### Installing via NPM9697Add the following to your Claude Desktop configuration file:9899**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`100101**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`102103```json104{105 "mcpServers": {106 "hledger": {107 "command": "npx",108 "args": ["-y", "@iiatlas/hledger-mcp", "/path/to/your/master.journal"]109 }110 }111}112```113114Replace `/path/to/your/master.journal` with the actual path to your HLedger journal file. If you have a `master.journal` I'd recommend that, as this tool has support for any other files brought in using HLedgers existing `!include` syntax. See [test/resources/master.journal](test/resources/master.journal) for an example journal.115116#### Configuration options117118You can toggle write behaviour with optional flags:119120- `--read-only` — disables the add-transaction tool entirely; all write attempts return an error.121- `--skip-backup` — prevents the server from creating `.bak` files before appending to an existing journal.122123Flags may appear before or after the journal path. Both options default to `false`. I recommend starting with `--read-only` enabled until you get more comfortable with the tool. Below is that sample config:124125```json126{127 "mcpServers": {128 "hledger": {129 "command": "npx",130 "args": [131 "-y",132 "@iiatlas/hledger-mcp",133 "/path/to/your/master.journal",134 "--read-only"135 ]136 }137 }138}139```140141#### Environment variables142143MCP clients that prefer configuration via environment variables can set:144145- `HLEDGER_READ_ONLY` — set to `true` to force read-only mode.146- `HLEDGER_SKIP_BACKUP` — set to `true` to disable automatic `.bak` backups.147- `HLEDGER_EXECUTABLE_PATH` — (Optional) absolute path to a specific `hledger` binary if it isn't on PATH; overrides auto-detection.148- `HLEDGER_WEB_EXECUTABLE_PATH` — (Optional) absolute path to a standalone `hledger web` binary (for example `hledger-web`). When set, the MCP uses this executable instead of running `hledger web` via the primary binary.149150The read/write toggles mirror the CLI flags above—CLI arguments take precedence if both are provided.151152You can also use environment variables in place of `args` in the json config. Here is an example:153154```json155{156 "mcpServers": {157 "hledger": {158 "command": "npx",159 "args": ["-y", "@iiatlas/hledger-mcp", "/path/to/your/master.journal"],160 "env": {161 "HLEDGER_READ_ONLY": "true",162 "HLEDGER_EXECUTABLE_PATH": "/opt/homebrew/bin/hledger"163 }164 }165 }166}167```168169### Other MCP Clients170171For other MCP-compatible applications, run the server with:172173```bash174npx @iiatlas/hledger-mcp /path/to/your/master.journal175```176177The server communicates via stdio and expects the journal file path as the first argument.178179### Write tools180181When the server is not in `--read-only` mode, these tools can modify the primary journal:182183- `hledger_add_transaction` accepts structured postings and appends a new transaction after validating with `hledger check`. Enable `dryRun` to preview the entry without writing.184- `hledger_remove_entry` deletes a transaction by exact text and location, re-validating with `hledger check` and respecting optional backups.185- `hledger_replace_entry` swaps an existing entry for new content, keeping spacing tidy and performing a validation pass before committing.186- `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. Successful imports create timestamped `.bak` files unless `--skip-backup` is active.187- `hledger_rewrite` runs `hledger rewrite` on a temporary copy, letting you specify one or more `addPostings` instructions for matching transactions. Use `dryRun` for a diff-only preview or `diff: true` to include the patch output alongside the applied change.188- `hledger_close` produces closing/opening assertions, retain-earnings, or clopen transactions via `hledger close`. Preview the generated entries with `dryRun`, then append them atomically (with optional backups) once you’re satisfied.189190All write tools include a `dryRun` parameter to "try it out" before writing.191192### Web tools193194- `hledger_web` launches the hledger web UI/API on a free port unless a specific port/socket is supplied. The response includes an `instanceId` that can be used to track or terminate the server later.195- `hledger_web_list` returns metadata for each active web instance started by this MCP session (PID, command, base URL, access mode, etc.).196- `hledger_web_stop` stops a selected instance by `instanceId`, `pid`, or `port`, or stops everything with `all=true`. You can optionally choose the shutdown signal (`SIGTERM` by default) and timeout.197198When the MCP server runs in read-only mode every web instance is forced to `allow: "view"`. Otherwise the server defaults to `allow: "add"` unless `allow: "edit"` is explicitly requested.199200## Example Queries201202Once configured, you can ask Claude natural language questions about your financial data:203204- "What's my current account balance?"205- "Show me a balance sheet for last quarter"206- "What were my expenses in the food category last month?"207- "Generate an income statement for 2024"208- "Who are my top payees by transaction volume?"209- "Show me cash flow for the past 6 months"210211## Tool Parameters212213Most tools support common HLedger options including:214215- **Date ranges**: `--begin`, `--end`, `--period`216- **Output formats**: `txt`, `csv`, `json`, `html`217- **Account filtering**: Pattern matching and regex support218- **Calculation modes**: Historical, cumulative, change analysis219- **Display options**: Flat vs tree view, sorting, percentages220221## Development222223### Building from Source224225```bash226# Clone the repository227git clone <repository-url>228cd hledger-mcp229230# (Optional) If you have nvm, use this version231nvm use232233# Install dependencies234npm install235236# Build the server237npm run build238239# Test240npm run test241242# Run the debug server243npm run debug244```245246### Project Structure247248```249src/250├── index.ts # Main server entry point251├── base-tool.ts # Base tool classes and utilities252├── executor.ts # Command execution utilities253├── journal-writer.ts # Safe journal writing operations254├── resource-loader.ts # MCP resource discovery and loading255├── types.ts # Shared type definitions256└── tools/ # Individual tool implementations257 ├── accounts.ts # List account names and structures258 ├── activity.ts # Account activity analysis259 ├── add.ts # Add new transactions260 ├── balance.ts # Balance reports261 └── ... # ...and many more262263test/264├── resources/ # Test journal files265│ ├── master.journal # Example master journal with includes266│ ├── 01-jan.journal # Monthly journal files267│ ├── 02-feb.journal268│ └── ...269├── *.test.ts # Unit tests for tools and utilities270└── ...271```272273## Troubleshooting274275### "hledger CLI is not installed"276277Ensure HLedger is installed and available in your PATH:278279```bash280hledger --version281```282283The hledger cli path attempts to be found automatically at common location (see [hledger-path.ts:8](src/hledger-path.ts)). If that's not working, you can set the `HLEDGER_EXECUTABLE_PATH` environment variable to the discrete path.284285```bash286# Find hledger installation path287which hledger288```289290### "hledger web command is failing"291292Not all instances of hledger include the `hledger-web` binary. Additionaly, some installation methods (like `.mcpb`) have a hard time finding it. If you're struggling to launch the web UI I'd recommend first installing or finding the current installation:293294```bash295# Find hledger-web installation path296which hledger-web297```298299Then setting that to the environment variable. For my installation via homebrew, that's:300301```302HLEDGER_WEB_EXECUTABLE_PATH=/opt/homebrew/bin/hledger-web303```304305### "Journal file path is required"306307The server requires a journal file path as an argument. Check your config to make sure one is included, and valid.308309### Claude Desktop Connection Issues3103111. Verify the journal file path is correct and accessible3122. Check that the configuration file syntax is valid JSON3133. Restart Claude Desktop after configuration changes314315## License316317MIT License (See [LICENSE](LICENSE))318319## Contributing320321See `CONTRIBUTING.md` for setup instructions, coding standards, and tips on testing and debugging changes locally. We welcome issues and pull requests!322323## Related Projects324325- [HLedger](https://hledger.org/) - The underlying accounting software326- [Model Context Protocol](https://modelcontextprotocol.io/) - The protocol specification327- [Claude Desktop](https://claude.ai/) - AI assistant that supports MCP servers328
Full transparency — inspect the skill content before installing.