get_daybook
Retrieves all vouchers from TallyPrime Day Book for a specified date range. Input starting and ending dates in YYYYMMDD format.
Instructions
Get the Day Book (all vouchers) from TallyPrime for a date range.
Args: from_date: Start date YYYYMMDD. to_date: End date YYYYMMDD.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | Yes | ||
| to_date | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The get_daybook tool handler: fetches vouchers via client.get_vouchers(), formats them into a textual Day Book report string with date, type, number, amount, and narration.
@mcp.tool() async def get_daybook(from_date: str, to_date: str) -> str: """ Get the Day Book (all vouchers) from TallyPrime for a date range. Args: from_date: Start date YYYYMMDD. to_date: End date YYYYMMDD. """ try: vouchers = await client.get_vouchers(from_date, to_date, voucher_type="") if not vouchers: return "No entries found in the Day Book for this period." text = f"Day Book ({from_date} to {to_date}) -- {len(vouchers)} entries:\n\n" for v in vouchers: text += ( f" [{v['date']}] {v['type']:<12} #{v['number']:<10}" f" {v['amount']:>14}" + (f" {v['narration']}" if v["narration"] else "") + "\n" ) return text except TallyError as e: return f"Error: {e}" - src/tallyprime_mcp/tools/reports.py:57-69 (registration)Tool registration via @mcp.tool() decorator on the get_daybook function — the register() function in reports.py wires all report tools onto the MCP instance.
@mcp.tool() async def get_stock_summary(as_of_date: str) -> str: """ Get the Stock Summary (inventory) from TallyPrime as of a date. Args: as_of_date: Date YYYYMMDD (e.g. '20260516'). """ try: data = await client.get_stock_summary(as_of_date) return f"Stock Summary as of {as_of_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)register_all() calls reports.register(mcp, client), which ultimately registers get_daybook as an 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.get_vouchers() — the helper method called by the get_daybook handler to fetch voucher data from Tally via XML, parsing DATE, VOUCHERTYPENAME, VOUCHERNUMBER, NARRATION, and AMOUNT fields.
async def get_vouchers(self, from_date: str, to_date: str, voucher_type: str = "") -> list: from .xml_builder import get_vouchers_xml raw = await self.send_xml(get_vouchers_xml(from_date, to_date, voucher_type)) root = self._parse(raw) return [{"date": (v.findtext("DATE") or "").strip(), "type": (v.findtext("VOUCHERTYPENAME") or "").strip(), "number": (v.findtext("VOUCHERNUMBER") or "").strip(), "narration": (v.findtext("NARRATION") or "").strip(), "amount": (v.findtext("AMOUNT") or "0").strip()} for v in root.iter("VOUCHER")] - get_vouchers_xml() builds the XML request using <REPORTNAME>Day Book</REPORTNAME> with SVFROMDATE/SVTODATE and optional VOUCHERTYPENAME filter — the actual XML sent to Tally to retrieve Day Book data.
def get_vouchers_xml(from_date: str, to_date: str, voucher_type: str = "") -> str: """ from_date / to_date: YYYYMMDD strings voucher_type: e.g. "Sales", "Purchase", "" for all """ vtype_tag = f"<VOUCHERTYPENAME>{voucher_type}</VOUCHERTYPENAME>" if voucher_type else "" return f"""<ENVELOPE> <HEADER> <TALLYREQUEST>Export Data</TALLYREQUEST> </HEADER> <BODY> <EXPORTDATA> <REQUESTDESC> <REPORTNAME>Day Book</REPORTNAME> <STATICVARIABLES> <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> <SVFROMDATE>{from_date}</SVFROMDATE> <SVTODATE>{to_date}</SVTODATE> {vtype_tag} </STATICVARIABLES> </REQUESTDESC> </EXPORTDATA> </BODY> </ENVELOPE>"""