@sanlim/home-assistant-switch-mcp-server
Version:
A MCP server for Home Assistant switch services.
29 lines (28 loc) • 1.09 kB
JavaScript
import { z } from "zod";
import { BaseToolsController } from "./base/BaseToolsController.js";
export class HomeAssistantSwitchToolsController extends BaseToolsController {
service;
constructor(server, service) {
super(server);
this.service = service;
}
registerTools() {
this.registerSwitchServiceHandler();
}
registerSwitchServiceHandler() {
this.server.tool("home-assistant-switch", "Controls Home Assistant switches by turning them on or off", {
entity_id: z.string().describe("The entity ID of the switch to control (e.g., 'switch.living_room_light')"),
service: z.enum(['turn_on', 'turn_off']).describe("The service to call: 'turn_on' or 'turn_off'"),
}, async ({ entity_id, service }) => {
const text = await this.service.callSwitchService({ entity_id, service });
return {
content: [
{
type: "text",
text: text,
},
],
};
});
}
}