Skip to main content
Glama

Manage Docker Images

manage_images

Perform Docker image operations including listing available images, pulling from registries, removing unused images, and building new images from Dockerfiles.

Instructions

Manage Docker images (list, pull, remove, build)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on images
imageNoImage name or ID (required for pull, remove, build)
tagNoTag for the image (optional for pull, required for build)
dockerfileNoPath to Dockerfile (required for build)

Implementation Reference

  • The handler function for the 'manage_images' MCP tool. It takes input parameters (action, image, tag, dockerfile) and executes corresponding Docker commands: list images, pull image, remove image, or build image from Dockerfile or context.
    async ({ action, image, tag, dockerfile }) => {
      try {
        let command: string;
        
        switch (action) {
          case "list":
            command = "docker images";
            break;
          case "pull":
            if (!image) throw new Error("Image name is required for pull action");
            command = tag ? `docker pull ${image}:${tag}` : `docker pull ${image}`;
            break;
          case "remove":
            if (!image) throw new Error("Image name or ID is required for remove action");
            command = `docker rmi ${image}`;
            break;
          case "build":
            if (!image) throw new Error("Image name is required for build action");
            const buildTag = tag ? `${image}:${tag}` : image;
            const context = dockerfile ? dockerfile : ".";
            command = `docker build -t ${buildTag} ${context}`;
            break;
        }
        
        const result = await executeDockerCommand(command);
        
        return {
          content: [
            {
              type: "text",
              text: `Image ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error managing images: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • The input schema definition for the 'manage_images' tool using Zod validation. Defines parameters: action (enum: list/pull/remove/build), image (string optional), tag (string optional), dockerfile (string optional).
    {
      title: "Manage Docker Images",
      description: "Manage Docker images (list, pull, remove, build)",
      inputSchema: {
        action: z.enum(["list", "pull", "remove", "build"]).describe("Action to perform on images"),
        image: z.string().optional().describe("Image name or ID (required for pull, remove, build)"),
        tag: z.string().optional().describe("Tag for the image (optional for pull, required for build)"),
        dockerfile: z.string().optional().describe("Path to Dockerfile (required for build)")
      }
    },
  • src/index.ts:1260-1318 (registration)
    The registration of the 'manage_images' tool on the MCP server using server.registerTool, including title, description, inputSchema, and handler function.
    server.registerTool(
      "manage_images",
      {
        title: "Manage Docker Images",
        description: "Manage Docker images (list, pull, remove, build)",
        inputSchema: {
          action: z.enum(["list", "pull", "remove", "build"]).describe("Action to perform on images"),
          image: z.string().optional().describe("Image name or ID (required for pull, remove, build)"),
          tag: z.string().optional().describe("Tag for the image (optional for pull, required for build)"),
          dockerfile: z.string().optional().describe("Path to Dockerfile (required for build)")
        }
      },
      async ({ action, image, tag, dockerfile }) => {
        try {
          let command: string;
          
          switch (action) {
            case "list":
              command = "docker images";
              break;
            case "pull":
              if (!image) throw new Error("Image name is required for pull action");
              command = tag ? `docker pull ${image}:${tag}` : `docker pull ${image}`;
              break;
            case "remove":
              if (!image) throw new Error("Image name or ID is required for remove action");
              command = `docker rmi ${image}`;
              break;
            case "build":
              if (!image) throw new Error("Image name is required for build action");
              const buildTag = tag ? `${image}:${tag}` : image;
              const context = dockerfile ? dockerfile : ".";
              command = `docker build -t ${buildTag} ${context}`;
              break;
          }
          
          const result = await executeDockerCommand(command);
          
          return {
            content: [
              {
                type: "text",
                text: `Image ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error managing images: ${error instanceof Error ? error.message : String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It lists actions but doesn't describe their effects (e.g., 'remove' deletes images, 'build' creates new ones), permissions required, side effects, or error conditions. This is inadequate for a multi-action mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (one phrase) and front-loaded with all essential information. Every word earns its place, making it efficient for quick scanning without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a multi-action tool with no annotations and no output schema, the description is incomplete. It doesn't explain what each action does behaviorally, what the tool returns, or how errors are handled. This leaves significant gaps for an agent to understand the tool's full context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no parameter-specific semantics beyond implying the 'action' parameter's values, which are already in the enum. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool manages Docker images and enumerates the specific actions (list, pull, remove, build), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like manage_containers or manage_volumes, which handle different Docker resources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, context for choosing between actions, or how it relates to sibling tools like manage_containers or docker_compose, leaving the agent with no usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/TauqeerAhmad5201/docker-mcp-extension'

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