docker_mcp 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.
@@ -3,162 +3,96 @@
3
3
  module DockerMCP
4
4
  # MCP tool for removing Docker images.
5
5
  #
6
- # This tool provides the ability to permanently delete Docker images from
7
- # the local system to free up disk space and remove unused images. It
8
- # supports both regular and forced removal with options for parent image
9
- # handling.
6
+ # This tool provides the ability to delete Docker images from the
7
+ # local Docker daemon. It supports various removal options including
8
+ # forced removal and parent image cleanup management.
10
9
  #
11
10
  # == Features
12
11
  #
13
- # - Remove images by ID, name, or name:tag
12
+ # - Remove images by ID, name, or tag
14
13
  # - Force removal of images in use
15
- # - Control parent image cleanup
14
+ # - Control untagged parent image cleanup
16
15
  # - Comprehensive error handling
16
+ # - Validation of image existence
17
17
  # - Safe removal with dependency checking
18
18
  #
19
- # == ⚠️ Data Loss Warning ⚠️
20
- #
21
- # **DESTRUCTIVE OPERATION - PERMANENT DATA LOSS**
22
- #
23
- # This operation permanently deletes images and associated data:
24
- # - Image layers are deleted from disk
25
- # - All tags pointing to the image are removed
26
- # - Operation cannot be undone
27
- # - Dependent containers may become unusable
28
- # - Custom modifications to images are lost
29
- #
30
- # == Dependency Management
31
- #
32
- # Docker images have complex dependency relationships:
33
- # - **Child Images**: Images built FROM this image
34
- # - **Parent Images**: Base images this image depends on
35
- # - **Running Containers**: Containers using this image
36
- # - **Stopped Containers**: Containers that could be restarted
37
- #
38
19
  # == Security Considerations
39
20
  #
40
- # Image removal affects system security posture:
41
- # - Removes potentially vulnerable software
42
- # - May break running applications
43
- # - Could remove security patches
44
- # - Affects rollback capabilities
45
- #
46
- # Best practices:
47
- # - Verify no critical containers depend on the image
21
+ # Image removal involves important considerations:
22
+ # - **Data Loss**: Removed images cannot be recovered locally
23
+ # - **Service Disruption**: Removing images used by running containers
24
+ # - **Storage Cleanup**: Improper cleanup can leave orphaned layers
25
+ # - **Registry Impact**: Local removal doesn't affect registry copies
26
+ # - **Dependency Conflicts**: Force removal can break container dependencies
27
+ #
28
+ # **Security Recommendations**:
29
+ # - Verify image is not in use before removal
30
+ # - Use force option only when necessary
31
+ # - Consider impact on running containers
48
32
  # - Backup important images before removal
49
- # - Use force removal judiciously
50
- # - Monitor disk space after removal
51
- # - Maintain image inventory documentation
33
+ # - Monitor disk space after removal operations
34
+ # - Implement image lifecycle policies
52
35
  #
53
- # == Removal Options
36
+ # == Parameters
54
37
  #
55
- # - **Normal Removal**: Only removes if no containers use the image
56
- # - **Force Removal**: Removes even if containers depend on it
57
- # - **Prune Parents**: Automatically removes unused parent images
58
- # - **No Prune**: Keeps parent images even if unused
38
+ # - **id**: Image ID, name, or name:tag (required)
39
+ # - **force**: Force removal of the image (optional, default: false)
40
+ # - **noprune**: Do not delete untagged parents (optional, default: false)
59
41
  #
60
42
  # == Example Usage
61
43
  #
62
- # # Safe removal of unused image
63
- # RemoveImage.call(
44
+ # # Remove specific image
45
+ # response = RemoveImage.call(
64
46
  # server_context: context,
65
- # id: "old-app:v1.0"
47
+ # id: "myapp:old-version"
66
48
  # )
67
49
  #
68
- # # Force removal of image in use
69
- # RemoveImage.call(
50
+ # # Force remove image in use
51
+ # response = RemoveImage.call(
70
52
  # server_context: context,
71
- # id: "broken-image:latest",
53
+ # id: "abc123def456",
72
54
  # force: true
73
55
  # )
74
56
  #
75
- # # Remove image but keep parent layers
76
- # RemoveImage.call(
57
+ # # Remove without cleaning parent images
58
+ # response = RemoveImage.call(
77
59
  # server_context: context,
78
- # id: "temp-build:abc123",
60
+ # id: "test-image:latest",
79
61
  # noprune: true
