(server: McpServer, client: McpClient)
| 18 | * rotate-secret. Other reads scrub it. |
| 19 | */ |
| 20 | export function registerWebhookTools(server: McpServer, client: McpClient): void { |
| 21 | const filtersSchema = z |
| 22 | .object({ |
| 23 | agent_ids: z.array(z.string()).optional(), |
| 24 | conversation_ids: z.array(z.string()).optional(), |
| 25 | labels: z.array(z.string()).optional(), |
| 26 | }) |
| 27 | .strict() |
| 28 | .describe( |
| 29 | "Optional scope filters. Empty / missing keys mean 'no constraint of that type'. agent_ids must reference agents owned by the caller; cross-user ids are rejected. conversation_ids / labels are exact-match.", |
| 30 | ); |
| 31 | |
| 32 | // Map the snake_case tool filter shape to the SDK's camelCase |
| 33 | // WebhookFiltersView. Returns undefined for an absent filter so we |
| 34 | // don't send an empty object. |
| 35 | const mapFilters = ( |
| 36 | f?: { agent_ids?: string[]; conversation_ids?: string[]; labels?: string[] }, |
| 37 | ): { agentIds?: string[]; conversationIds?: string[]; labels?: string[] } | undefined => { |
| 38 | if (!f) return undefined; |
| 39 | return { |
| 40 | ...(f.agent_ids !== undefined ? { agentIds: f.agent_ids } : {}), |
| 41 | ...(f.conversation_ids !== undefined ? { conversationIds: f.conversation_ids } : {}), |
| 42 | ...(f.labels !== undefined ? { labels: f.labels } : {}), |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | server.registerTool( |
| 47 | "list_webhooks", |
| 48 | { |
| 49 | title: "List webhook subscribers", |
| 50 | annotations: { readOnlyHint: true }, |
| 51 | description: |
| 52 | "Returns every webhook subscriber owned by the authenticated user, enabled + disabled, with their event subscriptions, filters, and last-delivered timestamp. signing_secret is omitted (it is only ever returned on create + rotate). Read-only; cheap.", |
| 53 | inputSchema: strictInputSchema({}), |
| 54 | }, |
| 55 | async () => runTool(async () => ({ webhooks: await client.listWebhooks() })), |
| 56 | ); |
| 57 | |
| 58 | server.registerTool( |
| 59 | "get_webhook", |
| 60 | { |
| 61 | title: "Show one webhook subscriber", |
| 62 | annotations: { readOnlyHint: true }, |
| 63 | description: |
| 64 | "Fetch a single webhook by id. signing_secret is omitted — use rotate_webhook_secret if the secret was lost.", |
| 65 | inputSchema: strictInputSchema({ |
| 66 | id: z.string().min(1).describe("Webhook id (wh_…)."), |
| 67 | }), |
| 68 | }, |
| 69 | async (args) => runTool(() => client.getWebhook(args.id)), |
| 70 | ); |
| 71 | |
| 72 | server.registerTool( |
| 73 | "create_webhook", |
| 74 | { |
| 75 | title: "Create a webhook subscriber (returns plaintext signing_secret ONCE)", |
| 76 | annotations: { destructiveHint: false }, |
| 77 | description: |
no test coverage detected