get_vouchers
Fetch vouchers from TallyPrime Day Book for a date range. Optionally filter by voucher type: Sales, Purchase, Payment, Receipt, Journal.
Instructions
Fetch vouchers from TallyPrime Day Book for a date range.
Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20250430'). voucher_type: Filter — 'Sales', 'Purchase', 'Payment', 'Receipt', 'Journal'. Empty = all.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | Yes | ||
| to_date | Yes | ||
| voucher_type | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The MCP tool handler for 'get_vouchers'. Decorated with @mcp.tool() inside the register() function. Delegates to client.get_vouchers() and formats the result as a human-readable string.
@mcp.tool() async def get_vouchers(from_date: str, to_date: str, voucher_type: str = "") -> str: """ Fetch vouchers from TallyPrime Day Book for a date range. Args: from_date: Start date YYYYMMDD (e.g. '20250401'). to_date: End date YYYYMMDD (e.g. '20250430'). voucher_type: Filter — 'Sales', 'Purchase', 'Payment', 'Receipt', 'Journal'. Empty = all. """ try: vouchers = await client.get_vouchers(from_date, to_date, voucher_type) if not vouchers: return "No vouchers found for the given period." label = f" ({voucher_type})" if voucher_type else "" text = f"Found {len(vouchers)} vouchers{label} from {from_date} to {to_date}:\n\n" for v in vouchers: text += ( f" [{v['date']}] {v['type']} #{v['number']}" f" Amount: {v['amount']}" + (f" -- {v['narration']}" if v["narration"] else "") + "\n" ) return text except TallyError as e: return f"Error: {e}" - src/tallyprime_mcp/tools/__init__.py:7-11 (registration)Registration orchestration: register_all() calls vouchers.register(mcp, client), which is where the @mcp.tool() decorator registers 'get_vouchers'.
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 async method that sends the XML request to TallyPrime and parses the response into a list of voucher dicts.
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 TDL XML request string for fetching vouchers from the Day Book with date range and optional voucher type filter.
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>"""