80
62
  # )
81
63
  #
82
- # @see ListImages
83
- # @see BuildImage
84
64
  # @see Docker::Image#remove
85
65
  # @since 0.1.0
86
- class RemoveImage < MCP::Tool
66
+ REMOVE_IMAGE_DEFINITION = ToolForge.define(:remove_image) do
87
67
  description 'Remove a Docker image'
88
68
 
89
- input_schema(
90
- properties: {
91
- id: {
92
- type: 'string',
69
+ param :id,
70
+ type: :string,
93
71
  description: 'Image ID, name, or name:tag'
94
- },
95
- force: {
96
- type: 'boolean',
97
- description: 'Force removal of the image (default: false)'
98
- },
99
- noprune: {
100
- type: 'boolean',
101
- description: 'Do not delete untagged parents (default: false)'
102
- }
103
- },
104
- required: ['id']
105
- )
106
72
 
107
- # Remove a Docker image from the local system.
108
- #
109
- # This method permanently deletes the specified image from local storage.
110
- # By default, it performs safety checks to prevent removal of images with
111
- # dependent containers. Force removal bypasses these checks.
112
- #
113
- # @param id [String] image ID, name, or name:tag to remove
114
- # @param server_context [Object] MCP server context (unused but required)
115
- # @param force [Boolean] whether to force removal despite dependencies (default: false)
116
- # @param noprune [Boolean] whether to preserve parent images (default: false)
117
- #
118
- # @return [MCP::Tool::Response] removal operation results
119
- #
120
- # @raise [Docker::Error::NotFoundError] if image doesn't exist
121
- # @raise [StandardError] for removal failures or dependency conflicts
122
- #
123
- # @example Remove unused image
124
- # response = RemoveImage.call(
125
- # server_context: context,
126
- # id: "old-version:1.0"
127
- # )
128
- #
129
- # @example Force remove problematic image
130
- # response = RemoveImage.call(
131
- # server_context: context,
132
- # id: "corrupted-image",
133
- # force: true
134
- # )
135
- #
136
- # @example Remove while preserving layers
137
- # response = RemoveImage.call(
138
- # server_context: context,
139
- # id: "temp-image:build-123",
140
- # noprune: true
141
- # )
142
- #
143
- # @see Docker::Image#remove
144
- def self.call(id:, server_context:, force: false, noprune: false)
73
+ param :force,
74
+ type: :boolean,
75
+ description: 'Force removal of the image (default: false)',
76
+ required: false,
77
+ default: false
78
+
79
+ param :noprune,
80
+ type: :boolean,
81
+ description: 'Do not delete untagged parents (default: false)',
82
+ required: false,
83
+ default: false
84
+
85
+ execute do |id:, force: false, noprune: false|
145
86
  image = Docker::Image.get(id)
146
87
  image.remove(force: force, noprune: noprune)
147
88
 
148
- MCP::Tool::Response.new([{
149
- type: 'text',
150
- text: "Image #{id} removed successfully"
151
- }])
89
+ "Image #{id} removed successfully"
152
90
  rescue Docker::Error::NotFoundError
153
- MCP::Tool::Response.new([{
154
- type: 'text',
155
- text: "Image #{id} not found"
156
- }])
91
+ "Image #{id} not found"
157
92
  rescue StandardError => e
158
- MCP::Tool::Response.new([{
159
- type: 'text',
160
- text: "Error removing image: #{e.message}"
161
- }])
93
+ "Error removing image: #{e.message}"
162
94
  end
163
95
  end
96
+
97
+ RemoveImage = REMOVE_IMAGE_DEFINITION.to_mcp_tool
164
98
  end
@@ -3,134 +3,80 @@
3
3
  module DockerMCP
4
4
  # MCP tool for removing Docker networks.
5
5
  #
6
- # This tool provides the ability to permanently delete Docker networks from
7
- # the system. It safely removes custom networks while protecting built-in
8
- # system networks from accidental deletion.
6
+ # This tool provides the ability to delete Docker networks when they
7
+ # are no longer needed. Network removal helps maintain clean network
8
+ # configurations and prevents resource leaks.
9
9
  #
10
10
  # == Features
11
11
  #
12
- # - Remove custom Docker networks by ID or name
13
- # - Protection against removing built-in networks
12
+ # - Remove networks by ID or name
13
+ # - Validation of network existence
14
14
  # - Comprehensive error handling
