Skip to main content
Glama
minhyeoky

Ledger CLI MCP Server

by minhyeoky

ledger_register

Filter, sort, and group financial transactions by date, payee, or period using regex patterns and customizable parameters for precise financial analysis.

Instructions

Show transaction register

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • main.py:35-55 (schema)
    Pydantic model defining the input schema for the ledger_register tool parameters.
    class LedgerRegister(BaseModel): query: Optional[str] = Field( None, description="Filter transactions 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") sort: Optional[str] = Field( None, description="Sort transactions (date, amount, payee)" ) by_payee: bool = Field(False, description="Group by payee") current: bool = Field( False, description="Show only transactions on or before today" )
  • main.py:160-185 (handler)
    The handler function for the ledger_register tool. It constructs the ledger CLI command based on parameters and executes it using run_ledger helper.
    @mcp.tool(description="Show transaction register") def ledger_register(params: LedgerRegister) -> str: cmd = ["register"] 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") if params.sort: cmd.extend(["-S", params.sort]) if params.by_payee: cmd.append("-P") if params.current: cmd.append("-c") return run_ledger(cmd)
  • Shared helper function that executes ledger CLI commands safely, used by ledger_register 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