Skip to main content
Glama
minhyeoky

Ledger CLI MCP Server

by minhyeoky

ledger_balance

Display account balances with filtering by date, depth, or account pattern. Group results by day, week, month, or year for customized financial reporting and analysis.

Instructions

Show account balances

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • main.py:132-157 (handler)
    The main handler function for the 'ledger_balance' tool, decorated with @mcp.tool for automatic registration. It constructs the 'ledger balance' CLI command based on the input parameters and executes it using the run_ledger helper.
    @mcp.tool(description="Show account balances")
    def ledger_balance(params: LedgerBalance) -> str:
        cmd = ["balance"]
    
        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.depth is not None:
            cmd.extend(["--depth", str(params.depth)])
        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.flat:
            cmd.append("--flat")
        if params.no_total:
            cmd.append("--no-total")
    
        return run_ledger(cmd)
  • main.py:18-33 (schema)
    Pydantic model defining the input schema for the ledger_balance tool, specifying optional parameters for filtering, date ranges, depth, and various display options.
    class LedgerBalance(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)"
        )
        depth: Optional[int] = Field(None, description="Limit account depth displayed")
        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")
        flat: bool = Field(False, description="Show full account names without indentation")
        no_total: bool = Field(False, description="Don't show the final total")
  • Supporting helper function that runs ledger CLI commands securely via subprocess.run, handles the LEDGER_FILE path, validates arguments against injection, and manages errors.
    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
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but fails completely. It doesn't indicate whether this is a read-only operation, what permissions might be required, whether it has side effects, how results are formatted, or any rate limits. The simple phrase 'Show account balances' provides no behavioral context beyond the basic action implied by the verb 'show'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just three words, with no wasted language. It's front-loaded with the core action ('Show account balances') and contains no unnecessary elaboration. While this conciseness comes at the cost of completeness, the description itself is structurally efficient with every word serving a purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (10 parameters with various date, grouping, and filtering options), lack of annotations, and absence of an output schema, the description is completely inadequate. It doesn't explain what the tool returns, how to interpret results, what the various parameters do, or when to use this versus other ledger tools. For a tool with this level of parameter richness, the minimal description fails to provide the necessary context for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions no parameters at all, while the input schema reveals 10 parameters with 0% schema description coverage (all parameters have descriptions in the schema itself, but the description field provides no additional context). For a tool with this many parameters (begin_date, end_date, query, daily, monthly, etc.), the description should at least hint at filtering or grouping capabilities, but it provides zero parameter guidance beyond what's in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Show account balances' is a tautology that essentially restates the tool name 'ledger_balance'. It provides minimal information beyond the name itself, failing to specify what kind of balances (e.g., current, historical, filtered) or for what scope (all accounts, specific accounts). While it indicates the general domain (account balances), it lacks the specificity needed to distinguish it from potential sibling tools like 'ledger_register' or 'ledger_stats'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There is no mention of context, prerequisites, or comparisons to sibling tools like 'ledger_accounts' or 'ledger_register'. An AI agent would have no indication of whether this is for summary balances, detailed transaction listings, or other purposes, making it impossible to make an informed choice among the available ledger tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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