ruby_llm-docker 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,49 +2,52 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for creating Docker containers without starting them.
5
+ # MCP tool for creating Docker containers.
6
6
  #
7
- # This tool provides the ability to create Docker containers from images with
8
- # comprehensive configuration options. Unlike RunContainer, this tool only
9
- # creates the container but does not start it, allowing for additional
10
- # configuration or manual startup control.
7
+ # This tool creates a new Docker container from a specified image without
8
+ # starting it. The container is created in a "created" state and can be
9
+ # started later using the start_container tool. This two-step process
10
+ # allows for container configuration before execution.
11
11
  #
12
12
  # == Features
13
13
  #
14
- # - Create containers from any available Docker image
15
- # - Full container configuration support
16
- # - Port exposure and binding configuration
17
- # - Volume mounting capabilities
18
- # - Environment variable configuration
19
- # - Custom command specification
20
- # - Comprehensive error handling with specific error types
14
+ # - Creates containers from any available Docker image
15
+ # - Supports custom container naming
16
+ # - Configures command execution and environment variables
17
+ # - Sets up port exposure and network configuration
18
+ # - Applies advanced host configurations
19
+ # - Handles container labeling and metadata
21
20
  #
22
21
  # == Security Considerations
23
22
  #
24
- # - Containers inherit Docker daemon security context
25
- # - Host configuration can expose host resources
26
- # - Volume mounts provide filesystem access
27
- # - Port bindings expose services to networks
28
- # - Environment variables may contain sensitive data
23
+ # Container creation is a powerful operation that can:
24
+ # - **Resource Allocation**: Consume system resources and storage
25
+ # - **Network Access**: Create network endpoints and bindings
26
+ # - **File System Access**: Mount host directories and volumes
27
+ # - **Security Context**: Run with elevated privileges if configured
29
28
  #
30
- # Use appropriate security measures:
31
- # - Validate image sources and integrity
32
- # - Limit host resource exposure
33
- # - Use read-only volumes where appropriate
34
- # - Restrict network access through host configuration
35
- # - Sanitize environment variables
29
+ # Implement proper access controls and resource limits.
30
+ #
31
+ # == Parameters
32
+ #
33
+ # - **image**: Docker image to use (required)
34
+ # - **name**: Custom container name (optional)
35
+ # - **cmd**: Command to execute as space-separated string (optional)
36
+ # - **env**: Environment variables as comma-separated KEY=VALUE pairs (optional)
37
+ # - **exposed_ports**: Port exposure configuration as JSON object (optional)
38
+ # - **host_config**: Advanced host configuration as JSON object (optional)
36
39
  #
37
40
  # == Example Usage
38
41
  #
39
42
  # # Simple container creation
40
- # CreateContainer.call(
43
+ # response = CreateContainer.call(
41
44
  # server_context: context,
42
45
  # image: "nginx:latest",
43
46
  # name: "web-server"
44
47
  # )
45
48
  #
46
49
  # # Advanced container with configuration
47
- # CreateContainer.call(
50
+ # response = CreateContainer.call(
48
51
  # server_context: context,
49
52
  # image: "postgres:13",
50
53
  # name: "database",
@@ -56,76 +59,49 @@ module RubyLLM
56
59
  # }
57
60
  # )
58
61
  #
59
- # @see RunContainer
60
- # @see StartContainer
61
- # @see Docker::Container.create
62
+ # @see ::Docker::Container.create
62
63
  # @since 0.1.0
63
- class CreateContainer < RubyLLM::Tool
64
+ CREATE_CONTAINER_DEFINITION = ToolForge.define(:create_container) do
64
65
  description 'Create a Docker container'
65
66
 
66
- param :image, desc: 'Image name to use (e.g., "ubuntu:22.04")'
67
- param :name, desc: 'Container name (optional)', required: false
68
- param :cmd, desc: 'Command to run (optional)', required: false
67
+ param :image,
68
+ type: :string,
69
+ description: 'Image name to use (e.g., "ubuntu:22.04")'
70
+
71
+ param :name,
72
+ type: :string,
73
+ description: 'Container name (optional)',
74
+ required: false
75
+
76
+ param :cmd,
77
+ type: :string,
78
+ description: 'Command to run as space-separated string (optional, e.g., "npm start" or "python app.py")',
79
+ required: false
80
+
69
81
  param :env,
70
- desc: 'Environment variables as comma-separated KEY=VALUE pairs ' \
71
- '(optional, e.g., "VAR1=value1,VAR2=value2")',
82
+ type: :string,
83
+ description: 'Environment variables as comma-separated KEY=VALUE pairs (optional)',
72
84
  required: false
