expense_add
Add new expense entries to track business spending with detailed categorization, vendor information, and financial data for accurate accounting and reporting.
Instructions
Add a new expense entry
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| category | Yes | ||
| costCenter | No | ||
| date | Yes | ||
| description | No | ||
| expenseId | Yes | ||
| invoiceNumber | No | ||
| projectId | No | ||
| recurring | No | ||
| recurringFrequency | No | ||
| subcategory | No | ||
| tags | No | ||
| taxDeductible | No | ||
| vendorId | Yes |
Implementation Reference
- src/tools/expense-tools.ts:41-56 (handler)JS handler function for 'expense_add' tool that delegates to Python ExpenseTracker.add_expense via PythonBridgehandler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'expense_tracking', function: 'ExpenseTracker.add_expense', args: [], kwargs: { expense: args } }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
- src/tools/expense-tools.ts:10-40 (schema)Input schema defining parameters for adding an expenseinputSchema: { type: "object", properties: { expenseId: { type: "string" }, date: { type: "string", format: "date" }, vendorId: { type: "string" }, amount: { type: "number" }, category: { type: "string", enum: [ "Rent/Lease", "Utilities", "Salaries & Wages", "Employee Benefits", "Insurance", "Marketing & Advertising", "Office Supplies", "Maintenance & Repairs", "Professional Fees", "Travel & Entertainment", "Raw Materials", "Inventory Purchases", "Freight & Shipping", "Equipment", "Property", "Vehicles", "Software", "Interest Expense", "Bank Fees", "Taxes", "Depreciation", "Amortization", "Other" ] }, subcategory: { type: "string" }, description: { type: "string" }, invoiceNumber: { type: "string" }, costCenter: { type: "string" }, projectId: { type: "string" }, tags: { type: "array", items: { type: "string" } }, taxDeductible: { type: "boolean", default: true }, recurring: { type: "boolean", default: false }, recurringFrequency: { type: "string" } }, required: ["expenseId", "date", "vendorId", "amount", "category"] },
- src/tools/expense-tools.ts:7-57 (registration)Tool definition object registered in the exported expenseTools array{ name: "expense_add", description: "Add a new expense entry", inputSchema: { type: "object", properties: { expenseId: { type: "string" }, date: { type: "string", format: "date" }, vendorId: { type: "string" }, amount: { type: "number" }, category: { type: "string", enum: [ "Rent/Lease", "Utilities", "Salaries & Wages", "Employee Benefits", "Insurance", "Marketing & Advertising", "Office Supplies", "Maintenance & Repairs", "Professional Fees", "Travel & Entertainment", "Raw Materials", "Inventory Purchases", "Freight & Shipping", "Equipment", "Property", "Vehicles", "Software", "Interest Expense", "Bank Fees", "Taxes", "Depreciation", "Amortization", "Other" ] }, subcategory: { type: "string" }, description: { type: "string" }, invoiceNumber: { type: "string" }, costCenter: { type: "string" }, projectId: { type: "string" }, tags: { type: "array", items: { type: "string" } }, taxDeductible: { type: "boolean", default: true }, recurring: { type: "boolean", default: false }, recurringFrequency: { type: "string" } }, required: ["expenseId", "date", "vendorId", "amount", "category"] }, handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'expense_tracking', function: 'ExpenseTracker.add_expense', args: [], kwargs: { expense: args } }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
- src/index.ts:32-44 (registration)Global registration: expenseTools array spread into allTools used by MCP server's ListTools and CallTool handlersconst allTools = [ ...excelTools, ...financialTools, ...rentalTools, ...expenseTools, ...reportingTools, ...cashFlowTools, ...taxTools, ...analyticsTools, ...chartTools, ...complianceTools, ...propertyTools, ];
- Python backend implementation of ExpenseTracker.add_expense method called by the JS tool handlerdef add_expense(self, expense: Expense) -> str: """Add a new expense with validation""" # Validate vendor exists if expense.vendor_id not in self.vendors: raise ValueError(f"Vendor {expense.vendor_id} not found") # Check approval rules if self._requires_approval(expense): expense.approval_status = ApprovalStatus.PENDING else: expense.approval_status = ApprovalStatus.APPROVED self.expenses.append(expense) return expense.expense_id