Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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(),
      }));
    }
  • 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"),
          },
        ],
      };
    });
  • 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]}`;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ofershap/mcp-server-docker'

If you have feedback or need assistance with the MCP directory API, please join our Discord server