query_financial_history
Search through stored financial transactions using natural language queries to find relevant spending records and calculate 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 performs semantic search on the ChromaDB collection of transactions using the provided query, retrieves up to 10 results, processes them with pandas to compute totals, and returns a formatted string summary of matching 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
- my_finance_mcp.py:44-45 (helper)Initialization of the global ChromaDB persistent client and 'transactions' collection, which is directly used by the query_financial_history handler for storing embeddings and performing vector similarity searches.chroma_client = chromadb.PersistentClient(path=str(DB_PATH)) collection = chroma_client.get_or_create_collection("transactions")
- my_finance_mcp.py:93-93 (registration)The @mcp.tool() decorator registers the query_financial_history function as an MCP tool, making it available via the FastMCP server.@mcp.tool()