import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { PulseApiClient } from "../client.js";
import { formatResult } from "../format.js";
export function registerPaymentTools(server: McpServer, client: PulseApiClient) {
server.tool(
"list_payment_links",
"List all payment links in your account",
{
limit: z.string().optional().describe("Max results to return (default 20)"),
offset: z.string().optional().describe("Number of results to skip"),
},
async (params) => {
const result = await client.get("/api/v1/payment-links", {
limit: params.limit,
offset: params.offset,
});
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"create_payment_link",
"Create a new payment link that customers can use to pay",
{
title: z.string().describe("Payment link title"),
description: z.string().optional().describe("Description shown to payer"),
amount: z.string().describe("Amount to charge (e.g. '29.99')"),
currency: z
.string()
.optional()
.describe("Currency code (USD or BRL, defaults to USD)"),
},
async (params) => {
const result = await client.post("/api/v1/payment-links", params);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"get_payment_link",
"Get details about a specific payment link",
{ linkId: z.string().describe("The payment link ID") },
async ({ linkId }) => {
const result = await client.get(`/api/v1/payment-links/${linkId}`);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"list_payment_intents",
"List payment intents (attempted payments) for a specific payment link",
{
linkId: z.string().describe("The payment link ID"),
},
async ({ linkId }) => {
const result = await client.get(
`/api/v1/payment-links/${linkId}/intents`
);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"list_received_payments",
"List all received payments across all payment links",
{
limit: z.string().optional().describe("Max results to return (default 20)"),
offset: z.string().optional().describe("Number of results to skip"),
},
async (params) => {
const result = await client.get("/api/v1/received-payments", {
limit: params.limit,
offset: params.offset,
});
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
}