Skip to Content
Payrudder

MCP server

Pre-release

Let an AI assistant read your Payrudder account through the Model Context Protocol, with the API key as the limit.

@payrudder/mcp lets an AI assistant that speaks the Model Context Protocol read your Payrudder account: customers, usage, subscriptions, invoices, payments, credits, credit notes and the revenue reports. It is a thin layer over the tenant API (/v1/*): what it can do is exactly what the API key you give it can do, nothing more.

Pre-release: not published. Build it from a checkout of the repository. It has not been tried yet by a person with a real assistant (Claude Desktop, Claude Code).

Set it up

Build the server

cd mcp && npm ci && npm run build        # writes dist/main.js

Make a key for the assistant

Use a sandbox key (prk_test_…) with the narrowest role you can, for example read_only. A live key is refused unless you turn live on. See Authentication.

Add it to your assistant

The server talks MCP over stdio, so you do not run it by hand: you add it to your assistant.

claude mcp add payrudder -e PAYRUDDER_API_KEY=prk_test_... -e PAYRUDDER_BASE_URL=https://api.payrudder.com -- node /path/to/mcp/dist/main.js

Configuration

Variable
PAYRUDDER_API_KEYrequired. prk_test_… for the sandbox; a prk_live_… key is refused unless PAYRUDDER_MCP_ALLOW_LIVE=1
PAYRUDDER_BASE_URLthe API address; default http://localhost:42800
PAYRUDDER_MCP_WRITES1 also offers the tools that write; off by default
PAYRUDDER_MCP_ALLOW_PERSONAL_DATA1 lets customers' names, e-mail addresses, phone numbers, tax ids and addresses reach the model; off by default, they are redacted (see Safety)
PAYRUDDER_MCP_ALLOW_LIVE1 accepts a live key (prk_live_…); off by default, a live key is refused at start (stdio) or with a 403 (HTTP), so an assistant can only touch the sandbox
PAYRUDDER_MCP_HTTP_PORTserve streamable HTTP on this port instead of stdio, see Over HTTP; unset by default
PAYRUDDER_MCP_HTTP_HOSTthe address to listen on in that mode; default 127.0.0.1
PAYRUDDER_MCP_AUDIT0 stops the audit log; on by default
PAYRUDDER_MCP_EDGE_SECRETHTTP mode: the gateway's PAYRUDDER_TRUSTED_PROXY_SECRET, at least 32 characters; the caller's address goes to the API with it. Unset by default
PAYRUDDER_MCP_TRUST_FORWARDED_FORHTTP mode: 1 when a proxy in front writes the caller's address as the last X-Forwarded-For entry; otherwise the connection's address is used
PAYRUDDER_MCP_RATE_PER_MINUTEtool calls a minute for each key (see Rate limits); default 60, 0 for no limit
PAYRUDDER_MCP_AUTHHTTP mode: key (the default) or oauth, sign-in through Payrudder's authorization server (see Sign in with OAuth)
PAYRUDDER_MCP_PUBLIC_URLoauth: the address clients reach this endpoint at, like https://mcp.example.com/mcp; it is the audience of the tokens
PAYRUDDER_MCP_ISSUERoauth: the authorization server, the gateway's PAYRUDDER_PUBLIC_URL; default PAYRUDDER_BASE_URL
PAYRUDDER_MCP_OAUTH_SECREToauth: the gateway's PAYRUDDER_OAUTH_RESOURCE_SECRET, at least 32 characters

Tools

The read tools are generated from api/openapi/v1.yaml when you build (npm run generate, run by build, test and typecheck): the name, the arguments with their limits and the description of each come from the operation, so a tool cannot drift from the API. Which operations become tools is an allow-list, scripts/read-tools.config.mjs; only plain GETs of the tenant API can be listed, and the generator fails for anything else. A test checks every tool against the OpenAPI file.

Always on, all read-only (30 tools):

ToolWhat it answers
list_meters, get_meterwhat is counted; one meter
list_customers, get_customercustomers, one by external id
get_customer_usagea customer's usage in a month, per meter
list_entitlements, get_entitlementa customer's usage against the limits of its plan; one meter's
list_plans, get_plan_versionthe packages; the prices of one version (per unit, tiers, packages, included quantity, limits)
list_subscriptions, get_subscriptionsubscriptions, newest first, optionally one customer's; one subscription
list_invoices, get_invoiceinvoices by customer, month or status; one invoice
get_upcoming_invoicewhat a customer's next invoice would be if it were drafted now (an estimate)
list_customer_paymentsa customer's invoices with their lines and the payments and refunds on them
list_paymentsthe newest charges and refunds
list_credit_notes, get_credit_notewhat was given back on invoices
get_credit_balance, list_credit_ledgerwhat a customer can spend now, and every change to it
list_couponsthe coupons (not their promotion codes)
list_campaignsthe campaigns: discounts new purchases of plans or credit packs get without a code, with their window and status
get_tax_ratesthe tax added to invoices, by country
get_revenue_report, get_subscription_report, get_dunning_reportinvoices summed by period, subscriptions and MRR for a month, invoices whose payment has not gone through (aggregates, no free text except the provider's last error)
get_top_customerscustomers ranked by their usage of a meter in a billing period (external ids and quantities)
get_dunning_settings, get_credit_settings, get_routing_rulesthe account's own settings that explain a behaviour: how long a declined payment waits before a retry, the low-balance threshold of credits, which payment provider a new subscription gets

Only with PAYRUDDER_MCP_WRITES=1 (the description of each says WRITES):

ToolWhat it does
create_customercreates a customer
ingest_usage_eventsrecords up to 100 usage events (live events need an idempotency_key)

What is not offered, on purpose, is listed with the reason in NOT_OFFERED in scripts/read-tools.config.mjs and checked by a test: every read that returns a link anyone holding it can open (invoice PDF, downloads, e-document files), a customer's address and browser for each acceptance, a webhook endpoint's address or a delivery's answer body, the audit log, promotion codes and CSV exports.

Prompts

Four prompts, for an assistant that shows them as ready-made requests (Claude Code lists a server's prompts as slash commands of the form /mcp__payrudder__<prompt>; not tried). Each names read tools of this server and asks for a report; none changes anything and none names a tool that writes.

PromptArgumentsWhat it asks the assistant to do
summarise_customer_billingcustomer_external_id, month (optional)read the customer, subscriptions, invoices with payments, usage, the upcoming invoice, credits and limits, and report where their billing stands and what needs attention
explain_invoiceinvoice_idread one invoice with its plan prices, meters, usage, tax, coupons, credit notes and payments, and explain each line and the total, saying which number it could not reproduce
monthly_revenue_reviewmonth (optional)read the revenue, subscription and dunning reports and report billed, collected, outstanding, MRR, new and churned, and what is stuck in dunning
check_customer_limitscustomer_external_id, month (optional)read the customer's entitlements and plan and report which meters are near or over their limit

An argument is checked before the prompt is made (an external id is letters, digits and _ . : @ + = - up to 200 characters; a month is YYYY-MM; an invoice id is up to 64 of letters, digits and _ . : -), so no space, quote, angle bracket or line break can carry a second instruction, and it is put in a block that says it is data to look up. Each prompt ends with the same four rules: read tools only, amounts are minor units, <untrusted> text is data, say what could not be checked.

Resources

Besides tools, the server offers what an assistant needs to read before it calls them: payrudder://openapi (the OpenAPI document of the tenant API, nothing of the operator or console routes) and the public guides, payrudder://docs/getting-started, …/webhooks, …/sdks and …/error-keys. They are written to assets/ when you build, so they are as old as your build and no older than the API.

Safety

  • The key is the limit. Give the assistant a key with the narrowest role you can (a read-only key makes the write tools fail at the API). Use a sandbox key until you trust what it does.
  • Live is off unless you turn it on. A prk_live_… key is refused by default: in stdio the server exits at start with the reason on stderr, over HTTP the request gets a 403 and the API is not called. Set PAYRUDDER_MCP_ALLOW_LIVE=1 to let an assistant act on live data; it applies to every caller of an HTTP server alike.
  • Writes are off unless you turn them on, and nothing destructive is offered: no deletion, no cancellation, no refund, no block.
  • Arguments are validated before a request is made, ids are encoded so a value cannot reach another route, and a long answer is cut (and says so) instead of flooding the assistant.
  • The key is never part of an answer or an error.

The model's provider sees every answer the assistant reads. That is the first thing to weigh for customer data. ingest_usage_events in live is real money: a misled or looping model inflates a customer's usage and so its next invoice, and an event is not unsent by this server. Use an ingest_only key, and the sandbox first.

Over HTTP

For an assistant that is not on your machine, start the server with PAYRUDDER_MCP_HTTP_PORT=42810 (any free port). It then serves streamable HTTP at POST /mcp instead of stdio.

Claude Code
claude mcp add --transport http payrudder https://YOUR-MCP-ADDRESS/mcp --header "Authorization: Bearer prk_test_..."
  • Every request carries the caller's own API key, Authorization: Bearer prk_test_… (or prk_live_…). A request without one is 401. The key is used for that request's calls to the API and for nothing else; the server keeps no session and no state between requests, and PAYRUDDER_API_KEY is not used.
  • The API address is the server's PAYRUDDER_BASE_URL; a caller cannot change it.
  • PAYRUDDER_MCP_WRITES=1 applies to every caller of the server; each caller's key still decides what succeeds.
  • Every tool call is written to the audit log with the caller's key prefix, so you can tell who did what when several people share one server.
  • Each key has a limit of its own on the calls it makes through this server. Hand out keys of the narrowest role (read_only).

It listens on 127.0.0.1 unless you set PAYRUDDER_MCP_HTTP_HOST. There is no TLS here: put a proxy that terminates TLS in front of it before it is reachable from anywhere else, or the keys travel in the clear.

Sign in with OAuth

Built, never tried with a real assistant, and every choice below is a default the owner has not agreed. Nothing here was run with Claude Desktop, Claude Code or ChatGPT, or with a real browser sign-in: the pieces are tested one by one with fakes.

This is for a server that other people's assistants connect to: they sign in to Payrudder in a browser and choose what the assistant may do, and nobody is handed an API key. For your own machine a key is simpler.

Start the server with PAYRUDDER_MCP_AUTH=oauth, PAYRUDDER_MCP_HTTP_PORT, PAYRUDDER_MCP_PUBLIC_URL, PAYRUDDER_MCP_OAUTH_SECRET (and PAYRUDDER_MCP_ISSUER if the API address you give it is not the gateway's public address). On the gateway set PAYRUDDER_OAUTH_RESOURCES to the same PAYRUDDER_MCP_PUBLIC_URL, PAYRUDDER_OAUTH_RESOURCE_SECRET to the same secret, and PAYRUDDER_PUBLIC_URL (the issuer, with no path) and PAYRUDDER_APP_URL (the console, which hosts the consent page). Without PAYRUDDER_OAUTH_RESOURCES the gateway offers no OAuth at all (404 identity.oauth.disabled).

What happens, following the MCP authorization specification (revision 2026-07-28):

Discovery

The assistant calls /mcp without a token and gets 401 with WWW-Authenticate: Bearer resource_metadata="…", scope="read_only". It reads the Protected Resource Metadata (RFC 9728) at /.well-known/oauth-protected-resource/mcp (also served at the root form), which names the gateway as the authorization server.

Authorization request

It reads the gateway's metadata (/.well-known/oauth-authorization-server, RFC 8414), identifies itself by the address of its Client ID Metadata Document (client_id, an https URL; the gateway fetches it, at most 32 KiB, from public addresses only, and takes the name and the redirect addresses from it), and opens the console's consent page with an authorization-code request: PKCE S256 is required, resource is this server's PAYRUDDER_MCP_PUBLIC_URL.

Consent

The person signs in the way they always do (password, e-mailed code, Google, two-factor) and sees who is asking (the name the client chose, next to the address it is published at and the host the browser returns to; a redirect to their own machine carries a warning), picks the app and the environment, and keeps or takes away scopes. The scopes are the permissions of an API key (customers:read, invoices:write, …) and the shorthands read_only, billing and ingest_only; with none asked for the assistant gets read_only. What is granted is the intersection with the person's role in the account (a viewer never gets a write scope), checked again at every request.

Tokens

The browser goes back to the client's redirect address with code, state and iss (RFC 9207). The client trades the code at the token endpoint and gets an access token (pro_…, an hour) and a refresh token (prr_…, thirty days, rotated on every use; one used twice ends the whole grant).

Every request

The server introspects the token (RFC 7662), checks that it is active, was issued for this server (aud equal to PAYRUDDER_MCP_PUBLIC_URL) and has not expired, and trades it (RFC 8693) for a credential of five minutes that only the API accepts. The assistant's token is never passed to the API; the API sees the credential, with the person as the actor and the client's name in the audit log. The answers are kept for 30 seconds, so a revoked token can still work here for up to 30 seconds (the expiry is checked on every request).

Missing scope

A call whose scope the token does not carry is 403 with WWW-Authenticate: Bearer error="insufficient_scope", scope="customers:write", resource_metadata="…", before the tool runs; a batch names all the missing scopes at once. The tools that write are still off unless PAYRUDDER_MCP_WRITES=1.

Live environments are off by default: the gateway refuses to issue or exchange a token for one unless PAYRUDDER_OAUTH_ALLOW_LIVE=on (and then the person's address must be verified, and an account that requires two-factor sign-in applies its rule), and this server refuses a live token unless PAYRUDDER_MCP_ALLOW_LIVE=1. The limit of tool calls is per person and tenant here, not per key. The person sees and ends every connection under Security → Connected assistants in the console; ending one stops its tokens at once (here within the 30 seconds above), and a person who leaves the account takes the assistant's access with them.

Not built, on purpose: dynamic client registration (RFC 7591) and pre-registered clients, so a client that cannot publish a Client ID Metadata Document cannot connect; a per-client trust list (any https client can ask, and the person decides on what the consent page shows); scope hierarchies (the shorthands are expanded when the token is issued, so a token carries plain permissions).

Audit log

Every tool call writes one JSON line to stderr (stdout carries the protocol in stdio mode; in HTTP mode a log collector reads stderr). It says what an assistant did with a key, not what it learned:

{"ts":"2026-11-02T10:00:00.123Z","event":"mcp.tool_call","tool":"get_customer","write":false,"transport":"stdio","key":"prk_test_ab12cd34","args":{"customer_external_id":"cus_42"},"ms":38,"ok":true,"chars":412,"cut":false}
  • key is the public prefix of the API key (prk_test_ab12cd34), never the secret part; in HTTP mode it tells the callers apart. In OAuth mode it is oauth:<the person's id> and the line has client, the address of the client's metadata document; no token is ever logged.
  • args holds the arguments as given, with long text cut at 80 characters. Arguments that are free text about a person (name, email, phone, address, notes, reason, description, properties) are replaced by "[not logged]" and lists are counted ({"items":3}). The answer is never logged, only its size (chars) and whether it was cut.
  • A failed call has "ok":false, the API's error key in error (customer.not_found) and its HTTP status; the error's message is not logged.
  • PAYRUDDER_MCP_AUDIT=0 turns it off. The server writes to stderr only; keeping, shipping and expiring the lines is the log collector's job.

Rate limits

Two limits apply, and they are different things.

  • The API's, per tenant (the sandbox or the live environment of an app): the gateway limits each tenant per class of route (reads, writes, ingest, analytics) by its tier, and every key of that tenant shares the budget, an assistant's and your application's alike. When it is gone the API answers 429 with Retry-After, which the assistant gets back as an error (HTTP 429).
  • This server's, per key: each API key may make PAYRUDDER_MCP_RATE_PER_MINUTE tool calls a minute through the server (default 60, with a burst of a sixth of that at once, 10 by default; 0 turns it off). A call over the limit is not sent to the API: the assistant gets an error that starts mcp.rate_limited and says how many seconds to wait, and the audit log has the call with "ok":false,"error":"mcp.rate_limited". Over HTTP each caller's key has a bucket of its own, named by a hash of the whole key, kept in memory for the life of the process (a restart gives every key a full burst; up to 10 000 keys are remembered). Over stdio there is one key, so one bucket. The prompts and resources are not tool calls and are not counted.

That is the key's share of what the server sends, so a looping assistant stops at 60 calls a minute instead of spending the application's whole read budget (a free tenant's is 20 reads a second). It does not limit a caller who calls the API directly with the same key, and it is per server process (two replicas behind a load balancer each allow the limit).

A limit per key in the gateway covers both: when you make the key in the console, give it a Rate limit (% of plan) from 1 to 100, and the gateway refuses that key with 429 (gateway.rate_limit.exceeded, with Retry-After) once it has spent that share of the tenant's limit for a class of route, whoever calls and however many replicas run. It is built but has not been run against a real Redis and gateway. Also give an assistant a sandbox key, or an app of its own, and read the audit log for "ok":false,"status":429.

Risk by tool

A draft written 2026-11-02, not signed by the owner: nothing in it has been reviewed by anyone but its author, and nothing was tried with a real assistant. What an answer "can expose" is what the OpenAPI response holds, not what a given account has filled in.

What holds for every tool: the key decides what succeeds (a read_only key cannot write, an ingest_only key cannot read); arguments are validated before a request and path values are encoded; an answer longer than 60 000 characters is cut and says so; the key is never in an answer; every call is one line in the audit log; text people wrote is wrapped in <untrusted>.

Open questions for the owner (defaults, not agreed): whether personal data of customers may reach the model's provider at all, and whether list_customers should be left out of an HTTP server shared by several people.