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,78 +3,54 @@
3
3
  module DockerMCP
4
4
  # MCP tool for listing Docker images.
5
5
  #
6
- # This tool provides functionality to list all Docker images available on
7
- # the local system. It returns comprehensive information about each image
8
- # including IDs, tags, sizes, creation dates, and other metadata.
6
+ # This tool provides comprehensive information about all Docker images
7
+ # stored on the local system. It returns detailed metadata including
8
+ # image sizes, creation dates, tags, and usage statistics.
9
9
  #
10
10
  # == Features
11
11
  #
12
- # - List all local Docker images
13
- # - Comprehensive image metadata
14
- # - No configuration required
15
- # - Read-only operation
16
- # - Includes both tagged and untagged images
12
+ # - Lists all locally stored Docker images
13
+ # - Provides detailed image metadata and statistics
14
+ # - Shows image sizes and storage usage
15
+ # - Displays repository tags and digests
16
+ # - Includes creation timestamps and labels
17
+ # - Reports container usage counts
17
18
  #
18
- # == Image Information Included
19
+ # == Security Considerations
19
20
  #
20
- # The response typically includes:
21
- # - **Image ID**: Unique identifier for the image
22
- # - **Repository Tags**: All tags associated with the image
23
- # - **Size**: Virtual and actual size of the image
24
- # - **Created**: Timestamp when image was created
25
- # - **Parent ID**: Base image information
26
- # - **RepoDigests**: Content-addressable identifiers
21
+ # This tool provides information that could be useful for:
22
+ # - **System Analysis**: Reveals installed software and versions
23
+ # - **Vulnerability Assessment**: Shows potential attack surfaces
24
+ # - **Resource Planning**: Exposes storage usage patterns
27
25
  #
28
- # == Security Considerations
26
+ # Monitor access to this tool in production environments.
29
27
  #
30
- # This is a read-only operation that reveals system information:
31
- # - Exposes available images and versions
32
- # - May reveal internal application details
33
- # - Shows image sources and repositories
34
- # - Could aid in reconnaissance activities
28
+ # == Return Format
35
29
  #
36
- # While generally safe, consider access control:
37
- # - Limit exposure of image inventory
38
- # - Be cautious with sensitive image names
39
- # - Monitor for unauthorized image access attempts
30
+ # Returns an array of image objects with comprehensive metadata:
31
+ # - Repository tags and digests
32
+ # - Image sizes and virtual sizes
33
+ # - Creation timestamps
34
+ # - Container usage counts
35
+ # - Labels and annotations
36
+ # - Parent-child relationships
40
37
  #
41
38
  # == Example Usage
42
39
  #
43
- # # List all images
44
- # ListImages.call(server_context: context)
40
+ # images = ListImages.call(server_context: context)
41
+ # images.each do |image|
42
+ # puts "#{image['RepoTags']}: #{image['Size']} bytes"
43
+ # end
45
44
  #
46
- # @example Usage in container management
47
- # # Get available images before container creation
48
- # images_response = ListImages.call(server_context: context)
49
- # # Use image information to select appropriate base images
50
- #
51
- # @see PullImage
52
- # @see BuildImage
53
45
  # @see Docker::Image.all
54
46
  # @since 0.1.0
55
- class ListImages < MCP::Tool
47
+ LIST_IMAGES_DEFINITION = ToolForge.define(:list_images) do
56
48
  description 'List Docker images'
57
49
 
58
- # List all Docker images available on the local system.
59
- #
60
- # This method retrieves information about all Docker images stored
61
- # locally, including both tagged and untagged images. The information
62
- # includes comprehensive metadata for each image.
63
- #
64
- # @param args [Array] variable arguments (unused but accepted for compatibility)
65
- #
66
- # @return [MCP::Tool::Response] comprehensive image information
67
- #
68
- # @example List all local images
69
- # response = ListImages.call
70
- # # Returns detailed info for all local Docker images
71
- #
72
- # @see Docker::Image.all
73
- def self.call(*)
74
- MCP::Tool::Response.new([{
75
- type: 'text',
76
- text: Docker::Image.all.map(&:info).to_s
77
- }])
50
+ execute do
51
+ Docker::Image.all.map(&:info)
78
52
  end
79
53
  end
54
+
55
+ ListImages = LIST_IMAGES_DEFINITION.to_mcp_tool
80
56
  end
@@ -3,82 +3,55 @@
3
3
  module DockerMCP
4
4
  # MCP tool for listing Docker networks.
5
5
  #
6
- # This tool provides functionality to list all Docker networks available on
7
- # the system, including built-in networks (bridge, host, none) and custom
8
- # user-defined networks. It returns comprehensive information about network
9
- # configuration, drivers, and connected containers.
6
+ # This tool provides comprehensive information about all Docker networks
7
+ # configured on the system. It returns detailed network configuration
8
+ # including IPAM settings, connected containers, and network drivers.
10
9
  #