15
- # - Dependency checking (prevents removal if containers are connected)
15
+ # - Prevention of removing networks in use
16
16
  # - Safe cleanup of network resources
17
- #
18
- # == ⚠️ Service Disruption Warning ⚠️
19
- #
20
- # **NETWORK REMOVAL CAN DISRUPT SERVICES**
21
- #
22
- # Removing networks can cause immediate service disruption:
23
- # - Connected containers lose network connectivity
24
- # - Inter-container communication is broken
25
- # - Services may become unreachable
26
- # - Application functionality can be severely impacted
27
- # - Network-dependent processes may fail
28
- #
29
- # == Protected Networks
30
- #
31
- # Docker protects certain built-in networks from removal:
32
- # - **bridge**: Default bridge network
33
- # - **host**: Host networking
34
- # - **none**: No networking
35
- # - **System networks**: Docker-managed networks
17
+ # - Network dependency checking
36
18
  #
37
19
  # == Security Considerations
38
20
  #
39
- # Network removal affects security boundaries:
40
- # - Removes network isolation between containers
41
- # - May expose containers to unintended networks
42
- # - Could impact security segmentation strategies
43
- # - Affects network-based access controls
21
+ # Network removal involves important considerations:
22
+ # - **Service Disruption**: Removing active networks disconnects containers
23
+ # - **Data Isolation**: Network removal can affect container communication
24
+ # - **Resource Cleanup**: Improper removal can leave network artifacts
25
+ # - **Container Dependencies**: Containers may fail without expected networks
26
+ # - **Network Policies**: Removal affects security and access policies
44
27
  #
45
- # Security implications:
46
- # - Ensure no critical containers depend on the network
47
- # - Verify alternative connectivity exists if needed
48
- # - Consider impact on security boundaries
49
- # - Monitor for unauthorized network modifications
28
+ # **Security Recommendations**:
29
+ # - Verify no containers are connected before removal
30
+ # - Check for dependent services and applications
31
+ # - Document network removal in change logs
32
+ # - Implement network lifecycle management
33
+ # - Monitor for orphaned network resources
34
+ # - Use network removal as part of cleanup procedures
50
35
  #
51
- # Best practices:
52
- # - Stop containers before removing their networks
53
- # - Verify network dependencies before removal
54
- # - Have rollback plans for critical networks
55
- # - Document network removal procedures
56
- # - Monitor network connectivity after removal
36
+ # == Parameters
37
+ #
38
+ # - **id**: Network ID or name (required)
57
39
  #
58
40
  # == Example Usage
59
41
  #
60
- # # Remove custom network
61
- # RemoveNetwork.call(
42
+ # # Remove network by name
43
+ # response = RemoveNetwork.call(
62
44
  # server_context: context,
63
45
  # id: "app-network"
64
46
  # )
65
47
  #
66
- # # Remove by network ID
67
- # RemoveNetwork.call(
48
+ # # Remove network by ID
49
+ # response = RemoveNetwork.call(
68
50
  # server_context: context,
69
51
  # id: "abc123def456"
70
52
  # )
71
53
  #
72
- # @see CreateNetwork
73
- # @see ListNetworks
54
+ # # Clean up test networks
55
+ # response = RemoveNetwork.call(
56
+ # server_context: context,
57
+ # id: "test-isolated-network"
58
+ # )
59
+ #
74
60
  # @see Docker::Network#delete
75
61
  # @since 0.1.0
76
- class RemoveNetwork < MCP::Tool
62
+ REMOVE_NETWORK_DEFINITION = ToolForge.define(:remove_network) do
77
63
  description 'Remove a Docker network'
78
64
 
79
- input_schema(
80
- properties: {
81
- id: {
82
- type: 'string',
65
+ param :id,
66
+ type: :string,
83
67
  description: 'Network ID or name'
84
- }
85
- },
86
- required: ['id']
87
- )
88
68
 
89
- # Remove a Docker network from the system.
90
- #
91
- # This method permanently deletes the specified network. The network
92
- # must not have any containers connected to it, and built-in system
93
- # networks cannot be removed.
94
- #
95
- # @param id [String] network ID or name to remove
96
- # @param server_context [Object] MCP server context (unused but required)
97
- #
98
- # @return [MCP::Tool::Response] removal operation results
99
- #
100
- # @raise [Docker::Error::NotFoundError] if network doesn't exist
101
- # @raise [StandardError] for removal failures or dependency conflicts
102
- #
103
- # @example Remove custom network
104
- # response = RemoveNetwork.call(
105
- # server_context: context,
106
- # id: "frontend-network"
107
- # )
108
- #
109
- # @example Remove by ID
110
- # response = RemoveNetwork.call(
111
- # server_context: context,
112
- # id: "1a2b3c4d5e6f"
113
- # )
114
- #
115
- # @see Docker::Network#delete
116
- def self.call(id:, server_context:)
69
+ execute do |id:|
117
70
  network = Docker::Network.get(id)
