Skip to main content
Glama

get_financial_statements

Retrieve financial statements including Profit and Loss, Balance Sheet, and Cash Flow reports for specific companies with customizable date ranges and periodicity.

Instructions

    Get standard financial reports (P&L, Balance Sheet, Cash Flow).
    
    Args:
        report_type: Type of financial statement 
                   ('Profit and Loss Statement', 'Balance Sheet', 'Cash Flow')
        company: Company name
        from_date: Start date (YYYY-MM-DD format, optional)
        to_date: End date (YYYY-MM-DD format, optional) 
        periodicity: Periodicity (Monthly, Quarterly, Half-Yearly, Yearly)
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
report_typeYes
companyYes
from_dateNo
to_dateNo
periodicityNoYearly

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'get_financial_statements' MCP tool. It executes Frappe query reports for financial statements by posting to frappe.desk.query_report.run with appropriate filters.
    @mcp.tool()
    async def get_financial_statements(
        report_type: str,
        company: str,
        from_date: Optional[str] = None,
        to_date: Optional[str] = None,
        periodicity: Optional[str] = "Yearly"
    ) -> str:
        """
        Get standard financial reports (P&L, Balance Sheet, Cash Flow).
        
        Args:
            report_type: Type of financial statement 
                       ('Profit and Loss Statement', 'Balance Sheet', 'Cash Flow')
            company: Company name
            from_date: Start date (YYYY-MM-DD format, optional)
            to_date: End date (YYYY-MM-DD format, optional) 
            periodicity: Periodicity (Monthly, Quarterly, Half-Yearly, Yearly)
        """
        try:
            client = get_client()
            
            # Build filters for financial report
            filters = {
                "company": company,
                "periodicity": periodicity
            }
            
            if from_date:
                filters["from_date"] = from_date
            if to_date:
                filters["to_date"] = to_date
            
            # Prepare request data
            request_data = {
                "cmd": "frappe.desk.query_report.run",
                "report_name": report_type,
                "filters": json.dumps(filters),
                "ignore_prepared_report": 1
            }
            
            # Run the financial report
            response = await client.post("api/method/frappe.desk.query_report.run", json_data=request_data)
            
            if "message" in response:
                result = response["message"]
                
                formatted_result = {
                    "report_type": report_type,
                    "company": company,
                    "filters": filters,
                    "columns": result.get("columns", []),
                    "data": result.get("result", [])
                }
                
                return json.dumps(formatted_result, indent=2)
            else:
                return json.dumps(response, indent=2)
                
        except Exception as error:
            return _format_error_response(error, "get_financial_statements")
  • src/server.py:39-42 (registration)
    Registers the reports module tools (including get_financial_statements) with the MCP server instance.
    helpers.register_tools(mcp)
    documents.register_tools(mcp)
    schema.register_tools(mcp)
    reports.register_tools(mcp)
  • Helper function used by get_financial_statements (and other report tools) to format error responses.
    def _format_error_response(error: Exception, operation: str) -> str:
        """Format error response with detailed information."""
        credentials_check = validate_api_credentials()
        
        # Check for missing credentials first
        if not credentials_check["valid"]:
            error_msg = f"Authentication failed: {credentials_check['message']}. "
            error_msg += "API key/secret is the only supported authentication method."
            return error_msg
        
        # Handle FrappeApiError
        if isinstance(error, FrappeApiError):
            error_msg = f"Frappe API error: {error}"
            if error.status_code in (401, 403):
                error_msg += " Please check your API key and secret."
            return error_msg
        
        # Default error handling
        return f"Error in {operation}: {str(error)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral context. It mentions what data is retrieved but doesn't disclose authentication requirements, rate limits, error conditions, or what format the financial statements are returned in. The description doesn't contradict any annotations since none exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose in the first sentence. The parameter documentation is well-structured with clear formatting. While efficient, the parameter documentation could be slightly more concise by avoiding repetition of format details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (financial data retrieval with 5 parameters) and the presence of an output schema, the description is moderately complete. It explains what the tool does and documents parameters well, but lacks behavioral context about authentication, errors, and data freshness that would be important for financial reporting tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides clear semantic meaning for all 5 parameters, including enum values for report_type and periodicity, format specifications for dates, and optionality indicators. This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Get') and resources ('standard financial reports'), explicitly listing the three report types (P&L, Balance Sheet, Cash Flow). It distinguishes itself from sibling tools by focusing on financial statements rather than general document operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. While it's clear this tool retrieves financial statements, there's no mention of when to choose it over other reporting tools like 'run_doctype_report' or 'list_reports' among the siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/appliedrelevance/frappe-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server