11
10
  # == Features
12
11
  #
13
- # - List all Docker networks on the system
14
- # - Comprehensive network metadata
15
- # - No configuration required
16
- # - Read-only operation
17
- # - Includes built-in and custom networks
12
+ # - Lists all Docker networks (built-in and custom)
13
+ # - Provides detailed network configuration
14
+ # - Shows IPAM (IP Address Management) settings
15
+ # - Displays connected containers
16
+ # - Includes driver information and options
17
+ # - Reports network scope and capabilities
18
18
  #
19
- # == Network Information Included
19
+ # == Security Considerations
20
20
  #
21
- # The response typically includes:
22
- # - **Network ID**: Unique identifier for the network
23
- # - **Name**: Human-readable network name
24
- # - **Driver**: Network driver (bridge, host, overlay, etc.)
25
- # - **Scope**: Network scope (local, global, swarm)
26
- # - **IPAM**: IP Address Management configuration
27
- # - **Connected Containers**: Containers attached to the network
28
- # - **Options**: Driver-specific configuration options
21
+ # Network information can be sensitive as it reveals:
22
+ # - **Network Topology**: Internal network architecture
23
+ # - **IP Addressing**: Subnet configurations and ranges
24
+ # - **Container Connectivity**: Service interconnections
25
+ # - **Network Isolation**: Security boundary configurations
29
26
  #
30
- # == Security Considerations
27
+ # Restrict access to this tool in production environments.
31
28
  #
32
- # This is a read-only operation that reveals network topology:
33
- # - Exposes network architecture and segmentation
34
- # - Shows container connectivity patterns
35
- # - May reveal internal network design
36
- # - Could aid in network reconnaissance
29
+ # == Return Format
37
30
  #
38
- # While generally safe, consider access control:
39
- # - Limit exposure of network topology information
40
- # - Be cautious with sensitive network names
41
- # - Monitor for unauthorized network discovery
42
- # - Consider network isolation requirements
31
+ # Returns an array of network objects with comprehensive metadata:
32
+ # - Network names and IDs
33
+ # - Driver types and configurations
34
+ # - IPAM settings and subnet information
35
+ # - Connected container details
36
+ # - Network options and labels
37
+ # - Scope and capability flags
43
38
  #
44
39
  # == Example Usage
45
40
  #
46
- # # List all networks
47
- # ListNetworks.call(server_context: context)
41
+ # networks = ListNetworks.call(server_context: context)
42
+ # networks.each do |network|
43
+ # puts "#{network['Name']}: #{network['Driver']}"
44
+ # end
48
45
  #
49
- # @example Usage in network management
50
- # # Get available networks before container creation
51
- # networks_response = ListNetworks.call(server_context: context)
52
- # # Use network information to select appropriate networks
53
- #
54
- # @see CreateNetwork
55
- # @see RemoveNetwork
56
46
  # @see Docker::Network.all
57
47
  # @since 0.1.0
58
- class ListNetworks < MCP::Tool
48
+ LIST_NETWORKS_DEFINITION = ToolForge.define(:list_networks) do
59
49
  description 'List Docker networks'
60
50
 
61
- # List all Docker networks available on the system.
62
- #
63
- # This method retrieves information about all Docker networks, including
64
- # both system-created networks (bridge, host, none) and user-defined
65
- # custom networks. The information includes comprehensive metadata for
66
- # each network.
67
- #
68
- # @param args [Array] variable arguments (unused but accepted for compatibility)
69
- #
70
- # @return [MCP::Tool::Response] comprehensive network information
71
- #
72
- # @example List all networks
73
- # response = ListNetworks.call
74
- # # Returns detailed info for all Docker networks
75
- #
76
- # @see Docker::Network.all
77
- def self.call(*)
78
- MCP::Tool::Response.new([{
79
- type: 'text',
80
- text: Docker::Network.all.map(&:info).to_s
81
- }])
51
+ execute do
52
+ Docker::Network.all.map(&:info)
82
53
  end
83
54
  end
55
+
56
+ ListNetworks = LIST_NETWORKS_DEFINITION.to_mcp_tool
84
57
  end
@@ -3,89 +3,55 @@
3
3
  module DockerMCP
4
4
  # MCP tool for listing Docker volumes.
5
5
  #
6
- # This tool provides functionality to list all Docker volumes on the system,
7
- # including both named volumes and anonymous volumes. It returns comprehensive
8
- # information about volume configuration, drivers, mount points, and usage.
6
+ # This tool provides comprehensive information about all Docker volumes
7
+ # configured on the system. It returns detailed volume metadata including
8
+ # mount points, drivers, usage statistics, and associated containers.
9
9
  #
10
10
  # == Features
11
11
  #