73
- param :exposed_ports, desc: 'Exposed ports as JSON object (optional)', required: false
74
- param :host_config, desc: 'Host configuration including port bindings, volumes, etc. as JSON object (optional)',
75
- required: false
76
85
 
77
- # Create a new Docker container from an image.
78
- #
79
- # This method creates a container with the specified configuration but does
80
- # not start it. The container can be started later using StartContainer or
81
- # other Docker commands. All configuration parameters are optional except
82
- # for the base image.
83
- #
84
- # @param image [String] Docker image name with optional tag (e.g., "nginx:latest")
85
- # @param server_context [Object] RubyLLM context (unused but required)
86
- # @param name [String, nil] custom name for the container
87
- # @param cmd [String, nil] command to execute in the container
88
- # @param env [String, nil] environment variables as comma-separated KEY=VALUE pairs
89
- # @param exposed_ports [Hash, nil] ports to expose in {"port/protocol" => {}} format
90
- # @param host_config [Hash, nil] Docker host configuration including bindings and volumes
91
- #
92
- # @return [RubyLLM::Tool::Response] creation results with container ID and name
93
- #
94
- # @raise [Docker::Error::NotFoundError] if the specified image doesn't exist
95
- # @raise [Docker::Error::ConflictError] if container name already exists
96
- # @raise [StandardError] for other creation failures
97
- #
98
- # @example Create simple container
99
- # response = CreateContainer.call(
100
- # server_context: context,
101
- # image: "alpine:latest",
102
- # name: "test-container"
103
- # )
104
- #
105
- # @example Create container with full configuration
106
- # response = CreateContainer.call(
107
- # server_context: context,
108
- # image: "redis:7-alpine",
109
- # name: "redis-cache",
110
- # env: "REDIS_PASSWORD=secret",
111
- # exposed_ports: {"6379/tcp" => {}},
112
- # host_config: {
113
- # "PortBindings" => {"6379/tcp" => [{"HostPort" => "6379"}]},
114
- # "RestartPolicy" => {"Name" => "unless-stopped"}
115
- # }
116
- # )
117
- #
118
- # @see Docker::Container.create
119
- def execute(image:, name: nil, cmd: nil, env: nil, exposed_ports: nil, host_config: nil)
86
+ param :exposed_ports,
87
+ type: :object,
88
+ description: 'Exposed ports as {"port/protocol": {}} (optional)',
89
+ required: false
90
+
91
+ param :host_config,
92
+ type: :object,
93
+ description: 'Host configuration including port bindings, volumes, etc. (optional)',
94
+ required: false
95
+
96
+ execute do |image:, name: nil, cmd: nil, env: nil, exposed_ports: nil, host_config: nil|
120
97
  config = { 'Image' => image }
121
98
  config['name'] = name if name
122
- config['Cmd'] = cmd if cmd
123
99
 
124
- # Parse environment variables string into array if provided
125
- if env && !env.empty?
126
- env_array = env.split(',').map(&:strip).select { |e| e.include?('=') }
127
- config['Env'] = env_array unless env_array.empty?
128
- end
100
+ # Parse cmd string into array if provided
101
+ config['Cmd'] = Shellwords.split(cmd) if cmd && !cmd.strip.empty?
102
+
103
+ # Parse env string into array if provided
104
+ config['Env'] = env.split(',').map(&:strip) if env && !env.strip.empty?
129
105
 
130
106
  config['ExposedPorts'] = exposed_ports if exposed_ports
131
107
  config['HostConfig'] = host_config if host_config
@@ -142,5 +118,7 @@ module RubyLLM
142
118
  "Error creating container: #{e.message}"
143
119
  end
144
120
  end
121
+
122
+ CreateContainer = CREATE_CONTAINER_DEFINITION.to_ruby_llm_tool
145
123
  end
146
124
  end
@@ -2,116 +2,98 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for creating Docker networks.
5
+ # MCP tool for creating Docker networks.
6
6
  #
7
- # This tool provides the ability to create custom Docker networks for
8
- # container communication and isolation. Networks enable containers to
9
- # communicate securely while providing isolation from other network
10
- # segments.
7
+ # This tool provides the ability to create custom Docker networks
8
+ # for container communication and isolation. Networks enable secure
9
+ # and controlled communication between containers and external systems.
11
10
  #
12
11
  # == Features
13
12
  #
14
13
  # - Create custom Docker networks
15
- # - Support for different network drivers
16
- # - Duplicate name detection
14
+ # - Support for multiple network drivers (bridge, overlay, host, etc.)
15
+ # - Duplicate name checking and validation
16
+ # - Network configuration and options
17
17
  # - Comprehensive error handling
