list_images
Lists Docker images available on the host system for container management and deployment.
Instructions
List Docker images on the host.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/docker.ts:181-189 (handler)The handler function that executes the list_images tool logic. It calls docker.listImages() to fetch Docker images and maps the results to ImageInfo objects with formatted id, tags, size, and created date.
export async function listImages(): Promise<ImageInfo[]> { const images = await docker.listImages(); return images.map((img) => ({ id: img.Id.replace("sha256:", "").slice(0, 12), tags: img.RepoTags ?? ["<none>"], size: formatBytes(img.Size), created: new Date(img.Created * 1000).toISOString(), })); } - src/docker.ts:24-29 (schema)Type definition for the image data returned by the list_images tool, defining the structure of ImageInfo with id, tags, size, and created fields.
export interface ImageInfo { id: string; tags: string[]; size: string; created: string; } - src/index.ts:155-173 (registration)Registration of the list_images tool with the MCP server. The tool takes no parameters (empty schema {}) and returns a formatted text output of all Docker images.
server.tool("list_images", "List Docker images on the host.", {}, async () => { const images = await listImages(); return { content: [ { type: "text", text: images.length === 0 ? "No images found." : images .map( (img) => `${img.id} ${img.tags.join(", ").padEnd(40)} ${img.size.padEnd(10)} ${img.created}`, ) .join("\n"), }, ], }; }); - src/docker.ts:31-37 (helper)Helper utility function used by listImages to convert raw byte values into human-readable format (B, KB, MB, GB).
function formatBytes(bytes: number): string { if (bytes === 0) return "0 B"; const k = 1024; const sizes = ["B", "KB", "MB", "GB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`; }