get_cash_flow_data
Retrieve quarterly cash flow data for A-share stocks to analyze financial performance and liquidity metrics.
Instructions
Quarterly cash flow data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| year | Yes | ||
| quarter | Yes | ||
| limit | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/financial_reports.py:63-69 (handler)The main handler function for the 'get_cash_flow_data' tool, decorated with @app.tool(). It wraps the use case execution with error handling via run_tool_with_handling and provides the tool's docstring and signature defining input/output schema.@app.tool() def get_cash_flow_data(code: str, year: str, quarter: int, limit: int = 250, format: str = "markdown") -> str: """Quarterly cash flow data.""" return run_tool_with_handling( lambda: fetch_cash_flow_data(active_data_source, code=code, year=year, quarter=quarter, limit=limit, format=format), context=f"get_cash_flow_data:{code}:{year}Q{quarter}", )
- mcp_server.py:52-52 (registration)The call to register_financial_report_tools, which defines and registers the get_cash_flow_data tool among others, passing the MCP app and active data source.register_financial_report_tools(app, active_data_source)
- The use case function fetch_cash_flow_data that performs input validation, fetches raw data from the data source, and formats the output as markdown or other specified format.def fetch_cash_flow_data(data_source: FinancialDataSource, *, code: str, year: str, quarter: int, limit: int, format: str) -> str: validate_year(year) validate_quarter(quarter) validate_output_format(format) df = data_source.get_cash_flow_data(code=code, year=year, quarter=quarter) return _format_financial_df(df, code=code, year=year, quarter=quarter, dataset="Cash Flow", format=format, limit=limit)
- src/baostock_data_source.py:429-431 (helper)The concrete implementation in BaostockDataSource that calls the Baostock API bs.query_cash_flow_data via a shared helper _fetch_financial_data to retrieve the raw DataFrame.def get_cash_flow_data(self, code: str, year: str, quarter: int) -> pd.DataFrame: """Fetches quarterly cash flow data using Baostock.""" return _fetch_financial_data(bs.query_cash_flow_data, "Cash Flow", code, year, quarter)
- src/data_source_interface.py:150-152 (schema)The abstract method definition in the FinancialDataSource interface, defining the expected signature for cash flow data retrieval.@abstractmethod def get_cash_flow_data(self, code: str, year: str, quarter: int) -> pd.DataFrame: pass