Skip to main content
Glama

YNAB MCP Server

by calebl
ApproveTransactionTool.js2.65 kB
import { MCPTool, logger } from "mcp-framework"; import { z } from "zod"; import * as ynab from "ynab"; class ApproveTransactionTool extends MCPTool { name = "approve_transaction"; description = "Approves an existing transaction in your YNAB budget."; api; budgetId; constructor() { super(); this.api = new ynab.API(process.env.YNAB_API_TOKEN || ""); this.budgetId = process.env.YNAB_BUDGET_ID || ""; } schema = { budgetId: { type: z.string().optional(), description: "The id of the budget containing the transaction (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)", }, transactionId: { type: z.string(), description: "The id of the transaction to approve", }, approved: { type: z.boolean().default(true), description: "Whether the transaction should be marked as approved", }, }; async execute(input) { const budgetId = input.budgetId || this.budgetId; if (!budgetId) { throw new Error("No budget ID provided. Please provide a budget ID or set the YNAB_BUDGET_ID environment variable."); } try { // First, get the existing transaction to ensure we don't lose any data const existingTransaction = await this.api.transactions.getTransactionById(budgetId, input.transactionId); if (!existingTransaction.data.transaction) { throw new Error("Transaction not found"); } const existingTransactionData = existingTransaction.data.transaction; const transaction = { transaction: { approved: input.approved, } }; const response = await this.api.transactions.updateTransaction(budgetId, existingTransactionData.id, transaction); if (!response.data.transaction) { throw new Error("Failed to update transaction - no transaction data returned"); } return { success: true, transactionId: response.data.transaction.id, message: "Transaction updated successfully", }; } catch (error) { logger.error(`Error getting unapproved transactions for budget ${budgetId}:`); logger.error(JSON.stringify(error, null, 2)); return `Error getting unapproved transactions: ${error instanceof Error ? error.message : JSON.stringify(error)}`; } } } export default ApproveTransactionTool;

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

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