get_cni_index_detail
Retrieve constituent stock details for specific Chinese stock market indices by providing index code and date to analyze index composition and holdings.
Instructions
获取指定指数的成分股样本详情
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | 指数代码 (例如: '399001') | |
| date | Yes | 日期,格式为 YYYYMM (例如: '202404') | |
| output_format | No | 输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown | markdown |
Implementation Reference
- src/china_stock_mcp/server.py:1025-1037 (handler)The handler function implementing the tool logic: fetches index constituent details using akshare.index_detail_cni for the given symbol and date, handles empty data, and formats output as specified.def get_cni_index_detail( symbol: Annotated[str, Field(description="指数代码 (例如: '399001')")], date: Annotated[str, Field(description="日期,格式为 YYYYMM (例如: '202404')")], output_format: Annotated[ Literal["json", "csv", "xml", "excel", "markdown", "html"], Field(description="输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown"), ] = "markdown" ) -> str: """获取指定指数的成分股样本详情.""" df = ak.index_detail_cni(symbol=symbol, date=date) if df.empty: df = pd.DataFrame() return _format_dataframe_output(df, output_format)
- src/china_stock_mcp/server.py:1022-1024 (registration)Registers the tool using FastMCP's @mcp.tool decorator with the tool name and description.@mcp.tool( name="get_cni_index_detail", description="获取指定指数的成分股样本详情" )
- Pydantic schema definitions for tool inputs using Annotated and Field for validation and descriptions.symbol: Annotated[str, Field(description="指数代码 (例如: '399001')")], date: Annotated[str, Field(description="日期,格式为 YYYYMM (例如: '202404')")], output_format: Annotated[ Literal["json", "csv", "xml", "excel", "markdown", "html"], Field(description="输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown"), ] = "markdown" ) -> str: