Skip to Content
Payments

AI Agent

Payment tools for AI agents as MCP tools, with refunds always gated on approval.

Usage

import { paymentTools } from "@dapplelight/signet-payments/agent"
import { approvalGate, createMcpServer } from "@dapplelight/signet-server/mcp"
import { payments } from "./payments"
import { session } from "./session"

const tools = paymentTools(payments, {
  userId: session.userId, // the agent only sees this user's payments
  approve: approvalGate, // refunds ask a person first
  maxRows: 25,
})

const server = createMcpServer({ name: "billing", version: "1.0.0", tools })

paymentTools needs createPayments({ db }), and a userId unless allUsers: true. It throws BAD_INPUT otherwise. The tools are plain MCP tool objects (name, description, inputSchema as JSON Schema, annotations, run(input, ctx)), so there is no dependency on signet-server.

API

ExportWhat it does
paymentTools(payments, options)Returns the tool list
PaymentToolsOptionsOptions type
PaymentToolOne tool: name, description, annotations, inputSchema, run
ApprovalRequest{ summary, details, args } passed to approve

paymentTools(payments, options)

OptionTypeDefault
userIdstringRequired unless allUsers. Another user's payment reads as NOT_FOUND
allUsersbooleanfalseAn operator agent that sees every user's payments
maxRowsnumber50Most rows list_payments returns
actorActor{ type: "agent", id: "agent" }Recorded on refunds
approve(ctx, request) => unknownundefined means approved. Anything else is returned as the tool result. Pass signet-server's approvalGate
entitlements{ applySubscription(sub, { subject }) }signet-db entitlements. Adds refresh_entitlement

Tools

ToolInputRead-onlyWhat it does
find_paymentgateway, idyesOne payment: status, amount, refunded so far
list_paymentsstatus?, gateway?, limit?, offset?yesNewest first, at most maxRows per call
payment_timelinegateway, idyesStored events, including who asked for refunds
find_subscriptiongateway, idyesReads live from the gateway. Only subscriptions linked to one of the user's payments
refund_paymentgateway, id, reason, idempotencyKey, amount?noAlways gated on approval
refresh_entitlementgateway, idnoOnly with entitlements. Re-reads the subscription and re-applies it to the owner's plan

Refunds

  • amount is minor units. Omit it for a full refund of what is left.
  • Without approve, the tool refunds nothing and returns APPROVAL_REQUIRED with the summary for a person to act on.
  • The idempotency key is part of what is approved: a new key is a new refund and needs a new yes. Retry a lost call with the same key and it refunds once.
  • A gateway that cannot refund from the server (the App Store) returns UNSUPPORTED without asking anyone.

Examples

Let an operator agent look across all users

import { paymentTools } from "@dapplelight/signet-payments/agent"
import { approvalGate } from "@dapplelight/signet-server/mcp"
import { payments } from "./payments"

const tools = paymentTools(payments, {
  allUsers: true,
  actor: { type: "agent", id: "support-bot" },
  approve: approvalGate,
})