Skip to content

// ai agents · 1 December 2026 · 4 min read

Your AI agent can issue refunds. Can you prove what it did?

I built MCPLedger: one line in an MCP server, and every tool call is recorded, masked and chained so nobody can quietly edit it.

AI agents are getting real permissions. Not “summarise this document”, but “issue a refund”, “freeze this card”, “update the payout account”. The moment that happens, someone will ask a question most teams can’t answer: what exactly did the agent do, for whom, with which data, and can you prove it?

I’ve spent years on payment backends where every movement of money has a ledger entry and an audit trail. Agents calling tools have nothing like it. So I built one, and open-sourced it: MCPLedger.

First, what MCP is

Assistants like Claude, ChatGPT and Cursor can now take actions, not just answer. A company lets them do that by writing an MCP server: a small program that offers the assistant a list of actions, such as “look up a customer” or “issue a refund”. MCP, the Model Context Protocol, is the standard way assistants talk to those servers. Each action the assistant takes is a tool call.

Today, those tool calls end up scattered across chat histories and app logs, often with card numbers in plain text, in tables anyone with database access can change.

One line, then every call is on the record

You add one line to the MCP server:

import { instrument } from "@mcpledger/sdk";

instrument(server, { apiKey: process.env.MCPLEDGER_KEY, endpoint: "https://audit.your-company.com" });

The Python version is the same shape, pip install mcpledger. From then on, every tool call is sent to a collector you run: who asked, which assistant, which tool, the arguments, whether it worked and how long it took. Your tools don’t change, and if the collector is down they keep working.

How a tool call flows through MCPLedger: an AI agent calls a tool on your MCP server; instrument() masks card numbers, IBANs, emails and secrets inside the server; the masked event goes to the MCPLedger collector, which hash-chains each event to the one before, signs the chain head, and offers verify, export, a dashboard and alert webhooks.

The diagram shows the whole path: the agent calls a tool, the event is masked inside your server, and the collector chains it to the event before.

Mask it before it leaves

An audit log full of card numbers is a new liability, not a fix. So masking happens inside your own server process, before anything is sent, and again at the collector. Card numbers (checked with the Luhn test so random digits aren’t hit), IBANs and emails are masked wherever they appear, and so are fields named like passwords, tokens, keys and PINs. This is a real event from the demo, as stored:

{"tool":"lookup_customer","args":{"email":"[email]"},"status":"ok","duration_ms":35}

What it can’t guess on its own is a customer’s name or address sitting in a field with an ordinary name. You list those field names, and they’re masked too.

A log that tells on itself

A log is only evidence if someone can’t quietly edit it. Each event stores a hash of its own content and of the event before it, the same trick that makes a ledger hard to rewrite. Change one row and every link after it stops matching.

In the demo, an agent issued a refund of 120. I then changed that row in the database to 12, the way someone with database access would. The verify call names the exact event:

{"ok":false,"checked":2,"startsAfterSeq":0,"brokenAtSeq":3,"reason":"event content was changed"}

Deleting the newest events is caught too, because the collector signs the newest link with a key kept outside the database. An auditor doesn’t have to trust my code either: the export is plain JSON lines, and a 20-line script re-checks every hash.

The demo: an agent’s calls fill the dashboard, card numbers show masked, then one edited refund breaks the chain at event #3.

Who it’s for

Teams that let agents touch real money or real customer data: payments, lending, finance operations, support teams with refund powers. Especially the ones that answer to an auditor, or must keep data in their own country. The collector is one Node service and Postgres, so it can run in your own cloud account and region, and nothing leaves your infrastructure.

If you want the plain-English version of where an agent like this would sit, I wrote about how money actually moves in a bank-plus-crypto app. And if you think agents mostly fail by going rogue, I’d argue the containment around them is what fails. A record of every action is part of that containment.

What it doesn’t do

It doesn’t make you compliant by itself, and no tool honestly can. Standards like PCI DSS, SOC 2 and ISO 27001 expect a record of who accessed sensitive systems and what they did, and an agent acting through MCP is a new kind of access most teams don’t record yet. MCPLedger gives you that record. It also doesn’t read the AI’s conversation or grade its answers. That’s a different product. It records the actions the agent took through your server.

How I tested it

The demo is a pretend payments server with five tools (look up a customer, list transactions, issue a refund, freeze a card, change a payout IBAN) driven by a few agent sessions: 12 tool calls, 2 of them failing on purpose. I edited one row directly in the database and ran verify. The repo has 55 tests for the TypeScript side and 37 for Python, covering masking, the chain, signing, retention and the exit paths that flush events when a server stops.

What this doesn’t cover: real production traffic. It hasn’t run under a busy payments system yet, and the hosted trial runs on a small server meant for evaluation, with test data only.

Try it

The code is on GitHub, MIT licensed. Install with npm install @mcpledger/sdk or pip install mcpledger. I’m looking for a few teams that already let agents touch real records to try it with me and tell me what their auditor actually asks for.

The question isn’t whether your agent will make a mistake. It’s whether you can show what happened when it does.

Muhammad Mairaj is a Senior Backend Engineer with 8 years building payment and data systems. He writes about data engineering, measured. More about him.