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 registerCustomerTools(server: McpServer, client: PulseApiClient) {
server.tool(
"list_customers",
"List all customers for a product",
{ productId: z.string().describe("The product ID") },
async ({ productId }) => {
const result = await client.get(
`/api/v1/metering/products/${productId}/customers`
);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"create_customer",
"Create a new customer for a product",
{
productId: z.string().describe("The product ID"),
externalId: z.string().describe("Your unique identifier for this customer"),
name: z.string().optional().describe("Customer name"),
email: z.string().optional().describe("Customer email"),
},
async ({ productId, ...body }) => {
const result = await client.post(
`/api/v1/metering/products/${productId}/customers`,
body
);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"update_customer",
"Update an existing customer's details",
{
productId: z.string().describe("The product ID"),
customerId: z.string().describe("The customer ID"),
name: z.string().optional().describe("Updated customer name"),
email: z.string().optional().describe("Updated customer email"),
},
async ({ productId, customerId, ...body }) => {
const result = await client.patch(
`/api/v1/metering/products/${productId}/customers/${customerId}`,
body
);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
}