manage_volumes
Manage Docker volumes by listing, creating, removing, inspecting, or pruning them to organize storage for containers.
Instructions
Manage Docker volumes (list, create, remove, inspect)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform on volumes | |
| volume | No | Volume name (required for create, remove, inspect) | |
| driver | No | Volume driver (optional for create) |
Implementation Reference
- src/index.ts:1386-1431 (handler)The main handler function for the 'manage_volumes' tool. It takes action, volume, and driver parameters, constructs the corresponding Docker volume command (ls, create, rm, inspect, prune), executes it using executeDockerCommand, and returns formatted text output or error response.try { let command: string; switch (action) { case "list": command = "docker volume ls"; break; case "create": if (!volume) throw new Error("Volume name is required for create action"); command = `docker volume create${driver ? ` --driver ${driver}` : ""} ${volume}`; break; case "remove": if (!volume) throw new Error("Volume name is required for remove action"); command = `docker volume rm ${volume}`; break; case "inspect": if (!volume) throw new Error("Volume name is required for inspect action"); command = `docker volume inspect ${volume}`; break; case "prune": command = "docker volume prune -f"; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Volume ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing volumes: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:1380-1384 (schema)Input schema for the manage_volumes tool defined using Zod. Specifies the action enum and optional volume name and driver parameters with descriptions.action: z.enum(["list", "create", "remove", "inspect", "prune"]).describe("Action to perform on volumes"), volume: z.string().optional().describe("Volume name (required for create, remove, inspect)"), driver: z.string().optional().describe("Volume driver (optional for create)") } },
- src/index.ts:1375-1433 (registration)Registration of the 'manage_volumes' MCP tool using server.registerTool, including title, description, input schema, and inline handler function."manage_volumes", { title: "Docker Volume Management", description: "Manage Docker volumes (list, create, remove, inspect)", inputSchema: { action: z.enum(["list", "create", "remove", "inspect", "prune"]).describe("Action to perform on volumes"), volume: z.string().optional().describe("Volume name (required for create, remove, inspect)"), driver: z.string().optional().describe("Volume driver (optional for create)") } }, async ({ action, volume, driver }) => { try { let command: string; switch (action) { case "list": command = "docker volume ls"; break; case "create": if (!volume) throw new Error("Volume name is required for create action"); command = `docker volume create${driver ? ` --driver ${driver}` : ""} ${volume}`; break; case "remove": if (!volume) throw new Error("Volume name is required for remove action"); command = `docker volume rm ${volume}`; break; case "inspect": if (!volume) throw new Error("Volume name is required for inspect action"); command = `docker volume inspect ${volume}`; break; case "prune": command = "docker volume prune -f"; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Volume ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing volumes: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
- src/index.ts:383-390 (helper)Helper function executeDockerCommand used by the manage_volumes handler (and other tools) to run Docker commands asynchronously via child_process.exec.async function executeDockerCommand(command: string): Promise<{ stdout: string; stderr: string }> { try { const result = await execAsync(command); return result; } catch (error: any) { throw new Error(`Docker command failed: ${error.message}`); } }