delete_flow
Delete cash flow entries for a given period. Specify a category to remove a single entry, or omit it to clear all entries for that month.
Instructions
Delete flow entries for a period. If category is provided, only that single entry is removed; otherwise all entries for the period are deleted.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | Yes | YYYY-MM | |
| type | No | Required when category is provided | |
| sub_type | No | Required when category is provided | |
| category | No | Specific category — if omitted, deletes all entries for the period |
Implementation Reference
- apps/mcp/src/tools/mutate.ts:521-543 (handler)The actual handler function for the 'delete_flow' MCP tool. It deletes flow entries from the database. If a 'category' is provided (along with required 'type' and 'sub_type'), it deletes a single specific entry matching all four fields. Otherwise, it deletes all flow entries for the given 'period'. Returns success with deleted count or an error if nothing matched.
async ({ period, type, sub_type, category }) => { const db = getDb(); if (category) { if (!type || !sub_type) return err('type and sub_type are required when category is provided'); const res = db .delete(flowEntries) .where( and( eq(flowEntries.period, period), eq(flowEntries.type, type), eq(flowEntries.sub_type, sub_type), eq(flowEntries.category, category), ), ) .run(); if (res.changes === 0) return err(`No flow entry matched`); return ok({ deleted: res.changes, period, category }); } const res = db.delete(flowEntries).where(eq(flowEntries.period, period)).run(); if (res.changes === 0) return err(`No flow entries for ${period}`); return ok({ deleted: res.changes, period }); }, - apps/mcp/src/tools/mutate.ts:512-520 (schema)Zod schema (input validation) for the 'delete_flow' tool. Defines the expected parameters: 'period' (YYYY-MM, required), 'type' (income/expense, optional but required when category provided), 'sub_type' (optional but required when category provided), and 'category' (optional string, if omitted deletes all entries for the period).
{ period: z.string().describe('YYYY-MM'), type: z.enum(['income', 'expense']).optional().describe('Required when category is provided'), sub_type: z.string().optional().describe('Required when category is provided'), category: z .string() .optional() .describe('Specific category — if omitted, deletes all entries for the period'), }, - apps/mcp/src/tools/mutate.ts:509-544 (registration)Registration of the 'delete_flow' tool on the MCP server via server.tool(). Nested inside the registerMutateTools function (line 12). The call includes the tool name, description, Zod input schema, and the handler callback.
server.tool( 'delete_flow', 'Delete flow entries for a period. If category is provided, only that single entry is removed; otherwise all entries for the period are deleted.', { period: z.string().describe('YYYY-MM'), type: z.enum(['income', 'expense']).optional().describe('Required when category is provided'), sub_type: z.string().optional().describe('Required when category is provided'), category: z .string() .optional() .describe('Specific category — if omitted, deletes all entries for the period'), }, async ({ period, type, sub_type, category }) => { const db = getDb(); if (category) { if (!type || !sub_type) return err('type and sub_type are required when category is provided'); const res = db .delete(flowEntries) .where( and( eq(flowEntries.period, period), eq(flowEntries.type, type), eq(flowEntries.sub_type, sub_type), eq(flowEntries.category, category), ), ) .run(); if (res.changes === 0) return err(`No flow entry matched`); return ok({ deleted: res.changes, period, category }); } const res = db.delete(flowEntries).where(eq(flowEntries.period, period)).run(); if (res.changes === 0) return err(`No flow entries for ${period}`); return ok({ deleted: res.changes, period }); }, ); - apps/mcp/src/helpers.ts:67-74 (helper)Helper functions 'ok' and 'err' used by the delete_flow handler to format success (as JSON text) and error (with isError flag) responses.
export const ok = (data: unknown) => ({ content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }], }); export const err = (msg: string) => ({ content: [{ type: 'text' as const, text: `Error: ${msg}` }], isError: true, });