get_active_company
Retrieve the name of the currently active company open in TallyPrime.
Instructions
Get the currently active company open in TallyPrime.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tallyprime_mcp/tools/company.py:5-14 (handler)The MCP tool handler function registered as @mcp.tool() which calls TallyClient.get_active_company() and returns the active company name.
def register(mcp, client: TallyClient): @mcp.tool() async def get_active_company() -> str: """Get the currently active company open in TallyPrime.""" try: result = await client.get_active_company() return f"Active company: {result['company']}" except TallyError as e: return f"Error: {e}" - The TallyClient method that sends a List of Accounts XML request and parses the <SVCURRENTCOMPANY> tag from the XML response to get the active company name.
async def get_active_company(self) -> dict: import re from .xml_builder import get_all_ledgers_xml raw = await self.send_xml(get_all_ledgers_xml()) match = re.search(r"<SVCURRENTCOMPANY>(.*?)</SVCURRENTCOMPANY>", raw) name = match.group(1).strip() if match else "Unknown" return {"company": name} - Builds the XML request payload for fetching the active company (List of Companies report).
def get_active_company_xml() -> str: return """<ENVELOPE> <HEADER> <TALLYREQUEST>Export Data</TALLYREQUEST> </HEADER> <BODY> <EXPORTDATA> <REQUESTDESC> <REPORTNAME>List of Companies</REPORTNAME> <STATICVARIABLES> <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> </STATICVARIABLES> </REQUESTDESC> </EXPORTDATA> </BODY> </ENVELOPE>""" - src/tallyprime_mcp/tools/__init__.py:7-11 (registration)The register_all function that calls company.register(mcp, client) to register the get_active_company tool.
def register_all(mcp: FastMCP, client: TallyClient): company.register(mcp, client) ledgers.register(mcp, client) vouchers.register(mcp, client) reports.register(mcp, client) - src/tallyprime_mcp/server.py:10-16 (registration)The server entry point that creates FastMCP instance and calls register_all to register all tools.
mcp = FastMCP("tallyprime-mcp") _client = TallyClient(url=TALLY_URL, timeout=TALLY_TIMEOUT) register_all(mcp, _client) def main(): mcp.run()