calculate_income_tax
Calculate French income tax using net taxable income and household composition to determine tax liability for residents.
Instructions
Calculate French income tax based on net taxable income and household composition
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ctx | No | ||
| household_parts | No | ||
| net_taxable_income | Yes | ||
| year | No |
Implementation Reference
- french_tax_mcp/server.py:361-364 (registration)MCP tool registration decorator defining the 'calculate_income_tax' tool with its name and description.@mcp.tool( name="calculate_income_tax", description="Calculate French income tax based on net taxable income and household composition", )
- french_tax_mcp/server.py:365-395 (handler)Handler wrapper function for the calculate_income_tax tool. It receives parameters, logs via context if provided, calls the core calculate_income_tax function from income_analyzer, and handles exceptions.async def calculate_income_tax_wrapper( net_taxable_income: float, household_parts: float = 1.0, year: Optional[int] = None, ctx: Optional[Context] = None, ) -> Optional[Dict]: """Calculate income tax based on net taxable income and household composition. Args: net_taxable_income: Net taxable income in euros household_parts: Number of household parts (quotient familial) year: Tax year (defaults to current year) ctx: MCP context for logging Returns: Dict: Dictionary containing tax calculation details """ try: if ctx: await ctx.info(f"Calculating income tax for {net_taxable_income}€ with {household_parts} parts") result = await calculate_income_tax(net_taxable_income, household_parts, year) return result except Exception as e: if ctx: await ctx.error(f"Failed to calculate income tax: {e}") return { "status": "error", "message": f"Error calculating income tax: {str(e)}", }
- Core logic of income tax calculation in the IncomeTaxAnalyzer class method. Fetches tax brackets, computes tax using _calculate_tax helper, formats results.async def calculate_income_tax( self, net_taxable_income: float, household_parts: float = 1.0, year: Optional[int] = None, ) -> Dict: """Calculate income tax based on net taxable income and household composition. Args: net_taxable_income: Net taxable income in euros household_parts: Number of household parts (quotient familial) year: Tax year (defaults to current year) Returns: Dictionary containing tax calculation details """ # Set default year to current year if not specified current_year = datetime.now().year tax_year = year or current_year - 1 # Default to previous year for tax declarations logger.info( f"Calculating income tax for {net_taxable_income}€ with {household_parts} parts for year {tax_year}" ) try: # Get tax brackets brackets_response = await get_tax_brackets(tax_year) if brackets_response["status"] != "success": return { "status": "error", "message": f"Failed to retrieve tax brackets: {brackets_response.get('message', 'Unknown error')}", "year": tax_year, } brackets = brackets_response["data"]["brackets"] # Calculate income tax tax_result = self._calculate_tax(net_taxable_income, household_parts, brackets) # Log data source data_source = brackets_response.get("source", "unknown") logger.info(f"Tax calculation completed using data from: {data_source}") return { "status": "success", "data": { "year": tax_year, "net_taxable_income": net_taxable_income, "household_parts": household_parts, "income_per_part": tax_result["income_per_part"], "tax_per_part": tax_result["tax_per_part"], "total_tax": tax_result["total_tax"], "average_tax_rate": tax_result["average_tax_rate"], "marginal_tax_rate": tax_result["marginal_tax_rate"], "bracket_details": tax_result["bracket_details"], "brackets_source": data_source, }, "message": f"Successfully calculated income tax for {tax_year} using {data_source}", } except Exception as e: logger.error(f"Error calculating income tax: {e}") return { "status": "error", "message": f"Failed to calculate income tax: {str(e)}", "year": tax_year, }
- Top-level convenience function that delegates to the singleton IncomeTaxAnalyzer instance.async def calculate_income_tax( net_taxable_income: float, household_parts: float = 1.0, year: Optional[int] = None, ) -> Dict: """Calculate income tax based on net taxable income and household composition. Args: net_taxable_income: Net taxable income in euros household_parts: Number of household parts (quotient familial) year: Tax year (defaults to current year) Returns: Dictionary containing tax calculation details """ return await income_tax_analyzer.calculate_income_tax(net_taxable_income, household_parts, year)