get_income_statements
Retrieve income statements for a company by providing its ticker symbol, period, and limit. Access financial data to analyze company performance directly through the Financial Datasets MCP Server.
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 |
|---|---|---|---|
| limit | No | ||
| period | No | annual | |
| ticker | Yes |
Implementation Reference
- server.py:43-72 (handler)The handler function for the 'get_income_statements' tool. It is decorated with @mcp.tool() for registration. Includes parameter type hints and docstring serving as schema. Fetches income statements from the Financial Datasets API using the make_request helper, processes the response, and returns JSON string.@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)Supporting helper function used by get_income_statements 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)}
- server.py:43-43 (registration)The @mcp.tool() decorator registers the get_income_statements function as an MCP tool.@mcp.tool()
- server.py:44-48 (schema)Function signature with type annotations defining the input schema (parameters: ticker (str), period (str, default 'annual'), limit (int, default 4); output str). Docstring provides further description.async def get_income_statements( ticker: str, period: str = "annual", limit: int = 4, ) -> str: