Skip to main content
Glama
minhyeoky

Ledger CLI MCP Server

by minhyeoky

ledger_budget

Generate budget reports by filtering accounts, setting date ranges, and grouping data by day, week, month, or year using Ledger CLI financial data.

Instructions

Show budget report

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • main.py:242-261 (handler)
    The main handler function for the 'ledger_budget' tool. It builds the ledger CLI command based on input parameters and executes it via the run_ledger helper.
    @mcp.tool(description="Show budget report") def ledger_budget(params: LedgerBudget) -> str: cmd = ["budget"] if params.query: cmd.append(params.query) if params.begin_date: cmd.extend(["-b", params.begin_date]) if params.end_date: cmd.extend(["-e", params.end_date]) if params.monthly: cmd.append("--monthly") if params.weekly: cmd.append("--weekly") if params.daily: cmd.append("--daily") if params.yearly: cmd.append("--yearly") return run_ledger(cmd)
  • Pydantic BaseModel schema defining the input parameters for the ledger_budget tool, including filters and period groupings.
    class LedgerBudget(BaseModel): query: Optional[str] = Field(None, description="Filter accounts by regex pattern") begin_date: Optional[str] = Field( None, description="Start date for transactions (YYYY/MM/DD)" ) end_date: Optional[str] = Field( None, description="End date (exclusive) for transactions (YYYY/MM/DD)" ) monthly: bool = Field(False, description="Group by month") weekly: bool = Field(False, description="Group by week") daily: bool = Field(False, description="Group by day") yearly: bool = Field(False, description="Group by year")
  • Shared helper function that executes ledger CLI commands safely, handling subprocess calls and error messages. Used by ledger_budget and other tools.
    def run_ledger(args: List[str]) -> str: try: if not LEDGER_FILE: return "Ledger file path not set. Please provide it via --ledger-file argument or LEDGER_FILE environment variable." # Validate inputs to prevent command injection for arg in args: if ";" in arg or "&" in arg or "|" in arg: return "Error: Invalid characters in command arguments." result = subprocess.run( ["ledger", "-f", LEDGER_FILE] + args, check=True, text=True, capture_output=True, ) return result.stdout except subprocess.CalledProcessError as e: error_message = f"Ledger command failed: {e.stderr}" if "couldn't find file" in e.stderr: error_message = f"Ledger file not found at {LEDGER_FILE}. Please provide a valid path via --ledger-file argument or LEDGER_FILE environment variable." return error_message

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/minhyeoky/mcp-server-ledger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server