Skip to main content
Glama
davidkim9

Container Exec MCP Server

by davidkim9

list_containers

Display Docker containers to monitor running instances or view all containers including stopped ones for container management.

Instructions

List Docker containers. By default shows only running containers, use all=true to show all containers including stopped ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
allNoShow all containers (default shows just running)

Implementation Reference

  • The async handler function that executes the tool logic: lists Docker containers (running or all), formats their details (name, ID, image, state, status, ports), handles empty list and errors, returns formatted text content.
    async function handler(params: z.infer<typeof inputSchema>, context: ToolContext): Promise<CallToolResult> {
      const { all } = params;
      const { docker } = context;
    
      try {
        const containers = await docker.listContainers({ all });
    
        if (containers.length === 0) {
          return {
            content: [{
              type: 'text',
              text: all ? 'No containers found.' : 'No running containers found. Use all=true to see all containers.'
            }]
          };
        }
    
        // Format container list
        let output = `${all ? 'All' : 'Running'} Containers:\n${'='.repeat(80)}\n\n`;
    
        for (const container of containers) {
          const name = container.Names?.map(n => n.replace(/^\//, '')).join(', ') || 'unknown';
          const image = container.Image;
          const status = container.Status;
          const state = container.State;
          const ports = container.Ports?.map(p => {
            if (p.PublicPort) {
              return `${p.IP || '0.0.0.0'}:${p.PublicPort}->${p.PrivatePort}/${p.Type}`;
            }
            return `${p.PrivatePort}/${p.Type}`;
          }).join(', ') || 'none';
    
          output += `Name:    ${name}\n`;
          output += `ID:      ${container.Id.substring(0, 12)}\n`;
          output += `Image:   ${image}\n`;
          output += `State:   ${state}\n`;
          output += `Status:  ${status}\n`;
          output += `Ports:   ${ports}\n`;
          output += '-'.repeat(80) + '\n\n';
        }
    
        return {
          content: [{
            type: 'text',
            text: output.trim()
          }]
        };
    
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `Error listing containers: ${error instanceof Error ? error.message : 'Unknown error'}`
          }]
        };
      }
    }
  • Zod schema for tool input: optional 'all' boolean to show all containers including stopped ones.
    const inputSchema = z.object({
      all: z.boolean().optional().default(false).describe('Show all containers (default shows just running)')
    });
  • ToolDefinition export bundling name, description, inputSchema, and handler for the list_containers tool.
    export const listContainers: ToolDefinition = {
      name: 'list_containers',
      description: 'List Docker containers. By default shows only running containers, use all=true to show all containers including stopped ones.',
      inputSchema,
      handler
    };
  • Central registry where listContainers is included in the AVAILABLE_TOOLS array for tool discovery.
    export const AVAILABLE_TOOLS: ToolDefinition[] = [
      execCommand,
      listContainers,
      getContainerInfo
    ];
Behavior3/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 describes the default behavior (shows only running containers) and how to change it (use all=true), which adds useful context. However, it lacks details on output format, pagination, or error handling, leaving some behavioral aspects unclear for a tool with no annotations.

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 front-loaded with the core purpose ('List Docker containers') and efficiently follows with usage details in a single, clear sentence. Every part of the description earns its place by providing essential information without any waste or unnecessary elaboration.

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is reasonably complete for basic usage. It covers the purpose and key parameter behavior. However, without annotations or an output schema, it lacks details on return values or potential errors, which could be important for full contextual understanding.

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?

The input schema has 100% description coverage, with the 'all' parameter fully documented in the schema. The description adds value by explaining the default behavior and the effect of setting 'all=true', but this is largely redundant with the schema's description. Since schema coverage is high, the baseline score of 3 is appropriate, as the description provides some reinforcement but no significant additional semantics.

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

Purpose5/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 specific and unambiguous. It distinguishes this tool from sibling tools like 'exec' and 'get_container_info' by focusing on listing rather than executing commands or getting detailed information about individual containers.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: 'By default shows only running containers, use all=true to show all containers including stopped ones.' This clearly defines the default behavior and how to modify it, offering practical usage instructions without needing to reference alternatives explicitly, as the context is straightforward.

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/davidkim9/container-exec-mcp'

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