Providerâagnostic payment layer for MCP (Model Context Protocol) tools and agents.
paymcp
is a lightweight SDK that helps you add monetization to your MCPâbased tools, servers, or agents. It supports multiple payment providers and integrates seamlessly with MCP's tool / resource interface.
This is the Node / TypeScript port of the original Python
paymcp
library.
Conceptually the same: you mark tools as paid and choose a payment flow.
Implementation details differ (no decorators; price lives inregisterTool()
config).
price
config when you register MCP tools to enable payments.installPayMCP(server, options)
â no need to rewrite tools.The paymentFlow
option controls how the user is guided through payment. Pick what fits your UX & client capabilities.
PaymentFlow.TWO_STEP
(default)
Splits the tool into two MCP methods.
payment_url
+ payment_id
+ next_step
(e.g. confirm_add_payment
).Works in almost all clients (even very simple ones).
When the tool is called, PayMCP sends the user a payment link via MCP elicitation (if the client supports the capability). The user can Accept / Cancel inline; once paid, the original tool runs in the same call. Falls back to a pending response if elicitation is unsupported.
Keeps the tool call open, shows a payment link, and streams progress updates while polling the provider in the background. Automatically returns the tool result when payment clears (or error / timeout).
PaymentFlow.OOB
(OutâofâBand)
Reserved for asynchronous / deferred flows. Not yet implemented.
When in doubt, start with
TWO_STEP
â highest compatibility.
npm install paymcp # or pnpm add paymcp # or yarn add paymcp
Requires Node 18+, an MCP server (official SDK or compatible), and at least one payment provider API key.
1. Create (or import) your MCP serverimport { Server } from "@modelcontextprotocol/sdk/server"; const server = new Server({ name: "my-ai-agent", version: "0.0.1" });
import { installPayMCP, PaymentFlow } from "paymcp"; installPayMCP(server, { providers: { "provider_name": {"apiKey": "your-api-key-here"}, }, paymentFlow: PaymentFlow.ELICITATION, // or TWO_STEP / PROGRESS });
The first provider listed is used by default for priced tools. Multiâprovider selection coming soon.
Specify a price
object in the tool config you pass to registerTool()
.
import { z } from "zod"; server.registerTool( "add", { title: "Add", description: "Add two numbers. This is a paid function.", inputSchema: { a: z.number(), b: z.number(), }, price: { amount: 0.19, currency: "USD" }, }, async ({ a, b }, extra) => { // `extra` is required by the PayMCP tool signature â include it even if unused return { content: [{ type: "text", text: String(a + b) }], }; } );
Start your MCP transport (stdio / http / ws) as usual. Any MCP client that connects will see the tool (andâdepending on flowâbe prompted to pay).
Demo server: For a complete setup (Express + Streamable HTTP), see the example repo: node-paymcp-server-demo.
payment_status
.Every provider implements two methods:
interface PaymentProvider { createPayment( amount: number, currency: string, description: string ): Promise<{ paymentId: string; paymentUrl: string }>; getPaymentStatus(paymentId: string): Promise<string>; // \"paid\" | \"pending\" | \"canceled\" | ... }
See src/providers/walleot.ts
and src/providers/stripe.ts
for examples. Add yours, export it from the provider map, and pass config to installPayMCP()
.
content
in tool results to satisfy strict MCP clients (Pydantic validation).MIT License
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4