get_all_ledgers
Retrieve all ledgers from TallyPrime with their group and closing balance for financial analysis.
Instructions
Get all ledgers in TallyPrime with their group and closing balance.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tallyprime_mcp/tools/ledgers.py:6-20 (handler)The MCP tool handler for 'get_all_ledgers'. Defines the async function that calls `client.get_all_ledgers()` and formats the result as a human-readable string.
def register(mcp, client: TallyClient): @mcp.tool() async def get_all_ledgers() -> str: """Get all ledgers in TallyPrime with their group and closing balance.""" try: ledgers = await client.get_all_ledgers() if not ledgers: return "No ledgers found." text = f"Found {len(ledgers)} ledgers:\n\n" for l in ledgers: text += f" * {l['name']} (Group: {l['group']}, Balance: {l['closing']})\n" return text except TallyError as e: return f"Error: {e}" - src/tallyprime_mcp/tools/ledgers.py:6-7 (registration)Tool registration via the `register()` function. Called by `register_all` in tools/__init__.py, which is invoked from both server.py and server_http.py.
def register(mcp, client: TallyClient): - TallyClient.get_all_ledgers() — sends the XML request to TallyPrime and parses the response into a list of dicts with name, group, and closing balance.
async def get_all_ledgers(self) -> list: from .xml_builder import get_all_ledgers_xml raw = await self.send_xml(get_all_ledgers_xml()) root = self._parse(raw) return [{"name": (l.findtext("NAME") or l.get("NAME") or "").strip(), "group": (l.findtext("PARENT") or "").strip(), "closing": (l.findtext("CLOSINGBALANCE") or "0").strip()} for l in root.iter("LEDGER")] - get_all_ledgers_xml() — builds the Tally XML request string to export all ledgers (List of Accounts with ACCOUNTTYPE=Ledgers).
def get_all_ledgers_xml() -> str: return """<ENVELOPE> <HEADER> <TALLYREQUEST>Export Data</TALLYREQUEST> </HEADER> <BODY> <EXPORTDATA> <REQUESTDESC> <REPORTNAME>List of Accounts</REPORTNAME> <STATICVARIABLES> <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> <ACCOUNTTYPE>Ledgers</ACCOUNTTYPE> </STATICVARIABLES> </REQUESTDESC> </EXPORTDATA> </BODY> </ENVELOPE>"""