list_industries
Retrieve distinct industry classifications for A-share stocks on a specified date to analyze market sectors and industry composition.
Instructions
List distinct industries for a given date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/indices.py:65-72 (handler)The main handler function for the 'list_industries' tool. It is decorated with @app.tool() which registers it with the MCP server, logs the call, and executes the core logic via run_tool_with_handling delegating to fetch_list_industries.
@app.tool() def list_industries(date: Optional[str] = None, format: str = "markdown") -> str: """List distinct industries for a given date.""" logger.info("Tool 'list_industries' called date=%s", date or "latest") return run_tool_with_handling( lambda: fetch_list_industries(active_data_source, date=date, format=format), context="list_industries", ) - src/use_cases/indices.py:38-47 (helper)Helper function containing the core business logic: fetches stock industry data, extracts unique sorted industries, and formats as markdown table.
def fetch_list_industries(data_source: FinancialDataSource, *, date: Optional[str], format: str) -> str: validate_output_format(format) df = data_source.get_stock_industry(code=None, date=date) if df is None or df.empty: return "(No data available to display)" col = "industry" if "industry" in df.columns else df.columns[-1] out = df[[col]].drop_duplicates().sort_values(by=col) out = out.rename(columns={col: "industry"}) meta = {"as_of": date or "latest", "count": int(out.shape[0])} return format_table_output(out, format=format, max_rows=out.shape[0], meta=meta) - mcp_server.py:53-53 (registration)Invocation of register_index_tools during server startup, which triggers the registration of the list_industries tool.
register_index_tools(app, active_data_source)