18
- # - Flexible network configuration
19
- #
20
- # == Network Drivers
21
- #
22
- # Docker supports various network drivers:
23
- # - **bridge**: Default isolated network for single-host networking
24
- # - **host**: Remove network isolation, use host networking directly
25
- # - **overlay**: Multi-host networking for swarm services
26
- # - **macvlan**: Assign MAC addresses to containers
27
- # - **none**: Disable networking completely
28
- # - **Custom**: Third-party network drivers
18
+ # - Network isolation and security controls
29
19
  #
30
20
  # == Security Considerations
31
21
  #
32
- # Network creation affects system security:
33
- # - **Network Isolation**: Networks provide security boundaries
34
- # - **Traffic Control**: Custom networks enable traffic filtering
35
- # - **Access Control**: Networks control container communication
36
- # - **DNS Resolution**: Networks provide internal DNS services
22
+ # Network creation involves important security considerations:
23
+ # - **Network Isolation**: Improper networks can compromise container isolation
24
+ # - **Traffic Control**: Networks affect inter-container communication
25
+ # - **External Access**: Bridge networks may expose containers externally
26
+ # - **Resource Usage**: Networks consume system resources
27
+ # - **DNS Resolution**: Custom networks affect service discovery
28
+ # - **Firewall Bypass**: Networks can bypass host firewall rules
37
29
  #
38
- # Security implications:
39
- # - Bridge networks isolate containers from host network
40
- # - Host networks expose containers to all host traffic
41
- # - Custom networks should follow least-privilege principles
42
- # - Network names may reveal infrastructure details
43
- #
44
- # Best practices:
45
- # - Use descriptive but not sensitive network names
30
+ # **Security Recommendations**:
31
+ # - Use appropriate network drivers for use case
46
32
  # - Implement network segmentation strategies
47
- # - Limit container access to necessary networks only
48
- # - Monitor network traffic and connections
33
+ # - Monitor network traffic and usage
34
+ # - Avoid exposing internal networks externally
35
+ # - Use network policies for access control
49
36
  # - Regular audit of network configurations
50
37
  #
38
+ # == Parameters
39
+ #
40
+ # - **name**: Name of the network (required)
41
+ # - **driver**: Driver to use (optional, default: "bridge")
42
+ # - **check_duplicate**: Check for networks with duplicate names (optional, default: true)
43
+ #
44
+ # == Network Drivers
45
+ #
46
+ # - **bridge**: Default driver for single-host networking
47
+ # - **overlay**: Multi-host networking for Docker Swarm
48
+ # - **host**: Uses host's network stack directly
49
+ # - **none**: Disables networking for containers
50
+ # - **macvlan**: Assigns MAC addresses to containers
51
+ #
51
52
  # == Example Usage
52
53
  #
53
54
  # # Create basic bridge network
54
- # CreateNetwork.call(
55
+ # response = CreateNetwork.call(
55
56
  # server_context: context,
56
57
  # name: "app-network"
57
58
  # )
58
59
  #
59
- # # Create network with specific driver
60
- # CreateNetwork.call(
60
+ # # Create overlay network for swarm
61
+ # response = CreateNetwork.call(
61
62
  # server_context: context,
62
- # name: "frontend-net",
63
- # driver: "bridge"
63
+ # name: "swarm-network",
64
+ # driver: "overlay"
64
65
  # )
65
66
  #
66
- # # Create without duplicate checking
67
- # CreateNetwork.call(
67
+ # # Create network allowing duplicates
68
+ # response = CreateNetwork.call(
68
69
  # server_context: context,
69
- # name: "temp-network",
70
+ # name: "test-network",
71
+ # driver: "bridge",
70
72
  # check_duplicate: false
71
73
  # )
72
74
  #
73
- # @see ListNetworks
74
- # @see RemoveNetwork
75
- # @see Docker::Network.create
75
+ # @see ::Docker::Network.create
76
76
  # @since 0.1.0
77
- class CreateNetwork < RubyLLM::Tool
77
+ CREATE_NETWORK_DEFINITION = ToolForge.define(:create_network) do
78
78
  description 'Create a Docker network'
79
79
 
80
- param :name, type: :string, desc: 'Name of the network'
81
- param :driver, type: :string, desc: 'Driver to use (default: bridge)', required: false
82
- param :check_duplicate, type: :boolean, desc: 'Check for networks with duplicate names (default: true)',
83
- required: false
80
+ param :name,
81
+ type: :string,
82
+ description: 'Name of the network'
84
83
 
