import { SystemManager } from '../managers/system.js';
import { z } from 'zod';
export function getSystemTools() {
return [
{
name: 'docker_system_info',
description: 'Get Docker system information',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'docker_version',
description: 'Get Docker version information',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'docker_prune_system',
description: 'Remove unused data (containers, networks, images, build cache). Requires confirmation for safety. First call without confirm to see what will be removed, then call again with confirm=true to proceed.',
inputSchema: {
type: 'object',
properties: {
filters: {
type: 'object',
description: 'Filters to apply',
additionalProperties: {
type: 'array',
items: { type: 'string' },
},
},
confirm: {
type: 'boolean',
description: 'Confirmation flag. Must be true to actually prune resources. First call without this to see what will be removed.',
},
},
},
},
{
name: 'docker_prune_images',
description: 'Remove unused images. Requires confirmation for safety. First call without confirm to see what will be removed, then call again with confirm=true to proceed.',
inputSchema: {
type: 'object',
properties: {
filters: {
type: 'object',
description: 'Filters to apply',
additionalProperties: {
type: 'array',
items: { type: 'string' },
},
},
confirm: {
type: 'boolean',
description: 'Confirmation flag. Must be true to actually prune images. First call without this to see what will be removed.',
},
},
},
},
{
name: 'docker_prune_containers',
description: 'Remove stopped containers. Requires confirmation for safety. First call without confirm to see what will be removed, then call again with confirm=true to proceed.',
inputSchema: {
type: 'object',
properties: {
filters: {
type: 'object',
description: 'Filters to apply',
additionalProperties: {
type: 'array',
items: { type: 'string' },
},
},
confirm: {
type: 'boolean',
description: 'Confirmation flag. Must be true to actually prune containers. First call without this to see what will be removed.',
},
},
},
},
{
name: 'docker_prune_volumes',
description: 'Remove unused volumes. Requires confirmation for safety. First call without confirm to see what will be removed, then call again with confirm=true to proceed.',
inputSchema: {
type: 'object',
properties: {
filters: {
type: 'object',
description: 'Filters to apply',
additionalProperties: {
type: 'array',
items: { type: 'string' },
},
},
confirm: {
type: 'boolean',
description: 'Confirmation flag. Must be true to actually prune volumes. First call without this to see what will be removed.',
},
},
},
},
{
name: 'docker_prune_networks',
description: 'Remove unused networks. Requires confirmation for safety. First call without confirm to see what will be removed, then call again with confirm=true to proceed.',
inputSchema: {
type: 'object',
properties: {
filters: {
type: 'object',
description: 'Filters to apply',
additionalProperties: {
type: 'array',
items: { type: 'string' },
},
},
confirm: {
type: 'boolean',
description: 'Confirmation flag. Must be true to actually prune networks. First call without this to see what will be removed.',
},
},
},
},
];
}
export async function handleSystemTool(
name: string,
args: any,
systemManager: SystemManager
): Promise<any> {
try {
switch (name) {
case 'docker_system_info': {
const info = await systemManager.getSystemInfo();
return {
content: [
{
type: 'text',
text: JSON.stringify(info, null, 2),
},
],
};
}
case 'docker_version': {
const version = await systemManager.getVersion();
return {
content: [
{
type: 'text',
text: JSON.stringify(version, null, 2),
},
],
};
}
case 'docker_prune_system': {
const parsed = z
.object({
filters: z.record(z.array(z.string())).optional(),
confirm: z.boolean().optional(),
})
.parse(args);
// First call: Show warning and request confirmation
if (!parsed.confirm) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
warning: '⚠️ CONFIRMATION REQUIRED: System prune will remove ALL unused containers, networks, images, and build cache',
message: 'This is a destructive operation that cannot be undone. To proceed, call this tool again with confirm=true',
example: {
name: 'docker_prune_system',
arguments: {
filters: parsed.filters,
confirm: true,
},
},
}, null, 2),
},
],
};
}
// Second call with confirm=true: Actually prune
if (parsed.confirm === true) {
const result = await systemManager.pruneSystem({
filters: parsed.filters,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: '✅ System pruned successfully',
result,
}, null, 2),
},
],
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Invalid confirmation state',
message: 'Please set confirm=true to proceed with system prune',
}, null, 2),
},
],
isError: true,
};
}
case 'docker_prune_images': {
const parsed = z
.object({
filters: z.record(z.array(z.string())).optional(),
confirm: z.boolean().optional(),
})
.parse(args);
if (!parsed.confirm) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
warning: '⚠️ CONFIRMATION REQUIRED: This will remove all unused images',
message: 'To proceed, call this tool again with confirm=true',
example: {
name: 'docker_prune_images',
arguments: {
filters: parsed.filters,
confirm: true,
},
},
}, null, 2),
},
],
};
}
if (parsed.confirm === true) {
const result = await systemManager.pruneImages({
filters: parsed.filters,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: '✅ Images pruned successfully',
result,
}, null, 2),
},
],
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Invalid confirmation state',
message: 'Please set confirm=true to proceed',
}, null, 2),
},
],
isError: true,
};
}
case 'docker_prune_containers': {
const parsed = z
.object({
filters: z.record(z.array(z.string())).optional(),
confirm: z.boolean().optional(),
})
.parse(args);
if (!parsed.confirm) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
warning: '⚠️ CONFIRMATION REQUIRED: This will remove all stopped containers',
message: 'To proceed, call this tool again with confirm=true',
example: {
name: 'docker_prune_containers',
arguments: {
filters: parsed.filters,
confirm: true,
},
},
}, null, 2),
},
],
};
}
if (parsed.confirm === true) {
const result = await systemManager.pruneContainers({
filters: parsed.filters,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: '✅ Containers pruned successfully',
result,
}, null, 2),
},
],
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Invalid confirmation state',
message: 'Please set confirm=true to proceed',
}, null, 2),
},
],
isError: true,
};
}
case 'docker_prune_volumes': {
const parsed = z
.object({
filters: z.record(z.array(z.string())).optional(),
confirm: z.boolean().optional(),
})
.parse(args);
if (!parsed.confirm) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
warning: '⚠️ CONFIRMATION REQUIRED: This will remove all unused volumes',
message: 'To proceed, call this tool again with confirm=true',
example: {
name: 'docker_prune_volumes',
arguments: {
filters: parsed.filters,
confirm: true,
},
},
}, null, 2),
},
],
};
}
if (parsed.confirm === true) {
const result = await systemManager.pruneVolumes({
filters: parsed.filters,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: '✅ Volumes pruned successfully',
result,
}, null, 2),
},
],
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Invalid confirmation state',
message: 'Please set confirm=true to proceed',
}, null, 2),
},
],
isError: true,
};
}
case 'docker_prune_networks': {
const parsed = z
.object({
filters: z.record(z.array(z.string())).optional(),
confirm: z.boolean().optional(),
})
.parse(args);
if (!parsed.confirm) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
warning: '⚠️ CONFIRMATION REQUIRED: This will remove all unused networks',
message: 'To proceed, call this tool again with confirm=true',
example: {
name: 'docker_prune_networks',
arguments: {
filters: parsed.filters,
confirm: true,
},
},
}, null, 2),
},
],
};
}
if (parsed.confirm === true) {
const result = await systemManager.pruneNetworks({
filters: parsed.filters,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: '✅ Networks pruned successfully',
result,
}, null, 2),
},
],
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Invalid confirmation state',
message: 'Please set confirm=true to proceed',
}, null, 2),
},
],
isError: true,
};
}
default:
return null;
}
} catch (error: any) {
if (error.message?.includes('Unknown tool')) {
return null;
}
throw error;
}
}