@coffeerunhobby/mcp-ha-connect 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +1 -1
- package/README.md +24 -2
- package/dist/omadaClient/accessControl.d.ts +290 -0
- package/dist/omadaClient/accessControl.js +509 -0
- package/dist/omadaClient/accessControl.js.map +1 -0
- package/dist/omadaClient/client.d.ts +6 -1
- package/dist/omadaClient/client.js +12 -1
- package/dist/omadaClient/client.js.map +1 -1
- package/dist/omadaClient/diagnose.d.ts +68 -0
- package/dist/omadaClient/diagnose.js +164 -0
- package/dist/omadaClient/diagnose.js.map +1 -0
- package/dist/omadaClient/index.d.ts +9 -0
- package/dist/omadaClient/index.js +19 -0
- package/dist/omadaClient/index.js.map +1 -1
- package/dist/omadaClient/macGroups.d.ts +58 -0
- package/dist/omadaClient/macGroups.js +110 -0
- package/dist/omadaClient/macGroups.js.map +1 -0
- package/dist/omadaClient/serialize.d.ts +13 -0
- package/dist/omadaClient/serialize.js +29 -0
- package/dist/omadaClient/serialize.js.map +1 -0
- package/dist/omadaClient/timeRange.d.ts +41 -0
- package/dist/omadaClient/timeRange.js +109 -0
- package/dist/omadaClient/timeRange.js.map +1 -0
- package/dist/tools/infra/actions.d.ts +1 -1
- package/dist/tools/infra/actions.js +1 -1
- package/dist/tools/omada/accessControl.d.ts +151 -0
- package/dist/tools/omada/accessControl.js +158 -0
- package/dist/tools/omada/accessControl.js.map +1 -0
- package/dist/tools/omada/index.js +9 -0
- package/dist/tools/omada/index.js.map +1 -1
- package/dist/tools/omada/macGroups.d.ts +19 -0
- package/dist/tools/omada/macGroups.js +77 -0
- package/dist/tools/omada/macGroups.js.map +1 -0
- package/dist/tools/omada/namespace.js +16 -0
- package/dist/tools/omada/namespace.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -1
- package/.codex/review-rules.md +0 -16
- package/.dockerignore +0 -8
- package/.gitattributes +0 -30
- package/.github/workflows/ci.yml +0 -193
- package/AGENTS.md +0 -389
- package/Dockerfile +0 -50
- package/docker-compose.yml +0 -23
- package/docs/CHANGELOG.md +0 -341
- package/docs/COVERAGE.md +0 -219
- package/docs/QUICK_START.md +0 -240
- package/eslint.config.js +0 -33
- package/n8n/ai-agent-safety-monitor.json +0 -355
- package/openapi.json +0 -1259
- package/scripts/check-version-sync.mjs +0 -69
- package/scripts/generate-jwt.ts +0 -121
- package/src/config.ts +0 -440
- package/src/haClient/automations.ts +0 -261
- package/src/haClient/calendars.ts +0 -94
- package/src/haClient/config.ts +0 -52
- package/src/haClient/devices.ts +0 -653
- package/src/haClient/entities.ts +0 -128
- package/src/haClient/events.ts +0 -689
- package/src/haClient/history.ts +0 -73
- package/src/haClient/index.ts +0 -336
- package/src/haClient/request.ts +0 -142
- package/src/haClient/services.ts +0 -45
- package/src/haClient/states.ts +0 -60
- package/src/haClient/updates.ts +0 -58
- package/src/haClient/wsCommand.ts +0 -44
- package/src/index.ts +0 -164
- package/src/localAI/index.ts +0 -88
- package/src/localAI/prompts.ts +0 -50
- package/src/localAI/providers/base.ts +0 -120
- package/src/localAI/providers/ollama.ts +0 -78
- package/src/localAI/providers/openai.ts +0 -86
- package/src/localAI/types.ts +0 -67
- package/src/omadaClient/auth.ts +0 -178
- package/src/omadaClient/client.ts +0 -337
- package/src/omadaClient/device.ts +0 -118
- package/src/omadaClient/index.ts +0 -310
- package/src/omadaClient/network.ts +0 -284
- package/src/omadaClient/request.ts +0 -365
- package/src/omadaClient/security.ts +0 -51
- package/src/omadaClient/site.ts +0 -344
- package/src/ownerQuestions/service.ts +0 -536
- package/src/permissions/index.ts +0 -143
- package/src/resources/index.ts +0 -213
- package/src/server/auth.ts +0 -175
- package/src/server/chatFace.ts +0 -789
- package/src/server/chatSlice.ts +0 -57
- package/src/server/common.ts +0 -170
- package/src/server/eventSubscription.ts +0 -343
- package/src/server/http.ts +0 -626
- package/src/server/instructions.ts +0 -97
- package/src/server/rateLimiter.ts +0 -227
- package/src/server/stdio.ts +0 -41
- package/src/server/stream.ts +0 -205
- package/src/tools/ai/analyzeSensors.ts +0 -33
- package/src/tools/ai/index.ts +0 -20
- package/src/tools/common.ts +0 -442
- package/src/tools/homeassistant/askOwner.ts +0 -133
- package/src/tools/homeassistant/automationControls.ts +0 -66
- package/src/tools/homeassistant/calendar.ts +0 -97
- package/src/tools/homeassistant/callService.ts +0 -25
- package/src/tools/homeassistant/controlClimate.ts +0 -68
- package/src/tools/homeassistant/controlCover.ts +0 -48
- package/src/tools/homeassistant/controlFan.ts +0 -44
- package/src/tools/homeassistant/controlLight.ts +0 -38
- package/src/tools/homeassistant/controlMediaPlayer.ts +0 -50
- package/src/tools/homeassistant/createAutomation.ts +0 -35
- package/src/tools/homeassistant/deleteAutomation.ts +0 -24
- package/src/tools/homeassistant/entityAction.ts +0 -35
- package/src/tools/homeassistant/entityGuard.ts +0 -28
- package/src/tools/homeassistant/getAllSensors.ts +0 -46
- package/src/tools/homeassistant/getAutomationTrace.ts +0 -30
- package/src/tools/homeassistant/getDomainSummary.ts +0 -29
- package/src/tools/homeassistant/getEntitiesByDomain.ts +0 -56
- package/src/tools/homeassistant/getHistory.ts +0 -24
- package/src/tools/homeassistant/getState.ts +0 -24
- package/src/tools/homeassistant/getStates.ts +0 -46
- package/src/tools/homeassistant/getVersion.ts +0 -21
- package/src/tools/homeassistant/index.ts +0 -121
- package/src/tools/homeassistant/listAutomations.ts +0 -35
- package/src/tools/homeassistant/listEntities.ts +0 -44
- package/src/tools/homeassistant/listPersons.ts +0 -46
- package/src/tools/homeassistant/sceneAndScript.ts +0 -53
- package/src/tools/homeassistant/searchEntities.ts +0 -58
- package/src/tools/homeassistant/sendNotification.ts +0 -179
- package/src/tools/homeassistant/systemTools.ts +0 -52
- package/src/tools/homeassistant/triggerAutomation.ts +0 -24
- package/src/tools/index.ts +0 -78
- package/src/tools/infra/actions.ts +0 -95
- package/src/tools/infra/index.ts +0 -138
- package/src/tools/omada/blockClient.ts +0 -28
- package/src/tools/omada/cyclePoePort.ts +0 -32
- package/src/tools/omada/deleteClient.ts +0 -27
- package/src/tools/omada/disableClientRateLimit.ts +0 -23
- package/src/tools/omada/getClient.ts +0 -14
- package/src/tools/omada/getDevice.ts +0 -14
- package/src/tools/omada/getFirewallSetting.ts +0 -14
- package/src/tools/omada/getInternetInfo.ts +0 -14
- package/src/tools/omada/getLanNetworkList.ts +0 -14
- package/src/tools/omada/getLanProfileList.ts +0 -14
- package/src/tools/omada/getPortForwardingStatus.ts +0 -26
- package/src/tools/omada/getRateLimitProfiles.ts +0 -14
- package/src/tools/omada/getSiteNtpStatus.ts +0 -14
- package/src/tools/omada/getSsidDetail.ts +0 -22
- package/src/tools/omada/getSsidList.ts +0 -21
- package/src/tools/omada/getSwitchStackDetail.ts +0 -14
- package/src/tools/omada/getThreatList.ts +0 -42
- package/src/tools/omada/getWlanGroupList.ts +0 -14
- package/src/tools/omada/graph.ts +0 -187
- package/src/tools/omada/index.ts +0 -153
- package/src/tools/omada/listBlockedClients.ts +0 -17
- package/src/tools/omada/listClients.ts +0 -14
- package/src/tools/omada/listClientsActivity.ts +0 -25
- package/src/tools/omada/listClientsPastConnections.ts +0 -44
- package/src/tools/omada/listDevices.ts +0 -14
- package/src/tools/omada/listDevicesStats.ts +0 -41
- package/src/tools/omada/listMostActiveClients.ts +0 -14
- package/src/tools/omada/listSites.ts +0 -18
- package/src/tools/omada/namespace.ts +0 -1164
- package/src/tools/omada/searchDevices.ts +0 -20
- package/src/tools/omada/setClientRateLimit.ts +0 -26
- package/src/tools/omada/setClientRateLimitProfile.ts +0 -25
- package/src/tools/omada/setSiteNtpServers.ts +0 -36
- package/src/tools/omada/setSsidEnabled.ts +0 -38
- package/src/tools/omada/unblockClient.ts +0 -26
- package/src/tools/types.ts +0 -11
- package/src/tools/utils/pagination-schema.ts +0 -27
- package/src/types/ai/index.ts +0 -11
- package/src/types/ai/types.ts +0 -67
- package/src/types/homeassistant/automations.ts +0 -43
- package/src/types/homeassistant/calendars.ts +0 -26
- package/src/types/homeassistant/config.ts +0 -14
- package/src/types/homeassistant/entities.ts +0 -14
- package/src/types/homeassistant/errors.ts +0 -33
- package/src/types/homeassistant/haConfig.ts +0 -7
- package/src/types/homeassistant/history.ts +0 -13
- package/src/types/homeassistant/index.ts +0 -46
- package/src/types/homeassistant/request.ts +0 -6
- package/src/types/homeassistant/serviceCall.ts +0 -18
- package/src/types/homeassistant/states.ts +0 -58
- package/src/types/homeassistant/updates.ts +0 -28
- package/src/types/index.ts +0 -12
- package/src/types/omada/activeClientInfo.ts +0 -17
- package/src/types/omada/clientActivity.ts +0 -32
- package/src/types/omada/clientBlockStatus.ts +0 -11
- package/src/types/omada/clientPastConnection.ts +0 -82
- package/src/types/omada/index.ts +0 -14
- package/src/types/omada/omadaApiResponse.ts +0 -5
- package/src/types/omada/omadaClientInfo.ts +0 -11
- package/src/types/omada/omadaDeviceInfo.ts +0 -11
- package/src/types/omada/omadaDeviceStats.ts +0 -31
- package/src/types/omada/omadaSiteSummary.ts +0 -5
- package/src/types/omada/oswStackDetail.ts +0 -11
- package/src/types/omada/paginatedResult.ts +0 -6
- package/src/types/omada/rateLimitProfile.ts +0 -58
- package/src/types/omada/threatInfo.ts +0 -38
- package/src/types/omada/tokenResult.ts +0 -6
- package/src/types.ts +0 -2
- package/src/utils/config-validations.ts +0 -68
- package/src/utils/jwt.ts +0 -112
- package/src/utils/logger.ts +0 -121
- package/src/utils/plainText.ts +0 -48
- package/src/utils/redact.ts +0 -59
- package/src/utils/sanitizeError.ts +0 -18
- package/src/utils/tlsDispatcher.ts +0 -69
- package/src/version.ts +0 -5
- package/tests/bdd/automation-creation.spec.ts +0 -214
- package/tests/bdd/automation-management.spec.ts +0 -267
- package/tests/bdd/calendar.spec.ts +0 -190
- package/tests/bdd/configuration.spec.ts +0 -283
- package/tests/bdd/device-control.spec.ts +0 -344
- package/tests/bdd/entity-listing.spec.ts +0 -208
- package/tests/bdd/entity-search.spec.ts +0 -183
- package/tests/bdd/history-retrieval.spec.ts +0 -195
- package/tests/bdd/notifications.spec.ts +0 -238
- package/tests/bdd/service-calls.spec.ts +0 -144
- package/tests/bdd/state-retrieval.spec.ts +0 -204
- package/tests/bench/hotpaths.bench.ts +0 -68
- package/tests/config.test.ts +0 -355
- package/tests/features/automation-creation.feature +0 -36
- package/tests/features/automation-management.feature +0 -54
- package/tests/features/calendar.feature +0 -37
- package/tests/features/configuration.feature +0 -70
- package/tests/features/device-control.feature +0 -100
- package/tests/features/entity-listing.feature +0 -51
- package/tests/features/entity-search.feature +0 -44
- package/tests/features/history-retrieval.feature +0 -38
- package/tests/features/notifications.feature +0 -37
- package/tests/features/service-calls.feature +0 -35
- package/tests/features/state-retrieval.feature +0 -37
- package/tests/fixtures/openapi-default-slice.json +0 -290
- package/tests/haClient/automationTrace.test.ts +0 -59
- package/tests/haClient/automations.test.ts +0 -149
- package/tests/haClient/config.test.ts +0 -117
- package/tests/haClient/entities.test.ts +0 -188
- package/tests/haClient/events.test.ts +0 -455
- package/tests/haClient/eventsTls.test.ts +0 -52
- package/tests/haClient/history.test.ts +0 -228
- package/tests/haClient/index.test.ts +0 -243
- package/tests/haClient/request.test.ts +0 -217
- package/tests/haClient/services.test.ts +0 -120
- package/tests/haClient/states.test.ts +0 -119
- package/tests/haClient/updates.test.ts +0 -193
- package/tests/index.test.ts +0 -160
- package/tests/integration/homeassistant.test.ts +0 -144
- package/tests/integration/omada.test.ts +0 -167
- package/tests/integration/server.test.ts +0 -151
- package/tests/localAI/index.test.ts +0 -177
- package/tests/localAI/ollama.test.ts +0 -187
- package/tests/localAI/openai.test.ts +0 -257
- package/tests/omadaClient/actions.test.ts +0 -161
- package/tests/omadaClient/clientBlocks.test.ts +0 -170
- package/tests/omadaClient/ntp.test.ts +0 -381
- package/tests/omadaClient/site.test.ts +0 -37
- package/tests/ownerQuestions/service.test.ts +0 -499
- package/tests/ownerQuestions/tools.test.ts +0 -186
- package/tests/permissions/index.test.ts +0 -217
- package/tests/resources/index.test.ts +0 -288
- package/tests/scripts/generateJwt.test.ts +0 -44
- package/tests/security/accessControl.test.ts +0 -223
- package/tests/security/authentication.test.ts +0 -117
- package/tests/security/configuration.test.ts +0 -170
- package/tests/security/cryptoTransport.test.ts +0 -172
- package/tests/security/dependencies.test.ts +0 -152
- package/tests/security/injection.test.ts +0 -117
- package/tests/security/insecureDesign.test.ts +0 -121
- package/tests/security/logging.test.ts +0 -131
- package/tests/security/resourceConsumption.test.ts +0 -142
- package/tests/server/auth.test.ts +0 -249
- package/tests/server/chatFace.test.ts +0 -320
- package/tests/server/common.test.ts +0 -84
- package/tests/server/http.test.ts +0 -561
- package/tests/server/instructions.test.ts +0 -152
- package/tests/server/memoizeJsonSchema.test.ts +0 -71
- package/tests/server/stdio.test.ts +0 -99
- package/tests/server/stream.test.ts +0 -285
- package/tests/server/toolVisibility.http.test.ts +0 -111
- package/tests/server/toolVisibility.test.ts +0 -129
- package/tests/tools/ai/analyzeSensors.test.ts +0 -227
- package/tests/tools/common.test.ts +0 -123
- package/tests/tools/homeassistant/handlers.test.ts +0 -872
- package/tests/tools/infra/invokeAction.test.ts +0 -280
- package/tests/tools/omada/graph.test.ts +0 -385
- package/tests/tools/omada/handlers.test.ts +0 -897
- package/tests/tools/omada/namespace.test.ts +0 -483
- package/tests/tools/registry.test.ts +0 -168
- package/tests/utils/config-validations.test.ts +0 -352
- package/tests/utils/jwt.test.ts +0 -115
- package/tests/utils/logger.test.ts +0 -327
- package/tests/utils/redact.test.ts +0 -105
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -38
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calendar tools - List calendars and get calendar events
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { listCalendarsSchema, getCalendarEventsSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import type { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
type GetCalendarEventsArgs = z.infer<typeof getCalendarEventsSchema>;
|
|
11
|
-
|
|
12
|
-
export function registerListCalendarsTool(server: McpServer, client: HaClient): void {
|
|
13
|
-
server.registerTool(
|
|
14
|
-
'listCalendars',
|
|
15
|
-
{
|
|
16
|
-
description: 'List all calendar entities in Home Assistant. Returns calendar names and their current state.',
|
|
17
|
-
inputSchema: listCalendarsSchema,
|
|
18
|
-
},
|
|
19
|
-
wrapToolHandler('listCalendars', async () => {
|
|
20
|
-
const calendars = await client.getCalendars();
|
|
21
|
-
return toToolResult({
|
|
22
|
-
count: calendars.length,
|
|
23
|
-
calendars,
|
|
24
|
-
});
|
|
25
|
-
}, Permission.QUERY)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function registerGetCalendarEventsTool(server: McpServer, client: HaClient): void {
|
|
30
|
-
server.registerTool(
|
|
31
|
-
'getCalendarEvents',
|
|
32
|
-
{
|
|
33
|
-
description: `Get events from one or all Home Assistant calendars.
|
|
34
|
-
|
|
35
|
-
Examples:
|
|
36
|
-
- All calendars, next 30 days: {}
|
|
37
|
-
- Specific calendar: { entity_id: "calendar.family" }
|
|
38
|
-
- Next 7 days: { days: 7 }
|
|
39
|
-
- Date range: { start_date: "2026-01-01", end_date: "2026-01-31" }
|
|
40
|
-
- Specific calendar + date range: { entity_id: "calendar.work", start_date: "2026-02-01", days: 14 }`,
|
|
41
|
-
inputSchema: getCalendarEventsSchema,
|
|
42
|
-
},
|
|
43
|
-
wrapToolHandler('getCalendarEvents', async (args: GetCalendarEventsArgs) => {
|
|
44
|
-
// Parse dates
|
|
45
|
-
const startDate = args.start_date ? new Date(args.start_date) : new Date();
|
|
46
|
-
|
|
47
|
-
let endDate: Date;
|
|
48
|
-
if (args.days) {
|
|
49
|
-
endDate = new Date(startDate.getTime() + args.days * 24 * 60 * 60 * 1000);
|
|
50
|
-
} else if (args.end_date) {
|
|
51
|
-
endDate = new Date(args.end_date);
|
|
52
|
-
} else {
|
|
53
|
-
// Default: 30 days from start
|
|
54
|
-
endDate = new Date(startDate.getTime() + 30 * 24 * 60 * 60 * 1000);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (args.entity_id) {
|
|
58
|
-
// Get events from specific calendar
|
|
59
|
-
const events = await client.getCalendarEvents(args.entity_id, startDate, endDate);
|
|
60
|
-
return toToolResult({
|
|
61
|
-
calendar: args.entity_id,
|
|
62
|
-
start: startDate.toISOString(),
|
|
63
|
-
end: endDate.toISOString(),
|
|
64
|
-
count: events.length,
|
|
65
|
-
events: events.map(e => ({
|
|
66
|
-
summary: e.summary,
|
|
67
|
-
start: e.start.dateTime || e.start.date,
|
|
68
|
-
end: e.end.dateTime || e.end.date,
|
|
69
|
-
description: e.description,
|
|
70
|
-
location: e.location,
|
|
71
|
-
})),
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
// Get events from all calendars
|
|
75
|
-
const allEvents = await client.getAllCalendarEvents(startDate, endDate);
|
|
76
|
-
const totalCount = allEvents.reduce((sum, cal) => sum + cal.events.length, 0);
|
|
77
|
-
|
|
78
|
-
return toToolResult({
|
|
79
|
-
start: startDate.toISOString(),
|
|
80
|
-
end: endDate.toISOString(),
|
|
81
|
-
total_count: totalCount,
|
|
82
|
-
calendars: allEvents.map(cal => ({
|
|
83
|
-
calendar: cal.calendar,
|
|
84
|
-
count: cal.events.length,
|
|
85
|
-
events: cal.events.map(e => ({
|
|
86
|
-
summary: e.summary,
|
|
87
|
-
start: e.start.dateTime || e.start.date,
|
|
88
|
-
end: e.end.dateTime || e.end.date,
|
|
89
|
-
description: e.description,
|
|
90
|
-
location: e.location,
|
|
91
|
-
})),
|
|
92
|
-
})),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}, Permission.QUERY)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* callService tool - Call a Home Assistant service
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import type { ServiceCallData } from '../../types/index.js';
|
|
8
|
-
import { serviceCallSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
9
|
-
|
|
10
|
-
export function registerCallServiceTool(server: McpServer, client: HaClient): void {
|
|
11
|
-
server.registerTool(
|
|
12
|
-
'callService',
|
|
13
|
-
{
|
|
14
|
-
description: 'Call a Home Assistant service (e.g., turn on a light, set temperature).',
|
|
15
|
-
inputSchema: serviceCallSchema,
|
|
16
|
-
},
|
|
17
|
-
wrapToolHandler('callService', async (args: ServiceCallData) => {
|
|
18
|
-
if (!args.domain || !args.service) {
|
|
19
|
-
return toToolResult({ error: 'domain and service are required' }, true);
|
|
20
|
-
}
|
|
21
|
-
const result = await client.callService(args);
|
|
22
|
-
return toToolResult({ success: true, context: result.context });
|
|
23
|
-
}, Permission.CONTROL)
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* controlClimate tool - Control climate/thermostat devices
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { controlClimateSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type ControlClimateArgs = z.infer<typeof controlClimateSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerControlClimateTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'controlClimate',
|
|
16
|
-
{
|
|
17
|
-
description: 'Control a climate/thermostat device with temperature and mode settings.',
|
|
18
|
-
inputSchema: controlClimateSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('controlClimate', async (args: ControlClimateArgs) => {
|
|
21
|
-
const missing = await entityNotFoundResult(client, args.entity_id);
|
|
22
|
-
if (missing) return missing;
|
|
23
|
-
const results: unknown[] = [];
|
|
24
|
-
|
|
25
|
-
if (args.hvac_mode !== undefined) {
|
|
26
|
-
const result = await client.callService({
|
|
27
|
-
domain: 'climate',
|
|
28
|
-
service: 'set_hvac_mode',
|
|
29
|
-
target: { entity_id: args.entity_id },
|
|
30
|
-
service_data: { hvac_mode: args.hvac_mode },
|
|
31
|
-
});
|
|
32
|
-
results.push({ action: 'set_hvac_mode', hvac_mode: args.hvac_mode, context: result.context });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (args.temperature !== undefined) {
|
|
36
|
-
const result = await client.callService({
|
|
37
|
-
domain: 'climate',
|
|
38
|
-
service: 'set_temperature',
|
|
39
|
-
target: { entity_id: args.entity_id },
|
|
40
|
-
service_data: { temperature: args.temperature },
|
|
41
|
-
});
|
|
42
|
-
results.push({ action: 'set_temperature', temperature: args.temperature, context: result.context });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (args.fan_mode !== undefined) {
|
|
46
|
-
const result = await client.callService({
|
|
47
|
-
domain: 'climate',
|
|
48
|
-
service: 'set_fan_mode',
|
|
49
|
-
target: { entity_id: args.entity_id },
|
|
50
|
-
service_data: { fan_mode: args.fan_mode },
|
|
51
|
-
});
|
|
52
|
-
results.push({ action: 'set_fan_mode', fan_mode: args.fan_mode, context: result.context });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (args.preset_mode !== undefined) {
|
|
56
|
-
const result = await client.callService({
|
|
57
|
-
domain: 'climate',
|
|
58
|
-
service: 'set_preset_mode',
|
|
59
|
-
target: { entity_id: args.entity_id },
|
|
60
|
-
service_data: { preset_mode: args.preset_mode },
|
|
61
|
-
});
|
|
62
|
-
results.push({ action: 'set_preset_mode', preset_mode: args.preset_mode, context: result.context });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return toToolResult({ success: true, entity_id: args.entity_id, actions: results });
|
|
66
|
-
}, Permission.CONTROL)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* controlCover tool - Control covers/blinds
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { controlCoverSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type ControlCoverArgs = z.infer<typeof controlCoverSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerControlCoverTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'controlCover',
|
|
16
|
-
{
|
|
17
|
-
description: 'Control a cover/blind with position and tilt settings.',
|
|
18
|
-
inputSchema: controlCoverSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('controlCover', async (args: ControlCoverArgs) => {
|
|
21
|
-
const missing = await entityNotFoundResult(client, args.entity_id);
|
|
22
|
-
if (missing) return missing;
|
|
23
|
-
const actionMap: Record<string, string> = {
|
|
24
|
-
open: 'open_cover',
|
|
25
|
-
close: 'close_cover',
|
|
26
|
-
stop: 'stop_cover',
|
|
27
|
-
set_position: 'set_cover_position',
|
|
28
|
-
set_tilt: 'set_cover_tilt_position',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const serviceData: Record<string, unknown> = {};
|
|
32
|
-
if (args.action === 'set_position' && args.position !== undefined) {
|
|
33
|
-
serviceData.position = args.position;
|
|
34
|
-
}
|
|
35
|
-
if (args.action === 'set_tilt' && args.tilt_position !== undefined) {
|
|
36
|
-
serviceData.tilt_position = args.tilt_position;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const result = await client.callService({
|
|
40
|
-
domain: 'cover',
|
|
41
|
-
service: actionMap[args.action] || args.action,
|
|
42
|
-
target: { entity_id: args.entity_id },
|
|
43
|
-
service_data: Object.keys(serviceData).length > 0 ? serviceData : undefined,
|
|
44
|
-
});
|
|
45
|
-
return toToolResult({ success: true, entity_id: args.entity_id, action: args.action, context: result.context });
|
|
46
|
-
}, Permission.CONTROL)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* controlFan tool - Control fans
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { controlFanSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type ControlFanArgs = z.infer<typeof controlFanSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerControlFanTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'controlFan',
|
|
16
|
-
{
|
|
17
|
-
description: 'Control a fan with speed, oscillation, and direction settings.',
|
|
18
|
-
inputSchema: controlFanSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('controlFan', async (args: ControlFanArgs) => {
|
|
21
|
-
const missing = await entityNotFoundResult(client, args.entity_id);
|
|
22
|
-
if (missing) return missing;
|
|
23
|
-
let service: string = args.action;
|
|
24
|
-
const serviceData: Record<string, unknown> = {};
|
|
25
|
-
|
|
26
|
-
if (args.action === 'set_speed') {
|
|
27
|
-
service = 'set_percentage';
|
|
28
|
-
if (args.percentage !== undefined) serviceData.percentage = args.percentage;
|
|
29
|
-
} else if (args.action === 'oscillate') {
|
|
30
|
-
if (args.oscillating !== undefined) serviceData.oscillating = args.oscillating;
|
|
31
|
-
} else if (args.action === 'set_direction') {
|
|
32
|
-
if (args.direction !== undefined) serviceData.direction = args.direction;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const result = await client.callService({
|
|
36
|
-
domain: 'fan',
|
|
37
|
-
service,
|
|
38
|
-
target: { entity_id: args.entity_id },
|
|
39
|
-
service_data: Object.keys(serviceData).length > 0 ? serviceData : undefined,
|
|
40
|
-
});
|
|
41
|
-
return toToolResult({ success: true, entity_id: args.entity_id, action: args.action, context: result.context });
|
|
42
|
-
}, Permission.CONTROL)
|
|
43
|
-
);
|
|
44
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* controlLight tool - Control lights with advanced options
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { controlLightSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type ControlLightArgs = z.infer<typeof controlLightSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerControlLightTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'controlLight',
|
|
16
|
-
{
|
|
17
|
-
description: 'Control a light with advanced options like brightness, color, and color temperature.',
|
|
18
|
-
inputSchema: controlLightSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('controlLight', async (args: ControlLightArgs) => {
|
|
21
|
-
const missing = await entityNotFoundResult(client, args.entity_id);
|
|
22
|
-
if (missing) return missing;
|
|
23
|
-
const serviceData: Record<string, unknown> = {};
|
|
24
|
-
if (args.brightness_pct !== undefined) serviceData.brightness_pct = args.brightness_pct;
|
|
25
|
-
if (args.color_temp_kelvin !== undefined) serviceData.color_temp_kelvin = args.color_temp_kelvin;
|
|
26
|
-
if (args.rgb_color !== undefined) serviceData.rgb_color = args.rgb_color;
|
|
27
|
-
if (args.transition !== undefined) serviceData.transition = args.transition;
|
|
28
|
-
|
|
29
|
-
const result = await client.callService({
|
|
30
|
-
domain: 'light',
|
|
31
|
-
service: args.action,
|
|
32
|
-
target: { entity_id: args.entity_id },
|
|
33
|
-
service_data: Object.keys(serviceData).length > 0 ? serviceData : undefined,
|
|
34
|
-
});
|
|
35
|
-
return toToolResult({ success: true, entity_id: args.entity_id, action: args.action, settings: serviceData, context: result.context });
|
|
36
|
-
}, Permission.CONTROL)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* controlMediaPlayer tool - Control media players
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { controlMediaPlayerSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type ControlMediaPlayerArgs = z.infer<typeof controlMediaPlayerSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerControlMediaPlayerTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'controlMediaPlayer',
|
|
16
|
-
{
|
|
17
|
-
description: 'Control a media player with playback, volume, and media selection.',
|
|
18
|
-
inputSchema: controlMediaPlayerSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('controlMediaPlayer', async (args: ControlMediaPlayerArgs) => {
|
|
21
|
-
const missing = await entityNotFoundResult(client, args.entity_id);
|
|
22
|
-
if (missing) return missing;
|
|
23
|
-
const actionMap: Record<string, string> = {
|
|
24
|
-
play: 'media_play',
|
|
25
|
-
pause: 'media_pause',
|
|
26
|
-
stop: 'media_stop',
|
|
27
|
-
next: 'media_next_track',
|
|
28
|
-
previous: 'media_previous_track',
|
|
29
|
-
volume_set: 'volume_set',
|
|
30
|
-
volume_mute: 'volume_mute',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const serviceData: Record<string, unknown> = {};
|
|
34
|
-
if (args.action === 'volume_set' && args.volume_level !== undefined) {
|
|
35
|
-
serviceData.volume_level = args.volume_level;
|
|
36
|
-
}
|
|
37
|
-
if (args.action === 'volume_mute' && args.is_volume_muted !== undefined) {
|
|
38
|
-
serviceData.is_volume_muted = args.is_volume_muted;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const result = await client.callService({
|
|
42
|
-
domain: 'media_player',
|
|
43
|
-
service: actionMap[args.action] || args.action,
|
|
44
|
-
target: { entity_id: args.entity_id },
|
|
45
|
-
service_data: Object.keys(serviceData).length > 0 ? serviceData : undefined,
|
|
46
|
-
});
|
|
47
|
-
return toToolResult({ success: true, entity_id: args.entity_id, action: args.action, context: result.context });
|
|
48
|
-
}, Permission.CONTROL)
|
|
49
|
-
);
|
|
50
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createAutomation tool - Create a new automation
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import type { AutomationTrigger, AutomationCondition, AutomationAction } from '../../types/index.js';
|
|
8
|
-
import { createAutomationSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type CreateAutomationArgs = z.infer<typeof createAutomationSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerCreateAutomationTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'createAutomation',
|
|
16
|
-
{
|
|
17
|
-
description: 'Create a new Home Assistant automation. Requires specifying triggers, conditions (optional), and actions.',
|
|
18
|
-
inputSchema: createAutomationSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('createAutomation', async (args: CreateAutomationArgs) => {
|
|
21
|
-
if (!args.alias || !args.trigger || !args.action) {
|
|
22
|
-
return toToolResult({ error: 'alias, trigger, and action are required' }, true);
|
|
23
|
-
}
|
|
24
|
-
const result = await client.createAutomation({
|
|
25
|
-
alias: args.alias,
|
|
26
|
-
description: args.description,
|
|
27
|
-
mode: args.mode,
|
|
28
|
-
trigger: args.trigger as AutomationTrigger | AutomationTrigger[],
|
|
29
|
-
condition: args.condition as AutomationCondition | AutomationCondition[] | undefined,
|
|
30
|
-
action: args.action as AutomationAction | AutomationAction[],
|
|
31
|
-
});
|
|
32
|
-
return toToolResult({ success: true, automation_id: result.id, alias: args.alias, message: 'Automation created successfully' });
|
|
33
|
-
}, Permission.CONFIGURE)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* deleteAutomation tool - Delete an automation
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { automationIdSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import type { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
type DeleteAutomationArgs = z.infer<typeof automationIdSchema>;
|
|
11
|
-
|
|
12
|
-
export function registerDeleteAutomationTool(server: McpServer, client: HaClient): void {
|
|
13
|
-
server.registerTool(
|
|
14
|
-
'deleteAutomation',
|
|
15
|
-
{
|
|
16
|
-
description: 'Delete a Home Assistant automation. Only works for automations created via the UI/API.',
|
|
17
|
-
inputSchema: automationIdSchema,
|
|
18
|
-
},
|
|
19
|
-
wrapToolHandler('deleteAutomation', async ({ automation_id }: DeleteAutomationArgs) => {
|
|
20
|
-
await client.deleteAutomation(automation_id);
|
|
21
|
-
return toToolResult({ success: true, automation_id, message: 'Automation deleted successfully' });
|
|
22
|
-
}, Permission.CONFIGURE)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* entityAction tool - Simple entity actions (turn_on, turn_off, toggle)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { entityActionSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
import { entityNotFoundResult } from './entityGuard.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
type EntityActionArgs = z.infer<typeof entityActionSchema>;
|
|
12
|
-
|
|
13
|
-
export function registerEntityActionTool(server: McpServer, client: HaClient): void {
|
|
14
|
-
server.registerTool(
|
|
15
|
-
'entityAction',
|
|
16
|
-
{
|
|
17
|
-
description: 'Perform a simple action on an entity (turn_on, turn_off, toggle). Automatically detects the domain.',
|
|
18
|
-
inputSchema: entityActionSchema,
|
|
19
|
-
},
|
|
20
|
-
wrapToolHandler('entityAction', async ({ entity_id, action }: EntityActionArgs) => {
|
|
21
|
-
const domain = entity_id.split('.')[0];
|
|
22
|
-
if (!domain) {
|
|
23
|
-
return toToolResult({ error: 'Invalid entity_id format', hint: 'entity_id must be in domain.name format such as light.living_room — use the searchEntities tool to discover valid entity IDs' }, true);
|
|
24
|
-
}
|
|
25
|
-
const missing = await entityNotFoundResult(client, entity_id);
|
|
26
|
-
if (missing) return missing;
|
|
27
|
-
const result = await client.callService({
|
|
28
|
-
domain,
|
|
29
|
-
service: action,
|
|
30
|
-
target: { entity_id },
|
|
31
|
-
});
|
|
32
|
-
return toToolResult({ success: true, entity_id, action, context: result.context });
|
|
33
|
-
}, Permission.CONTROL)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Existence guard for entity-targeted control tools.
|
|
3
|
-
*
|
|
4
|
-
* Home Assistant silently ignores service calls whose target entity_id does not
|
|
5
|
-
* exist: the call returns 200 with an empty change list. Without this guard the
|
|
6
|
-
* tool would report `success: true` for an action that never happened, so an
|
|
7
|
-
* LLM client would believe a typo'd light was switched on.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
11
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
12
|
-
import { toToolResult } from '../common.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Returns an error result when `entityId` does not exist in Home Assistant,
|
|
16
|
-
* or `null` when it does (the caller should then proceed with the action).
|
|
17
|
-
*/
|
|
18
|
-
export async function entityNotFoundResult(client: HaClient, entityId: string): Promise<CallToolResult | null> {
|
|
19
|
-
const state = await client.getState(entityId);
|
|
20
|
-
if (state) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return toToolResult({
|
|
24
|
-
error: 'Entity not found',
|
|
25
|
-
entity_id: entityId,
|
|
26
|
-
hint: 'No action was performed. Use the searchEntities tool with a keyword to find the correct entity_id',
|
|
27
|
-
}, true);
|
|
28
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getAllSensors tool - Get all sensor entities
|
|
3
|
-
* Returns paginated, lightweight entities by default to reduce response size.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
7
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
8
|
-
import { toLightweight } from '../../types/index.js';
|
|
9
|
-
import { haPaginationSchema, toToolResult, wrapToolHandler, Permission, paginateArray } from '../common.js';
|
|
10
|
-
|
|
11
|
-
export function registerGetAllSensorsTool(server: McpServer, client: HaClient): void {
|
|
12
|
-
server.registerTool(
|
|
13
|
-
'getAllSensors',
|
|
14
|
-
{
|
|
15
|
-
description: 'Get all sensor states from Home Assistant (sensor.* and binary_sensor.* entities). Returns paginated lightweight entities by default (50 per page). Use includeAttributes=true for full entity data.',
|
|
16
|
-
inputSchema: haPaginationSchema,
|
|
17
|
-
},
|
|
18
|
-
wrapToolHandler('getAllSensors', async (args) => {
|
|
19
|
-
const { page, pageSize, includeAttributes } = args;
|
|
20
|
-
const sensors = await client.getAllSensors();
|
|
21
|
-
|
|
22
|
-
if (includeAttributes) {
|
|
23
|
-
// Return full entities with all attributes
|
|
24
|
-
const result = paginateArray(sensors, page, pageSize);
|
|
25
|
-
return toToolResult({
|
|
26
|
-
page: result.page,
|
|
27
|
-
pageSize: result.pageSize,
|
|
28
|
-
totalCount: result.totalCount,
|
|
29
|
-
totalPages: result.totalPages,
|
|
30
|
-
entities: result.items,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Default: return lightweight entities
|
|
35
|
-
const lightweight = sensors.map(toLightweight);
|
|
36
|
-
const result = paginateArray(lightweight, page, pageSize);
|
|
37
|
-
return toToolResult({
|
|
38
|
-
page: result.page,
|
|
39
|
-
pageSize: result.pageSize,
|
|
40
|
-
totalCount: result.totalCount,
|
|
41
|
-
totalPages: result.totalPages,
|
|
42
|
-
entities: result.items,
|
|
43
|
-
});
|
|
44
|
-
}, Permission.QUERY)
|
|
45
|
-
);
|
|
46
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getAutomationTrace tool - Get automation execution history
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
8
|
-
import { entityIdSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
9
|
-
|
|
10
|
-
export const getAutomationTraceSchema = entityIdSchema.extend({
|
|
11
|
-
limit: z.number().int().min(1).max(20).optional().describe('How many of the most recent runs to return (default 5, max 20)'),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
type GetAutomationTraceArgs = z.infer<typeof getAutomationTraceSchema>;
|
|
15
|
-
|
|
16
|
-
export function registerGetAutomationTraceTool(server: McpServer, client: HaClient): void {
|
|
17
|
-
server.registerTool(
|
|
18
|
-
'getAutomationTrace',
|
|
19
|
-
{
|
|
20
|
-
description:
|
|
21
|
-
'Get the most recent runs of an automation, newest first: when it ran, what triggered it, how it ended (state, last step, error). ' +
|
|
22
|
-
'Only automations with an id (created in the UI, or YAML with an id) have traces.',
|
|
23
|
-
inputSchema: getAutomationTraceSchema,
|
|
24
|
-
},
|
|
25
|
-
wrapToolHandler('getAutomationTrace', async ({ entity_id, limit }: GetAutomationTraceArgs) => {
|
|
26
|
-
const traces = await client.getAutomationTrace(entity_id, limit);
|
|
27
|
-
return toToolResult({ entity_id, trace_count: traces.length, traces });
|
|
28
|
-
}, Permission.QUERY)
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getDomainSummary tool - Get summary of entities in a domain
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
7
|
-
import { domainSchema, toToolResult, wrapToolHandler, Permission } from '../common.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Shared handler — used by the MCP registration below AND the chat face
|
|
11
|
-
* (`POST /api/tools/getDomainSummary`) so both doors behave identically.
|
|
12
|
-
*/
|
|
13
|
-
export function createGetDomainSummaryHandler(client: HaClient) {
|
|
14
|
-
return wrapToolHandler('getDomainSummary', async ({ domain }: { domain: string }) => {
|
|
15
|
-
const summary = await client.getDomainSummary(domain);
|
|
16
|
-
return toToolResult(summary);
|
|
17
|
-
}, Permission.QUERY);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function registerGetDomainSummaryTool(server: McpServer, client: HaClient): void {
|
|
21
|
-
server.registerTool(
|
|
22
|
-
'getDomainSummary',
|
|
23
|
-
{
|
|
24
|
-
description: 'Get a summary of entities in a domain, including counts and state breakdown.',
|
|
25
|
-
inputSchema: domainSchema,
|
|
26
|
-
},
|
|
27
|
-
createGetDomainSummaryHandler(client)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getEntitiesByDomain tool - Get all entities for a specific domain
|
|
3
|
-
* Returns paginated, lightweight entities by default to reduce response size.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
8
|
-
import type { HaClient } from '../../haClient/index.js';
|
|
9
|
-
import { toLightweight } from '../../types/index.js';
|
|
10
|
-
import { toToolResult, wrapToolHandler, Permission, paginateArray } from '../common.js';
|
|
11
|
-
|
|
12
|
-
const getEntitiesByDomainSchema = z.object({
|
|
13
|
-
domain: z.string().describe('Domain name (e.g., "light", "sensor", "switch", "climate")'),
|
|
14
|
-
page: z.number().int().min(1).default(1).describe('Page number (starts at 1)'),
|
|
15
|
-
pageSize: z.number().int().min(1).max(200).default(50).describe('Entities per page (1-200, default 50)'),
|
|
16
|
-
includeAttributes: z.boolean().default(false).describe('Include full attributes (increases response size significantly)'),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export function registerGetEntitiesByDomainTool(server: McpServer, client: HaClient): void {
|
|
20
|
-
server.registerTool(
|
|
21
|
-
'getEntitiesByDomain',
|
|
22
|
-
{
|
|
23
|
-
description: 'Get all entities for a specific domain (e.g., all lights, all sensors). Returns paginated lightweight entities by default (50 per page). Use includeAttributes=true for full entity data.',
|
|
24
|
-
inputSchema: getEntitiesByDomainSchema,
|
|
25
|
-
},
|
|
26
|
-
wrapToolHandler('getEntitiesByDomain', async (args) => {
|
|
27
|
-
const { domain, page, pageSize, includeAttributes } = args;
|
|
28
|
-
const allEntities = await client.getEntitiesByDomain(domain);
|
|
29
|
-
|
|
30
|
-
if (includeAttributes) {
|
|
31
|
-
// Return full entities with all attributes
|
|
32
|
-
const result = paginateArray(allEntities, page, pageSize);
|
|
33
|
-
return toToolResult({
|
|
34
|
-
domain,
|
|
35
|
-
page: result.page,
|
|
36
|
-
pageSize: result.pageSize,
|
|
37
|
-
totalCount: result.totalCount,
|
|
38
|
-
totalPages: result.totalPages,
|
|
39
|
-
entities: result.items,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Default: return lightweight entities
|
|
44
|
-
const lightweight = allEntities.map(toLightweight);
|
|
45
|
-
const result = paginateArray(lightweight, page, pageSize);
|
|
46
|
-
return toToolResult({
|
|
47
|
-
domain,
|
|
48
|
-
page: result.page,
|
|
49
|
-
pageSize: result.pageSize,
|
|
50
|
-
totalCount: result.totalCount,
|
|
51
|
-
totalPages: result.totalPages,
|
|
52
|
-
entities: result.items,
|
|
53
|
-
});
|
|
54
|
-
}, Permission.QUERY)
|
|
55
|
-
);
|
|
56
|
-
}
|