118
71
  network.delete
119
72
 
120
- MCP::Tool::Response.new([{
121
- type: 'text',
122
- text: "Network #{id} removed successfully"
123
- }])
73
+ "Network #{id} removed successfully"
124
74
  rescue Docker::Error::NotFoundError
125
- MCP::Tool::Response.new([{
126
- type: 'text',
127
- text: "Network #{id} not found"
128
- }])
75
+ "Network #{id} not found"
129
76
  rescue StandardError => e
130
- MCP::Tool::Response.new([{
131
- type: 'text',
132
- text: "Error removing network: #{e.message}"
133
- }])
77
+ "Error removing network: #{e.message}"
134
78
  end
135
79
  end
80
+
81
+ RemoveNetwork = REMOVE_NETWORK_DEFINITION.to_mcp_tool
136
82
  end
@@ -3,144 +3,90 @@
3
3
  module DockerMCP
4
4
  # MCP tool for removing Docker volumes.
5
5
  #
6
- # This tool provides the ability to permanently delete Docker volumes from
7
- # the system. This is a destructive operation that will permanently delete
8
- # all data stored in the volume.
6
+ # This tool provides the ability to delete Docker volumes when they
7
+ # are no longer needed. Volume removal is critical for preventing
8
+ # storage leaks and maintaining clean Docker environments.
9
9
  #
10
10
  # == Features
11
11
  #
12
- # - Remove Docker volumes by name
13
- # - Force removal option for volumes in use
12
+ # - Remove volumes by name
13
+ # - Force removal of volumes in use
14
+ # - Validation of volume existence
14
15
  # - Comprehensive error handling
15
- # - Dependency checking (prevents removal if containers are using the volume)
16
- # - Safe cleanup of storage resources
17
- #
18
- # == ⚠️ CRITICAL DATA LOSS WARNING ⚠️
19
- #
20
- # **DESTRUCTIVE OPERATION - PERMANENT DATA LOSS**
21
- #
22
- # This operation permanently and irreversibly deletes data:
23
- # - **ALL DATA** in the volume is deleted forever
24
- # - No recovery possible after deletion
25
- # - Applications may lose critical data
26
- # - Databases and persistent state are destroyed
27
- # - Configuration files and user data are lost
28
- # - Operation cannot be undone
29
- #
30
- # == Volume Dependencies
31
- #
32
- # Volumes may have active dependencies:
33
- # - **Running Containers**: Containers currently using the volume
34
- # - **Stopped Containers**: Containers that could be restarted
35
- # - **Application Data**: Critical application state and databases
36
- # - **User Data**: User-generated content and files
16
+ # - Safe volume cleanup procedures
17
+ # - Prevention of accidental data loss
37
18
  #
38
19
  # == Security Considerations
39
20
  #
40
- # Volume removal has security implications:
41
- # - Sensitive data is not securely wiped
42
- # - Data may be recoverable from disk sectors
43
- # - Shared volumes may affect multiple applications
44
- # - Removal logs may reveal data existence
21
+ # Volume removal involves critical data considerations:
22
+ # - **Data Loss**: Removed volumes and their data are permanently deleted
23
+ # - **Service Disruption**: Removing volumes can break running containers
24
+ # - **Data Recovery**: Volume data cannot be recovered after removal
25
+ # - **Container Dependencies**: Applications may fail without expected volumes
26
+ # - **Storage Cleanup**: Improper removal can leave orphaned data
27
+ # - **Backup Requirements**: Critical data should be backed up before removal
45
28
  #
46
- # Critical security measures:
47
- # - **Backup critical data** before removal
48
- # - Verify no containers depend on the volume
49
- # - Consider secure data wiping for sensitive volumes
50
- # - Audit volume removal operations
51
- # - Monitor for unauthorized volume deletions
29
+ # **Security Recommendations**:
30
+ # - Always backup critical data before volume removal
31
+ # - Verify no containers are using the volume
32
+ # - Use force option only when absolutely necessary
33
+ # - Document volume removal in change management
34
+ # - Implement volume lifecycle and retention policies
35
+ # - Monitor storage usage after volume removal
36
+ # - Consider data migration instead of removal
52
37
  #