12
- # - List all Docker volumes on the system
13
- # - Comprehensive volume metadata
14
- # - No configuration required
15
- # - Read-only operation
16
- # - Includes named and anonymous volumes
12
+ # - Lists all Docker volumes (named and anonymous)
13
+ # - Provides detailed volume metadata
14
+ # - Shows mount points and storage locations
15
+ # - Displays driver information and options
16
+ # - Includes creation timestamps and labels
17
+ # - Reports volume scope and capabilities
17
18
  #
18
- # == Volume Information Included
19
- #
20
- # The response typically includes:
21
- # - **Volume Name**: Unique identifier for the volume
22
- # - **Driver**: Volume driver (local, nfs, etc.)
23
- # - **Mountpoint**: Physical location on host filesystem
24
- # - **Labels**: User-defined metadata labels
25
- # - **Options**: Driver-specific configuration options
26
- # - **Scope**: Volume scope (local, global)
27
- # - **CreatedAt**: Volume creation timestamp
28
- #
29
- # == Volume Types
19
+ # == Security Considerations
30
20
  #
31
- # Docker manages different types of volumes:
32
- # - **Named Volumes**: User-created persistent volumes
33
- # - **Anonymous Volumes**: Automatically created temporary volumes
34
- # - **Bind Mounts**: Direct host directory mounts (not shown in volume list)
35
- # - **tmpfs Mounts**: Memory-based temporary filesystems (not shown)
21
+ # Volume information can reveal sensitive details about:
22
+ # - **Data Storage**: Persistent data locations and structures
23
+ # - **File System Access**: Mount points and storage paths
24
+ # - **Container Dependencies**: Volume usage patterns
25
+ # - **Data Persistence**: Backup and recovery points
36
26
  #
37
- # == Security Considerations
27
+ # Monitor access to this tool and implement appropriate controls.
38
28
  #
39
- # This is a read-only operation that reveals storage information:
40
- # - Exposes data storage architecture
41
- # - Shows volume naming patterns
42
- # - May reveal application data locations
43
- # - Could aid in data discovery attacks
29
+ # == Return Format
44
30
  #
45
- # While generally safe, consider access control:
46
- # - Limit exposure of volume inventory
47
- # - Be cautious with sensitive volume names
48
- # - Monitor for unauthorized volume discovery
49
- # - Consider data classification implications
31
+ # Returns an array of volume objects with comprehensive metadata:
32
+ # - Volume names and mount points
33
+ # - Driver types and configurations
34
+ # - Creation timestamps
35
+ # - Labels and options
36
+ # - Scope information
37
+ # - Storage usage details
50
38
  #
51
39
  # == Example Usage
52
40
  #
53
- # # List all volumes
54
- # ListVolumes.call(server_context: context)
55
- #
56
- # @example Usage in data management
57
- # # Get available volumes before container creation
58
- # volumes_response = ListVolumes.call(server_context: context)
59
- # # Use volume information to select appropriate storage
41
+ # volumes = ListVolumes.call(server_context: context)
42
+ # volumes.each do |volume|
43
+ # puts "#{volume['Name']}: #{volume['Mountpoint']}"
44
+ # end
60
45
  #
61
- # @see CreateVolume
62
- # @see RemoveVolume
63
46
  # @see Docker::Volume.all
64
47
  # @since 0.1.0
65
- class ListVolumes < MCP::Tool
48
+ LIST_VOLUMES_DEFINITION = ToolForge.define(:list_volumes) do
66
49
  description 'List Docker volumes'
67
50
 
68
- # List all Docker volumes available on the system.
69
- #
70
- # This method retrieves information about all Docker volumes, including
71
- # both named volumes created by users and anonymous volumes created
72
- # automatically by containers. The information includes comprehensive
73
- # metadata for each volume.
74
- #
75
- # @param args [Array] variable arguments (unused but accepted for compatibility)
76
- #
77
- # @return [MCP::Tool::Response] comprehensive volume information
78
- #
79
- # @example List all volumes
80
- # response = ListVolumes.call
81
- # # Returns detailed info for all Docker volumes
82
- #
83
- # @see Docker::Volume.all
84
- def self.call(*)
85
- MCP::Tool::Response.new([{
86
- type: 'text',
87
- text: Docker::Volume.all.map(&:info).to_s
88
- }])
51
+ execute do
52
+ Docker::Volume.all.map(&:info)
89
53
  end
90
54
  end
55
+
56
+ ListVolumes = LIST_VOLUMES_DEFINITION.to_mcp_tool
91
57
  end
@@ -25,7 +25,7 @@ module DockerMCP
25
25
  # - **Supply Chain Attacks**: Legitimate-looking images may be malicious
26
26
  # - **Resource Consumption**: Large images can consume significant disk space
27
27
  #
