Skip to main content
Glama
16Coffee

Yahoo Finance MCP Server

by 16Coffee

get_financial_statement

Retrieve detailed financial statements for companies, including annual or quarterly income statements, balance sheets, and cash flow reports, using stock tickers and financial type specifications.

Instructions

获取公司财报,类型包括年度/季度的收入表、资产负债表和现金流量表。

参数说明: ticker: str 股票代码,例如 "AAPL" financial_type: str 财报类型:income_stmt_annual、income_stmt_quarterly、balance_sheet_annual、balance_sheet_quarterly、cashflow_annual、cashflow_quarterly

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
financial_typeYes
tickerYes

Implementation Reference

  • The async handler function that implements the get_financial_statement tool logic, fetching income statement, balance sheet, or cash flow from Financial Modeling Prep API based on ticker and financial_type.
    async def get_financial_statement(ticker: str, financial_type: str) -> str: """Get financial statement for a given ticker symbol""" api_key = os.environ.get("FMP_API_KEY") if not api_key: return "Error: FMP_API_KEY environment variable not set." base = "https://financialmodelingprep.com/api/v3" period = "annual" if financial_type in [ FinancialType.income_stmt_quarterly, FinancialType.balance_sheet_quarterly, FinancialType.cashflow_quarterly, ]: period = "quarter" endpoint_map = { FinancialType.income_stmt_annual: "income-statement", FinancialType.income_stmt_quarterly: "income-statement", FinancialType.balance_sheet_annual: "balance-sheet-statement", FinancialType.balance_sheet_quarterly: "balance-sheet-statement", FinancialType.cashflow_annual: "cash-flow-statement", FinancialType.cashflow_quarterly: "cash-flow-statement", } endpoint = endpoint_map.get(FinancialType(financial_type)) if not endpoint: return "Error: invalid financial type" url = f"{base}/{endpoint}/{ticker}" try: resp = requests.get(url, params={"period": period, "apikey": api_key}, timeout=10) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting financial statement for {ticker}: {e}" return json.dumps(data)
  • server.py:232-242 (registration)
    Registers the get_financial_statement tool with the FastMCP server using the @tool decorator, including name, description, and parameter details.
    @fmp_server.tool( name="get_financial_statement", description="""获取公司财报,类型包括年度/季度的收入表、资产负债表和现金流量表。 参数说明: ticker: str 股票代码,例如 "AAPL" financial_type: str 财报类型:income_stmt_annual、income_stmt_quarterly、balance_sheet_annual、balance_sheet_quarterly、cashflow_annual、cashflow_quarterly """, )
  • Defines the FinancialType enum used to validate and map the financial_type parameter to API endpoints.
    class FinancialType(str, Enum): income_stmt_annual = "income_stmt_annual" income_stmt_quarterly = "income_stmt_quarterly" balance_sheet_annual = "balance_sheet_annual" balance_sheet_quarterly = "balance_sheet_quarterly" cashflow_annual = "cashflow_annual" cashflow_quarterly = "cashflow_quarterly"

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/16Coffee/finance-mcp'

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