Skip to main content
Glama
davidkim9

Container Exec MCP Server

by davidkim9

get_container_info

Retrieve detailed Docker container information including state, network, mounts, environment, and resource configuration to monitor and manage container operations.

Instructions

Get detailed information about a specific Docker container including state, network, mounts, environment, and resource configuration.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesContainer ID or name

Implementation Reference

  • The handler function executes the core logic: inspects the specified Docker container and formats a comprehensive text report covering ID, state, network settings, mounts, environment variables, command, and resource limits.
    async function handler(params: z.infer<typeof inputSchema>, context: ToolContext): Promise<CallToolResult> {
      const { container_id } = params;
      const { docker } = context;
    
      try {
        const container = docker.getContainer(container_id);
        const info = await container.inspect();
    
        // Format the output
        const name = info.Name.replace(/^\//, '');
        const state = info.State;
        const config = info.Config;
        const hostConfig = info.HostConfig;
        const networkSettings = info.NetworkSettings;
    
        let output = `Container Information: ${name}\n${'='.repeat(80)}\n\n`;
    
        // Basic Info
        output += `ID:      ${info.Id}\n`;
        output += `Name:    ${name}\n`;
        output += `Image:   ${config.Image}\n`;
        output += `Created: ${info.Created}\n\n`;
    
        // State
        output += `State:\n`;
        output += `  Status:     ${state.Status}\n`;
        output += `  Running:    ${state.Running}\n`;
        output += `  Paused:     ${state.Paused}\n`;
        output += `  Restarting: ${state.Restarting}\n`;
        output += `  Pid:        ${state.Pid}\n`;
        output += `  Exit Code:  ${state.ExitCode}\n`;
        if (state.StartedAt) output += `  Started:    ${state.StartedAt}\n`;
        if (state.FinishedAt && state.FinishedAt !== '0001-01-01T00:00:00Z') {
          output += `  Finished:   ${state.FinishedAt}\n`;
        }
        output += '\n';
    
        // Network
        output += `Network:\n`;
        output += `  IP Address: ${networkSettings.IPAddress || 'none'}\n`;
        output += `  Gateway:    ${networkSettings.Gateway || 'none'}\n`;
    
        if (networkSettings.Ports && Object.keys(networkSettings.Ports).length > 0) {
          output += `  Ports:\n`;
          for (const [containerPort, hostBindings] of Object.entries(networkSettings.Ports)) {
            if (hostBindings && Array.isArray(hostBindings)) {
              for (const binding of hostBindings) {
                output += `    ${binding.HostIp}:${binding.HostPort} -> ${containerPort}\n`;
              }
            } else {
              output += `    ${containerPort} (not published)\n`;
            }
          }
        }
    
        if (networkSettings.Networks && Object.keys(networkSettings.Networks).length > 0) {
          output += `  Networks:\n`;
          for (const [networkName, networkInfo] of Object.entries(networkSettings.Networks)) {
            output += `    ${networkName}: ${(networkInfo as any).IPAddress || 'no IP'}\n`;
          }
        }
        output += '\n';
    
        // Mounts/Volumes
        if (info.Mounts && info.Mounts.length > 0) {
          output += `Mounts:\n`;
          for (const mount of info.Mounts) {
            output += `  ${mount.Type}: ${mount.Source} -> ${mount.Destination}\n`;
            if (mount.Mode) output += `    Mode: ${mount.Mode}\n`;
          }
          output += '\n';
        }
    
        // Environment Variables
        if (config.Env && config.Env.length > 0) {
          output += `Environment:\n`;
          for (const env of config.Env) {
            output += `  ${env}\n`;
          }
          output += '\n';
        }
    
        // Command
        if (config.Cmd && Array.isArray(config.Cmd) && config.Cmd.length > 0) {
          output += `Command: ${config.Cmd.join(' ')}\n`;
        }
        if (config.Entrypoint && Array.isArray(config.Entrypoint) && config.Entrypoint.length > 0) {
          output += `Entrypoint: ${config.Entrypoint.join(' ')}\n`;
        }
        if (config.WorkingDir) {
          output += `Working Dir: ${config.WorkingDir}\n`;
        }
        output += '\n';
    
        // Resource Limits
        output += `Resources:\n`;
        if (hostConfig.Memory) output += `  Memory: ${(hostConfig.Memory / 1024 / 1024).toFixed(0)} MB\n`;
        if (hostConfig.CpuShares) output += `  CPU Shares: ${hostConfig.CpuShares}\n`;
        if (hostConfig.NanoCpus) output += `  CPU Limit: ${hostConfig.NanoCpus / 1000000000} cores\n`;
    
        output += `\nRestart Policy: ${hostConfig.RestartPolicy?.Name || 'no'}`;
        if (hostConfig.RestartPolicy?.MaximumRetryCount) {
          output += ` (max: ${hostConfig.RestartPolicy.MaximumRetryCount})`;
        }
    
        return {
          content: [{
            type: 'text',
            text: output
          }]
        };
    
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `Error getting container info: ${error instanceof Error ? error.message : 'Unknown error'}`
          }]
        };
      }
    }
  • Zod input schema defining the required 'container_id' parameter.
    const inputSchema = z.object({
      container_id: z.string().describe('Container ID or name')
    });
  • Registers the getContainerInfo tool by including it in the AVAILABLE_TOOLS array exported from the registry.
    export const AVAILABLE_TOOLS: ToolDefinition[] = [
      execCommand,
      listContainers,
      getContainerInfo
    ];
  • Imports the getContainerInfo tool definition for registration.
    import { getContainerInfo } from './get-container-info.js';
  • Exports the complete ToolDefinition object for the get_container_info tool, wiring schema and handler.
    export const getContainerInfo: ToolDefinition = {
      name: 'get_container_info',
      description: 'Get detailed information about a specific Docker container including state, network, mounts, environment, and resource configuration.',
      inputSchema,
      handler
    };
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. While it indicates this is a read operation ('Get detailed information'), it doesn't specify whether it requires specific permissions, how it handles errors (e.g., invalid container IDs), latency, or output format. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior beyond the basic purpose.

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 a single, well-structured sentence that efficiently conveys the tool's purpose and scope. It front-loads the core action ('Get detailed information') and lists specific details without unnecessary elaboration, making it easy to parse and understand quickly.

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 nested objects) and high schema coverage (100%), the description adequately covers the basic purpose. However, with no annotations and no output schema, it lacks details on behavioral aspects like permissions, error handling, and return values. For a read-only tool, this is a moderate gap, making it minimally viable but not fully comprehensive.

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%, with the single parameter 'container_id' documented as 'Container ID or name' in the schema. The description doesn't add any further meaning beyond this, such as examples or constraints (e.g., case sensitivity, partial matches). Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description provides no additional parameter insights.

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 specific action ('Get detailed information') and resource ('about a specific Docker container'), with explicit enumeration of the information types included (state, network, mounts, environment, resource configuration). It distinguishes from sibling tools like 'list_containers' (which likely lists containers rather than providing detailed info) and 'exec' (which executes commands).

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 implies usage context by specifying 'about a specific Docker container' and listing the detailed information returned, which suggests it's for inspecting a known container. However, it doesn't explicitly state when to use this tool versus alternatives like 'list_containers' (e.g., for overview vs. details) or 'exec' (e.g., for inspection vs. interaction), 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/davidkim9/container-exec-mcp'

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