get_financial_metrics
Retrieve key financial metrics for Chinese companies using stock symbols to analyze financial performance and make informed investment decisions.
Instructions
获取公司关键财务指标
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | 股票代码 (例如: '000001') | |
| output_format | No | 输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown | markdown |
Implementation Reference
- src/china_stock_mcp/server.py:402-432 (handler)The main handler function decorated with @mcp.tool for 'get_financial_metrics'. It defines parameters, a nested fetcher helper, uses fallback data fetching, and formats output.@mcp.tool(name="get_financial_metrics", description="获取公司关键财务指标") def get_financial_metrics( symbol: Annotated[str, Field(description="股票代码 (例如: '000001')")], output_format: Annotated[ Literal["json", "csv", "xml", "excel", "markdown", "html"], Field(description="输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown"), ] = "markdown" ) -> str: """ 获取三大财务报表的关键财务指标. """ def get_get_financial_metrics_fetcher(source: str, **kwargs: Any) -> pd.DataFrame: if source == "sina": return ak.stock_financial_abstract(**kwargs) elif source == "ths": return ak.stock_financial_abstract_ths(**kwargs,indicator="按报告期") else: return ako.get_financial_metrics(**kwargs) df = _fetch_data_with_fallback( fetch_func=get_get_financial_metrics_fetcher, primary_source="sina", fallback_sources=[ "eastmoney_direct", "ths" ], symbol=symbol, ) if df.empty: df = pd.DataFrame() return _format_dataframe_output(df, output_format)
- Nested helper function that maps data sources to specific akshare functions for fetching financial metrics.def get_get_financial_metrics_fetcher(source: str, **kwargs: Any) -> pd.DataFrame: if source == "sina": return ak.stock_financial_abstract(**kwargs) elif source == "ths": return ak.stock_financial_abstract_ths(**kwargs,indicator="按报告期") else: return ako.get_financial_metrics(**kwargs)
- src/china_stock_mcp/server.py:402-402 (registration)The @mcp.tool decorator registering the 'get_financial_metrics' tool with its name and description.@mcp.tool(name="get_financial_metrics", description="获取公司关键财务指标")