docker_stop
Stop running Docker containers by name or ID to halt application processes and free system resources for development environments.
Instructions
Stop one or more running containers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| containers | Yes | Container name(s) or ID(s) | |
| timeout | No | Seconds to wait before killing container | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/docker.ts:249-253 (handler)The main handler function for the docker_stop tool that constructs and executes the 'docker stop' command via the executeDockerCommand helper.export async function dockerStop(args: z.infer<typeof dockerStopSchema>): Promise<ToolResponse> { const containers = Array.isArray(args.containers) ? args.containers.join(' ') : args.containers; const timeoutFlag = args.timeout ? `-t ${args.timeout}` : ''; return executeDockerCommand(`docker stop ${timeoutFlag} ${containers}`.trim(), args.cwd); }
- src/tools/docker.ts:119-123 (schema)Zod input validation schema for the docker_stop tool.export const dockerStopSchema = z.object({ containers: z.union([z.string(), z.array(z.string())]).describe('Container name(s) or ID(s)'), timeout: z.number().optional().describe('Seconds to wait before killing container'), cwd: z.string().optional().describe('Working directory') });
- src/tools/docker.ts:428-446 (registration)MCP tool registration definition in dockerTools array (used for tool listing), including name, description, and JSON input schema.{ name: 'docker_stop', description: 'Stop one or more running containers', inputSchema: { type: 'object', properties: { containers: { oneOf: [ { type: 'string' }, { type: 'array', items: { type: 'string' } } ], description: 'Container name(s) or ID(s)' }, timeout: { type: 'number', description: 'Seconds to wait before killing container' }, cwd: { type: 'string', description: 'Working directory' } }, required: ['containers'] } },
- src/index.ts:459-462 (registration)Dispatch/registration logic in the main CallToolRequest handler that validates arguments with dockerStopSchema and calls the dockerStop handler function.if (name === 'docker_stop') { const validated = dockerStopSchema.parse(args); return await dockerStop(validated); }
- src/tools/docker.ts:21-62 (helper)Shared helper function used by all Docker tools (including dockerStop) to execute docker commands and format responses.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 }; } }