Skip to content

feat: configurable context & container info #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sdub76
Copy link

@Sdub76 Sdub76 commented Jul 3, 2025

No description provided.

@Sdub76 Sdub76 closed this Jul 3, 2025
@Sdub76 Sdub76 reopened this Jul 3, 2025
@Sdub76
Copy link
Author

Sdub76 commented Jul 3, 2025

Sorry, I mistakenly submitted this before cleanup.

@Sdub76 Sdub76 changed the title Initial Feature Updates feat: configurable context & container info Jul 3, 2025
@Sdub76
Copy link
Author

Sdub76 commented Jul 3, 2025

Docker MCP Enhancement Summary

🎯 MINIMAL CHANGES IMPLEMENTED

This PR adds Docker context/host support and detailed container inspection while preserving all existing functionality.

✅ Changes Made

1. Docker Context/Host Support (5 lines added)

  • File: src/docker_mcp/handlers.py
  • Added: get_docker_client() function that supports:
    • DOCKER_HOST environment variable for remote Docker hosts
    • DOCKER_CONTEXT environment variable for Docker contexts
    • Backward compatible - defaults to local Docker if no env vars set
def get_docker_client():
    """Get DockerClient with support for DOCKER_HOST and DOCKER_CONTEXT env vars."""
    docker_host = os.getenv('DOCKER_HOST')
    docker_context = os.getenv('DOCKER_CONTEXT')

    if docker_host:
        return DockerClient(host=docker_host)
    elif docker_context:
        return DockerClient(context_name=docker_context)
    else:
        return DockerClient()

2. New Container Inspection Tool

  • Tool Name: get-container-info
  • Purpose: Provides comprehensive container details equivalent to docker container inspect
  • Includes:
    • Environment variables (as requested)
    • Volume mappings (as requested)
    • ✅ Port mappings
    • ✅ Network settings
    • ✅ Resource limits
    • ✅ Working directory & command
    • ✅ Container metadata (ID, status, image, created time)

🔄 What WASN'T Changed

  • ✅ All existing tools preserved exactly as-is
  • ✅ No breaking changes to existing functionality
  • ✅ Original list-containers tool unchanged
  • ✅ All existing tool signatures identical

📊 Tool Inventory

  1. create-container - Create standalone containers (unchanged)
  2. deploy-compose - Deploy Docker Compose stacks (unchanged)
  3. get-logs - Retrieve container logs (unchanged)
  4. list-containers - List all containers (unchanged)
  5. get-container-info - NEW - Detailed container inspection

🚀 Usage Examples

Remote Docker Host Support

{
  "mcpServers": {
    "docker-mcp": {
      "command": "uvx",
      "args": ["docker-mcp"],
      "env": {
        "DOCKER_HOST": "ssh://user@remote-host"
      }
    }
  }
}

Docker Context Support

{
  "mcpServers": {
    "docker-mcp": {
      "command": "uvx", 
      "args": ["docker-mcp"],
      "env": {
        "DOCKER_CONTEXT": "remote-context"
      }
    }
  }
}

Container Inspection

{
  "container_name": "my-app-container"
}

Returns detailed information including:

=== Container Information ===
Name: my-app-container
ID: abc123def456...
Status: running
Image: nginx:latest
Created: 2024-01-15T10:30:00Z
Started: 2024-01-15T10:30:05Z
=== Environment Variables ===
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  NGINX_VERSION=1.25.3
  
=== Port Mappings ===
  0.0.0.0:8080 -> 80/tcp
  
=== Volume Mounts ===
  bind: /host/data -> /usr/share/nginx/html (rw)
  
=== Network Settings ===
  Network: bridge (IP: 172.17.0.2)
  
=== Resource Limits ===
  Memory Limit: 512MB
  CPU Shares: Not set
  
=== Working Directory & Command ===
  Working Dir: /usr/share/nginx/html
  Command: nginx -g daemon off;

🎯 Benefits for Original Project

  1. Remote Docker Support: Enables use with remote Docker hosts and contexts
  2. Enhanced Monitoring: Detailed container inspection for debugging and monitoring
  3. Backward Compatibility: Zero breaking changes - all existing workflows preserved
  4. Minimal Scope: Small, focused addition that's easy to review and maintain
  5. Standard Patterns: Uses same error handling and debug patterns as existing code

📝 Technical Implementation

  • Library Used: Leverages existing python-on-whales dependency
  • Error Handling: Follows existing patterns with debug info
  • Code Style: Matches existing formatting and structure
  • Dependencies: No new dependencies required

✅ Testing

  • Context support works with environment variables
  • Backward compatibility verified - no existing functionality affected
  • New tool provides comprehensive container details
  • Error handling graceful for non-existent containers
  • All imports and syntax verified

This enhancement provides new functionality (context support, volume mappings, environment variables) while maintaining the smallest possible scope of change

@Sdub76 Sdub76 closed this Jul 3, 2025
@Sdub76 Sdub76 reopened this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant