get_profit_loss
Retrieve a Profit and Loss statement from TallyPrime by providing start and end dates.
Instructions
Get the Profit and Loss statement from TallyPrime.
Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20260331').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | Yes | ||
| to_date | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The MCP tool handler for 'get_profit_loss'. It is an async function decorated with @mcp.tool() that takes from_date and to_date, calls client.get_profit_loss(), and returns the result as formatted JSON.
@mcp.tool() async def get_profit_loss(from_date: str, to_date: str) -> str: """ Get the Profit and Loss statement from TallyPrime. Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20260331'). """ try: data = await client.get_profit_loss(from_date, to_date) return f"Profit & Loss ({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)Registration of all tool modules (including reports) onto the FastMCP server. The reports.register function registers 'get_profit_loss'.
def register_all(mcp: FastMCP, client: TallyClient): company.register(mcp, client) ledgers.register(mcp, client) vouchers.register(mcp, client) reports.register(mcp, client) - TallyClient.get_profit_loss() method that builds the XML via get_profit_loss_xml, sends it to TallyPrime, parses the response, and converts it to a dict.
async def get_profit_loss(self, from_date: str, to_date: str) -> dict: from .xml_builder import get_profit_loss_xml return self._elem_to_dict(self._parse(await self.send_xml(get_profit_loss_xml(from_date, to_date)))) - get_profit_loss_xml() builds the TDL XML request string for TallyPrime's 'Profit and Loss' report with from_date and to_date parameters.
def get_profit_loss_xml(from_date: str, to_date: str) -> str: return f"""<ENVELOPE> <HEADER> <TALLYREQUEST>Export Data</TALLYREQUEST> </HEADER> <BODY> <EXPORTDATA> <REQUESTDESC> <REPORTNAME>Profit and Loss</REPORTNAME> <STATICVARIABLES> <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> <SVFROMDATE>{from_date}</SVFROMDATE> <SVTODATE>{to_date}</SVTODATE> </STATICVARIABLES> </REQUESTDESC> </EXPORTDATA> </BODY> </ENVELOPE>"""