85
- # Create a new Docker network.
86
- #
87
- # This method creates a custom Docker network with the specified name
88
- # and driver. The network can then be used by containers for isolated
89
- # communication.
90
- #
91
- # @param name [String] name for the new network
92
- # @param server_context [Object] RubyLLM context (unused but required)
93
- # @param driver [String] network driver to use (default: "bridge")
94
- # @param check_duplicate [Boolean] whether to check for duplicate names (default: true)
95
- #
96
- # @return [RubyLLM::Tool::Response] network creation results with network ID
97
- #
98
- # @raise [Docker::Error::ConflictError] if network name already exists
99
- # @raise [StandardError] for other network creation failures
100
- #
101
- # @example Create application network
102
- # response = CreateNetwork.call(
103
- # server_context: context,
104
- # name: "webapp-network"
105
- # )
106
- #
107
- # @example Create host network
108
- # response = tool.execute(
109
- # name: "high-performance-net",
110
- # driver: "host"
111
- # )
112
- #
113
- # @see Docker::Network.create
114
- def execute(name:, driver: 'bridge', check_duplicate: true)
84
+ param :driver,
85
+ type: :string,
86
+ description: 'Driver to use (default: bridge)',
87
+ required: false,
88
+ default: 'bridge'
89
+
90
+ param :check_duplicate,
91
+ type: :boolean,
92
+ description: 'Check for networks with duplicate names (default: true)',
93
+ required: false,
94
+ default: true
95
+
96
+ execute do |name:, driver: 'bridge', check_duplicate: true|
115
97
  options = {
116
98
  'Name' => name,
117
99
  'Driver' => driver,
@@ -127,5 +109,7 @@ module RubyLLM
127
109
  "Error creating network: #{e.message}"
128
110
  end
129
111
  end
112
+
113
+ CreateNetwork = CREATE_NETWORK_DEFINITION.to_ruby_llm_tool
130
114
  end
131
115
  end
@@ -2,115 +2,91 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for creating Docker volumes.
5
+ # MCP tool for creating Docker volumes.
6
6
  #
7
- # This tool provides the ability to create persistent Docker volumes for
8
- # data storage that survives container lifecycle events. Volumes are the
9
- # preferred mechanism for persisting data generated and used by Docker
10
- # containers.
7
+ # This tool provides the ability to create Docker volumes for persistent
8
+ # data storage. Volumes are essential for maintaining data across container
9
+ # lifecycles and enabling data sharing between containers.
11
10
  #
12
11
  # == Features
13
12
  #
14
- # - Create named persistent volumes
15
- # - Support for different volume drivers
13
+ # - Create named Docker volumes
14
+ # - Support for multiple volume drivers
15
+ # - Persistent data storage management
16
+ # - Volume driver configuration
16
17
  # - Comprehensive error handling
17
- # - Duplicate name detection
18
- # - Flexible storage configuration
18
+ # - Volume lifecycle management
19
19
  #
20
- # == Volume Drivers
21
- #
22
- # Docker supports various volume drivers:
23
- # - **local**: Default driver using host filesystem
24
- # - **nfs**: Network File System for shared storage
25
- # - **cifs**: Common Internet File System
26
- # - **rexray**: External storage orchestration
27
- # - **Custom**: Third-party volume drivers
20
+ # == Security Considerations
28
21
  #
29
- # == Persistence Benefits
22
+ # Volume creation involves important security considerations:
23
+ # - **Data Persistence**: Volumes store data beyond container lifecycle
24
+ # - **Access Control**: Volume permissions affect data security
25
+ # - **Data Isolation**: Improper volumes can compromise data separation
26
+ # - **Storage Security**: Volume drivers may have security implications
27
+ # - **Resource Usage**: Volumes consume disk space and system resources
28
+ # - **Data Leakage**: Shared volumes can expose sensitive data
30
29
  #
31
- # Docker volumes provide several advantages:
32
- # - **Data Persistence**: Survive container deletion and recreation
33
- # - **Performance**: Better performance than bind mounts on Docker Desktop
34
- # - **Portability**: Can be moved between containers and hosts
35
- # - **Backup**: Easier to backup and restore than container filesystems
36
- # - **Sharing**: Can be shared between multiple containers
37
- # - **Management**: Managed by Docker daemon with proper lifecycle
30
+ # **Security Recommendations**:
31
+ # - Use appropriate volume drivers for security requirements
32
+ # - Implement proper access controls and permissions
33
+ # - Monitor volume usage and capacity
34
+ # - Regular backup of critical volume data
35
+ # - Audit volume access patterns
36
+ # - Use encryption for sensitive data volumes
37
+ # - Implement volume lifecycle policies
38
38
  #
39
- # == Security Considerations
39
+ # == Parameters
40
40
  #
41
- # Volume creation affects data security:
42
- # - **Data Isolation**: Volumes provide isolation between containers
43
- # - **Access Control**: Volume permissions affect data access
44
- # - **Storage Location**: Local volumes stored on host filesystem
45
- # - **Shared Access**: Multiple containers can access the same volume
41
+ # - **name**: Name of the volume (required)
42
+ # - **driver**: Driver to use (optional, default: "local")
46
43
  #
47
- # Security implications:
48
- # - Volumes persist data beyond container lifecycle
49
- # - Volume names may reveal application details
50
- # - Shared volumes can leak data between containers
51
- # - Storage driver choice affects security properties
44
+ # == Volume Drivers
52
45
  #
53
- # Best practices:
54
- # - Use descriptive but not sensitive volume names
55
- # - Implement proper volume access controls
56
- # - Regular backup of critical volume data
57
- # - Monitor volume usage and access patterns
58
- # - Choose appropriate drivers for security requirements
46
+ # - **local**: Default driver for local filesystem storage
47
+ # - **nfs**: Network File System driver for shared storage
48
+ # - **cifs**: Common Internet File System driver
49
+ # - **rexray**: REX-Ray driver for cloud storage integration
50
+ # - **convoy**: Convoy driver for snapshot management
59
51
  #
60
52
  # == Example Usage
61
53
  #
62
54
  # # Create basic local volume
63
- # CreateVolume.call(
55
+ # response = CreateVolume.call(
64
56
  # server_context: context,
65
57
  # name: "app-data"
66
58
  # )
67
59
  #
68
60
  # # Create volume with specific driver
69
- # CreateVolume.call(
61
+ # response = CreateVolume.call(
70
62
  # server_context: context,
71
63
  # name: "shared-storage",
72
64
  # driver: "nfs"
73
65
  # )
74
66
  #
75
- # @see ListVolumes
76
- # @see RemoveVolume
77
- # @see Docker::Volume.create
67
+ # # Create database volume
68
+ # response = CreateVolume.call(
69
+ # server_context: context,
70
+ # name: "postgres-data",
71
+ # driver: "local"
72
+ # )
73
+ #
74
+ # @see ::Docker::Volume.create
78
75
  # @since 0.1.0
79
- class CreateVolume < RubyLLM::Tool
76
+ CREATE_VOLUME_DEFINITION = ToolForge.define(:create_volume) do
80
77
  description 'Create a Docker volume'
81
78
 
82
- param :name, type: :string, desc: 'Name of the volume'
83
- param :driver, type: :string, desc: 'Driver to use (default: local)', required: false
79
+ param :name,
80
+ type: :string,
81
+ description: 'Name of the volume'
82
+
83
+ param :driver,
84
+ type: :string,
85
+ description: 'Driver to use (default: local)',
86
+ required: false,
87
+ default: 'local'
84
88
 
85
- # Create a new Docker volume for persistent data storage.
86
- #
87
- # This method creates a named Docker volume that can be used by containers
88
- # for persistent data storage. The volume will survive container deletion
89
- # and can be shared between multiple containers.
90
- #
91
- # @param name [String] name for the new volume
92
- # @param server_context [Object] RubyLLM context (unused but required)
93
- # @param driver [String] volume driver to use (default: "local")
94
- #
95
- # @return [RubyLLM::Tool::Response] volume creation results
96
- #
97
- # @raise [Docker::Error::ConflictError] if volume name already exists
98
- # @raise [StandardError] for other volume creation failures
99
- #
100
- # @example Create application data volume
101
- # response = CreateVolume.call(
102
- # server_context: context,
103
- # name: "webapp-data"
104
- # )
105
- #
106
- # @example Create NFS volume
107
- # response = tool.execute(
108
- # name: "shared-files",
109
- # driver: "nfs"
110
- # )
111
- #
112
- # @see Docker::Volume.create
113
- def execute(name:, driver: 'local')
89
+ execute do |name:, driver: 'local'|
114
90
  options = {
115
91
  'Name' => name,
116
92
  'Driver' => driver
@@ -125,5 +101,7 @@ module RubyLLM
125
101
  "Error creating volume: #{e.message}"
126
102
  end
127
103
  end
104
+
105
+ CreateVolume = CREATE_VOLUME_DEFINITION.to_ruby_llm_tool
128
106
  end
129
107
  end