53
- # == Force Removal Risks
38
+ # == Parameters
54
39
  #
55
- # Force removal bypasses safety checks:
56
- # - Removes volumes even if containers are using them
57
- # - Can cause immediate application failures
58
- # - May corrupt running applications
59
- # - Data loss occurs immediately
40
+ # - **name**: Volume name (required)
41
+ # - **force**: Force removal of the volume (optional, default: false)
60
42
  #
61
43
  # == Example Usage
62
44
  #
63
- # # Safe removal of unused volume
64
- # RemoveVolume.call(
45
+ # # Remove unused volume
46
+ # response = RemoveVolume.call(
65
47
  # server_context: context,
66
- # name: "temp-data"
48
+ # name: "old-app-data"
67
49
  # )
68
50
  #
69
- # # Force removal of volume in use (DANGEROUS)
70
- # RemoveVolume.call(
51
+ # # Force remove volume in use
52
+ # response = RemoveVolume.call(
71
53
  # server_context: context,
72
54
  # name: "stuck-volume",
73
55
  # force: true
74
56
  # )
75
57
  #
76
- # @see CreateVolume
77
- # @see ListVolumes
58
+ # # Clean up test volumes
59
+ # response = RemoveVolume.call(
60
+ # server_context: context,
61
+ # name: "test-data-volume"
62
+ # )
63
+ #
78
64
  # @see Docker::Volume#remove
79
65
  # @since 0.1.0
80
- class RemoveVolume < MCP::Tool
66
+ REMOVE_VOLUME_DEFINITION = ToolForge.define(:remove_volume) do
81
67
  description 'Remove a Docker volume'
82
68
 
83
- input_schema(
84
- properties: {
85
- name: {
86
- type: 'string',
69
+ param :name,
70
+ type: :string,
87
71
  description: 'Volume name'
88
- },
89
- force: {
90
- type: 'boolean',
91
- description: 'Force removal of the volume (default: false)'
92
- }
93
- },
94
- required: ['name']
95
- )
96
72
 
97
- # Remove a Docker volume permanently from the system.
98
- #
99
- # This method permanently deletes the specified volume and all data
100
- # contained within it. By default, it performs safety checks to prevent
101
- # removal of volumes with active container dependencies.
102
- #
103
- # @param name [String] name of the volume to remove
104
- # @param server_context [Object] MCP server context (unused but required)
105
- # @param force [Boolean] whether to force removal despite dependencies (default: false)
106
- #
107
- # @return [MCP::Tool::Response] removal operation results
108
- #
109
- # @raise [Docker::Error::NotFoundError] if volume doesn't exist
110
- # @raise [StandardError] for removal failures or dependency conflicts
111
- #
112
- # @example Remove unused volume
113
- # response = RemoveVolume.call(
114
- # server_context: context,
115
- # name: "old-cache-data"
116
- # )
117
- #
118
- # @example Force remove problematic volume
119
- # response = RemoveVolume.call(
120
- # server_context: context,
121
- # name: "corrupted-volume",
122
- # force: true
123
- # )
124
- #
125
- # @see Docker::Volume#remove
126
- def self.call(name:, server_context:, force: false)
73
+ param :force,
74
+ type: :boolean,
75
+ description: 'Force removal of the volume (default: false)',
76
+ required: false,
77
+ default: false
78
+
79
+ execute do |name:, force: false|
127
80
  volume = Docker::Volume.get(name)
128
81
  volume.remove(force: force)
129
82
 
130
- MCP::Tool::Response.new([{
131
- type: 'text',
132
- text: "Volume #{name} removed successfully"
133
- }])
83
+ "Volume #{name} removed successfully"
134
84
  rescue Docker::Error::NotFoundError
135
- MCP::Tool::Response.new([{
136
- type: 'text',
137
- text: "Volume #{name} not found"
138
- }])
85
+ "Volume #{name} not found"
139
86
  rescue StandardError => e
140
- MCP::Tool::Response.new([{
141
- type: 'text',
142
- text: "Error removing volume: #{e.message}"
143
- }])
87
+ "Error removing volume: #{e.message}"
144
88
  end
145
89
  end
90
+
91
+ RemoveVolume = REMOVE_VOLUME_DEFINITION.to_mcp_tool
146
92
  end