/**
* Server Lifecycle Tool Handlers
* Start, stop, and restart servers on Komodo
*/
import type { KomodoClient } from '../../core/KomodoClient';
import { Logger } from '../../utils/logger';
export interface ServerOptions {
timeout?: number;
force?: boolean;
waitForHealthy?: boolean;
removeContainer?: boolean;
}
export interface ServerLifecycleRequest {
id: string;
options?: ServerOptions;
}
export interface ServerLifecycleResponse {
success: boolean;
serverId: string;
action: 'start' | 'stop' | 'restart';
status: 'running' | 'stopped' | 'starting' | 'stopping' | 'error';
message: string;
timestamp: string;
containerInfo?: {
id?: string;
name?: string;
state?: string;
};
logs?: string[];
}
/**
* Start a server
*/
export async function startServer(
client: KomodoClient,
request: ServerLifecycleRequest
): Promise<ServerLifecycleResponse> {
const logger = Logger.getInstance();
try {
logger.info('Starting server', { serverId: request.id });
const response = await client.post<ServerLifecycleResponse>(
`/execute/server/${request.id}/start`,
request.options || {}
);
logger.info('Server start initiated', {
serverId: request.id,
status: response.status
});
return response;
} catch (error) {
logger.error('Failed to start server', {
serverId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}
/**
* Stop a server
*/
export async function stopServer(
client: KomodoClient,
request: ServerLifecycleRequest
): Promise<ServerLifecycleResponse> {
const logger = Logger.getInstance();
try {
logger.info('Stopping server', { serverId: request.id });
const response = await client.post<ServerLifecycleResponse>(
`/execute/server/${request.id}/stop`,
request.options || {}
);
logger.info('Server stop initiated', {
serverId: request.id,
status: response.status
});
return response;
} catch (error) {
logger.error('Failed to stop server', {
serverId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}
/**
* Restart a server
*/
export async function restartServer(
client: KomodoClient,
request: ServerLifecycleRequest
): Promise<ServerLifecycleResponse> {
const logger = Logger.getInstance();
try {
logger.info('Restarting server', { serverId: request.id });
const response = await client.post<ServerLifecycleResponse>(
`/execute/server/${request.id}/restart`,
request.options || {}
);
logger.info('Server restart initiated', {
serverId: request.id,
status: response.status
});
return response;
} catch (error) {
logger.error('Failed to restart server', {
serverId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}