A safe MCP server for a payment API
An MCP server lets an AI assistant call a real API: create an invoice, check whether a client paid, sum up the month. It also lets that assistant act on whatever it read last. A web page or a document with hidden instruc
An MCP server lets an AI assistant call a real API: create an invoice, check whether a client paid, sum up the month. It also lets that assistant act on whatever it read last. A web page or a document with hidden instructions can steer it, and the server cannot tell a request from the user from a request planted in a page.
Prompt injection cannot be filtered out reliably, so the design question is what the worst call can do when one gets through. This post walks through how the Stablevoy MCP server answers that, with the parts of the design that make the worst case dull.
Start from the worst case
Draw the line between what the server can reach and what it cannot, and make the reachable side harmless on its own.
Nothing a misled assistant can reach moves money or changes where it goes.
For a payment gateway the dangerous actions are clear: sending money out, changing where money goes, and handing out new access. None of them is on the left side:
- Moving money. Stablevoy holds no funds. A payment lands in the merchant's wallet, directly or through a contract that can only send it there (the security page explains how), so there is no balance to withdraw and no API call that sends money anywhere.
- Changing where money goes. The payout address, the webhooks, the limits and the API keys change only in the dashboard, where the merchant signs in with the wallet, and a new payout address needs a fresh wallet signature on top. The MCP server never holds a dashboard session.
- Handing out access. Adding a store to the server goes through the browser and the wallet too. The assistant cannot add one.
What remains on the reachable side is creating invoices that pay the merchant, cancelling an unpaid one, and reading. Each has a cost worth naming:
- Reading shows invoice amounts and references to whatever steered the assistant. This is the main exposure.
- Cancelling an unpaid invoice tells the buyer not to pay it and sends the shop an
invoice.cancelledwebhook, so an open order can be cancelled by mistake. No money is lost, but it is a nuisance. - A created invoice always pays the merchant, and its return page must be on the store's own website, so a misled assistant cannot send the buyer to a foreign page after paying.
A merchant who connects the server to an assistant that also browses the web should know this, and the next sections give them a way to shrink it further.
Give the server the weakest key that works
The server holds store API keys, nothing else. A store key reaches a short list of endpoints: invoices (create, list, read, cancel, summary), the payment page statistics, the transfers that matched no invoice, and the store's own settings to read. Every call that changes a setting needs the merchant's session, and the session lives in the browser.
Each key belongs to one store, and the merchant picks the stores at login. A key is listed on its store page in the dashboard as an MCP key with the name of the computer, and can be revoked there, one by one, without touching the shop's own keys.
Turn writes off, not down
Some merchants want the assistant to answer questions and never create anything. The tempting way is to keep the write tools and refuse at call time. The safer way is to not offer them at all, so the model never sees them:
const storeTools = readOnly ? reads : [...reads, new CreateInvoiceTool(directory), new CancelInvoiceTool(directory)];
With STABLEVOY_MCP_READ_ONLY=true in the client config, the server simply has no write tools. Here is the published server, version 0.9.1, started both ways and asked for its tool list over stdio (listing tools needs no key):
default: 12 tools
read-only: 10 tools
missing in read-only: cancel_invoice create_invoice
A tool that does not exist cannot be talked into running.
Make every write safe to repeat
Models repeat themselves. A timeout, a retry in the client or a second thought, and the same create call arrives twice. For a payment API that means two invoices for one order, and a buyer who may pay both.
Every create call carries an idempotency key built from the store, the amount and the reference:
import { createHash } from 'node:crypto';
const idempotencyKeyOf = (storeId, amount, reference) =>
`mcp-${createHash('sha256').update(JSON.stringify([storeId, amount, reference])).digest('hex')}`;
The API returns the invoice it already made for a key it has seen, so "bill Acme 250 dollars for October" asked twice gives one invoice:
same call twice: same key
another reference: different keys
The reference is hashed rather than sent as it is, because it may hold anything the model typed and the API accepts printable ASCII only in the key.
Get the key without copying it
Pasting an API key into a chat or a config file is how keys end up in screenshots and repositories. The server's login avoids that.
The key never passes through the browser, the clipboard or the chat.
npx stablevoy-mcp login opens the dashboard in the browser. The merchant signs in with the wallet and ticks the stores. The browser sends a one-time code back to a listener on 127.0.0.1, which checks the state it generated, and the command exchanges the code together with its PKCE verifier for one key per store. A code caught on the way is useless without the verifier, which never left the computer. The keys are written to a file with mode 0600, in a folder with mode 0700.
Read only what you mean to read
The server also answers questions from the Stablevoy documentation: "how do I verify a webhook in PHP" gets the right section. These tools need no key, which makes them the part most exposed to strange input, so they are fenced in:
- they read only pages of the Stablevoy site, listed in its llms.txt, and refuse any other address;
- they follow no redirects;
- every request has a 10-second timeout and a 1 MB limit;
- every page is kept in memory for an hour, so a chatty assistant does not hammer the site.
A server that fetches any URL the model names is a request forgery tool with a chat interface. This one has no such tool.
Ask instead of guessing
With several stores connected, a call that names no store has two possible meanings, and the server treats reads and writes differently. A read without a store asks every store and labels each answer with its store, so nothing is hidden. Creating an invoice never guesses: create_invoice without a store, when more than one is connected, comes back with an error that lists the connected stores and tells the model to name one. Cancelling needs no guess either, since only the store that owns the invoice can cancel it. An invoice in the wrong store is a small mistake, but it is the kind that ends with a buyer paying the wrong shop's link.
A checklist for your own server
| Question | What this server does |
|---|---|
| What is the worst call? | Reading invoices, or cancelling an unpaid one. Nothing reachable moves or redirects money. |
| Which credential does it hold? | Store keys only, one per chosen store, revocable one by one. |
| Can writes be switched off? | Yes, and then the write tools are not offered at all. |
| Is every write safe to repeat? | Yes, an idempotency key from store, amount and reference. |
| How does the key arrive? | Wallet login in the browser, PKCE and a local listener; never pasted. |
| What can it fetch? | Its own documentation pages only, no redirects, with time and size limits. |
| What happens when a call is ambiguous? | A read asks every store; creating an invoice asks for the store instead of picking one. |
The server is open source on GitHub, and the MCP page shows how to connect it to Claude, Cursor or any other client. The SDK page covers the libraries for the same API.
Questions
Can a prompt injection make the assistant send money?
No. Neither the server nor the API it uses has a call that sends money; payments land in the merchant's own wallet.
Can it change my payout wallet?
No. That needs a fresh signature from your wallet in the dashboard, which the server cannot produce.
What is the most it can do with a store key?
Create invoices that pay you, cancel an unpaid one, and read your invoices and totals. Run it read-only to remove the first two.
How do I take access away?
Revoke the key on the store page of the dashboard, or run npx stablevoy-mcp logout to revoke every key of that computer.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.