Files
komodo-mcp-server/src/types.ts
T

521 lines
17 KiB
TypeScript
Raw Normal View History

import { z } from "zod";
export const ResourceType = z.enum([
"stack",
"build",
"server",
"procedure",
"deployment",
"alerter",
"image_registry_account",
"sync_resource",
"user",
"tag",
"execution",
"access_request",
"action",
"repo",
"builder",
"swarm",
"variable",
"user_group",
"alert",
"terminal",
"git_provider_account",
]);
export type ResourceType = z.infer<typeof ResourceType>;
export const ExecuteOperation = z.enum([
"run_build",
"deploy_stack",
"deploy_stack_service",
"run_procedure",
"run_procedure_stage",
"run_deployment_action",
"run_deployment_sync",
"run_resource_sync",
"run_stack_refresh_cache",
"run_stack_refresh_content",
"run_stack_pull",
"run_stack_pull_deployment",
"run_stack_stop",
"run_stack_restart",
"run_stack_pause",
"run_stack_unpause",
"run_stack_remove_orphan_containers",
"run_stack_toggle_service_dependencies",
"run_stack_auto_update",
"run_stack_commit",
"run_server_refresh",
"run_server_refresh_containers",
"run_server_update_periphery",
"run_server_prune_images",
"run_server_prune_containers",
"run_server_prune_networks",
"run_server_stats",
"run_server_run_command",
"run_server_scripts",
"run_server_copy",
"run_server_move",
"run_deployment_execute",
"run_deployment_redeploy",
"run_deployment_destroy",
"run_deployment_stop",
"run_deployment_logs",
"run_sync_deployment",
"get_mcp_token",
"deploy",
"deploy_stack_if_changed",
"destroy_stack",
"destroy_container",
"destroy_deployment",
"build_repo",
"clone_repo",
"pull_repo",
"pull_deployment",
"cancel_repo_build",
"clear_repo_cache",
"run_action",
"cancel_action",
"cancel_build",
"cancel_procedure",
"start_container",
"stop_container",
"restart_container",
"pause_container",
"unpause_container",
"start_all_containers",
"stop_all_containers",
"restart_all_containers",
"pause_all_containers",
"unpause_all_containers",
"start_deployment",
"stop_deployment",
"restart_deployment",
"pause_deployment",
"unpause_deployment",
"start_stack",
"prune_buildx",
"prune_docker_builders",
"prune_system",
"prune_volumes",
"delete_image",
"delete_network",
"delete_volume",
"remove_swarm_nodes",
"remove_swarm_services",
"remove_swarm_configs",
"remove_swarm_secrets",
"remove_swarm_stacks",
"create_swarm_config",
"create_swarm_secret",
"rotate_swarm_config",
"rotate_swarm_secret",
"update_swarm_node",
"batch_run_build",
"batch_deploy_stack",
"batch_deploy_stack_if_changed",
"batch_deploy",
"batch_pull_stack",
"batch_pull_repo",
"batch_build_repo",
"batch_clone_repo",
"batch_run_procedure",
"batch_run_action",
"batch_destroy_deployment",
"batch_destroy_stack",
"backup_core_database",
"rotate_core_keys",
"rotate_all_server_keys",
"global_auto_update",
"send_alert",
"test_alerter",
"sleep",
]);
export type ExecuteOperation = z.infer<typeof ExecuteOperation>;
// Maps resource_type to the list/search RPC request name
export const LIST_REQUEST_MAP: Record<ResourceType, string> = {
stack: "ListStacks",
build: "ListBuilds",
server: "ListServers",
procedure: "ListProcedures",
deployment: "ListDeployments",
alerter: "ListAlerters",
image_registry_account: "ListImageRegistryAccounts",
sync_resource: "ListSyncResources",
user: "ListUsers",
tag: "ListTags",
execution: "ListExecutions",
access_request: "ListAccessRequests",
action: "ListActions",
repo: "ListRepos",
builder: "ListBuilders",
swarm: "ListSwarms",
variable: "ListVariables",
user_group: "ListUserGroups",
alert: "ListAlerts",
terminal: "ListTerminals",
git_provider_account: "ListGitProviderAccounts",
};
// Maps resource_type to the search RPC request name
export const SEARCH_REQUEST_MAP: Record<ResourceType, string> = {
stack: "SearchStacks",
build: "SearchBuilds",
server: "SearchServers",
procedure: "SearchProcedures",
deployment: "SearchDeployments",
alerter: "SearchAlerters",
image_registry_account: "SearchImageRegistryAccounts",
sync_resource: "SearchSyncResources",
user: "ListUsers",
tag: "ListTags",
execution: "ListExecutions",
access_request: "ListAccessRequests",
action: "ListActions",
repo: "ListRepos",
builder: "ListBuilders",
swarm: "ListSwarms",
variable: "ListVariables",
user_group: "ListUserGroups",
alert: "ListAlerts",
terminal: "ListTerminals",
git_provider_account: "ListGitProviderAccounts",
};
// Maps resource_type to the get RPC request name
export const GET_REQUEST_MAP: Record<ResourceType, string> = {
stack: "GetStack",
build: "GetBuild",
server: "GetServer",
procedure: "GetProcedure",
deployment: "GetDeployment",
alerter: "GetAlerter",
image_registry_account: "GetImageRegistryAccount",
sync_resource: "GetSyncResource",
user: "GetUser",
tag: "GetTag",
execution: "GetExecution",
access_request: "GetAccessRequest",
action: "GetAction",
repo: "GetRepo",
builder: "GetBuilder",
swarm: "GetSwarm",
variable: "GetVariable",
user_group: "GetUserGroup",
alert: "GetAlert",
terminal: "GetTerminal",
git_provider_account: "GetGitProviderAccount",
};
// Maps resource_type to the create RPC request name
export const CREATE_REQUEST_MAP: Partial<Record<ResourceType, string>> = {
stack: "CreateStack",
build: "CreateBuild",
server: "CreateServer",
procedure: "CreateProcedure",
deployment: "CreateDeployment",
alerter: "CreateAlerter",
image_registry_account: "CreateImageRegistryAccount",
sync_resource: "CreateResourceSync",
tag: "CreateTag",
action: "CreateAction",
repo: "CreateRepo",
builder: "CreateBuilder",
swarm: "CreateSwarm",
variable: "CreateVariable",
user_group: "CreateUserGroup",
terminal: "CreateTerminal",
git_provider_account: "CreateGitProviderAccount",
};
// Maps resource_type to the update RPC request name
export const UPDATE_REQUEST_MAP: Partial<Record<ResourceType, string>> = {
stack: "UpdateStack",
build: "UpdateBuild",
server: "UpdateServer",
procedure: "UpdateProcedure",
deployment: "UpdateDeployment",
alerter: "UpdateAlerter",
image_registry_account: "UpdateImageRegistryAccount",
sync_resource: "UpdateResourceSync",
user: "UpdateUser",
tag: "UpdateTagColor",
action: "UpdateAction",
repo: "UpdateRepo",
builder: "UpdateBuilder",
swarm: "UpdateSwarm",
variable: "UpdateVariableValue",
user_group: "UpdateUserGroup",
git_provider_account: "UpdateGitProviderAccount",
};
// Maps resource_type to the delete RPC request name
export const DELETE_REQUEST_MAP: Partial<Record<ResourceType, string>> = {
stack: "DeleteStack",
build: "DeleteBuild",
server: "DeleteServer",
procedure: "DeleteProcedure",
deployment: "DeleteDeployment",
alerter: "DeleteAlerter",
sync_resource: "DeleteSyncResource",
tag: "DeleteTag",
action: "DeleteAction",
repo: "DeleteRepo",
builder: "DeleteBuilder",
swarm: "DeleteSwarm",
variable: "DeleteVariable",
user_group: "DeleteUserGroup",
terminal: "DeleteTerminal",
git_provider_account: "DeleteGitProviderAccount",
};
// Maps execute operation to the RPC request name and the route
export const EXECUTE_REQUEST_MAP: Record<
ExecuteOperation,
{ route: "execute" | "read" | "write"; name: string }
> = {
run_build: { route: "execute", name: "RunBuild" },
deploy_stack: { route: "execute", name: "DeployStack" },
deploy_stack_service: { route: "execute", name: "DeployStackService" },
run_procedure: { route: "execute", name: "RunProcedure" },
run_procedure_stage: { route: "execute", name: "RunProcedureStage" },
run_deployment_action: { route: "execute", name: "RunDeploymentAction" },
run_deployment_sync: { route: "execute", name: "RunDeploymentSync" },
run_resource_sync: { route: "execute", name: "RunResourceSync" },
run_stack_refresh_cache: {
route: "execute",
name: "RunStackRefreshCache",
},
run_stack_refresh_content: {
route: "execute",
name: "RunStackRefreshContent",
},
run_stack_pull: { route: "execute", name: "RunStackPull" },
run_stack_pull_deployment: {
route: "execute",
name: "RunStackPullDeployment",
},
run_stack_stop: { route: "execute", name: "RunStackStop" },
run_stack_restart: { route: "execute", name: "RunStackRestart" },
run_stack_pause: { route: "execute", name: "RunStackPause" },
run_stack_unpause: { route: "execute", name: "RunStackUnpause" },
run_stack_remove_orphan_containers: {
route: "execute",
name: "RunStackRemoveOrphanContainers",
},
run_stack_toggle_service_dependencies: {
route: "execute",
name: "RunStackToggleServiceDependencies",
},
run_stack_auto_update: { route: "execute", name: "RunStackAutoUpdate" },
run_stack_commit: { route: "execute", name: "RunStackCommit" },
run_server_refresh: { route: "execute", name: "RunServerRefresh" },
run_server_refresh_containers: {
route: "execute",
name: "RunServerRefreshContainers",
},
run_server_update_periphery: {
route: "execute",
name: "RunServerUpdatePeriphery",
},
run_server_prune_images: {
route: "execute",
name: "RunServerPruneImages",
},
run_server_prune_containers: {
route: "execute",
name: "RunServerPruneContainers",
},
run_server_prune_networks: {
route: "execute",
name: "RunServerPruneNetworks",
},
run_server_stats: { route: "execute", name: "RunServerStats" },
run_server_run_command: {
route: "execute",
name: "RunServerRunCommand",
},
run_server_scripts: { route: "execute", name: "RunServerScripts" },
run_server_copy: { route: "execute", name: "RunServerCopy" },
run_server_move: { route: "execute", name: "RunServerMove" },
run_deployment_execute: {
route: "execute",
name: "RunDeploymentExecute",
},
run_deployment_redeploy: {
route: "execute",
name: "RunDeploymentRedeploy",
},
run_deployment_destroy: {
route: "execute",
name: "RunDeploymentDestroy",
},
run_deployment_stop: { route: "execute", name: "RunDeploymentStop" },
run_deployment_logs: { route: "execute", name: "RunDeploymentLogs" },
run_sync_deployment: { route: "execute", name: "RunSyncDeployment" },
get_mcp_token: { route: "execute", name: "GetMcpToken" },
deploy: { route: "execute", name: "Deploy" },
deploy_stack_if_changed: { route: "execute", name: "DeployStackIfChanged" },
destroy_stack: { route: "execute", name: "DestroyStack" },
destroy_container: { route: "execute", name: "DestroyContainer" },
destroy_deployment: { route: "execute", name: "DestroyDeployment" },
build_repo: { route: "execute", name: "BuildRepo" },
clone_repo: { route: "execute", name: "CloneRepo" },
pull_repo: { route: "execute", name: "PullRepo" },
pull_deployment: { route: "execute", name: "PullDeployment" },
cancel_repo_build: { route: "execute", name: "CancelRepoBuild" },
clear_repo_cache: { route: "execute", name: "ClearRepoCache" },
run_action: { route: "execute", name: "RunAction" },
cancel_action: { route: "execute", name: "CancelAction" },
cancel_build: { route: "execute", name: "CancelBuild" },
cancel_procedure: { route: "execute", name: "CancelProcedure" },
start_container: { route: "execute", name: "StartContainer" },
stop_container: { route: "execute", name: "StopContainer" },
restart_container: { route: "execute", name: "RestartContainer" },
pause_container: { route: "execute", name: "PauseContainer" },
unpause_container: { route: "execute", name: "UnpauseContainer" },
start_all_containers: { route: "execute", name: "StartAllContainers" },
stop_all_containers: { route: "execute", name: "StopAllContainers" },
restart_all_containers: { route: "execute", name: "RestartAllContainers" },
pause_all_containers: { route: "execute", name: "PauseAllContainers" },
unpause_all_containers: { route: "execute", name: "UnpauseAllContainers" },
start_deployment: { route: "execute", name: "StartDeployment" },
stop_deployment: { route: "execute", name: "StopDeployment" },
restart_deployment: { route: "execute", name: "RestartDeployment" },
pause_deployment: { route: "execute", name: "PauseDeployment" },
unpause_deployment: { route: "execute", name: "UnpauseDeployment" },
start_stack: { route: "execute", name: "StartStack" },
prune_buildx: { route: "execute", name: "PruneBuildx" },
prune_docker_builders: { route: "execute", name: "PruneDockerBuilders" },
prune_system: { route: "execute", name: "PruneSystem" },
prune_volumes: { route: "execute", name: "PruneVolumes" },
delete_image: { route: "execute", name: "DeleteImage" },
delete_network: { route: "execute", name: "DeleteNetwork" },
delete_volume: { route: "execute", name: "DeleteVolume" },
remove_swarm_nodes: { route: "execute", name: "RemoveSwarmNodes" },
remove_swarm_services: { route: "execute", name: "RemoveSwarmServices" },
remove_swarm_configs: { route: "execute", name: "RemoveSwarmConfigs" },
remove_swarm_secrets: { route: "execute", name: "RemoveSwarmSecrets" },
remove_swarm_stacks: { route: "execute", name: "RemoveSwarmStacks" },
create_swarm_config: { route: "execute", name: "CreateSwarmConfig" },
create_swarm_secret: { route: "execute", name: "CreateSwarmSecret" },
rotate_swarm_config: { route: "execute", name: "RotateSwarmConfig" },
rotate_swarm_secret: { route: "execute", name: "RotateSwarmSecret" },
update_swarm_node: { route: "execute", name: "UpdateSwarmNode" },
batch_run_build: { route: "execute", name: "BatchRunBuild" },
batch_deploy_stack: { route: "execute", name: "BatchDeployStack" },
batch_deploy_stack_if_changed: {
route: "execute",
name: "BatchDeployStackIfChanged",
},
batch_deploy: { route: "execute", name: "BatchDeploy" },
batch_pull_stack: { route: "execute", name: "BatchPullStack" },
batch_pull_repo: { route: "execute", name: "BatchPullRepo" },
batch_build_repo: { route: "execute", name: "BatchBuildRepo" },
batch_clone_repo: { route: "execute", name: "BatchCloneRepo" },
batch_run_procedure: { route: "execute", name: "BatchRunProcedure" },
batch_run_action: { route: "execute", name: "BatchRunAction" },
batch_destroy_deployment: {
route: "execute",
name: "BatchDestroyDeployment",
},
batch_destroy_stack: { route: "execute", name: "BatchDestroyStack" },
backup_core_database: { route: "execute", name: "BackupCoreDatabase" },
rotate_core_keys: { route: "execute", name: "RotateCoreKeys" },
rotate_all_server_keys: {
route: "execute",
name: "RotateAllServerKeys",
},
global_auto_update: { route: "execute", name: "GlobalAutoUpdate" },
send_alert: { route: "execute", name: "SendAlert" },
test_alerter: { route: "execute", name: "TestAlerter" },
sleep: { route: "execute", name: "Sleep" },
};
// Maps resource_type to the summary RPC request name
export const SUMMARY_REQUEST_MAP: Partial<Record<ResourceType, string>> = {
build: "GetBuildsSummary",
deployment: "GetDeploymentsSummary",
server: "GetServersSummary",
stack: "GetStacksSummary",
alerter: "GetAlertersSummary",
procedure: "GetProceduresSummary",
sync_resource: "GetResourceSyncsSummary",
repo: "GetReposSummary",
builder: "GetBuildersSummary",
swarm: "GetSwarmsSummary",
action: "GetActionsSummary",
};
// Maps inspect type to the inspect RPC request name.
// Server-scoped Docker objects also need an object param key (see
// INSPECT_PARAM_KEY below): Core v2.3.3 shapes are {server, container},
// {server, image}, {server, network}, {server, volume} — sending
// {id, server} fails with "duplicate field `server`".
export const INSPECT_PARAM_KEY: Record<string, string> = {
container: "container",
image: "image",
network: "network",
volume: "volume",
};
export const INSPECT_REQUEST_MAP: Record<string, string> = {
container: "InspectContainer",
image: "InspectImage",
network: "InspectNetwork",
volume: "InspectVolume",
deployment_container: "InspectDeploymentContainer",
deployment_swarm_service: "InspectDeploymentSwarmService",
stack_container: "InspectStackContainer",
stack_swarm_info: "InspectStackSwarmInfo",
stack_swarm_service: "InspectStackSwarmService",
swarm: "InspectSwarm",
swarm_config: "InspectSwarmConfig",
swarm_node: "InspectSwarmNode",
swarm_secret: "InspectSwarmSecret",
swarm_service: "InspectSwarmService",
swarm_stack: "InspectSwarmStack",
swarm_task: "InspectSwarmTask",
};
// Maps search log type to the RPC request name
export const SEARCH_LOG_REQUEST_MAP: Record<string, string> = {
container: "SearchContainerLog",
deployment: "SearchDeploymentLog",
stack: "SearchStackLog",
swarm_service: "SearchSwarmServiceLog",
};
// Maps list detail type to the RPC request name
export const LIST_DETAIL_REQUEST_MAP: Record<string, string> = {
containers: "ListContainers",
all_containers: "ListAllContainers",
images: "ListImages",
networks: "ListNetworks",
volumes: "ListVolumes",
system_processes: "ListSystemProcesses",
schedules: "ListSchedules",
permissions: "ListPermissions",
api_keys: "ListApiKeys",
api_keys_for_service_user: "ListApiKeysForServiceUser",
onboarding_keys: "ListOnboardingKeys",
secrets: "ListSecrets",
updates: "ListUpdates",
build_versions: "ListBuildVersions",
compose_projects: "ListComposeProjects",
user_target_permissions: "ListUserTargetPermissions",
full_stacks: "ListFullStacks",
full_builds: "ListFullBuilds",
full_servers: "ListFullServers",
full_deployments: "ListFullDeployments",
full_procedures: "ListFullProcedures",
full_repos: "ListFullRepos",
full_builders: "ListFullBuilders",
full_swarms: "ListFullSwarms",
full_actions: "ListFullActions",
full_alerters: "ListFullAlerters",
full_resource_syncs: "ListFullResourceSyncs",
};