UNPKG

domotz-mcp

Version:

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

60 lines (59 loc) 2.03 kB
import { z } from "zod"; import axios from "axios"; import { BaseDomotzTool } from "./BaseDomotzTool.js"; export default class GetDomotzDataTool extends BaseDomotzTool { name = "get_domotz_data"; description = "Fetch data from the Domotz API using the configured endpoint and API key"; schema = { endpoint: { type: z.string(), description: "The API endpoint path (e.g., 'agents', 'devices', etc.)" }, method: { type: z.enum(["GET", "POST", "PUT", "DELETE"]).default("GET"), description: "HTTP method to use" }, params: { type: z.record(z.any()).optional(), description: "Query parameters for the request" }, data: { type: z.any().optional(), description: "Request body data for POST/PUT requests" } }; 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 url = `${apiEndpoint}${input.endpoint}`; const config = { method: input.method || "GET", url, headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" }, params: input.params, data: input.data }; const response = await axios(config); return { success: true, data: response.data, status: response.status }; } catch (error) { return { success: false, error: error.message, status: error.response?.status, data: error.response?.data }; } } }