list_containers
Retrieve a list of Docker containers to monitor and manage running or all container instances for system oversight.
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 handler function for 'list_containers' tool. Executes 'docker ps' (with optional -a for all containers), parses tabular output into JSON array of {id, image, status, name}, returns as 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:69-81 (registration)Tool registration in ListToolsRequestHandler response, including name, description, and input schema.{ 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:17-19 (schema)TypeScript interface defining the input arguments for the list_containers tool.interface ContainerArgs { all?: boolean; }
- src/index.ts:189-190 (registration)Switch case in CallToolRequestHandler that routes 'list_containers' calls to the handler function.case 'list_containers': return await this.listContainers(request.params.arguments as unknown as ContainerArgs);