Skip to main content
Glama

store_transactions

Parse and store transaction data from uploaded financial documents. Extract transactions from statements, receipts, and CSV files into a structured format for financial tracking and analysis.

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
NameRequiredDescriptionDefault
transactionsYes

Implementation Reference

  • The handler function for the 'store_transactions' tool. Decorated with @mcp.tool() to register it with the MCP server. Parses transaction list, stores embeddings and metadata in ChromaDB for semantic search, and backs up raw data to JSON file.
    @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"
  • Helper function to load existing transactions from JSON backup file, used by store_transactions to append new data.
    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 []
  • Helper function to persist transactions list to JSON file, called by store_transactions after appending new 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)
  • The @mcp.tool() decorator registers the store_transactions function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xinrong-meng/my-finance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server