get_stock_basic_info
Retrieve essential stock profile information for Chinese A/B/H shares including company details, market data, and financial metrics using stock symbols.
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:460-494 (handler)The complete handler function for the 'get_stock_basic_info' tool, including decorator, input schema via Annotated Fields, logic to fetch data from multiple sources with fallback mechanism, and output formatting.@mcp.tool(name="get_stock_basic_info", description="获取指定股票的基本概要信息") def get_stock_basic_info( 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: """获取股票基本概要信息,支持 A 股和港股""" # 定义内部 fetch_func def get_stock_basic_info_fetcher(source: str, **kwargs: Any) -> pd.DataFrame: if source == "eastmoney": df = ak.stock_individual_info_em(symbol) elif source == "xueqiu": df = ak.stock_individual_basic_info_xq(symbol) elif source == "cninfo": df = ak.stock_profile_cninfo(symbol) elif source == "xq": df = ak.stock_individual_basic_info_hk_xq(symbol) return df df = _fetch_data_with_fallback( fetch_func=get_stock_basic_info_fetcher, primary_source="cninfo", fallback_sources=[ "eastmoney", "xq", "xueqiu", ], symbol=symbol, ) if df.empty: df = pd.DataFrame() return _format_dataframe_output(df, output_format)
- Input parameter schema definition for the tool using Pydantic Field and typing.Annotated, specifying symbol (stock code) and output_format (json/csv/etc.).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"
- src/china_stock_mcp/server.py:460-460 (registration)MCP tool registration using the @mcp.tool decorator with name and description.@mcp.tool(name="get_stock_basic_info", description="获取指定股票的基本概要信息")
- Inner helper fetcher function that retrieves stock basic information from different data sources (eastmoney, xueqiu, cninfo, xq) based on the source parameter.def get_stock_basic_info_fetcher(source: str, **kwargs: Any) -> pd.DataFrame: if source == "eastmoney": df = ak.stock_individual_info_em(symbol) elif source == "xueqiu": df = ak.stock_individual_basic_info_xq(symbol) elif source == "cninfo": df = ak.stock_profile_cninfo(symbol) elif source == "xq": df = ak.stock_individual_basic_info_hk_xq(symbol) return df