cash_flow_statement
Generate cash flow statements for specified periods to track financial inflows and outflows, supporting accounting workflows and financial analysis.
Instructions
Generate cash flow statement for specified period
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | ||
| startDate | Yes |
Implementation Reference
- src/python/cash_flow_analysis.py:59-106 (handler)Core implementation of the cash flow statement generation logic in CashFlowAnalyzer class. Filters cash flows by period, categorizes into operating, investing, and financing activities, calculates net cash flows, and provides detailed breakdowns.def generate_cash_flow_statement(self, start_date: date, end_date: date) -> Dict: """Generate formal cash flow statement""" period_flows = [ cf for cf in self.cash_flows if start_date <= cf.date <= end_date ] # Categorize cash flows operating_flows = [cf for cf in period_flows if cf.flow_type == CashFlowType.OPERATING] investing_flows = [cf for cf in period_flows if cf.flow_type == CashFlowType.INVESTING] financing_flows = [cf for cf in period_flows if cf.flow_type == CashFlowType.FINANCING] # Calculate net flows def calculate_net_flow(flows: List[CashFlowItem]) -> float: inflows = sum(cf.amount for cf in flows if cf.direction == CashFlowDirection.INFLOW) outflows = sum(cf.amount for cf in flows if cf.direction == CashFlowDirection.OUTFLOW) return inflows - outflows operating_cash_flow = calculate_net_flow(operating_flows) investing_cash_flow = calculate_net_flow(investing_flows) financing_cash_flow = calculate_net_flow(financing_flows) net_change_in_cash = operating_cash_flow + investing_cash_flow + financing_cash_flow # Detailed breakdown operating_detail = self._categorize_flows(operating_flows) investing_detail = self._categorize_flows(investing_flows) financing_detail = self._categorize_flows(financing_flows) return { 'period': f"{start_date} to {end_date}", 'operating_activities': { 'total': round(operating_cash_flow, 2), 'detail': operating_detail }, 'investing_activities': { 'total': round(investing_cash_flow, 2), 'detail': investing_detail }, 'financing_activities': { 'total': round(financing_cash_flow, 2), 'detail': financing_detail }, 'net_change_in_cash': round(net_change_in_cash, 2), 'opening_cash_balance': self.opening_balance, 'closing_cash_balance': round(self.opening_balance + net_change_in_cash, 2) }
- src/python/cash_flow_tools.py:7-19 (helper)Helper wrapper function that parses input dates and instantiates CashFlowAnalyzer to call the core generate_cash_flow_statement method. Exposed to the TypeScript Python bridge.def generate_cash_flow_statement(start_date: str, end_date: str) -> Dict[str, Any]: """Generate cash flow statement for period""" # This would integrate with the CashFlowAnalyzer from cash_flow_analysis import CashFlowAnalyzer analyzer = CashFlowAnalyzer() # In practice, would load data from storage start_dt = datetime.strptime(start_date, '%Y-%m-%d').date() end_dt = datetime.strptime(end_date, '%Y-%m-%d').date() return analyzer.generate_cash_flow_statement(start_dt, end_dt)
- src/tools/cash-flow-tools.ts:7-33 (registration)Registers the 'cash_flow_statement' MCP tool including name, description, input schema, and handler function that invokes the Python wrapper via PythonBridge.{ name: "cash_flow_statement", description: "Generate cash flow statement for specified period", inputSchema: { type: "object", properties: { startDate: { type: "string", format: "date" }, endDate: { type: "string", format: "date" } }, required: ["startDate", "endDate"] }, handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'cash_flow_tools', function: 'generate_cash_flow_statement', args: [args.startDate, args.endDate] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
- src/tools/cash-flow-tools.ts:10-17 (schema)JSON schema defining required startDate and endDate input parameters as date-formatted strings.inputSchema: { type: "object", properties: { startDate: { type: "string", format: "date" }, endDate: { type: "string", format: "date" } }, required: ["startDate", "endDate"] },