Skip to main content
Glama

exec_command

Execute commands within running Docker containers to manage processes, run scripts, or perform maintenance tasks directly from your AI assistant.

Instructions

Execute a command inside a running Docker container.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesContainer ID or name
commandYesCommand and arguments, e.g. ['ls', '-la']

Implementation Reference

  • Core handler function that executes a command inside a Docker container using Dockerode. Creates an exec instance, starts it, collects output chunks from the stream, and returns the combined output as a string.
    export async function execCommand(
      id: string,
      command: string[],
    ): Promise<string> {
      const container = docker.getContainer(id);
      const exec = await container.exec({
        Cmd: command,
        AttachStdout: true,
        AttachStderr: true,
      });
      const stream = await exec.start({ hijack: true, stdin: false });
      return new Promise((resolve) => {
        const chunks: Buffer[] = [];
        stream.on("data", (chunk: Buffer) => chunks.push(chunk));
        stream.on("end", () => {
          resolve(
            Buffer.concat(chunks)
              .toString("utf-8")
              .replace(/[\x00-\x08]/g, ""), // eslint-disable-line no-control-regex
          );
        });
      });
    }
  • src/index.ts:117-132 (registration)
    Registration of the exec_command tool with the MCP server. Defines the tool name, description, input schema, and async handler that calls execCommand and returns the result as text content.
    server.tool(
      "exec_command",
      "Execute a command inside a running Docker container.",
      {
        id: z.string().describe("Container ID or name"),
        command: z
          .array(z.string())
          .describe("Command and arguments, e.g. ['ls', '-la']"),
      },
      async ({ id, command }) => {
        const output = await execCommand(id, command);
        return {
          content: [{ type: "text", text: output || "(no output)" }],
        };
      },
    );
  • Zod schema definition for exec_command tool inputs: 'id' (string for container ID/name) and 'command' (array of strings for command and arguments).
    {
      id: z.string().describe("Container ID or name"),
      command: z
        .array(z.string())
        .describe("Command and arguments, e.g. ['ls', '-la']"),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it implies a mutation operation ('execute'), it doesn't disclose critical traits: whether this requires specific permissions, if commands run with container user privileges, potential security implications, error handling for invalid commands, or output format. This leaves significant gaps for a tool that executes arbitrary commands.

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, efficient sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 this is a command execution tool with no annotations and no output schema, the description is incomplete. It doesn't address security implications, error conditions, output handling, or execution context. For a tool that can run arbitrary commands in containers, more behavioral context is needed to use it safely and effectively.

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 both parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't clarify command execution context, shell vs. exec format, or environment variables). The baseline of 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 action ('execute a command') and target ('inside a running Docker container'), providing specific verb+resource information. However, it doesn't distinguish this tool from potential alternatives like 'container_logs' or 'container_stats' which also interact with containers but serve different purposes.

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 (e.g., the container must be running), exclusions (e.g., not for stopped containers), or comparisons with sibling tools like 'container_logs' (for viewing output) or 'restart_container' (for container management).

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