Skip to main content
Glama
dgalarza

YNAB MCP Server

by dgalarza

search_transactions

Find specific YNAB transactions by searching payee names or memo fields with optional date filters and result limits to track spending patterns.

Instructions

Search for transactions by text in payee name or memo.

Args:
    budget_id: The ID of the budget (use 'last-used' for default budget)
    search_term: Text to search for in payee name or memo (case-insensitive)
    since_date: Only search transactions on or after this date (YYYY-MM-DD format)
    until_date: Only search transactions on or before this date (YYYY-MM-DD format)
    limit: Maximum number of transactions to return (default: 100, max: 500)

Returns:
    JSON string with matching transactions and count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budget_idYes
limitNo
search_termYes
since_dateNo
until_dateNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for search_transactions. Registers the tool with @mcp.tool() decorator and implements the execution logic by delegating to YNABClient and returning JSON.
    @mcp.tool()
    async def search_transactions(
        budget_id: str,
        search_term: str,
        since_date: str = None,
        until_date: str = None,
        limit: int = None,
    ) -> str:
        """Search for transactions by text in payee name or memo.
    
        Args:
            budget_id: The ID of the budget (use 'last-used' for default budget)
            search_term: Text to search for in payee name or memo (case-insensitive)
            since_date: Only search transactions on or after this date (YYYY-MM-DD format)
            until_date: Only search transactions on or before this date (YYYY-MM-DD format)
            limit: Maximum number of transactions to return (default: 100, max: 500)
    
        Returns:
            JSON string with matching transactions and count
        """
        client = get_ynab_client()
        result = await client.search_transactions(budget_id, search_term, since_date, until_date, limit)
        return json.dumps(result, indent=2)
  • Core implementation of transaction search in YNABClient class. Fetches transactions from YNAB API, performs case-insensitive search on payee_name and memo, applies date and limit filters, formats results.
    async def search_transactions(
        self,
        budget_id: str,
        search_term: str,
        since_date: str | None = None,
        until_date: str | None = None,
        limit: int | None = None,
    ) -> dict[str, Any]:
        """Search transactions by text matching in payee name or memo.
    
        Args:
            budget_id: The budget ID or 'last-used'
            search_term: Text to search for in payee name or memo (case-insensitive)
            since_date: Only return transactions on or after this date (YYYY-MM-DD)
            until_date: Only return transactions on or before this date (YYYY-MM-DD)
            limit: Maximum number of transactions to return (default: 100, max: 500)
    
        Returns:
            Dictionary with matching transactions and count
        """
        try:
            # Get all transactions with date filtering
            url = f"{self.api_base_url}/budgets/{budget_id}/transactions"
            params = {}
            if since_date:
                params["since_date"] = since_date
    
            result = await self._make_request_with_retry("get", url, params=params)
    
            txn_data = result["data"]["transactions"]
    
            # Search and filter
            search_lower = search_term.lower()
            matching_transactions = []
    
            for txn in txn_data:
                # Filter by until_date if provided
                if until_date and txn["date"] > until_date:
                    continue
    
                # Search in payee_name and memo
                payee_name = (txn.get("payee_name") or "").lower()
                memo = (txn.get("memo") or "").lower()
    
                if search_lower in payee_name or search_lower in memo:
                    matching_transactions.append(
                        {
                            "id": txn["id"],
                            "date": txn["date"],
                            "amount": txn["amount"] / 1000 if txn.get("amount") else 0,
                            "memo": txn.get("memo"),
                            "cleared": txn.get("cleared"),
                            "approved": txn.get("approved"),
                            "account_id": txn.get("account_id"),
                            "account_name": txn.get("account_name"),
                            "payee_id": txn.get("payee_id"),
                            "payee_name": txn.get("payee_name"),
                            "category_id": txn.get("category_id"),
                            "category_name": txn.get("category_name"),
                        }
                    )
    
                    # Apply limit if specified
                    if limit and len(matching_transactions) >= limit:
                        break
    
            return {
                "search_term": search_term,
                "transactions": matching_transactions,
                "count": len(matching_transactions),
            }
        except Exception as e:
            raise Exception(f"Failed to search transactions: {e}") from e
  • The @mcp.tool() decorator registers 'search_transactions' as an MCP tool, defining its input schema from the function signature and docstring.
    @mcp.tool()
    async def search_transactions(
        budget_id: str,
        search_term: str,
        since_date: str = None,
        until_date: str = None,
        limit: int = None,
    ) -> str:
        """Search for transactions by text in payee name or memo.
    
        Args:
            budget_id: The ID of the budget (use 'last-used' for default budget)
            search_term: Text to search for in payee name or memo (case-insensitive)
            since_date: Only search transactions on or after this date (YYYY-MM-DD format)
            until_date: Only search transactions on or before this date (YYYY-MM-DD format)
            limit: Maximum number of transactions to return (default: 100, max: 500)
    
        Returns:
            JSON string with matching transactions and count
        """
        client = get_ynab_client()
        result = await client.search_transactions(budget_id, search_term, since_date, until_date, limit)
        return json.dumps(result, indent=2)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: case-insensitive search, default and max values for 'limit', date format requirements, and return format (JSON string with count). It does not mention rate limits, authentication needs, or pagination, but covers essential operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by a well-structured 'Args' and 'Returns' section. Every sentence earns its place by providing essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (5 parameters, no annotations, but has output schema), the description is complete enough. It explains all parameters in detail, specifies return format, and the output schema will handle return value documentation. No significant gaps remain for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate fully. It adds significant meaning beyond the bare schema by explaining each parameter's purpose, format constraints (e.g., YYYY-MM-DD), default values, and usage notes (e.g., 'last-used' for budget_id). This provides complete parameter semantics that the schema lacks.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('search') and resource ('transactions'), specifying it searches by text in payee name or memo. It distinguishes from siblings like 'get_transactions' (which likely retrieves all transactions without search) and 'get_transaction' (which retrieves a single transaction).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying search functionality and date filtering, but does not explicitly state when to use this tool versus alternatives like 'get_transactions' or 'get_unapproved_transactions'. It provides clear parameter guidance (e.g., 'use 'last-used' for default budget') but lacks explicit sibling comparisons.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/dgalarza/ynab-mcp-dgalarza'

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