remove_container
Delete a Docker container using its ID or name, optionally forcing removal of running containers. Simplifies container management in the Docker MCP Server environment.
Instructions
Remove a Docker container
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | Yes | Container ID or name | |
| force | No | Force removal of running container |
Input Schema (JSON Schema)
{
"properties": {
"container": {
"description": "Container ID or name",
"type": "string"
},
"force": {
"description": "Force removal of running container",
"type": "boolean"
}
},
"required": [
"container"
],
"type": "object"
}
Implementation Reference
- src/index.ts:332-351 (handler)The handler function that implements the 'remove_container' tool. It checks for the required 'container' argument, optionally adds force flag, executes 'docker rm' command, and returns the stdout as text content.private async removeContainer(args: ContainerActionArgs) { if (!args.container) { throw new McpError( ErrorCode.InvalidParams, 'Container parameter is required' ); } const force = args.force === true ? ' -f' : ''; const { stdout } = await execAsync(`docker rm${force} ${args.container}`); return { content: [ { type: 'text', text: stdout.trim(), }, ], }; }
- src/index.ts:151-168 (registration)Registration of the 'remove_container' tool in the ListTools response. Includes name, description, and inputSchema defining 'container' (required string) and optional 'force' boolean.{ name: 'remove_container', description: 'Remove a Docker container', inputSchema: { type: 'object', properties: { container: { type: 'string', description: 'Container ID or name', }, force: { type: 'boolean', description: 'Force removal of running container', }, }, required: ['container'], }, },
- src/index.ts:31-35 (schema)TypeScript interface ContainerActionArgs defining the input parameters for remove_container: container (string, required), force (boolean, optional). Used for type checking in the handler.interface ContainerActionArgs { container: string; force?: boolean; }
- src/index.ts:197-198 (registration)Dispatch case in CallToolRequest handler that routes 'remove_container' calls to the removeContainer method.case 'remove_container': return await this.removeContainer(request.params.arguments as unknown as ContainerActionArgs);