get_balance_sheets
Retrieve company balance sheets by entering a ticker symbol, specifying period (annual/quarterly), and setting result limits for financial analysis.
Instructions
Get balance sheets for a company.
Args:
ticker: Ticker symbol of the company (e.g. AAPL, GOOGL)
period: Period of the balance sheet (e.g. annual, quarterly, ttm)
limit: Number of balance sheets to return (default: 4)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | ||
| period | No | annual | |
| limit | No |
Implementation Reference
- server.py:75-104 (handler)The handler function for the 'get_balance_sheets' tool. It is decorated with @mcp.tool(), which also serves as registration. Fetches balance sheets data from the Financial Datasets API based on ticker, period, and limit, then returns JSON-formatted data.@mcp.tool() async def get_balance_sheets( ticker: str, period: str = "annual", limit: int = 4, ) -> str: """Get balance sheets for a company. Args: ticker: Ticker symbol of the company (e.g. AAPL, GOOGL) period: Period of the balance sheet (e.g. annual, quarterly, ttm) limit: Number of balance sheets to return (default: 4) """ # Fetch data from the API url = f"{FINANCIAL_DATASETS_API_BASE}/financials/balance-sheets/?ticker={ticker}&period={period}&limit={limit}" data = await make_request(url) # Check if data is found if not data: return "Unable to fetch balance sheets or no balance sheets found." # Extract the balance sheets balance_sheets = data.get("balance_sheets", []) # Check if balance sheets are found if not balance_sheets: return "Unable to fetch balance sheets or no balance sheets found." # Stringify the balance sheets return json.dumps(balance_sheets, indent=2)
- server.py:25-41 (helper)Helper function used by get_balance_sheets to make authenticated HTTP requests to the Financial Datasets API.async def make_request(url: str) -> dict[str, any] | None: """Make a request to the Financial Datasets API with proper error handling.""" # Load environment variables from .env file load_dotenv() headers = {} if api_key := os.environ.get("FINANCIAL_DATASETS_API_KEY"): headers["X-API-KEY"] = api_key async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception as e: return {"Error": str(e)}