Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

docker_exec

Execute commands inside running Docker containers to run scripts, debug applications, or perform administrative tasks within container environments.

Instructions

Execute a command inside a running container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer name or ID
commandYesCommand to execute
workdirNoWorking directory inside container
userNoUser to run command as
envNoEnvironment variables
cwdNoWorking directory

Implementation Reference

  • Main handler function that constructs and executes the docker exec command using the helper executeDockerCommand
    export async function dockerExec(args: z.infer<typeof dockerExecSchema>): Promise<ToolResponse> {
      const workdirFlag = args.workdir ? `-w ${args.workdir}` : '';
      const userFlag = args.user ? `-u ${args.user}` : '';
      const envFlags = args.env
        ? Object.entries(args.env).map(([key, value]) => `-e ${key}="${value}"`).join(' ')
        : '';
    
      // Escape the command for shell execution
      const escapedCommand = args.command.replace(/"/g, '\\"');
    
      return executeDockerCommand(
        `docker exec ${workdirFlag} ${userFlag} ${envFlags} ${args.container} sh -c "${escapedCommand}"`.trim(),
        args.cwd
      );
    }
  • Zod schema for validating docker_exec tool inputs
    export const dockerExecSchema = z.object({
      container: z.string().describe('Container name or ID'),
      command: z.string().describe('Command to execute'),
      workdir: z.string().optional().describe('Working directory inside container'),
      user: z.string().optional().describe('User to run command as'),
      env: z.record(z.string()).optional().describe('Environment variables'),
      cwd: z.string().optional().describe('Working directory')
    });
  • src/index.ts:451-453 (registration)
    Dispatch handler in main server that validates args with schema and calls the dockerExec function
    if (name === 'docker_exec') {
      const validated = dockerExecSchema.parse(args);
      return await dockerExec(validated);
  • Tool metadata definition in dockerTools array used for listing available tools
    {
      name: 'docker_exec',
      description: 'Execute a command inside a running container',
      inputSchema: {
        type: 'object',
        properties: {
          container: { type: 'string', description: 'Container name or ID' },
          command: { type: 'string', description: 'Command to execute' },
          workdir: { type: 'string', description: 'Working directory inside container' },
          user: { type: 'string', description: 'User to run command as' },
          env: { type: 'object', additionalProperties: { type: 'string' }, description: 'Environment variables' },
          cwd: { type: 'string', description: 'Working directory' }
        },
        required: ['container', 'command']
      }
    },
  • Helper function that executes docker commands and formats the ToolResponse
    async function executeDockerCommand(command: string, cwd?: string): Promise<ToolResponse> {
      try {
        const { stdout, stderr } = await execAsync(command, {
          cwd: cwd || process.cwd(),
          shell: '/bin/bash',
          maxBuffer: 10 * 1024 * 1024, // 10MB buffer for logs
          timeout: 60000 // 60 second timeout for builds
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: true,
                command: command,
                stdout: stdout.trim(),
                stderr: stderr.trim(),
                cwd: cwd || process.cwd()
              }, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: false,
                command: command,
                stdout: error.stdout?.trim() || '',
                stderr: error.stderr?.trim() || error.message,
                exitCode: error.code || 1,
                cwd: cwd || process.cwd()
              }, null, 2)
            }
          ],
          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 states the action but doesn't cover critical aspects like permissions required (e.g., Docker access), side effects (e.g., command output, potential container changes), error handling, or security implications (e.g., running arbitrary commands). This is a significant gap for a tool that executes commands in containers.

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, clear sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for the tool's complexity.

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 tool's complexity (command execution in containers), lack of annotations, and no output schema, the description is insufficient. It doesn't address behavioral traits, output format, error cases, or security considerations, leaving significant gaps for an AI agent to use it correctly.

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 documents all parameters (container, command, workdir, user, env, cwd). The description adds no additional meaning beyond implying execution context, but doesn't explain parameter interactions (e.g., 'workdir' vs 'cwd') or usage examples. Baseline 3 is appropriate when 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 container'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'shell_execute' or 'docker_compose_logs', which also involve command execution or container interaction.

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, or comparisons to siblings like 'shell_execute' (for host commands) or 'docker_compose_logs' (for container logs).

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/ConnorBoetig-dev/mcp2'

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