store_transactions
Store financial transactions from documents by parsing date, amount, description, and category into a structured format for analysis and reporting.
Instructions
Parse and store transaction data from uploaded financial documents.
If you receive unstructured financial data (statements, receipts, CSV files, etc.),
extract transactions into the format: [{"date": "YYYY-MM-DD", "amount": number, "description": "string", "category": "string"}]
Args:
transactions: List of transaction dictionaries, each containing:
- date: Transaction date (string, format: YYYY-MM-DD)
- amount: Transaction amount (number, can be negative for expenses)
- description: Transaction description (string)
- category: Transaction category (string, optional, e.g. "Food", "Transport", "Bills")
Returns:
Success message with count of stored transactions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transactions | Yes |
Implementation Reference
- my_finance_mcp.py:48-90 (handler)The store_transactions tool handler, registered via @mcp.tool(). Parses and stores transaction data in ChromaDB for semantic search and in a JSON backup file. Includes detailed docstring describing input schema.@mcp.tool() def store_transactions(transactions: List[Dict[str, Any]]) -> str: """ Parse and store transaction data from uploaded financial documents. If you receive unstructured financial data (statements, receipts, CSV files, etc.), extract transactions into the format: [{"date": "YYYY-MM-DD", "amount": number, "description": "string", "category": "string"}] Args: transactions: List of transaction dictionaries, each containing: - date: Transaction date (string, format: YYYY-MM-DD) - amount: Transaction amount (number, can be negative for expenses) - description: Transaction description (string) - category: Transaction category (string, optional, e.g. "Food", "Transport", "Bills") Returns: Success message with count of stored transactions """ # Store in ChromaDB ids = [] documents = [] metadatas = [] for i, txn in enumerate(transactions): txn_id = f"txn_{datetime.now().timestamp()}_{i}" doc = f"Date: {txn.get('date')} Amount: {txn.get('amount')} Description: {txn.get('description')} Category: {txn.get('category', 'unknown')}" ids.append(txn_id) documents.append(doc) metadatas.append(txn) collection.add( ids=ids, documents=documents, metadatas=metadatas ) # Also save to JSON file existing = _load_transactions() existing.extend(transactions) _save_transactions(existing) return f"Stored {len(transactions)} transactions successfully"
- my_finance_mcp.py:27-35 (helper)Helper function to load existing transactions from the JSON backup file, used by store_transactions.def _load_transactions() -> List[Dict[str, Any]]: if JSON_FILE.exists(): with JSON_FILE.open("r") as f: try: return json.load(f) except json.JSONDecodeError: return [] return []
- my_finance_mcp.py:38-42 (helper)Helper function to save transactions to the JSON backup file, used by store_transactions.def _save_transactions(transactions: List[Dict[str, Any]]) -> None: JSON_FILE.parent.mkdir(parents=True, exist_ok=True) with JSON_FILE.open("w") as f: json.dump(transactions, f, indent=2)