list_containers
Retrieve a list of Docker containers with options to display running or all containers. Enables efficient container management and monitoring through the Docker MCP Server.
Instructions
List all Docker containers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| all | No | Show all containers (default shows just running) |
Implementation Reference
- src/index.ts:217-236 (handler)The main handler function for the 'list_containers' tool. It executes 'docker ps' with optional '-a' flag based on args.all, parses the output into a structured list of containers (id, image, status, name), and returns it as JSON text content.private async listContainers(args: ContainerArgs) { const showAll = args?.all === true ? '-a' : ''; const { stdout } = await execAsync(`docker ps ${showAll} --format "{{.ID}}\\t{{.Image}}\\t{{.Status}}\\t{{.Names}}"`); const containers = stdout.trim().split('\n') .filter(line => line.trim() !== '') .map(line => { const [id, image, status, name] = line.split('\t'); return { id, image, status, name }; }); return { content: [ { type: 'text', text: JSON.stringify(containers, null, 2), }, ], }; }
- src/index.ts:17-19 (schema)TypeScript interface defining the input arguments for the list_containers tool: optional 'all' boolean to show all containers.interface ContainerArgs { all?: boolean; }
- src/index.ts:69-81 (registration)Tool registration in the ListToolsRequestHandler: defines name, description, and inputSchema for list_containers.{ name: 'list_containers', description: 'List all Docker containers', inputSchema: { type: 'object', properties: { all: { type: 'boolean', description: 'Show all containers (default shows just running)', }, }, }, },
- src/index.ts:189-190 (registration)Dispatch case in CallToolRequestHandler switch statement that routes 'list_containers' calls to the handler function.case 'list_containers': return await this.listContainers(request.params.arguments as unknown as ContainerArgs);