Skip to main content
Glama
Toowiredd

ChatGPT MCP Server

container_exec

Execute commands in running Docker containers to manage processes, troubleshoot issues, or perform administrative tasks directly from the ChatGPT interface.

Instructions

Execute a command in a running container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer ID or name
commandYesCommand to execute

Implementation Reference

  • Core implementation of container_exec tool: executes `docker exec <container> <command>` via the generic executeCommand method.
    async execInContainer(id: string, command: string): Promise<string> {
      return this.executeCommand(`exec ${id} ${command}`);
    }
  • Dispatch handler in MCP server for the 'container_exec' tool call, which parses arguments and invokes DockerService.execInContainer.
    case 'container_exec': {
      const { container, command } = request.params.arguments as {
        container: string;
        command: string;
      };
      const output = await this.dockerService.execInContainer(container, command);
      return {
        content: [{ type: 'text', text: output }],
      };
    }
  • Input schema and metadata for the 'container_exec' tool, defining required parameters 'container' and 'command'.
    {
      name: 'container_exec',
      description: 'Execute a command in a running container',
      inputSchema: {
        type: 'object',
        properties: {
          container: {
            type: 'string',
            description: 'Container ID or name',
          },
          command: {
            type: 'string',
            description: 'Command to execute',
          },
        },
        required: ['container', 'command'],
      },
    },
  • Generic helper method used by execInContainer (and other tools) to run arbitrary 'docker <command>' via child_process.exec.
    async executeCommand(command: string): Promise<string> {
      try {
        const { stdout } = await execAsync(`docker ${command}`);
        return stdout;
      } catch (error: any) {
        throw new McpError(
          ErrorCode.InternalError,
          `Docker command failed: ${error.message}`
        );
      }
    }

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/Toowiredd/chatgpt-mcp-server'

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