UNPKG

domotz-mcp

Version:

MCP server for Domotz API and BMS (Building Management System) integration with IoT device monitoring

53 lines (52 loc) 1.81 kB
import { z } from "zod"; import axios from "axios"; import { BaseDomotzTool } from "./BaseDomotzTool.js"; export default class BindWebhookTool extends BaseDomotzTool { name = "bind_webhook"; description = "Bind a webhook to a Domotz agent for receiving events"; schema = { agent_id: { type: z.number(), description: "The ID of the agent to bind the webhook to" }, webhook_url: { type: z.string().url(), description: "The webhook URL to receive events" }, events: { type: z.array(z.string()).optional(), description: "Array of event types to subscribe to (optional, defaults to all events)" } }; async execute(input) { const apiKey = process.env.DOMOTZ_API_KEY; const apiEndpoint = process.env.DOMOTZ_API_ENDPOINT || "https://api-eu-west-1-cell-1.domotz.com/public-api/v1/"; if (!apiKey) { throw new Error("DOMOTZ_API_KEY environment variable is not set"); } try { const response = await axios.post(`${apiEndpoint}agent/${input.agent_id}/webhook`, { url: input.webhook_url, events: input.events }, { headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" } }); return { success: true, message: "Webhook bound successfully", data: response.data }; } catch (error) { return { success: false, error: error.message, status: error.response?.status, data: error.response?.data }; } } }