Delete Transaction
ynab_delete_transactionPermanently delete a transaction from your YNAB budget. Irreversible action that removes the transaction immediately.
Instructions
Deletes a transaction from the budget. This action cannot be undone.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budgetId | No | The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable) | |
| transactionId | Yes | The ID of the transaction to delete |
Implementation Reference
- src/tools/DeleteTransactionTool.ts:25-60 (handler)The execute function that deletes a transaction via the YNAB API. Calls api.transactions.deleteTransaction and returns a success/error result.
export async function execute(input: DeleteTransactionInput, api: ynab.API) { try { const budgetId = getBudgetId(input.budgetId); const response = await api.transactions.deleteTransaction( budgetId, input.transactionId ); if (!response.data.transaction) { throw new Error("Failed to delete transaction - no transaction data returned"); } return { content: [{ type: "text" as const, text: JSON.stringify({ success: true, transactionId: response.data.transaction.id, message: "Transaction deleted successfully", }, null, 2), }], }; } catch (error) { console.error("Error deleting transaction:", error); return { content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: getErrorMessage(error), }, null, 2), }], }; } } - Input schema defining budgetId (optional string) and transactionId (required string) using Zod.
export const inputSchema = { budgetId: z.string().optional().describe("The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)"), transactionId: z.string().describe("The ID of the transaction to delete"), }; - src/index.ts:93-97 (registration)Registration of the tool on the server using server.registerTool with name, title, description, inputSchema, and execute handler.
server.registerTool(DeleteTransactionTool.name, { title: "Delete Transaction", description: DeleteTransactionTool.description, inputSchema: DeleteTransactionTool.inputSchema, }, async (input) => DeleteTransactionTool.execute(input, api)); - src/index.ts:17-17 (registration)Import of DeleteTransactionTool module in the main index.ts file.
import * as DeleteTransactionTool from "./tools/DeleteTransactionTool.js"; - Helper function getBudgetId that resolves budget ID from input or env var, throwing if not found.
function getBudgetId(inputBudgetId?: string): string { const budgetId = inputBudgetId || process.env.YNAB_BUDGET_ID || ""; if (!budgetId) { throw new Error("No budget ID provided. Please provide a budget ID or set the YNAB_BUDGET_ID environment variable."); } return budgetId; }