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 registerWebhookTools(server: McpServer, client: PulseApiClient) {
server.tool(
"list_webhooks",
"List all webhook subscriptions",
{},
async () => {
const result = await client.get("/api/v1/webhooks");
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"create_webhook",
"Create a webhook subscription to receive event notifications",
{
url: z.string().describe("The URL to receive webhook POST requests"),
events: z
.array(z.string())
.describe("Array of event types to subscribe to (e.g. ['payment.completed', 'invoice.sent'])"),
},
async (params) => {
const result = await client.post("/api/v1/webhooks", params);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
server.tool(
"delete_webhook",
"Delete a webhook subscription",
{
webhookId: z.string().describe("The webhook subscription ID to delete"),
},
async ({ webhookId }) => {
const result = await client.delete(`/api/v1/webhooks/${webhookId}`);
return { content: [{ type: "text", text: formatResult(result) }] };
}
);
}