UNPKG

domotz-mcp

Version:

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

43 lines (42 loc) 1.31 kB
import { MCPTool } from "mcp-framework"; export class BaseDomotzTool extends MCPTool { useStringify = true; apiKey; constructor() { super(); this.apiKey = process.env.DOMOTZ_API_KEY || ''; } // Override the toolCall method to handle errors properly async toolCall(request) { if (!this.apiKey) { return { content: [{ type: 'text', text: 'Error: DOMOTZ_API_KEY is not set.' }] }; } try { const result = await super.toolCall(request); // If the result contains an error type, convert it to text type if (result?.content?.[0]?.type === 'error') { return { content: [{ type: 'text', text: `Error: ${result.content[0].text}` }] }; } return result; } catch (error) { // Return errors as text content return { content: [{ type: 'text', text: `Error: ${error.message || 'An unknown error occurred'}` }] }; } } }