Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

docker_rm

Remove Docker containers by name or ID, with options to force removal of running containers and delete associated anonymous volumes.

Instructions

Remove one or more containers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containersYesContainer name(s) or ID(s) to remove
forceNoForce removal of running containers
volumesNoRemove anonymous volumes
cwdNoWorking directory

Implementation Reference

  • The core handler function for the 'docker_rm' tool. It processes input arguments, constructs the 'docker rm' command with optional flags, and executes it via the shared executeDockerCommand helper.
    export async function dockerRm(args: z.infer<typeof dockerRmSchema>): Promise<ToolResponse> { const containers = Array.isArray(args.containers) ? args.containers.join(' ') : args.containers; const forceFlag = args.force ? '-f' : ''; const volumesFlag = args.volumes ? '-v' : ''; return executeDockerCommand(`docker rm ${forceFlag} ${volumesFlag} ${containers}`.trim(), args.cwd); }
  • Zod schema used for input validation of the 'docker_rm' tool arguments.
    export const dockerRmSchema = z.object({ containers: z.union([z.string(), z.array(z.string())]).describe('Container name(s) or ID(s) to remove'), force: z.boolean().optional().default(false).describe('Force removal of running containers'), volumes: z.boolean().optional().default(false).describe('Remove anonymous volumes'), cwd: z.string().optional().describe('Working directory') });
  • MCP tool definition/registration for 'docker_rm' in the exported dockerTools array, providing the JSON schema for tool listing.
    name: 'docker_rm', description: 'Remove one or more containers', inputSchema: { type: 'object', properties: { containers: { oneOf: [ { type: 'string' }, { type: 'array', items: { type: 'string' } } ], description: 'Container name(s) or ID(s) to remove' }, force: { type: 'boolean', default: false, description: 'Force removal of running containers' }, volumes: { type: 'boolean', default: false, description: 'Remove anonymous volumes' }, cwd: { type: 'string', description: 'Working directory' } }, required: ['containers'] } },
  • src/index.ts:499-502 (registration)
    Tool dispatch/registration in the main MCP server request handler for CallToolRequestSchema.
    if (name === 'docker_rm') { const validated = dockerRmSchema.parse(args); return await dockerRm(validated); }
  • Shared helper function that executes all Docker commands and formats ToolResponse, used by dockerRm.
    async function executeDockerCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024, // 10MB buffer for logs timeout: 60000 // 60 second timeout for builds }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ConnorBoetig-dev/mcp2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server