get_hs300_stocks
Retrieve CSI 300 index constituents to analyze China's A-share market performance. Provides stock data for tracking major Chinese companies.
Instructions
CSI 300 constituents.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| limit | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/indices.py:41-47 (handler)The primary MCP tool handler function for 'get_hs300_stocks', decorated with @app.tool() for automatic registration, which delegates execution to the use case layer via run_tool_with_handling.@app.tool() def get_hs300_stocks(date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """CSI 300 constituents.""" return run_tool_with_handling( lambda: fetch_index_constituents(active_data_source, index="hs300", date=date, limit=limit, format=format), context="get_hs300_stocks", )
- mcp_server.py:53-53 (registration)The call to register_index_tools that registers the 'get_hs300_stocks' tool (along with other index tools) to the FastMCP app instance.register_index_tools(app, active_data_source)
- src/data_source_interface.py:191-193 (schema)Abstract method definition in the FinancialDataSource interface serving as the schema for the underlying data retrieval method called by the tool chain.@abstractmethod def get_hs300_stocks(self, date: Optional[str] = None) -> pd.DataFrame: pass
- src/use_cases/indices.py:25-35 (helper)Use case layer helper function 'fetch_index_constituents' that routes 'hs300' requests to data_source.get_hs300_stocks() and handles formatting.def fetch_index_constituents(data_source: FinancialDataSource, *, index: str, date: Optional[str], limit: int, format: str) -> str: validate_output_format(format) key = validate_index_key(index, INDEX_MAP) if key == "hs300": df = data_source.get_hs300_stocks(date=date) elif key == "sz50": df = data_source.get_sz50_stocks(date=date) else: df = data_source.get_zz500_stocks(date=date) meta = {"index": key, "as_of": date or "latest"} return format_table_output(df, format=format, max_rows=limit, meta=meta)
- src/baostock_data_source.py:574-576 (helper)Concrete data source implementation of 'get_hs300_stocks' using Baostock's query_hs300_stocks API via a shared helper _fetch_index_constituent_data.def get_hs300_stocks(self, date: Optional[str] = None) -> pd.DataFrame: """Fetches CSI 300 index constituents using Baostock.""" return _fetch_index_constituent_data(bs.query_hs300_stocks, "CSI 300", date)