@paddle/paddle-mcp
Version:
MCP Server for Paddle Billing
136 lines (135 loc) • 7.29 kB
JavaScript
import { createRequire } from "node:module";
import { LogLevel, Paddle } from "@paddle/paddle-node-sdk";
import * as funcs from "./functions.js";
import { TOOL_METHODS } from "./constants.js";
const require = createRequire(import.meta.url);
const { version } = require("../package.json");
const toolMap = {
[]: funcs.listProducts,
[]: funcs.createProduct,
[]: funcs.getProduct,
[]: funcs.updateProduct,
[]: funcs.listPrices,
[]: funcs.createPrice,
[]: funcs.getPrice,
[]: funcs.updatePrice,
[]: funcs.listTransactions,
[]: funcs.createTransaction,
[]: funcs.previewPrices,
[]: funcs.previewTransactionCreate,
[]: funcs.getTransaction,
[]: funcs.updateTransaction,
[]: funcs.reviseTransaction,
[]: funcs.listAdjustments,
[]: funcs.createAdjustment,
[]: funcs.getAdjustmentCreditNote,
[]: funcs.listCreditBalances,
[]: funcs.listCustomers,
[]: funcs.createCustomer,
[]: funcs.getCustomer,
[]: funcs.updateCustomer,
[]: funcs.listAddresses,
[]: funcs.createAddress,
[]: funcs.getAddress,
[]: funcs.updateAddress,
[]: funcs.listBusinesses,
[]: funcs.createBusiness,
[]: funcs.getBusiness,
[]: funcs.updateBusiness,
[]: funcs.listSavedPaymentMethods,
[]: funcs.getSavedPaymentMethod,
[]: funcs.deleteSavedPaymentMethod,
[]: funcs.createCustomerPortalSession,
[]: funcs.listNotificationSettings,
[]: funcs.createNotificationSetting,
[]: funcs.getNotificationSetting,
[]: funcs.updateNotificationSetting,
[]: funcs.deleteNotificationSetting,
[]: funcs.listEvents,
[]: funcs.listNotifications,
[]: funcs.getNotification,
[]: funcs.listNotificationLogs,
[]: funcs.replayNotification,
[]: funcs.listSimulations,
[]: funcs.createSimulation,
[]: funcs.getSimulation,
[]: funcs.updateSimulation,
[]: funcs.listSimulationRuns,
[]: funcs.createSimulationRun,
[]: funcs.getSimulationRun,
[]: funcs.listSimulationRunEvents,
[]: funcs.getSimulationRunEvent,
[]: funcs.replaySimulationRunEvent,
[]: funcs.getTransactionInvoice,
[]: funcs.listDiscounts,
[]: funcs.createDiscount,
[]: funcs.getDiscount,
[]: funcs.updateDiscount,
[]: funcs.listDiscountGroups,
[]: funcs.createDiscountGroup,
[]: funcs.getDiscountGroup,
[]: funcs.updateDiscountGroup,
[]: funcs.archiveDiscountGroup,
[]: funcs.getSubscription,
[]: funcs.updateSubscription,
[]: funcs.listSubscriptions,
[]: funcs.cancelSubscription,
[]: funcs.pauseSubscription,
[]: funcs.resumeSubscription,
[]: funcs.activateSubscription,
[]: funcs.previewSubscriptionUpdate,
[]: funcs.createSubscriptionCharge,
[]: funcs.previewSubscriptionCharge,
[]: funcs.listReports,
[]: funcs.createReport,
[]: funcs.getReport,
[]: funcs.getReportCsv,
[]: funcs.listClientSideTokens,
[]: funcs.createClientSideToken,
[]: funcs.getClientSideToken,
[]: funcs.revokeClientSideToken,
[]: funcs.getActiveSubscribers,
[]: funcs.getMonthlyRecurringRevenue,
[]: funcs.getRevenue,
[]: funcs.getRefunds,
[]: funcs.getChargebacks,
[]: funcs.getCheckoutConversion,
[]: funcs.getMonthlyRecurringRevenueChange,
};
class PaddleAPI {
paddle;
environment;
apiKey;
constructor(apiKey, environment) {
this.apiKey = apiKey;
this.environment = environment;
this.paddle = this.createPaddleClient();
}
createPaddleClient(customHeaders = {}) {
return new Paddle(this.apiKey, {
environment: this.environment,
logLevel: LogLevel.error,
customHeaders: {
"X-Paddle-Client": "paddle-mcp-server",
"X-Paddle-Client-Version": version,
...customHeaders,
},
});
}
setClientInfo(info) {
this.paddle = this.createPaddleClient({
"X-Paddle-Client-App": info.name,
"X-Paddle-Client-App-Version": info.version,
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async run(method, arg) {
const toolFunction = toolMap[method];
if (!toolFunction) {
throw new Error(`Invalid tool method: ${method}`);
}
const result = await toolFunction(this.paddle, arg);
return JSON.stringify(result);
}
}
export default PaddleAPI;