cd /news/ai-agents/a-safe-mcp-server-for-a-payment-api · home › topics › ai-agents › article
[ARTICLE · art-177514] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

A safe MCP server for a payment API

The Stablevoy project released version 0.9.1 of its MCP server for a payment API, designed so that a prompt-injected assistant cannot move money, change payout destinations, or grant new access. The server exposes only invoice creation, cancellation, and read operations to the model, holds store-scoped API keys, and offers a read-only mode that removes write tools entirely so the model never sees them. Create calls carry a SHA-256 idempotency key derived from store, amount, and reference to prevent duplicate invoices, and login uses a one-time code to a 127.0.0.1 listener so keys never pass through the browser or chat.

recommendation

Strip dangerous tools from the server's tool list rather than rejecting them at call time, and derive idempotency keys from store, amount, and reference so retried create calls cannot double-bill.

more in playbook: Securing agents and AI tools
by read6 min views6 publishedNov 27, 2026

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.

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:

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:

invoice.cancelled webhook, so an open order can be cancelled by mistake. No money is lost, but it is a nuisance. 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.

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.

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.

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.

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.

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:

A server that fetches any URL the model names is a request forgery tool with a chat interface. This one has no such tool.

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.

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.

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @stablevoy 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-safe-mcp-server-fo…] indexed:0 read:6min 2026-11-27 · —