Skip to main content
Glama
widjis
by widjis

ssh_docker_deploy

Deploy Docker containers via SSH using docker-compose, build, or run commands with working directory context, environment variables, port mappings, and volume configurations.

Instructions

Deploy Docker containers with working directory context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID
workingDirectoryYesDirectory containing docker-compose.yml or Dockerfile
deploymentTypeYesType of Docker deployment
imageNameNoDocker image name (for build/run)
containerNameNoContainer name (for run)
composeFileNoDocker compose file namedocker-compose.yml
buildArgsNoBuild arguments for Docker build
envVarsNoEnvironment variables
portsNoPort mappings (e.g., ["8080:80", "3000:3000"])
volumesNoVolume mappings (e.g., ["/host/path:/container/path"])
detachedNoRun in detached mode

Implementation Reference

  • The handler function for 'ssh_docker_deploy' tool. It validates input using DockerDeploySchema, constructs Docker commands (docker-compose up, docker build, or docker run) based on deploymentType, executes them remotely via SSH in the specified working directory, and returns the command output including stdout, stderr, and exit code.
    private async handleDockerDeploy(args: unknown) {
      const params = DockerDeploySchema.parse(args);
      
      const context = connectionContexts.get(params.connectionId);
      if (!context) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Connection ID '${params.connectionId}' not found`
        );
      }
    
      try {
        // Set working directory for this operation
        const workingDir = params.workingDirectory;
        
        let command = '';
        let envPrefix = '';
        
        // Build environment variables prefix
        if (params.envVars) {
          const envVarStrings = Object.entries(params.envVars).map(([key, value]) => `${key}="${value}"`);
          envPrefix = envVarStrings.join(' ') + ' ';
        }
        
        switch (params.deploymentType) {
          case 'compose':
            command = `${envPrefix}docker-compose`;
            if (params.composeFile && params.composeFile !== 'docker-compose.yml') {
              command += ` -f ${params.composeFile}`;
            }
            command += ' up';
            if (params.detached) {
              command += ' -d';
            }
            break;
            
          case 'build':
            if (!params.imageName) {
              throw new McpError(
                ErrorCode.InvalidParams,
                'imageName is required for build deployment type'
              );
            }
            command = `${envPrefix}docker build`;
            if (params.buildArgs) {
              Object.entries(params.buildArgs).forEach(([key, value]) => {
                command += ` --build-arg ${key}="${value}"`;
              });
            }
            command += ` -t ${params.imageName} .`;
            break;
            
          case 'run':
            if (!params.imageName) {
              throw new McpError(
                ErrorCode.InvalidParams,
                'imageName is required for run deployment type'
              );
            }
            command = `${envPrefix}docker run`;
            if (params.detached) {
              command += ' -d';
            }
            if (params.containerName) {
              command += ` --name ${params.containerName}`;
            }
            if (params.ports) {
              params.ports.forEach(port => {
                command += ` -p ${port}`;
              });
            }
            if (params.volumes) {
              params.volumes.forEach(volume => {
                command += ` -v ${volume}`;
              });
            }
            command += ` ${params.imageName}`;
            break;
        }
        
        const result = await context.ssh.execCommand(command, {
          cwd: workingDir,
        });
        
        return {
          content: [
            {
              type: 'text',
              text: `Docker ${params.deploymentType} deployment:\nCommand: ${command}\nExit Code: ${result.code}\n\nSTDOUT:\n${result.stdout}\n\nSTDERR:\n${result.stderr}`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Docker deployment failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema defining the input parameters and validation for the ssh_docker_deploy tool.
    const DockerDeploySchema = z.object({
      connectionId: z.string().describe('SSH connection ID'),
      workingDirectory: z.string().describe('Directory containing docker-compose.yml or Dockerfile'),
      deploymentType: z.enum(['compose', 'build', 'run']).describe('Type of Docker deployment'),
      imageName: z.string().optional().describe('Docker image name (for build/run)'),
      containerName: z.string().optional().describe('Container name (for run)'),
      composeFile: z.string().default('docker-compose.yml').describe('Docker compose file name'),
      buildArgs: z.record(z.string()).optional().describe('Build arguments for Docker build'),
      envVars: z.record(z.string()).optional().describe('Environment variables'),
      ports: z.array(z.string()).optional().describe('Port mappings (e.g., ["8080:80", "3000:3000"])'),
      volumes: z.array(z.string()).optional().describe('Volume mappings (e.g., ["/host/path:/container/path"])'),
      detached: z.boolean().default(true).describe('Run in detached mode')
    });
  • src/index.ts:443-463 (registration)
    Tool registration in the ListTools response, defining name, description, and inputSchema mirroring the Zod schema.
    {
      name: 'ssh_docker_deploy',
      description: 'Deploy Docker containers with working directory context',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: { type: 'string', description: 'SSH connection ID' },
          workingDirectory: { type: 'string', description: 'Directory containing docker-compose.yml or Dockerfile' },
          deploymentType: { type: 'string', enum: ['compose', 'build', 'run'], description: 'Type of Docker deployment' },
          imageName: { type: 'string', description: 'Docker image name (for build/run)' },
          containerName: { type: 'string', description: 'Container name (for run)' },
          composeFile: { type: 'string', default: 'docker-compose.yml', description: 'Docker compose file name' },
          buildArgs: { type: 'object', description: 'Build arguments for Docker build' },
          envVars: { type: 'object', description: 'Environment variables' },
          ports: { type: 'array', items: { type: 'string' }, description: 'Port mappings (e.g., ["8080:80", "3000:3000"])' },
          volumes: { type: 'array', items: { type: 'string' }, description: 'Volume mappings (e.g., ["/host/path:/container/path"])' },
          detached: { type: 'boolean', default: true, description: 'Run in detached mode' }
        },
        required: ['connectionId', 'workingDirectory', 'deploymentType']
      },
    },
  • src/index.ts:517-518 (registration)
    Dispatch case in the CallToolRequest handler that routes to the handleDockerDeploy function.
    case 'ssh_docker_deploy':
      return await this.handleDockerDeploy(args);
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. It mentions 'working directory context' but fails to detail critical behaviors: it doesn't specify if this is a read-only or destructive operation (likely destructive as it deploys containers), what happens on failure, or any side effects like network changes. For a complex deployment tool with 11 parameters, this is a significant gap in transparency.

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 gets straight to the point without fluff. It's front-loaded with the core action ('Deploy Docker containers') and includes a key constraint. However, it could be more structured by explicitly mentioning the three deployment types or linking to sibling tools, but it avoids wastefulness.

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 (11 parameters, no annotations, no output schema), the description is insufficient. It doesn't cover behavioral aspects like error handling, output format, or prerequisites (e.g., SSH connection setup). For a deployment tool that likely involves mutations and side effects, more context is needed to guide the agent effectively, making it incomplete.

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 11 parameters thoroughly. The description adds minimal value beyond the schema—it hints at the 'workingDirectory' parameter's role but doesn't explain parameter interactions (e.g., how deploymentType affects other params). Baseline 3 is appropriate as the schema does the heavy lifting, though the description could have clarified dependencies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Deploy Docker containers with working directory context' states the general action (deploy Docker containers) and mentions a key constraint (working directory context), but it's vague about what 'deploy' entails—it could mean building, running, or composing. It doesn't clearly distinguish from sibling tools like ssh_docker_status, which monitors containers, leaving ambiguity about its specific role.

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?

No explicit guidance is provided on when to use this tool versus alternatives. While the description implies it's for Docker deployments, it doesn't specify prerequisites (e.g., needing an SSH connection first) or contrast with siblings like ssh_execute for general commands. The lack of when-to-use or when-not-to-use statements leaves the agent to infer context from parameters alone.

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/widjis/mcp-ssh'

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