Skip to main content
Glama

list_containers

Retrieve and display Docker container information, including active and optionally stopped containers, to monitor and manage container status.

Instructions

List Docker containers. Set all=true to include stopped containers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
allNoInclude stopped containers

Implementation Reference

  • The main handler function that executes the list_containers tool logic. It calls the Docker API to list containers and maps the results to a simplified ContainerInfo format with formatted fields for id, name, image, state, status, ports, and creation date.
    export async function listContainers(all: boolean): Promise<ContainerInfo[]> {
      const containers = await docker.listContainers({ all });
      return containers.map((c) => ({
        id: c.Id.slice(0, 12),
        name: c.Names[0]?.replace(/^\//, "") ?? "",
        image: c.Image,
        state: c.State,
        status: c.Status,
        ports: formatPorts(c.Ports),
        created: new Date(c.Created * 1000).toISOString(),
      }));
    }
  • Schema definition for the ContainerInfo interface that defines the output structure returned by the list_containers tool. Specifies the fields: id, name, image, state, status, ports, and created.
    export interface ContainerInfo {
      id: string;
      name: string;
      image: string;
      state: string;
      status: string;
      ports: string;
      created: string;
    }
  • src/index.ts:22-51 (registration)
    Registration of the list_containers tool with the MCP server. Defines the tool name, description, input schema using Zod (boolean 'all' parameter with default false), and the async handler that calls listContainers and formats the output as text.
    server.tool(
      "list_containers",
      "List Docker containers. Set all=true to include stopped containers.",
      {
        all: z
          .boolean()
          .optional()
          .default(false)
          .describe("Include stopped containers"),
      },
      async ({ all }) => {
        const containers = await listContainers(all);
        return {
          content: [
            {
              type: "text",
              text:
                containers.length === 0
                  ? "No containers found."
                  : containers
                      .map(
                        (c) =>
                          `${c.id}  ${c.name.padEnd(30)}  ${c.image.padEnd(30)}  ${c.state.padEnd(10)}  ${c.status}`,
                      )
                      .join("\n"),
            },
          ],
        };
      },
    );
  • Helper function formatPorts used by listContainers to format Docker port mappings into a human-readable string format (e.g., '8080->80/tcp').
    function formatPorts(ports: Dockerode.Port[]): string {
      return ports
        .map((p) => {
          if (p.PublicPort) return `${p.PublicPort}->${p.PrivatePort}/${p.Type}`;
          return `${p.PrivatePort}/${p.Type}`;
        })
        .join(", ");
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the 'all' parameter behavior but doesn't describe other important traits: whether this is a read-only operation, what the output format looks like (e.g., list of container IDs/names), if there are rate limits, or if specific permissions are required. For a tool with zero annotation coverage, this leaves significant gaps.

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 with two short sentences that directly address the tool's function and key parameter. Every word earns its place, and it's front-loaded with the main purpose. There's zero waste or redundancy.

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?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a list of container objects with properties), behavioral constraints, or error conditions. For a tool in a Docker management context with multiple siblings, more guidance on output and usage context would be helpful.

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 already fully documents the single parameter ('all'). The description adds minimal value by restating the parameter's effect ('include stopped containers'), which is essentially what the schema description says. With high schema coverage, the baseline is 3, and the description doesn't provide additional syntax or format details beyond the schema.

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 verb ('List') and resource ('Docker containers'), making the purpose immediately understandable. It distinguishes from siblings like 'list_images' by specifying containers rather than images, but doesn't explicitly differentiate from other container-related tools like 'container_stats' or 'container_logs'.

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

Usage Guidelines3/5

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

The description provides implied usage guidance by mentioning the 'all' parameter to include stopped containers, suggesting this tool is for viewing container status. However, it doesn't explicitly state when to use this tool versus alternatives like 'container_stats' for performance metrics or 'container_logs' for logs, nor does it mention prerequisites or exclusions.

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/ofershap/mcp-server-docker'

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