Home / Home / Integrations / Spend Control for Mastra

Spend Control for Mastra

Mastra is the TypeScript agent framework for building stateful, tool-using agents — and tools are how agents spend. A guard keeps the tools honest.

Why Mastra agents overspend

Tool-calling agents hit paid endpoints as part of their loop.

Workflow steps can trigger purchases without a budget check.

Retries and reflection loops multiply tool calls.

How it works

Register the guard as a tool (or call the HTTP API from a custom tool). Before any spend, the agent asks sipi.bot: APPROVED, BLOCKED, or FLAGGED.

Rules that fit Mastra workloads

Per-transaction cap on tool purchases.

Merchant allowlist for known paid tools.

Velocity limit so loops die fast.

Guard tool

import { tool } from "mastra/core/tool";

const guardSpend = tool({
  id: "guardSpend",
  inputSchema: { amount: "number", merchant: "string", category: "string" },
  execute: async ({ amount, merchant, category }) => {
    const res = await fetch("https://sipi.bot/v1/transactions/evaluate", {
      method: "POST", headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ amount, merchant, category }),
    });
    return (await res.json()).decision; // APPROVED | BLOCKED | FLAGGED
  },
});

One tool, deterministic policy.

FAQ

Does this work in TS runtimes?

Yes — it's a plain fetch to an HTTPS endpoint.

Can I cap a whole workflow?

Yes — per-agent rules apply to everything the agent spends.

Related

Stop the next $12,400 night.

One API call (or MCP tool) in front of every agent transaction — APPROVED, BLOCKED, or FLAGGED, deterministic, ~5 ms, fully logged.

See plans — from $99/mo Try a live check