Skip to main content
Glama
minhyeoky

Ledger CLI MCP Server

by minhyeoky

ledger_print

Filter and print financial transactions in ledger format using date ranges or regex patterns for reporting and analysis with Ledger CLI.

Instructions

Print transactions in ledger format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • main.py:218-229 (handler)
    The handler function for the 'ledger_print' tool, decorated with @mcp.tool for registration. It builds the 'ledger print' command based on input parameters and executes it via the run_ledger helper.
    @mcp.tool(description="Print transactions in ledger format")
    def ledger_print(params: LedgerPrint) -> str:
        cmd = ["print"]
    
        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])
    
        return run_ledger(cmd)
  • main.py:72-82 (schema)
    Pydantic input schema (BaseModel) defining parameters for the ledger_print tool: query, begin_date, and end_date.
    class LedgerPrint(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)"
        )
  • Helper function used by ledger_print (and other tools) to safely execute ledger CLI commands with input validation and error handling.
    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
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Print' suggests output generation, but the description doesn't disclose behavioral traits like output format details, pagination, performance characteristics, or whether this is a read-only operation. It mentions 'ledger format' but doesn't explain what that entails.

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

Conciseness4/5

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

The description is extremely concise (4 words) and front-loaded with the core purpose. However, this brevity comes at the cost of completeness - it's under-specified rather than efficiently informative.

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

Completeness2/5

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

Given no annotations, no output schema, and 3 parameters with 0% schema coverage, the description is inadequate. For a tool with multiple parameters and sibling alternatives, it should explain more about what 'ledger format' means, when to use it, and what parameters control.

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 schema has 3 parameters (begin_date, end_date, query) with 0% schema description coverage. The description fails to compensate for this complete lack of parameter documentation in the schema, leaving all parameters semantically undefined.

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

Purpose3/5

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

The description 'Print transactions in ledger format' states a clear verb ('Print') and resource ('transactions'), but is vague about scope and format. It doesn't specify what 'ledger format' means or distinguish this from sibling tools like 'ledger_register' or 'ledger_raw_command' that might also output transaction data.

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

Usage Guidelines2/5

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

No guidance is provided about when to use this tool versus alternatives. With multiple sibling tools for ledger data (accounts, balance, register, stats, etc.), the description offers no indication of when 'ledger_print' is appropriate versus other transaction-related tools like 'ledger_register'.

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