Skip to main content
Glama
README.md
# mcp-server-stripe

A [Model Context Protocol](https://modelcontextprotocol.io) server for the [Stripe API](https://docs.stripe.com/api). It lets an MCP client (Claude or any other MCP-capable assistant) do the everyday work in a Stripe account: look up customers, payments, invoices, subscriptions, payouts and the balance, and, when writes are enabled, create and send invoices and credit notes, refund a payment to the payer, change or cancel subscriptions, and keep products, prices and payment links up to date.

> This is an independent, unofficial project. It is not developed, endorsed or supported by Stripe.

- Read-only by default; writes are opt-in per instance.
- Who gets the money is never chosen by a tool. A refund always goes back to the payment method of the original payment; nothing creates a payout or a transfer, touches a connected account, or changes bank details or payment methods (see [What the server never does](#what-the-server-never-does)).
- Every change is sent once, with an `Idempotency-Key`, and never repeated by the server.
- Deletion only of what has had no effect outside Stripe (a draft invoice, an invoice line not yet invoiced), with the status read right before.
- One Stripe account per server instance; the server does no per-user authorization itself (see [Security model](#security-model)).
- Two transports: stdio for local clients, stateless streamable HTTP for containers and gateways.
- Embeddable: the `./gateway` export exposes the same tools, validation, policy and audit to a host application, with a catalog that marks the tools that move money.

## Access

The server authenticates with one secret, sent as `Authorization: Bearer` to `api.stripe.com` only:

- **A Stripe App with OAuth** (for a host serving many accounts): the account owner installs the app and accepts its permissions; the host keeps the access token (valid for one hour) and refreshes it with the refresh token, and gives the current access token to the gateway. The permissions the tools need are listed below.
- **A restricted key** (recommended for one account): in the Stripe Dashboard, *Developers → API keys → Create restricted key*. Give it only what you will use:

| Permission | Level | Used by |
|---|---|---|
| Balance, Balance transaction sources, Payouts | Read | balance, balance transactions, payouts, the connection check |
| Customers | Write (Read for reads only) | customers |
| Charges and Refunds, PaymentIntents | Write | payments, charges, refunds, capture and cancel |
| Invoices, Credit notes | Write | invoices, invoice items, credit notes |
| Subscriptions | Write | subscriptions |
| Products, Prices | Write | products, prices |
| Payment Links | Write | payment links |
| Disputes | Write | disputes |
| Transfers, Connect, Payouts write, Treasury, Issuing, Webhook endpoints, everything else | None | not used |

A secret key also works but gives the key far more than the tools use. A sandbox key works the same way and is what to try the server with: `check_connection` says whether the key is live or a sandbox key.

Every request asks for one API version (`STRIPE_API_VERSION` in `src/stripe/client.ts`), so answers have the same shape whatever the account's default version is.

## Tools

All tools take Stripe ids as they appear in Stripe (`cus_…`, `pi_…`, `in_…`). Amounts are integers in minor units (125.50 DKK is `12550`) with a lower-case ISO 4217 currency code; dates in filters are `YYYY-MM-DD` (UTC, both days included). Lists return `{ data, hasMore, nextStartingAfter }`; give `nextStartingAfter` as `startingAfter` for the next page. Stripe's objects are returned as Stripe gives them.

### Read

| Tool | Purpose |
|---|---|
| `stripe_check_connection` | Whether the key works, and whether it is live or a sandbox; on failure, why (key rejected, permission missing, Stripe unavailable). |
| `stripe_get_balance` | Available, pending and reserved balance per currency. |
| `stripe_list_balance_transactions`, `stripe_get_balance_transaction` | Movements of the balance (charges, refunds, fees, payouts), filterable by payout for reconciliation. |
| `stripe_list_payouts`, `stripe_get_payout` | Payouts to the company's own bank account. |
| `stripe_list_customers`, `stripe_search_customers`, `stripe_get_customer` | Customers by e-mail, by part of the name or phone, or by id (optionally with their open invoices). |
| `stripe_list_payment_intents`, `stripe_get_payment_intent` | Payments. |
| `stripe_list_charges`, `stripe_get_charge` | Charges: amounts captured and refunded, card brand and last four digits, receipt link. |
| `stripe_list_refunds`, `stripe_get_refund` | Refunds. |
| `stripe_list_disputes`, `stripe_get_dispute` | Disputes and their evidence deadlines. |
| `stripe_list_invoices`, `stripe_get_invoice`, `stripe_list_invoice_lines`, `stripe_list_invoice_items` | Invoices, their lines and pending invoice items. |
| `stripe_list_credit_notes`, `stripe_get_credit_note`, `stripe_preview_credit_note` | Credit notes, and what one would look like before it is made. |
| `stripe_list_subscriptions`, `stripe_get_subscription` | Subscriptions. |
| `stripe_list_products`, `stripe_get_product`, `stripe_list_prices`, `stripe_get_price` | Products and prices. |
| `stripe_list_payment_links`, `stripe_get_payment_link` | Payment links and what they sell. |

### Change *(writes enabled)*

Tools marked 💸 move money or release money held for the account; the gateway catalog marks them `movesMoney: true`.

| Tool | Purpose |
|---|---|
| `stripe_create_customer`, `stripe_update_customer` | Create a customer, or change name, e-mail, phone, description, address, languages, VAT treatment or metadata. Not payment methods, bank details or the credit balance. |
| `stripe_create_invoice` | Create a draft invoice (sent for payment by default, never finalized by itself). |
| `stripe_add_invoice_item` | Add a line from a price, or an amount with a description, to a draft invoice or the next invoice. |
| `stripe_update_invoice` | Change a draft's text, footer, due date or metadata. |
| `stripe_finalize_invoice`, `stripe_send_invoice` | Finalize an invoice, and e-mail it to the customer. |
| `stripe_void_invoice`, `stripe_mark_invoice_uncollectible` | Void an unpaid invoice, or mark it uncollectible. |
| `stripe_pay_invoice` 💸 | Collect an open invoice now from the customer's saved payment method, or mark it paid outside Stripe. The payment method cannot be chosen. |
| `stripe_delete_draft_invoice` | Delete a draft invoice; refused for anything but a draft. |
| `stripe_delete_invoice_item` | Delete an invoice line not yet invoiced or on a draft; refused otherwise. |
| `stripe_create_credit_note` 💸 | Credit all or part of an invoice and e-mail the credit note; on a paid invoice the credit can be refunded to the payer, put on the customer's balance or recorded as paid back outside Stripe. |
| `stripe_void_credit_note` | Void a credit note. |
| `stripe_create_refund` 💸 | Refund all or part of a payment to the payer. Refused unless the payment has succeeded, is not disputed and the amount is at most what is left. |
| `stripe_capture_payment_intent` 💸 | Capture an authorized payment, at most the amount authorized. |
| `stripe_cancel_payment_intent` 💸 | Cancel a payment that has not succeeded; a reservation is released to the payer. |
| `stripe_update_dispute` | Give written evidence for a dispute, and submit it. |
| `stripe_close_dispute` 💸 | Accept a dispute (the payer keeps the money). |
| `stripe_update_subscription` 💸 | Change items and quantities, end at the period end or take that back, pause or resume collection. Quantity changes are prorated onto the next invoice; switching to a price with another interval (or from free to paid) makes Stripe invoice and charge at once. |
| `stripe_cancel_subscription` | Cancel at the period end (default) or at once. |
| `stripe_create_product`, `stripe_update_product` | Create a product (optionally with a default price), change it, or archive it. |
| `stripe_create_price`, `stripe_update_price` | Create a price (one-time or recurring), or archive it. |
| `stripe_create_payment_link`, `stripe_update_payment_link` | Create a payment link for prices, or deactivate it. |

Every change accepts an optional `idempotencyKey` (8-100 letters, digits, underscores or dashes), sent as Stripe's `Idempotency-Key`; without one the server makes a new key for the call. The server never repeats a change itself. When a change may have failed after it reached Stripe (a timeout, a dropped connection, a 5xx), the error says so: look the object up first, and repeat the change only with the same `idempotencyKey`, so Stripe carries it out once. On a 4xx Stripe has done nothing, and the error says that too.

## What the server never does

Whatever the configuration, no tool exists for these, and the client refuses such a request before anything is sent: only the changes in `ALLOWED_WRITES` are ever sent, never with a field in `FORBIDDEN_FIELDS` (both in `src/stripe/client.ts`, exported from `./gateway`, with the list `stripeNeverOffered`).

| Never | Why |
|---|---|
| Create, cancel or reverse a payout, or choose its destination | chooses who gets money |
| Transfers, and anything with connected accounts (Connect): `destination`, `transfer_data`, `on_behalf_of`, application fees | chooses who gets money |
| A refund to anyone but the payer: `instructions_email`, `origin`, a customer balance, reversed transfers | chooses who gets money |
| Change bank accounts, cards, payment methods or payment sources | bank details |
| Change a customer's credit or cash balance directly | moves money outside an invoice or a credit note |
| Change the account's settings, API keys, webhook endpoints, Treasury or Issuing | settings in the system |
| Delete a customer, a finalized invoice, or anything else with history | deletes something with history |

## Quick start

Requires Node.js 22 or later and a Stripe key (a sandbox key to try it).

```bash
git clone https://github.com/borgels/mcp-server-stripe.git
cd mcp-server-stripe
npm ci
npm run build
```

Claude Code:

```bash
claude mcp add stripe --env STRIPE_API_KEY=<restricted key> -- node /path/to/mcp-server-stripe/dist/transports/stdio.js
```

Claude Desktop (`claude_desktop_config.json`), or any client that launches stdio servers:

```json
{
  "mcpServers": {
    "stripe": {
      "command": "node",
      "args": ["/path/to/mcp-server-stripe/dist/transports/stdio.js"],
      "env": {
        "STRIPE_API_KEY": "<restricted key>",
        "STRIPE_ENABLE_WRITES": "false"
      }
    }
  }
}
```

The npm name `mcp-server-stripe` belongs to another project; this server is not published to npm.

### Docker and HTTP

Images are published to `ghcr.io/borgels/mcp-server-stripe`: `latest` and the commit SHA from `main`, and `vX.Y.Z` for release tags. The container serves streamable HTTP at `/mcp` on port 3000, plus an unauthenticated `GET /healthz`.

```bash
TOKEN=$(openssl rand -hex 32); echo "$TOKEN"
docker run -d --name stripe-mcp -p 127.0.0.1:3000:3000 \
  -e STRIPE_API_KEY=<restricted key> \
  -e MCP_HTTP_TOKEN="$TOKEN" \
  ghcr.io/borgels/mcp-server-stripe:latest

claude mcp add --transport http stripe http://127.0.0.1:3000/mcp \
  --header "Authorization: Bearer $TOKEN"
```

To keep an audit log in the container, mount a writable directory and point `STRIPE_AUDIT_LOG` into it (e.g. `-v stripe-audit:/audit -e STRIPE_AUDIT_LOG=/audit/audit.jsonl`); the image runs as the `node` user and `/app` is not writable.

Clients send `Authorization: Bearer <MCP_HTTP_TOKEN>`. The server will not start on a non-loopback address without a token of at least 32 characters. It does not terminate TLS; run it behind a reverse proxy or gateway that does.

## Configuration

Configuration is read from the environment (see `.env.example`). Invalid numbers, booleans, URLs and unknown tool names stop the server at startup. Booleans accept `true`/`false`, `1`/`0`, `yes`/`no` and `on`/`off`.

### Stripe

| Variable | Default | Description |
|---|---|---|
| `STRIPE_API_KEY` | – | **Required.** A restricted key (recommended), a secret key, or an OAuth access token of a Stripe App. |
| `STRIPE_BASE_URL` | `https://api.stripe.com` | Only for a local mock (loopback `http` is allowed); any other host needs `STRIPE_ALLOW_CUSTOM_BASE_URL`. |
| `STRIPE_ALLOW_CUSTOM_BASE_URL` | `false` | Allow a base URL outside `api.stripe.com`. |
| `STRIPE_TIMEOUT_MS` | `30000` | Timeout per request attempt. |
| `STRIPE_MAX_CONCURRENCY` | `4` | Maximum concurrent requests to Stripe (Stripe allows 25 per second in a sandbox, 100 live). |
| `STRIPE_MAX_RESPONSE_BYTES` | `10485760` | Largest response body read (at most 100 MB). |

### Access control

| Variable | Default | Description |
|---|---|---|
| `STRIPE_ENABLE_WRITES` | `false` | Enable the change tools. |
| `STRIPE_DISABLED_TOOLS` | – | Comma-separated tool names to disable, with or without the `stripe_` prefix. |
| `STRIPE_AUDIT_LOG` | – | Path of a JSONL audit log: one record per tool call start, finish and error, with Stripe ids, amounts and words from fixed lists in clear, other text hashed, metadata by its number of keys, duration, status and the caller passed by an embedding host. Change tools refuse to run if the log cannot be written. |

### HTTP transport

| Variable | Default | Description |
|---|---|---|
| `MCP_HTTP_TOKEN` | – | Bearer token, at least 32 printable ASCII characters (also on loopback). Required unless bound to loopback. |
| `MCP_HTTP_HOST` or `HOST` | `127.0.0.1` (`0.0.0.0` in the image) | Bind address; `MCP_HTTP_HOST` takes precedence. |
| `PORT` | `3000` | Listen port. |
| `MCP_ALLOWED_ORIGINS` | localhost origins | Comma-separated browser origins allowed to call the server. |
| `MCP_ALLOW_ANY_ORIGIN` | `false` | Allow any origin; requires a token. |
| `MCP_ALLOWED_HOSTS` | loopback names on a loopback bind | Comma-separated accepted `Host` header names. |
| `MCP_MAX_BODY_BYTES` | `10485760` | Maximum request body. |
| `MCP_AUTH_FAILURE_LIMIT`, `MCP_AUTH_FAILURE_WINDOW_MS` | `20`, `60000` | Failed-authentication limit per client address; `0` disables it. |
| `MCP_HTTP_ALLOW_UNAUTHENTICATED` | `false` | Permit a non-loopback bind without a token. Only for isolated networks. |

## Embedding (`./gateway`)

A host application can run the tools in-process instead of over MCP:

```ts
import { createStripeGateway, stripeToolCatalog } from 'mcp-server-stripe/gateway';

const gateway = createStripeGateway({ apiKey: account.accessToken, policy: { enableWrites: true } });
const change = gateway.resolveChange('create_refund', { paymentIntentId: 'pi_123', amount: 2500 });
// change.change.movesMoney === true; log it, then:
const result = await gateway.callTool('create_refund', { paymentIntentId: 'pi_123', amount: 2500 }, { caller: 'person-42', requestId: 'call-1' });
```

- **Explicit credentials.** `apiKey` is required; a missing or unusable key throws when the gateway is created. The address is `https://api.stripe.com`; under a host's policy only that host (or a loopback mock) is accepted. A gateway never reads `STRIPE_API_KEY` or `STRIPE_BASE_URL` from the environment. Refreshing a Stripe App's access token is the host's job: create a gateway with the current token.
- **Several tenants in one process.** Create one gateway per Stripe account. Each instance redacts error text, tool results and audit records with its own key only; no secret is kept in a process-wide registry, and a dropped instance releases its key.
- **Instance policy from the host.** Pass `policy`: `enableWrites` (default false), `disabledTools` (must name known tools) and `audit`, a function that receives each audit record instead of `STRIPE_AUDIT_LOG` (without it the instance writes no audit; a change does not run if the sink throws on its start record). An instance with `policy` reads none of `STRIPE_ENABLE_WRITES`, `STRIPE_DISABLED_TOOLS`, `STRIPE_AUDIT_LOG` or `STRIPE_ALLOW_CUSTOM_BASE_URL`. Per-user and per-tenant authorization is the host's job.
- **Tool catalog.** `stripeToolCatalog` is a frozen list of every tool: `name` (without the `stripe_` prefix), `title`, `description`, `riskLevel` (`read`, `write` or `destructive`), `enabledByDefault`, `inputSchema` (JSON Schema), `upstream` (the requests the tool may make: `access`, `method`, path template), `broad` (false for every tool), `movesMoney` (true for the 💸 tools above), `requiresConfirmation` (the same value, under the name hosts built from the server template read; this server asks for no confirmation itself) and, for a change, `change`: its `action`, `record`, `movesMoney` and `logFields`.
- **What a change does, before it is sent.** `resolveStripeChange(tool, input)` (or `gateway.resolveChange`, which also leaves out a value that holds a piece of the instance's key) validates the input as `callTool` does and returns `{ tool, action, record, movesMoney, values }`. `values` holds only the `logFields` that have their type: Stripe ids, amounts in minor units, currencies, flags, words from fixed lists (a reason, a feedback), and for an update the names of the fields given (`fields: "email,name"`); never a name, an e-mail address, a description or metadata.
- **Result format.** A successful `callTool` result has `structuredContent` (Stripe's data, as it came) and one text block: a short summary, a blank line, and the same data as compact JSON. An error result has only its text and, when Stripe answered with an HTTP error, `failure: { httpStatus, requestId? }` (Stripe's `Request-Id`). The text holds the status, Stripe's error type and code only when they are on a fixed list we wrote down (`resource_missing`, `charge_already_refunded`, `card_declined`, ...), our own hint, and for a change whether it can have been carried out; never Stripe's message.
- **Act as a person.** Stripe's API has no users of its own: every call is made as the account the key belongs to. A valid `actAs` in the call context is accepted and sent nowhere; a malformed one refuses the call before anything is sent. The host's own log is where the person is recorded.

## Threat model

What this server guarantees about the key, and what it does not. It is the yardstick for every change that touches errors, results or audit.

**Scope.** Guarantees (a), (b) and (c) apply to the embeddable gateway (`./gateway`), the surface a multi-tenant host uses. The standalone MCP server, configured from the environment for one key, keeps best-effort redaction.

**Guaranteed:**

- **(a) The key never reaches anything persisted or shared:** audit sinks and the audit log file, logs, error texts. Errors are our own texts; audit records and everything a gateway instance returns are redacted with the instance's own key before they leave it.
- **(b) No vendor-controlled free text in errors.** An error carries our own fixed text, the HTTP status, numbers we parse (Retry-After), and Stripe's error type and code only from a fixed list we wrote down; never a response body, Stripe's message or parameter name, a redirect's `Location`, or the message of an error thrown while reading a response. A failure kept inside an otherwise returned result (the open invoices of `get_customer`, the line items of `get_payment_link`) is the status or a fixed text as well. Stripe reports no failures inside a successful body; the failure fields of a payment (`failure_message`, `last_payment_error`) are data about that payment and are passed on as data.
- **(c) Results go only to the tenant whose key it is.** One gateway instance per tenant; every call runs in a scope of its own; nothing about a tenant is kept in process-wide state.

**Not guaranteed (residual risk):** data that echoes the key back. Results are redacted on a best-effort basis: the exact key, its URL- and JSON-encoded forms and any piece of it of 6 characters or more are replaced by `"‹redacted›"` before anything is serialised, and a result that still holds such a piece is withheld whole. A Stripe key can contain part of the account id, so an answer that holds the account id can be withheld; no tool reads the account object.

**Key admission.** A gateway accepts only printable ASCII of at least 16 characters, and, as a cheap first filter, refuses a key that shares a piece of 6 characters with a string literal in `src/` (`src/fixed-corpus.generated.ts`, kept up to date by a test). The refusal never repeats the key.

## Security model

- **One shared identity.** Every caller acts with the rights of the configured key. Use a restricted key or a Stripe App with the permissions above, and rotate keys regularly.
- **Per-user authorization belongs in front of the server.** The server checks a single bearer token and does not know the end user. For multi-user use, run it behind an identity-aware gateway that decides which users may call which tools, or embed it through `./gateway` and pass the caller into the audit log.
- **Writes are off by default.** Read-only tools get a client that refuses anything but GET. When `STRIPE_AUDIT_LOG` (or a host's audit sink) is set, a change does not run unless its start record is written.
- **Money moves only where Stripe sends it.** No tool takes a field that chooses who gets money, and the client refuses such a field anyway. Refunds, captures and invoice payments are checked against Stripe's current state right before, and sent once.
- **Upstream content is untrusted input.** Customer names, descriptions and metadata are written by people; tool results label them as data.
- **The key stays on Stripe's origin.** Redirects are never followed, the base URL must be `https://api.stripe.com` (or a loopback mock), and errors and audit records are redacted and size-capped.
- **The HTTP transport fails closed.** It refuses to start on a non-loopback address or with any origin allowed unless a token is set, compares tokens in constant time, throttles failed authentication per client address, checks `Origin` and `Host`, and caps request bodies.

Report vulnerabilities as described in [SECURITY.md](SECURITY.md).

## Development

```bash
npm run dev          # stdio transport
npm run dev:http     # HTTP transport on 127.0.0.1:3000
npm run typecheck
npm test             # against a fake Stripe; no key or network needed
npm run build
```

To try it against a Stripe sandbox, create a restricted key there and run `STRIPE_API_KEY=<sandbox key> npm run dev`; the key is read from the environment and never written to the repository.

| Path | Contents |
|---|---|
| `src/tools/stripe.ts` | Shared tool table (MCP and gateway), change specs, policy and audit wrapper. |
| `src/stripe/client.ts` | Stripe client: form encoding, Idempotency-Key, the allowed changes and forbidden fields. |
| `src/stripe/money.ts` | Refunds, captures, cancellations, invoice payment, disputes and deletions, each checked right before. |
| `src/stripe/resources.ts` | Lists, paging and simple calls. |
| `src/transports/` | stdio and HTTP entry points; HTTP auth, origin and host checks. |
| `src/gateway.ts` | Embeddable entry point (`./gateway` export). |

## Releasing

1. Bump the version in `package.json`, `server.json` (`version` and the npm package `version`) and `src/version.ts`; tests and CI check that they agree. Update `CHANGELOG.md`. Merge.
2. Tag the merged commit and push the tag: `git tag vX.Y.Z && git push origin vX.Y.Z`. `publish.yml` pushes the `vX.Y.Z` image.

## License

The code is source-available under the [Functional Source License, Version 1.1, ALv2 Future License](LICENSE) (FSL-1.1-ALv2).

In plain words:

- **Allowed:** reading the code, running it, changing it, using it inside your own organisation (also commercially), using it for non-commercial education and research, and contributing changes back.
- **Not allowed:** making it, or something built from it, available to others as a commercial product or service that competes with it, for example a hosted service with the same functionality.
- **Becomes Apache-2.0:** each version is also licensed under the Apache License 2.0 from two years after it is released.

The terms in [LICENSE](LICENSE) are what apply; this summary does not replace them.

TDQS

B3.4/5.0

Scored across 59 tools

Disambiguation4/5

Most tools map cleanly to distinct Stripe resources and actions, and the detailed descriptions clarify boundaries such as invoice lines vs invoice items. A few areas are close enough to invite confusion, especially among invoice, credit-note, balance, and payment lifecycle operations, but the set is generally distinguishable.

Naming Consistency5/5

All tools use a consistent stripe_<verb>_<noun> snake_case pattern with no casing or prefix drift. Domain-specific verbs like capture, cancel, finalize, void, and mark are still predictable and readable.

Tool Count1/5

At 59 tools, this is far beyond the typical 3-15 well-scoped range and exceeds the 25+ threshold for being too many. Even though Stripe is broad, the surface is sprawling enough to impose high selection and navigation cost.

Completeness3/5

The server covers many Stripe workflows, including invoices, refunds, disputes, customers, products, prices, payment links, and subscriptions. However, there are notable gaps such as creating subscriptions or payment intents and managing payment methods, while some invoice and credit-note operations are near-duplicative rather than filling lifecycle holes.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues