get_trial_balance
Retrieves the Trial Balance from TallyPrime for a specified date range, summarizing account balances.
Instructions
Get the Trial Balance from TallyPrime.
Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20250930').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | Yes | ||
| to_date | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- MCP tool handler: the 'get_trial_balance' async function decorated with @mcp.tool(). Receives from_date/to_date, calls client.get_trial_balance(), and returns JSON-formatted string.
async def get_trial_balance(from_date: str, to_date: str) -> str: """ Get the Trial Balance from TallyPrime. Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20250930'). """ try: data = await client.get_trial_balance(from_date, to_date) return f"Trial Balance ({from_date} to {to_date}):\n\n" + json.dumps(data, indent=2) except TallyError as e: return f"Error: {e}" - src/tallyprime_mcp/tools/__init__.py:7-11 (registration)Tool registration: register_all() calls reports.register(mcp, client) which decorates the get_trial_balance function with @mcp.tool().
def register_all(mcp: FastMCP, client: TallyClient): company.register(mcp, client) ledgers.register(mcp, client) vouchers.register(mcp, client) reports.register(mcp, client) - TallyClient method: get_trial_balance() sends the XML request to TallyPrime and converts the response to a dict using _elem_to_dict().
async def get_trial_balance(self, from_date: str, to_date: str) -> dict: from .xml_builder import get_trial_balance_xml return self._elem_to_dict(self._parse(await self.send_xml(get_trial_balance_xml(from_date, to_date)))) - XML builder: get_trial_balance_xml() constructs the TDL XML request string with REPORTNAME 'Trial Balance' and date range parameters.
def get_trial_balance_xml(from_date: str, to_date: str) -> str: return f"""<ENVELOPE> <HEADER> <TALLYREQUEST>Export Data</TALLYREQUEST> </HEADER> <BODY> <EXPORTDATA> <REQUESTDESC> <REPORTNAME>Trial Balance</REPORTNAME> <STATICVARIABLES> <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> <SVFROMDATE>{from_date}</SVFROMDATE> <SVTODATE>{to_date}</SVTODATE> </STATICVARIABLES> </REQUESTDESC> </EXPORTDATA> </BODY> </ENVELOPE>"""