refactor: optimize configuration and tool implementations
- Standardized error handling across tool implementations - Improved return type consistency for tool execution results - Simplified configuration parsing and type definitions - Enhanced type safety for various configuration schemas - Cleaned up and normalized tool response structures - Updated SSE and event subscription tool implementations
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Interface for a tool that can be executed by the MCP
|
||||
* @interface Tool
|
||||
*/
|
||||
export interface Tool {
|
||||
/** Unique name identifier for the tool */
|
||||
name: string;
|
||||
/** Description of what the tool does */
|
||||
description: string;
|
||||
/** Zod schema for validating tool parameters */
|
||||
parameters: z.ZodType<any>;
|
||||
/** Function to execute the tool with the given parameters */
|
||||
execute: (params: any) => Promise<any>;
|
||||
/** Unique name identifier for the tool */
|
||||
name: string;
|
||||
/** Description of what the tool does */
|
||||
description: string;
|
||||
/** Zod schema for validating tool parameters */
|
||||
parameters: z.ZodType<any>;
|
||||
/** Function to execute the tool with the given parameters */
|
||||
execute: (params: any) => Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,26 +20,26 @@ export interface Tool {
|
||||
* @interface CommandParams
|
||||
*/
|
||||
export interface CommandParams {
|
||||
/** Command to execute (e.g., turn_on, turn_off) */
|
||||
command: string;
|
||||
/** Entity ID to control */
|
||||
entity_id: string;
|
||||
/** Common parameters */
|
||||
state?: string;
|
||||
/** Light parameters */
|
||||
brightness?: number;
|
||||
color_temp?: number;
|
||||
rgb_color?: [number, number, number];
|
||||
/** Cover parameters */
|
||||
position?: number;
|
||||
tilt_position?: number;
|
||||
/** Climate parameters */
|
||||
temperature?: number;
|
||||
target_temp_high?: number;
|
||||
target_temp_low?: number;
|
||||
hvac_mode?: string;
|
||||
fan_mode?: string;
|
||||
humidity?: number;
|
||||
/** Command to execute (e.g., turn_on, turn_off) */
|
||||
command: string;
|
||||
/** Entity ID to control */
|
||||
entity_id: string;
|
||||
/** Common parameters */
|
||||
state?: string;
|
||||
/** Light parameters */
|
||||
brightness?: number;
|
||||
color_temp?: number;
|
||||
rgb_color?: [number, number, number];
|
||||
/** Cover parameters */
|
||||
position?: number;
|
||||
tilt_position?: number;
|
||||
/** Climate parameters */
|
||||
temperature?: number;
|
||||
target_temp_high?: number;
|
||||
target_temp_low?: number;
|
||||
hvac_mode?: string;
|
||||
fan_mode?: string;
|
||||
humidity?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,22 +47,22 @@ export interface CommandParams {
|
||||
* @interface HassEntity
|
||||
*/
|
||||
export interface HassEntity {
|
||||
/** Entity ID in format domain.name */
|
||||
entity_id: string;
|
||||
/** Current state of the entity */
|
||||
state: string;
|
||||
/** Entity attributes */
|
||||
attributes: Record<string, any>;
|
||||
/** Last state change timestamp */
|
||||
last_changed?: string;
|
||||
/** Last update timestamp */
|
||||
last_updated?: string;
|
||||
/** Context information */
|
||||
context?: {
|
||||
id: string;
|
||||
parent_id?: string;
|
||||
user_id?: string;
|
||||
};
|
||||
/** Entity ID in format domain.name */
|
||||
entity_id: string;
|
||||
/** Current state of the entity */
|
||||
state: string;
|
||||
/** Entity attributes */
|
||||
attributes: Record<string, any>;
|
||||
/** Last state change timestamp */
|
||||
last_changed?: string;
|
||||
/** Last update timestamp */
|
||||
last_updated?: string;
|
||||
/** Context information */
|
||||
context?: {
|
||||
id: string;
|
||||
parent_id?: string;
|
||||
user_id?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,19 +70,19 @@ export interface HassEntity {
|
||||
* @interface HassState
|
||||
*/
|
||||
export interface HassState {
|
||||
/** Entity ID in format domain.name */
|
||||
entity_id: string;
|
||||
/** Current state of the entity */
|
||||
state: string;
|
||||
/** Entity attributes */
|
||||
attributes: {
|
||||
/** Human-readable name */
|
||||
friendly_name?: string;
|
||||
/** Entity description */
|
||||
description?: string;
|
||||
/** Additional attributes */
|
||||
[key: string]: any;
|
||||
};
|
||||
/** Entity ID in format domain.name */
|
||||
entity_id: string;
|
||||
/** Current state of the entity */
|
||||
state: string;
|
||||
/** Entity attributes */
|
||||
attributes: {
|
||||
/** Human-readable name */
|
||||
friendly_name?: string;
|
||||
/** Entity description */
|
||||
description?: string;
|
||||
/** Additional attributes */
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,6 +90,41 @@ export interface HassState {
|
||||
* @interface HassAddon
|
||||
*/
|
||||
export interface HassAddon {
|
||||
/** Add-on name */
|
||||
name: string;
|
||||
/** Add-on slug identifier */
|
||||
slug: string;
|
||||
/** Add-on description */
|
||||
description: string;
|
||||
/** Add-on version */
|
||||
version: string;
|
||||
/** Whether the add-on is installed */
|
||||
installed: boolean;
|
||||
/** Whether the add-on is available */
|
||||
available: boolean;
|
||||
/** Current state of the add-on */
|
||||
state: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from Home Assistant add-on API
|
||||
* @interface HassAddonResponse
|
||||
*/
|
||||
export interface HassAddonResponse {
|
||||
/** Response data */
|
||||
data: {
|
||||
/** List of add-ons */
|
||||
addons: HassAddon[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from Home Assistant add-on info API
|
||||
* @interface HassAddonInfoResponse
|
||||
*/
|
||||
export interface HassAddonInfoResponse {
|
||||
/** Response data */
|
||||
data: {
|
||||
/** Add-on name */
|
||||
name: string;
|
||||
/** Add-on slug identifier */
|
||||
@@ -98,50 +133,15 @@ export interface HassAddon {
|
||||
description: string;
|
||||
/** Add-on version */
|
||||
version: string;
|
||||
/** Whether the add-on is installed */
|
||||
installed: boolean;
|
||||
/** Whether the add-on is available */
|
||||
available: boolean;
|
||||
/** Current state of the add-on */
|
||||
/** Current state */
|
||||
state: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from Home Assistant add-on API
|
||||
* @interface HassAddonResponse
|
||||
*/
|
||||
export interface HassAddonResponse {
|
||||
/** Response data */
|
||||
data: {
|
||||
/** List of add-ons */
|
||||
addons: HassAddon[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from Home Assistant add-on info API
|
||||
* @interface HassAddonInfoResponse
|
||||
*/
|
||||
export interface HassAddonInfoResponse {
|
||||
/** Response data */
|
||||
data: {
|
||||
/** Add-on name */
|
||||
name: string;
|
||||
/** Add-on slug identifier */
|
||||
slug: string;
|
||||
/** Add-on description */
|
||||
description: string;
|
||||
/** Add-on version */
|
||||
version: string;
|
||||
/** Current state */
|
||||
state: string;
|
||||
/** Status information */
|
||||
status: string;
|
||||
/** Add-on options */
|
||||
options: Record<string, any>;
|
||||
/** Additional properties */
|
||||
[key: string]: any;
|
||||
};
|
||||
/** Status information */
|
||||
status: string;
|
||||
/** Add-on options */
|
||||
options: Record<string, any>;
|
||||
/** Additional properties */
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,22 +149,22 @@ export interface HassAddonInfoResponse {
|
||||
* @interface HacsRepository
|
||||
*/
|
||||
export interface HacsRepository {
|
||||
/** Repository name */
|
||||
name: string;
|
||||
/** Repository description */
|
||||
description: string;
|
||||
/** Repository category */
|
||||
category: string;
|
||||
/** Whether the repository is installed */
|
||||
installed: boolean;
|
||||
/** Installed version */
|
||||
version_installed: string;
|
||||
/** Available version */
|
||||
available_version: string;
|
||||
/** Repository authors */
|
||||
authors: string[];
|
||||
/** Repository domain */
|
||||
domain: string;
|
||||
/** Repository name */
|
||||
name: string;
|
||||
/** Repository description */
|
||||
description: string;
|
||||
/** Repository category */
|
||||
category: string;
|
||||
/** Whether the repository is installed */
|
||||
installed: boolean;
|
||||
/** Installed version */
|
||||
version_installed: string;
|
||||
/** Available version */
|
||||
available_version: string;
|
||||
/** Repository authors */
|
||||
authors: string[];
|
||||
/** Repository domain */
|
||||
domain: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,8 +172,8 @@ export interface HacsRepository {
|
||||
* @interface HacsResponse
|
||||
*/
|
||||
export interface HacsResponse {
|
||||
/** List of repositories */
|
||||
repositories: HacsRepository[];
|
||||
/** List of repositories */
|
||||
repositories: HacsRepository[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,18 +181,18 @@ export interface HacsResponse {
|
||||
* @interface AutomationConfig
|
||||
*/
|
||||
export interface AutomationConfig {
|
||||
/** Automation name */
|
||||
alias: string;
|
||||
/** Automation description */
|
||||
description?: string;
|
||||
/** How multiple triggers are handled */
|
||||
mode?: 'single' | 'parallel' | 'queued' | 'restart';
|
||||
/** List of triggers */
|
||||
trigger: any[];
|
||||
/** List of conditions */
|
||||
condition?: any[];
|
||||
/** List of actions */
|
||||
action: any[];
|
||||
/** Automation name */
|
||||
alias: string;
|
||||
/** Automation description */
|
||||
description?: string;
|
||||
/** How multiple triggers are handled */
|
||||
mode?: "single" | "parallel" | "queued" | "restart";
|
||||
/** List of triggers */
|
||||
trigger: any[];
|
||||
/** List of conditions */
|
||||
condition?: any[];
|
||||
/** List of actions */
|
||||
action: any[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,8 +200,8 @@ export interface AutomationConfig {
|
||||
* @interface AutomationResponse
|
||||
*/
|
||||
export interface AutomationResponse {
|
||||
/** Created/updated automation ID */
|
||||
automation_id: string;
|
||||
/** Created/updated automation ID */
|
||||
automation_id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,8 +209,8 @@ export interface AutomationResponse {
|
||||
* @interface SSEHeaders
|
||||
*/
|
||||
export interface SSEHeaders {
|
||||
/** Callback for connection abort */
|
||||
onAbort?: () => void;
|
||||
/** Callback for connection abort */
|
||||
onAbort?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,14 +218,14 @@ export interface SSEHeaders {
|
||||
* @interface SSEParams
|
||||
*/
|
||||
export interface SSEParams {
|
||||
/** Authentication token */
|
||||
token: string;
|
||||
/** Event types to subscribe to */
|
||||
events?: string[];
|
||||
/** Entity ID to monitor */
|
||||
entity_id?: string;
|
||||
/** Domain to monitor */
|
||||
domain?: string;
|
||||
/** Authentication token */
|
||||
token: string;
|
||||
/** Event types to subscribe to */
|
||||
events?: string[];
|
||||
/** Entity ID to monitor */
|
||||
entity_id?: string;
|
||||
/** Domain to monitor */
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,16 +233,16 @@ export interface SSEParams {
|
||||
* @interface HistoryParams
|
||||
*/
|
||||
export interface HistoryParams {
|
||||
/** Entity ID to get history for */
|
||||
entity_id: string;
|
||||
/** Start time in ISO format */
|
||||
start_time?: string;
|
||||
/** End time in ISO format */
|
||||
end_time?: string;
|
||||
/** Whether to return minimal response */
|
||||
minimal_response?: boolean;
|
||||
/** Whether to only return significant changes */
|
||||
significant_changes_only?: boolean;
|
||||
/** Entity ID to get history for */
|
||||
entity_id: string;
|
||||
/** Start time in ISO format */
|
||||
start_time?: string;
|
||||
/** End time in ISO format */
|
||||
end_time?: string;
|
||||
/** Whether to return minimal response */
|
||||
minimal_response?: boolean;
|
||||
/** Whether to only return significant changes */
|
||||
significant_changes_only?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,10 +250,10 @@ export interface HistoryParams {
|
||||
* @interface SceneParams
|
||||
*/
|
||||
export interface SceneParams {
|
||||
/** Action to perform */
|
||||
action: 'list' | 'activate';
|
||||
/** Scene ID for activation */
|
||||
scene_id?: string;
|
||||
/** Action to perform */
|
||||
action: "list" | "activate";
|
||||
/** Scene ID for activation */
|
||||
scene_id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,14 +261,14 @@ export interface SceneParams {
|
||||
* @interface NotifyParams
|
||||
*/
|
||||
export interface NotifyParams {
|
||||
/** Notification message */
|
||||
message: string;
|
||||
/** Notification title */
|
||||
title?: string;
|
||||
/** Notification target */
|
||||
target?: string;
|
||||
/** Additional notification data */
|
||||
data?: Record<string, any>;
|
||||
/** Notification message */
|
||||
message: string;
|
||||
/** Notification title */
|
||||
title?: string;
|
||||
/** Notification target */
|
||||
target?: string;
|
||||
/** Additional notification data */
|
||||
data?: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,10 +276,10 @@ export interface NotifyParams {
|
||||
* @interface AutomationParams
|
||||
*/
|
||||
export interface AutomationParams {
|
||||
/** Action to perform */
|
||||
action: 'list' | 'toggle' | 'trigger';
|
||||
/** Automation ID */
|
||||
automation_id?: string;
|
||||
/** Action to perform */
|
||||
action: "list" | "toggle" | "trigger";
|
||||
/** Automation ID */
|
||||
automation_id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,12 +287,19 @@ export interface AutomationParams {
|
||||
* @interface AddonParams
|
||||
*/
|
||||
export interface AddonParams {
|
||||
/** Action to perform */
|
||||
action: 'list' | 'info' | 'install' | 'uninstall' | 'start' | 'stop' | 'restart';
|
||||
/** Add-on slug */
|
||||
slug?: string;
|
||||
/** Version to install */
|
||||
version?: string;
|
||||
/** Action to perform */
|
||||
action:
|
||||
| "list"
|
||||
| "info"
|
||||
| "install"
|
||||
| "uninstall"
|
||||
| "start"
|
||||
| "stop"
|
||||
| "restart";
|
||||
/** Add-on slug */
|
||||
slug?: string;
|
||||
/** Version to install */
|
||||
version?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,14 +307,20 @@ export interface AddonParams {
|
||||
* @interface PackageParams
|
||||
*/
|
||||
export interface PackageParams {
|
||||
/** Action to perform */
|
||||
action: 'list' | 'install' | 'uninstall' | 'update';
|
||||
/** Package category */
|
||||
category: 'integration' | 'plugin' | 'theme' | 'python_script' | 'appdaemon' | 'netdaemon';
|
||||
/** Repository URL or name */
|
||||
repository?: string;
|
||||
/** Version to install */
|
||||
version?: string;
|
||||
/** Action to perform */
|
||||
action: "list" | "install" | "uninstall" | "update";
|
||||
/** Package category */
|
||||
category:
|
||||
| "integration"
|
||||
| "plugin"
|
||||
| "theme"
|
||||
| "python_script"
|
||||
| "appdaemon"
|
||||
| "netdaemon";
|
||||
/** Repository URL or name */
|
||||
repository?: string;
|
||||
/** Version to install */
|
||||
version?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,23 +328,23 @@ export interface PackageParams {
|
||||
* @interface AutomationConfigParams
|
||||
*/
|
||||
export interface AutomationConfigParams {
|
||||
/** Action to perform */
|
||||
action: 'create' | 'update' | 'delete' | 'duplicate';
|
||||
/** Automation ID */
|
||||
automation_id?: string;
|
||||
/** Automation configuration */
|
||||
config?: {
|
||||
/** Automation name */
|
||||
alias: string;
|
||||
/** Automation description */
|
||||
description?: string;
|
||||
/** How multiple triggers are handled */
|
||||
mode?: 'single' | 'parallel' | 'queued' | 'restart';
|
||||
/** List of triggers */
|
||||
trigger: any[];
|
||||
/** List of conditions */
|
||||
condition?: any[];
|
||||
/** List of actions */
|
||||
action: any[];
|
||||
};
|
||||
}
|
||||
/** Action to perform */
|
||||
action: "create" | "update" | "delete" | "duplicate";
|
||||
/** Automation ID */
|
||||
automation_id?: string;
|
||||
/** Automation configuration */
|
||||
config?: {
|
||||
/** Automation name */
|
||||
alias: string;
|
||||
/** Automation description */
|
||||
description?: string;
|
||||
/** How multiple triggers are handled */
|
||||
mode?: "single" | "parallel" | "queued" | "restart";
|
||||
/** List of triggers */
|
||||
trigger: any[];
|
||||
/** List of conditions */
|
||||
condition?: any[];
|
||||
/** List of actions */
|
||||
action: any[];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user