list_customer_charges_credits
List all charges and credits for a customer. Filter by status or type (charge/credit) to view specific billing transactions.
Instructions
List charges and credits for a customer. GET /customers/{customerId}/charges_credits. Optional filters: status, type (charge or credit).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customerId | Yes | Customer ID (required) | |
| status | No | Filter by status | |
| type | No | Filter by type: charge or credit | |
| pageNo | No | Page number (1-based) | |
| itemPerPage | No | Items per page |
Implementation Reference
- The handler function that orchestrates the tool logic: parses Zod-validated args, then calls the service layer's listCustomerChargesCredits to perform the GET request.
async function handler(client: Client, args: Record<string, unknown> | undefined) { const parsed = schema.safeParse(args); if (!parsed.success) { return errorResult(parsed.error.errors.map((e) => e.message).join("; ")); } const { customerId, status, type, pageNo, itemPerPage } = parsed.data; return handleToolCall(() => customerService.listCustomerChargesCredits(client, customerId, { status, type, pageNo, itemPerPage, }) ); } - Zod schema for input validation. Validates customerId (required string), status (optional string), type (optional enum 'charge'|'credit'), pageNo and itemPerPage (optional positive integers).
const schema = z.object({ customerId: z.string().min(1, "customerId is required"), status: z.string().optional(), type: z.enum(["charge", "credit"]).optional(), pageNo: z.number().int().min(1).optional(), itemPerPage: z.number().int().min(1).optional(), }); - Tool definition/registration metadata: MCP tool name, description, and input schema (JSON Schema format) for the MCP protocol.
const definition = { name: "list_customer_charges_credits", description: "List charges and credits for a customer. GET /customers/{customerId}/charges_credits. Optional filters: status, type (charge or credit).", inputSchema: { type: "object" as const, properties: { customerId: { type: "string", description: "Customer ID (required)" }, status: { type: "string", description: "Filter by status" }, type: { type: "string", description: "Filter by type: charge or credit" }, pageNo: { type: "number", description: "Page number (1-based)" }, itemPerPage: { type: "number", description: "Items per page" }, }, required: ["customerId"], }, }; - src/tools/customers/index.ts:31-56 (registration)Registration: the tool is included in the array returned by registerCustomerTools(), which collects all customer tools for the main tool registry.
export function registerCustomerTools(): Tool[] { return [ listCustomersTool, getCustomerTool, createCustomerTool, updateCustomerTool, deleteCustomerTool, getCustomerInvoicesTool, getCustomerUnpaidInvoicesTool, getCustomerSubscriptionsTool, getCustomerLogsTool, listCustomerAddressesTool, getCustomerAddressTool, createCustomerAddressTool, updateCustomerAddressTool, deleteCustomerAddressTool, listCustomerPaymentMethodsTool, getCustomerPaymentMethodTool, createCustomerPaymentMethodTool, updateCustomerPaymentMethodTool, deleteCustomerPaymentMethodTool, listCustomerChargesCreditsTool, createCustomerChargeCreditTool, deleteCustomerChargeCreditTool, ]; } - Service-layer helper function that builds the URLSearchParams and performs the GET /customers/{customerId}/charges_credits HTTP request using the API client.
export async function listCustomerChargesCredits( client: Client, customerId: string, params?: ListChargesCreditsParams ): Promise<PaginatedResponse<unknown>> { const search = new URLSearchParams(); if (params?.status) search.append("status", params.status); if (params?.type) search.append("type", params.type); if (params?.include) search.append("include", params.include); if (params?.pageNo != null) search.append("pageNo", String(params.pageNo)); if (params?.itemPerPage != null) search.append("itemPerPage", String(params.itemPerPage)); const q = search.toString(); return client.get<PaginatedResponse<unknown>>( `/customers/${customerId}/charges_credits${q ? `?${q}` : ""}` ); }