28
- # Security recommendations:
28
+ # **Security Recommendations**:
29
29
  # - Only pull images from trusted registries and publishers
30
30
  # - Verify image signatures when available
31
31
  # - Scan pulled images for vulnerabilities
@@ -41,78 +41,41 @@ module DockerMCP
41
41
  # - If no tag specified, default to "latest"
42
42
  # - Supports all Docker tag conventions
43
43
  #
44
+ # == Parameters
45
+ #
46
+ # - **from_image**: Image name to pull (required, e.g., "ubuntu" or "ubuntu:22.04")
47
+ # - **tag**: Tag to pull (optional, defaults to "latest" if not specified in from_image)
48
+ #
44
49
  # == Example Usage
45
50
  #
46
51
  # # Pull latest version
47
- # PullImage.call(
52
+ # response = PullImage.call(
48
53
  # server_context: context,
49
54
  # from_image: "nginx"
50
55
  # )
51
56
  #
52
57
  # # Pull specific version
53
- # PullImage.call(
58
+ # response = PullImage.call(
54
59
  # server_context: context,
55
- # from_image: "postgres:13"
60
+ # from_image: "postgres",
61
+ # tag: "13.8"
56
62
  # )
57
63
  #
58
- # # Pull with separate tag parameter
59
- # PullImage.call(
60
- # server_context: context,
61
- # from_image: "redis",
62
- # tag: "7-alpine"
63
- # )
64
- #
65
- # @see BuildImage
66
- # @see ListImages
67
64
  # @see Docker::Image.create
68
65
  # @since 0.1.0
69
- class PullImage < MCP::Tool
66
+ PULL_IMAGE_DEFINITION = ToolForge.define(:pull_image) do
70
67
  description 'Pull a Docker image'
71
68
 
72
- input_schema(
73
- properties: {
74
- from_image: {
75
- type: 'string',
69
+ param :from_image,
70
+ type: :string,
76
71
  description: 'Image name to pull (e.g., "ubuntu" or "ubuntu:22.04")'
77
- },
78
- tag: {
79
- type: 'string',
80
- description: 'Tag to pull (optional, defaults to "latest" if not specified in from_image)'
81
- }
82
- },
83
- required: ['from_image']
84
- )
85
72
 
86
- # Pull a Docker image from a registry.
87
- #
88
- # This method downloads the specified image from a Docker registry to
89
- # the local system. It handles tag resolution automatically and provides
90
- # feedback on the pull operation status.
91
- #
92
- # @param from_image [String] image name (may include registry and tag)
93
- # @param server_context [Object] MCP server context (unused but required)
94
- # @param tag [String, nil] specific tag to pull (overrides tag in from_image)
95
- #
96
- # @return [MCP::Tool::Response] pull operation results with image ID
97
- #
98
- # @raise [Docker::Error::NotFoundError] if image doesn't exist in registry
99
- # @raise [StandardError] for network or authentication failures
100
- #
101
- # @example Pull official image
102
- # response = PullImage.call(
103
- # server_context: context,
104
- # from_image: "ubuntu:22.04"
105
- # )
106
- #
107
- # @example Pull from custom registry
108
- # response = PullImage.call(
109
- # server_context: context,
110
- # from_image: "registry.example.com/myapp",
111
- # tag: "v1.0"
112
- # )
113
- #
114
- # @see Docker::Image.create
115
- def self.call(from_image:, server_context:, tag: nil)
73
+ param :tag,
74
+ type: :string,
75
+ description: 'Tag to pull (optional, defaults to "latest" if not specified in from_image)',
76
+ required: false
77
+
78
+ execute do |from_image:, tag: nil|
116
79
  # If tag is provided separately, append it to from_image
117
80
  # If from_image already has a tag (contains :), use as-is
118
81
  # Otherwise default to :latest
@@ -126,20 +89,13 @@ module DockerMCP
126
89
 
127
90
  image = Docker::Image.create('fromImage' => image_with_tag)
128
91
 
129
- MCP::Tool::Response.new([{
130
- type: 'text',
131
- text: "Image #{image_with_tag} pulled successfully. ID: #{image.id}"
132
- }])
92
+ "Image #{image_with_tag} pulled successfully. ID: #{image.id}"
133
93
  rescue Docker::Error::NotFoundError
134
- MCP::Tool::Response.new([{
135
- type: 'text',
136
- text: "Image #{image_with_tag} not found"
137
- }])
94
+ "Image #{image_with_tag} not found"
138
95
  rescue StandardError => e
139
- MCP::Tool::Response.new([{
140
- type: 'text',
141
- text: "Error pulling image: #{e.message}"
142
- }])
96
+ "Error pulling image: #{e.message}"
143
97
  end
144
98
  end
99
+
100
+ PullImage = PULL_IMAGE_DEFINITION.to_mcp_tool
145
101
  end