get_income_statements
Retrieve income statements for companies by ticker symbol to analyze financial performance over specified periods like annual or quarterly.
Instructions
Get income statements for a company.
Args:
ticker: Ticker symbol of the company (e.g. AAPL, GOOGL)
period: Period of the income statement (e.g. annual, quarterly, ttm)
limit: Number of income statements to return (default: 4)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | ||
| period | No | annual | |
| limit | No |
Implementation Reference
- server.py:43-72 (handler)The main handler function for the 'get_income_statements' tool, decorated with @mcp.tool() for automatic registration and schema inference from the function signature and docstring. It fetches income statements data from the Financial Datasets API via a helper function.@mcp.tool() async def get_income_statements( ticker: str, period: str = "annual", limit: int = 4, ) -> str: """Get income statements for a company. Args: ticker: Ticker symbol of the company (e.g. AAPL, GOOGL) period: Period of the income statement (e.g. annual, quarterly, ttm) limit: Number of income statements to return (default: 4) """ # Fetch data from the API url = f"{FINANCIAL_DATASETS_API_BASE}/financials/income-statements/?ticker={ticker}&period={period}&limit={limit}" data = await make_request(url) # Check if data is found if not data: return "Unable to fetch income statements or no income statements found." # Extract the income statements income_statements = data.get("income_statements", []) # Check if income statements are found if not income_statements: return "Unable to fetch income statements or no income statements found." # Stringify the income statements return json.dumps(income_statements, indent=2)
- server.py:25-41 (helper)Shared helper function used by get_income_statements (and other tools) 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)}