unsubscribe
Cancel a persistent monitor watch by providing its ID to stop notifications.
Instructions
Cancel a persistent watch (monitor). Use the monitor ID returned from subscribe.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| monitorId | Yes | Monitor ID from subscribe (e.g., 'mon_...') |
Implementation Reference
- src/index.ts:838-878 (registration)The tool 'unsubscribe' is registered via server.tool() with zod schema for monitorId input.
server.tool( "unsubscribe", "Cancel a persistent watch (monitor). Use the monitor ID returned from subscribe.", { monitorId: z.string().min(1).describe("Monitor ID from subscribe (e.g., 'mon_...')"), }, async ({ monitorId }) => { log("unsubscribe", monitorId); try { const headers: Record<string, string> = {}; if (API_KEY) headers["X-API-Key"] = API_KEY; const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), 15_000); try { const res = await fetch(`${API_BASE}/api/v1/monitor?id=${encodeURIComponent(monitorId)}`, { method: "DELETE", headers, signal: controller.signal, }); if (!res.ok) { const data = await res.json(); throw new Error(data.error || `API error ${res.status}`); } return { content: [{ type: "text" as const, text: `Monitor ${monitorId} cancelled. You will no longer receive alerts for this watch.` }], }; } finally { clearTimeout(timeout); } } catch (err) { return { content: [{ type: "text" as const, text: `Error cancelling monitor: ${err instanceof Error ? err.message : String(err)}` }], isError: true, }; } } ); - src/index.ts:844-877 (handler)The async handler function for 'unsubscribe' – sends a DELETE request to /api/v1/monitor with the monitorId and returns a cancellation message.
async ({ monitorId }) => { log("unsubscribe", monitorId); try { const headers: Record<string, string> = {}; if (API_KEY) headers["X-API-Key"] = API_KEY; const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), 15_000); try { const res = await fetch(`${API_BASE}/api/v1/monitor?id=${encodeURIComponent(monitorId)}`, { method: "DELETE", headers, signal: controller.signal, }); if (!res.ok) { const data = await res.json(); throw new Error(data.error || `API error ${res.status}`); } return { content: [{ type: "text" as const, text: `Monitor ${monitorId} cancelled. You will no longer receive alerts for this watch.` }], }; } finally { clearTimeout(timeout); } } catch (err) { return { content: [{ type: "text" as const, text: `Error cancelling monitor: ${err instanceof Error ? err.message : String(err)}` }], isError: true, }; } } - src/index.ts:841-843 (schema)Input schema for 'unsubscribe': a single required string parameter 'monitorId' with min length 1.
{ monitorId: z.string().min(1).describe("Monitor ID from subscribe (e.g., 'mon_...')"), },