Skip to main content
Glama

Remote Docker Connection

docker_remote_connection

Connect to remote Docker hosts via SSH or configure Docker host connections for managing containers and images from a distance.

Instructions

Connect to remote Docker hosts via SSH or configure Docker host

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesConnection action
hostNoDocker host URL (e.g., ssh://user@host, tcp://host:2376)
userNoSSH username
keyPathNoPath to SSH private key

Implementation Reference

  • The main handler function for the 'docker_remote_connection' tool. It processes actions like 'connect', 'disconnect', 'status', and 'test' by interacting with the RemoteDockerManager class.
    async ({ action, host, user, keyPath }) => {
      try {
        switch (action) {
          case "connect":
            if (!host) {
              throw new Error("Host is required for connection");
            }
            
            // Configure SSH connection if needed
            if (host.startsWith("ssh://")) {
              const sshHost = host.replace("ssh://", "");
              if (user && !sshHost.includes("@")) {
                host = `ssh://${user}@${sshHost}`;
              }
            }
            
            RemoteDockerManager.setDockerHost(host);
            const isConnected = await RemoteDockerManager.testConnection();
            
            if (!isConnected) {
              throw new Error("Failed to connect to remote Docker host");
            }
            
            return {
              content: [
                {
                  type: "text",
                  text: `✅ Successfully connected to Docker host: ${host}\n\nUse 'docker_remote_connection' with action 'status' to check connection status.`
                }
              ]
            };
    
          case "disconnect":
            RemoteDockerManager.setDockerHost("");
            delete process.env.DOCKER_HOST;
            
            return {
              content: [
                {
                  type: "text",
                  text: "✅ Disconnected from remote Docker host. Using local Docker daemon."
                }
              ]
            };
    
          case "status":
            const connectionInfo = await RemoteDockerManager.getConnectionInfo();
            return {
              content: [
                {
                  type: "text",
                  text: `## Docker Connection Status\n\n${connectionInfo}`
                }
              ]
            };
    
          case "test":
            const testResult = await RemoteDockerManager.testConnection();
            const currentHost = RemoteDockerManager.getDockerHost();
            
            return {
              content: [
                {
                  type: "text",
                  text: `## Connection Test\n\nHost: ${currentHost || 'local'}\nStatus: ${testResult ? '✅ Connected' : '❌ Failed'}`
                }
              ]
            };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error with remote connection: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • The schema definition for the 'docker_remote_connection' tool, including title, description, and Zod inputSchema for validation.
    {
      title: "Remote Docker Connection",
      description: "Connect to remote Docker hosts via SSH or configure Docker host",
      inputSchema: {
        action: z.enum(["connect", "disconnect", "status", "test"]).describe("Connection action"),
        host: z.string().optional().describe("Docker host URL (e.g., ssh://user@host, tcp://host:2376)"),
        user: z.string().optional().describe("SSH username"),
        keyPath: z.string().optional().describe("Path to SSH private key")
      }
    },
  • src/index.ts:726-819 (registration)
    The server.registerTool call that registers the 'docker_remote_connection' tool with its schema and handler function.
    server.registerTool(
      "docker_remote_connection",
      {
        title: "Remote Docker Connection",
        description: "Connect to remote Docker hosts via SSH or configure Docker host",
        inputSchema: {
          action: z.enum(["connect", "disconnect", "status", "test"]).describe("Connection action"),
          host: z.string().optional().describe("Docker host URL (e.g., ssh://user@host, tcp://host:2376)"),
          user: z.string().optional().describe("SSH username"),
          keyPath: z.string().optional().describe("Path to SSH private key")
        }
      },
      async ({ action, host, user, keyPath }) => {
        try {
          switch (action) {
            case "connect":
              if (!host) {
                throw new Error("Host is required for connection");
              }
              
              // Configure SSH connection if needed
              if (host.startsWith("ssh://")) {
                const sshHost = host.replace("ssh://", "");
                if (user && !sshHost.includes("@")) {
                  host = `ssh://${user}@${sshHost}`;
                }
              }
              
              RemoteDockerManager.setDockerHost(host);
              const isConnected = await RemoteDockerManager.testConnection();
              
              if (!isConnected) {
                throw new Error("Failed to connect to remote Docker host");
              }
              
              return {
                content: [
                  {
                    type: "text",
                    text: `✅ Successfully connected to Docker host: ${host}\n\nUse 'docker_remote_connection' with action 'status' to check connection status.`
                  }
                ]
              };
    
            case "disconnect":
              RemoteDockerManager.setDockerHost("");
              delete process.env.DOCKER_HOST;
              
              return {
                content: [
                  {
                    type: "text",
                    text: "✅ Disconnected from remote Docker host. Using local Docker daemon."
                  }
                ]
              };
    
            case "status":
              const connectionInfo = await RemoteDockerManager.getConnectionInfo();
              return {
                content: [
                  {
                    type: "text",
                    text: `## Docker Connection Status\n\n${connectionInfo}`
                  }
                ]
              };
    
            case "test":
              const testResult = await RemoteDockerManager.testConnection();
              const currentHost = RemoteDockerManager.getDockerHost();
              
              return {
                content: [
                  {
                    type: "text",
                    text: `## Connection Test\n\nHost: ${currentHost || 'local'}\nStatus: ${testResult ? '✅ Connected' : '❌ Failed'}`
                  }
                ]
              };
          }
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error with remote connection: ${error instanceof Error ? error.message : String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • The RemoteDockerManager class providing static methods for managing Docker host connections, testing connectivity, and getting connection info, used by the tool handler.
    class RemoteDockerManager {
      private static currentHost: string | null = null;
    
      static setDockerHost(host: string): void {
        this.currentHost = host;
        process.env.DOCKER_HOST = host;
      }
    
      static getDockerHost(): string | null {
        return this.currentHost || process.env.DOCKER_HOST || null;
      }
    
      static async testConnection(): Promise<boolean> {
        try {
          await executeDockerCommand("docker version");
          return true;
        } catch {
          return false;
        }
      }
    
      static async getConnectionInfo(): Promise<string> {
        const host = this.getDockerHost();
        const isConnected = await this.testConnection();
        
        return `Docker Host: ${host || 'local'}\nConnection: ${isConnected ? '✅ Connected' : '❌ Failed'}`;
      }
    }
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 mentions connection and configuration actions but fails to describe critical traits: whether this tool mutates state (e.g., persistent configuration changes), requires authentication details beyond parameters, has side effects (e.g., network timeouts), or returns specific output formats. For a tool with multiple actions and remote operations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It avoids redundancy and wastes no words, though it could benefit from slightly more detail given the tool's complexity. The structure is clear but minimal.

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 (4 parameters, multiple actions, remote operations) and lack of annotations and output schema, the description is incomplete. It doesn't cover behavioral aspects like error handling, output format, or security implications, leaving the agent under-informed for safe and effective use.

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 input schema fully documents all parameters (action, host, user, keyPath). The description adds no additional meaning beyond the schema—it doesn't explain parameter interactions (e.g., 'host' required for 'connect' but not 'status'), usage examples, or constraints. Baseline 3 is appropriate as the schema handles 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 tool's purpose: 'Connect to remote Docker hosts via SSH or configure Docker host.' It specifies the verb ('connect') and resource ('remote Docker hosts'), and mentions configuration as an alternative action. However, it doesn't explicitly differentiate from sibling tools like 'docker_compose' or 'execute_docker_command', which might also involve remote connections indirectly.

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., SSH setup), exclusions (e.g., not for local Docker), or compare to siblings like 'docker_compose' for orchestration. The lack of context leaves the agent guessing about appropriate use cases.

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/TauqeerAhmad5201/docker-mcp-extension'

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