query_financial_history
Search stored financial transactions using natural language queries to find relevant records and generate summaries with totals.
Instructions
Search through all stored financial data using semantic search.
Args:
query: Search query string to find relevant transactions
Returns:
Formatted summary of matching transactions with totals
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- my_finance_mcp.py:93-132 (handler)The main handler function for the 'query_financial_history' tool. It uses ChromaDB to perform semantic search on stored transactions based on the query, formats the results into a summary including total amount and recent transactions.@mcp.tool() def query_financial_history(query: str) -> str: """ Search through all stored financial data using semantic search. Args: query: Search query string to find relevant transactions Returns: Formatted summary of matching transactions with totals """ # Search ChromaDB results = collection.query( query_texts=[query], n_results=10 ) # Format results found_transactions = [] if results['metadatas'][0]: for metadata in results['metadatas'][0]: found_transactions.append(metadata) # Create summary if found_transactions: df = pd.DataFrame(found_transactions) total_amount = df['amount'].sum() if 'amount' in df.columns else 0 count = len(found_transactions) response = f"Found {count} relevant transactions.\n" response += f"Total amount: ${total_amount:.2f}\n\n" response += "Recent transactions:\n" for txn in found_transactions[:5]: response += f"- {txn.get('date')}: ${txn.get('amount'):.2f} - {txn.get('description')}\n" else: response = "No matching transactions found." return response