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 registerProductTools(server: McpServer, client: PulseApiClient) {
server.tool(
"list_products",
"List all products in your Pulse account",
{},
async () => {
const result = await client.get("/api/v1/metering/products");
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"get_product",
"Get details of a specific product including its meters",
{ productId: z.string().describe("The product ID") },
async ({ productId }) => {
const result = await client.get(`/api/v1/metering/products/${productId}`);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"create_product",
"Create a new product for usage metering",
{
name: z.string().describe("Product name"),
type: z.string().optional().describe("Product type (e.g. 'saas', 'api')"),
description: z.string().optional().describe("Product description"),
},
async (params) => {
const result = await client.post("/api/v1/metering/products", params);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"create_meter",
"Create a meter (usage dimension) for a product",
{
productId: z.string().describe("The product ID"),
name: z.string().describe("Meter identifier (e.g. 'api_calls', 'tokens')"),
displayName: z.string().describe("Human-readable meter name"),
unit: z.string().describe("Unit of measurement (e.g. 'request', 'token')"),
unitPrice: z.string().describe("Price per unit (e.g. '0.001')"),
},
async ({ productId, ...body }) => {
const result = await client.post(
`/api/v1/metering/products/${productId}/meters`,
body
);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
}