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.
- checksums.yaml +4 -4
- data/examples/docker_chat.rb +41 -0
- data/lib/ruby_llm/docker/build_image.rb +64 -65
- data/lib/ruby_llm/docker/copy_to_container.rb +89 -134
- data/lib/ruby_llm/docker/create_container.rb +64 -86
- data/lib/ruby_llm/docker/create_network.rb +63 -79
- data/lib/ruby_llm/docker/create_volume.rb +57 -79
- data/lib/ruby_llm/docker/exec_container.rb +94 -111
- data/lib/ruby_llm/docker/fetch_container_logs.rb +63 -85
- data/lib/ruby_llm/docker/list_containers.rb +46 -40
- data/lib/ruby_llm/docker/list_images.rb +34 -55
- data/lib/ruby_llm/docker/list_networks.rb +35 -57
- data/lib/ruby_llm/docker/list_volumes.rb +35 -64
- data/lib/ruby_llm/docker/pull_image.rb +24 -48
- data/lib/ruby_llm/docker/push_image.rb +60 -89
- data/lib/ruby_llm/docker/recreate_container.rb +47 -79
- data/lib/ruby_llm/docker/remove_container.rb +48 -76
- data/lib/ruby_llm/docker/remove_image.rb +53 -95
- data/lib/ruby_llm/docker/remove_network.rb +42 -78
- data/lib/ruby_llm/docker/remove_volume.rb +52 -85
- data/lib/ruby_llm/docker/run_container.rb +73 -53
- data/lib/ruby_llm/docker/start_container.rb +35 -58
- data/lib/ruby_llm/docker/stop_container.rb +40 -66
- data/lib/ruby_llm/docker/tag_image.rb +67 -95
- data/lib/ruby_llm/docker/version.rb +10 -1
- data/lib/ruby_llm/docker.rb +13 -0
- metadata +15 -1
|
@@ -2,143 +2,124 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyLLM
|
|
4
4
|
module Docker
|
|
5
|
-
#
|
|
5
|
+
# MCP tool for executing commands inside Docker containers.
|
|
6
6
|
#
|
|
7
|
-
# This tool provides the ability to execute arbitrary commands inside
|
|
8
|
-
# Docker containers
|
|
9
|
-
#
|
|
7
|
+
# This tool provides the ability to execute arbitrary commands inside
|
|
8
|
+
# running Docker containers. It supports interactive and non-interactive
|
|
9
|
+
# execution, environment variable injection, working directory specification,
|
|
10
|
+
# and user context switching within the container.
|
|
10
11
|
#
|
|
11
|
-
# ==
|
|
12
|
+
# == Features
|
|
12
13
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# -
|
|
16
|
-
# -
|
|
17
|
-
# -
|
|
18
|
-
# -
|
|
19
|
-
# -
|
|
14
|
+
# - Execute arbitrary commands in running containers
|
|
15
|
+
# - Support for command arguments and shell parsing
|
|
16
|
+
# - Environment variable injection
|
|
17
|
+
# - Working directory specification
|
|
18
|
+
# - User context switching (run as specific user)
|
|
19
|
+
# - Standard input, output, and error handling
|
|
20
|
+
# - Configurable execution timeouts
|
|
20
21
|
#
|
|
21
|
-
#
|
|
22
|
-
# - Ensure containers run with minimal privileges
|
|
23
|
-
# - Use read-only filesystems where possible
|
|
24
|
-
# - Implement proper network segmentation
|
|
25
|
-
# - Monitor and audit all command executions
|
|
26
|
-
# - Never expose this tool to untrusted clients
|
|
22
|
+
# == Security Considerations
|
|
27
23
|
#
|
|
28
|
-
#
|
|
24
|
+
# **CRITICAL WARNING**: This tool provides arbitrary command execution
|
|
25
|
+
# capabilities with significant security implications:
|
|
26
|
+
#
|
|
27
|
+
# - **Code Execution**: Can run any command available in the container
|
|
28
|
+
# - **File System Access**: Can read, write, and modify container files
|
|
29
|
+
# - **Network Access**: Can initiate network connections from container
|
|
30
|
+
# - **Process Manipulation**: Can start, stop, and signal processes
|
|
31
|
+
# - **Data Exposure**: Can access sensitive data within the container
|
|
32
|
+
# - **Privilege Escalation**: May exploit container or kernel vulnerabilities
|
|
33
|
+
# - **Resource Consumption**: Can consume container and host resources
|
|
34
|
+
#
|
|
35
|
+
# **Security Recommendations**:
|
|
36
|
+
# - Implement strict access controls and authentication
|
|
37
|
+
# - Use dedicated execution containers with minimal privileges
|
|
38
|
+
# - Monitor and log all command executions
|
|
39
|
+
# - Apply resource limits and timeouts
|
|
40
|
+
# - Validate and sanitize all command inputs
|
|
41
|
+
# - Consider using read-only file systems where possible
|
|
42
|
+
# - Implement network segmentation for container environments
|
|
29
43
|
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# -
|
|
33
|
-
# -
|
|
34
|
-
# -
|
|
35
|
-
# -
|
|
36
|
-
# -
|
|
44
|
+
# == Parameters
|
|
45
|
+
#
|
|
46
|
+
# - **id**: Container ID or name (required)
|
|
47
|
+
# - **cmd**: Command to execute (shell-parsed into arguments) (required)
|
|
48
|
+
# - **working_dir**: Working directory for command execution (optional)
|
|
49
|
+
# - **user**: User to run the command as (optional, e.g., "1000" or "username")
|
|
50
|
+
# - **env**: Environment variables as comma-separated KEY=VALUE pairs (optional)
|
|
51
|
+
# - **stdin**: Input to send to command via stdin (optional)
|
|
52
|
+
# - **timeout**: Timeout in seconds (optional, default: 60)
|
|
37
53
|
#
|
|
38
54
|
# == Example Usage
|
|
39
55
|
#
|
|
40
|
-
# #
|
|
41
|
-
# ExecContainer.call(
|
|
56
|
+
# # Basic command execution
|
|
57
|
+
# response = ExecContainer.call(
|
|
42
58
|
# server_context: context,
|
|
43
|
-
# id: "
|
|
44
|
-
# cmd: "
|
|
59
|
+
# id: "web-container",
|
|
60
|
+
# cmd: "nginx -t"
|
|
45
61
|
# )
|
|
46
62
|
#
|
|
47
|
-
# # Advanced execution with
|
|
48
|
-
# ExecContainer.call(
|
|
63
|
+
# # Advanced execution with environment
|
|
64
|
+
# response = ExecContainer.call(
|
|
49
65
|
# server_context: context,
|
|
50
|
-
# id: "
|
|
51
|
-
# cmd: "
|
|
66
|
+
# id: "app-container",
|
|
67
|
+
# cmd: "bundle exec rails console",
|
|
52
68
|
# working_dir: "/app",
|
|
53
|
-
# user: "
|
|
54
|
-
# env:
|
|
55
|
-
# timeout:
|
|
69
|
+
# user: "rails",
|
|
70
|
+
# env: "RAILS_ENV=production,DEBUG=true",
|
|
71
|
+
# timeout: 300
|
|
56
72
|
# )
|
|
57
73
|
#
|
|
58
|
-
# @see Docker::Container#exec
|
|
74
|
+
# @see ::Docker::Container#exec
|
|
59
75
|
# @since 0.1.0
|
|
60
|
-
|
|
76
|
+
EXEC_CONTAINER_DEFINITION = ToolForge.define(:exec_container) do
|
|
61
77
|
description 'Execute a command inside a running Docker container. ' \
|
|
62
78
|
'WARNING: This provides arbitrary command execution within the container. ' \
|
|
63
79
|
'Ensure proper security measures are in place.'
|
|
64
80
|
|
|
65
|
-
param :id,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
# @raise [StandardError] for other execution failures
|
|
101
|
-
#
|
|
102
|
-
# @example Basic command execution
|
|
103
|
-
# response = ExecContainer.call(
|
|
104
|
-
# server_context: context,
|
|
105
|
-
# id: "web-container",
|
|
106
|
-
# cmd: "nginx -t"
|
|
107
|
-
# )
|
|
108
|
-
#
|
|
109
|
-
# @example Advanced execution with environment
|
|
110
|
-
# response = tool.execute(
|
|
111
|
-
# id: "app-container",
|
|
112
|
-
# cmd: "bundle exec rails console",
|
|
113
|
-
# working_dir: "/app",
|
|
114
|
-
# user: "rails",
|
|
115
|
-
# env: ["RAILS_ENV=production"],
|
|
116
|
-
# timeout: 300
|
|
117
|
-
# )
|
|
118
|
-
#
|
|
119
|
-
# @see Docker::Container#exec
|
|
120
|
-
def execute(id:, cmd:, working_dir: nil, user: nil,
|
|
121
|
-
env: nil, stdin: nil, timeout: 60)
|
|
81
|
+
param :id,
|
|
82
|
+
type: :string,
|
|
83
|
+
description: 'Container ID or name'
|
|
84
|
+
|
|
85
|
+
param :cmd,
|
|
86
|
+
type: :string,
|
|
87
|
+
description: 'Command to execute (e.g., "ls -la /app" or "python script.py")'
|
|
88
|
+
|
|
89
|
+
param :working_dir,
|
|
90
|
+
type: :string,
|
|
91
|
+
description: 'Working directory for the command (optional)',
|
|
92
|
+
required: false
|
|
93
|
+
|
|
94
|
+
param :user,
|
|
95
|
+
type: :string,
|
|
96
|
+
description: 'User to run the command as (optional, e.g., "1000" or "username")',
|
|
97
|
+
required: false
|
|
98
|
+
|
|
99
|
+
param :env,
|
|
100
|
+
type: :string,
|
|
101
|
+
description: 'Environment variables as comma-separated KEY=VALUE pairs (optional)',
|
|
102
|
+
required: false
|
|
103
|
+
|
|
104
|
+
param :stdin,
|
|
105
|
+
type: :string,
|
|
106
|
+
description: 'Input to send to the command via stdin (optional)',
|
|
107
|
+
required: false
|
|
108
|
+
|
|
109
|
+
param :timeout,
|
|
110
|
+
type: :integer,
|
|
111
|
+
description: 'Timeout in seconds (optional, default: 60)',
|
|
112
|
+
required: false,
|
|
113
|
+
default: 60
|
|
114
|
+
|
|
115
|
+
execute do |id:, cmd:, working_dir: nil, user: nil, env: nil, stdin: nil, timeout: 60|
|
|
122
116
|
container = ::Docker::Container.get(id)
|
|
123
117
|
|
|
124
118
|
# Parse command string into array
|
|
125
|
-
# Simple shell-like parsing: split on spaces but respect quoted strings
|
|
126
119
|
cmd_array = Shellwords.split(cmd)
|
|
127
120
|
|
|
128
|
-
# Parse environment variables string
|
|
129
|
-
|
|
130
|
-
env_array = env.split(',').map(&:strip).select { |e| e.include?('=') } if env && !env.empty?
|
|
131
|
-
|
|
132
|
-
# Build exec options
|
|
133
|
-
exec_options = {
|
|
134
|
-
'Cmd' => cmd_array,
|
|
135
|
-
'AttachStdout' => true,
|
|
136
|
-
'AttachStderr' => true
|
|
137
|
-
}
|
|
138
|
-
exec_options['WorkingDir'] = working_dir if working_dir
|
|
139
|
-
exec_options['User'] = user if user
|
|
140
|
-
exec_options['Env'] = env_array if env_array
|
|
141
|
-
exec_options['AttachStdin'] = true if stdin
|
|
121
|
+
# Parse environment variables from comma-separated string to array
|
|
122
|
+
env.split(',').map(&:strip) if env && !env.empty?
|
|
142
123
|
|
|
143
124
|
# Execute the command
|
|
144
125
|
stdout_data = []
|
|
@@ -181,5 +162,7 @@ module RubyLLM
|
|
|
181
162
|
"Error executing command: #{e.message}"
|
|
182
163
|
end
|
|
183
164
|
end
|
|
165
|
+
|
|
166
|
+
ExecContainer = EXEC_CONTAINER_DEFINITION.to_ruby_llm_tool
|
|
184
167
|
end
|
|
185
168
|
end
|
|
@@ -2,116 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyLLM
|
|
4
4
|
module Docker
|
|
5
|
-
#
|
|
5
|
+
# MCP tool for fetching Docker container logs.
|
|
6
6
|
#
|
|
7
|
-
# This tool
|
|
8
|
-
#
|
|
9
|
-
#
|
|
7
|
+
# This tool retrieves log output from Docker containers, including both
|
|
8
|
+
# standard output and standard error streams. It supports filtering by
|
|
9
|
+
# stream type, limiting output length, timestamp inclusion, and retrieving
|
|
10
|
+
# logs from both running and stopped containers.
|
|
10
11
|
#
|
|
11
12
|
# == Features
|
|
12
13
|
#
|
|
13
|
-
# -
|
|
14
|
-
# -
|
|
15
|
-
# -
|
|
16
|
-
# -
|
|
17
|
-
# -
|
|
18
|
-
# -
|
|
19
|
-
#
|
|
20
|
-
# == Log Sources
|
|
21
|
-
#
|
|
22
|
-
# Docker containers can generate logs from multiple sources:
|
|
23
|
-
# - **stdout**: Standard output from container processes
|
|
24
|
-
# - **stderr**: Standard error from container processes
|
|
25
|
-
# - **timestamps**: Docker-generated timestamps for each log line
|
|
14
|
+
# - Fetch logs from running and stopped containers
|
|
15
|
+
# - Separate or combined stdout and stderr streams
|
|
16
|
+
# - Configurable output length limiting (tail functionality)
|
|
17
|
+
# - Optional timestamp inclusion for log entries
|
|
18
|
+
# - Support for container identification by ID or name
|
|
19
|
+
# - Comprehensive error handling and status reporting
|
|
26
20
|
#
|
|
27
21
|
# == Security Considerations
|
|
28
22
|
#
|
|
29
23
|
# Container logs may contain sensitive information:
|
|
30
|
-
# - Application
|
|
31
|
-
# -
|
|
32
|
-
# -
|
|
33
|
-
# -
|
|
34
|
-
# -
|
|
24
|
+
# - **Application Data**: Database queries, API keys, user data
|
|
25
|
+
# - **System Information**: Internal paths, configuration details
|
|
26
|
+
# - **Error Details**: Stack traces revealing application internals
|
|
27
|
+
# - **Access Patterns**: User behavior and system usage information
|
|
28
|
+
# - **Debugging Information**: Temporary credentials or session data
|
|
29
|
+
#
|
|
30
|
+
# Implement proper access controls and data sanitization for log access.
|
|
35
31
|
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
# -
|
|
39
|
-
# -
|
|
40
|
-
# -
|
|
41
|
-
# -
|
|
32
|
+
# == Parameters
|
|
33
|
+
#
|
|
34
|
+
# - **id**: Container ID or name (required)
|
|
35
|
+
# - **stdout**: Include stdout in logs (optional, default: true)
|
|
36
|
+
# - **stderr**: Include stderr in logs (optional, default: true)
|
|
37
|
+
# - **timestamps**: Show timestamps for log entries (optional, default: false)
|
|
38
|
+
# - **tail**: Number of lines to show from end of logs (optional, default: all)
|
|
42
39
|
#
|
|
43
40
|
# == Example Usage
|
|
44
41
|
#
|
|
45
|
-
# #
|
|
46
|
-
# FetchContainerLogs.call(
|
|
42
|
+
# # Fetch all logs
|
|
43
|
+
# response = FetchContainerLogs.call(
|
|
47
44
|
# server_context: context,
|
|
48
45
|
# id: "web-server"
|
|
49
46
|
# )
|
|
50
47
|
#
|
|
51
|
-
# #
|
|
52
|
-
# FetchContainerLogs.call(
|
|
48
|
+
# # Fetch recent errors with timestamps
|
|
49
|
+
# response = FetchContainerLogs.call(
|
|
53
50
|
# server_context: context,
|
|
54
51
|
# id: "app-container",
|
|
55
|
-
# tail: 100,
|
|
56
|
-
# timestamps: true
|
|
57
|
-
# )
|
|
58
|
-
#
|
|
59
|
-
# # Get only error logs
|
|
60
|
-
# FetchContainerLogs.call(
|
|
61
|
-
# server_context: context,
|
|
62
|
-
# id: "database",
|
|
63
52
|
# stdout: false,
|
|
64
|
-
# stderr: true
|
|
53
|
+
# stderr: true,
|
|
54
|
+
# timestamps: true,
|
|
55
|
+
# tail: 100
|
|
65
56
|
# )
|
|
66
57
|
#
|
|
67
|
-
# @see
|
|
68
|
-
# @see Docker::Container#logs
|
|
58
|
+
# @see ::Docker::Container#logs
|
|
69
59
|
# @since 0.1.0
|
|
70
|
-
|
|
60
|
+
FETCH_CONTAINER_LOGS_DEFINITION = ToolForge.define(:fetch_container_logs) do
|
|
71
61
|
description 'Fetch Docker container logs'
|
|
72
62
|
|
|
73
|
-
param :id,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
param :id,
|
|
64
|
+
type: :string,
|
|
65
|
+
description: 'Container ID or name'
|
|
66
|
+
|
|
67
|
+
param :stdout,
|
|
68
|
+
type: :boolean,
|
|
69
|
+
description: 'Include stdout (default: true)',
|
|
70
|
+
required: false,
|
|
71
|
+
default: true
|
|
72
|
+
|
|
73
|
+
param :stderr,
|
|
74
|
+
type: :boolean,
|
|
75
|
+
description: 'Include stderr (default: true)',
|
|
76
|
+
required: false,
|
|
77
|
+
default: true
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
# @return [RubyLLM::Tool::Response] container logs as text
|
|
94
|
-
#
|
|
95
|
-
# @raise [Docker::Error::NotFoundError] if container doesn't exist
|
|
96
|
-
# @raise [StandardError] for other log retrieval failures
|
|
97
|
-
#
|
|
98
|
-
# @example Get all logs
|
|
99
|
-
# response = FetchContainerLogs.call(
|
|
100
|
-
# server_context: context,
|
|
101
|
-
# id: "nginx-server"
|
|
102
|
-
# )
|
|
103
|
-
#
|
|
104
|
-
# @example Get recent error logs with timestamps
|
|
105
|
-
# response = tool.execute(
|
|
106
|
-
# id: "app-container",
|
|
107
|
-
# stdout: false,
|
|
108
|
-
# stderr: true,
|
|
109
|
-
# tail: 50,
|
|
110
|
-
# timestamps: true
|
|
111
|
-
# )
|
|
112
|
-
#
|
|
113
|
-
# @see Docker::Container#logs
|
|
114
|
-
def execute(id:, stdout: true, stderr: true, tail: nil, timestamps: false)
|
|
79
|
+
param :tail,
|
|
80
|
+
type: :integer,
|
|
81
|
+
description: 'Number of lines to show from the end of logs (default: all)',
|
|
82
|
+
required: false
|
|
83
|
+
|
|
84
|
+
param :timestamps,
|
|
85
|
+
type: :boolean,
|
|
86
|
+
description: 'Show timestamps (default: false)',
|
|
87
|
+
required: false,
|
|
88
|
+
default: false
|
|
89
|
+
|
|
90
|
+
execute do |id:, stdout: true, stderr: true, tail: nil, timestamps: false|
|
|
115
91
|
container = ::Docker::Container.get(id)
|
|
116
92
|
|
|
117
93
|
options = {
|
|
@@ -128,5 +104,7 @@ module RubyLLM
|
|
|
128
104
|
"Error fetching logs: #{e.message}"
|
|
129
105
|
end
|
|
130
106
|
end
|
|
107
|
+
|
|
108
|
+
FetchContainerLogs = FETCH_CONTAINER_LOGS_DEFINITION.to_ruby_llm_tool
|
|
131
109
|
end
|
|
132
110
|
end
|
|
@@ -2,58 +2,64 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyLLM
|
|
4
4
|
module Docker
|
|
5
|
-
#
|
|
5
|
+
# MCP tool for listing Docker containers.
|
|
6
6
|
#
|
|
7
|
-
# This tool provides
|
|
8
|
-
# including both running and stopped containers. It returns
|
|
9
|
-
#
|
|
7
|
+
# This tool provides comprehensive information about all Docker containers
|
|
8
|
+
# on the system, including both running and stopped containers. It returns
|
|
9
|
+
# detailed metadata for each container including names, images, status,
|
|
10
|
+
# network configuration, and resource usage.
|
|
10
11
|
#
|
|
11
|
-
# ==
|
|
12
|
+
# == Features
|
|
12
13
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
14
|
+
# - Lists all containers (running and stopped)
|
|
15
|
+
# - Provides detailed container metadata
|
|
16
|
+
# - Shows network configuration and port mappings
|
|
17
|
+
# - Displays resource usage and statistics
|
|
18
|
+
# - Includes mount point information
|
|
19
|
+
# - Shows container labels and annotations
|
|
16
20
|
#
|
|
17
|
-
# ==
|
|
21
|
+
# == Security Considerations
|
|
22
|
+
#
|
|
23
|
+
# This tool provides system information that could be useful for:
|
|
24
|
+
# - **System Reconnaissance**: Reveals running services and configurations
|
|
25
|
+
# - **Network Discovery**: Shows internal network topology
|
|
26
|
+
# - **Resource Analysis**: Exposes system resource usage patterns
|
|
18
27
|
#
|
|
19
|
-
#
|
|
20
|
-
# ListContainers.call(server_context: context)
|
|
28
|
+
# Use with appropriate access controls in production environments.
|
|
21
29
|
#
|
|
22
|
-
#
|
|
23
|
-
# ListContainers.call(server_context: context, all: true)
|
|
30
|
+
# == Return Format
|
|
24
31
|
#
|
|
25
|
-
#
|
|
32
|
+
# Returns an array of container objects with comprehensive metadata:
|
|
33
|
+
# - Container names and IDs
|
|
34
|
+
# - Image information and tags
|
|
35
|
+
# - Current state and status
|
|
36
|
+
# - Network settings and port bindings
|
|
37
|
+
# - Mount points and volumes
|
|
38
|
+
# - Labels and environment details
|
|
39
|
+
#
|
|
40
|
+
# == Example Usage
|
|
41
|
+
#
|
|
42
|
+
# containers = ListContainers.call(server_context: context)
|
|
43
|
+
# containers.each do |container|
|
|
44
|
+
# puts "#{container['Names'].first}: #{container['State']}"
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
47
|
+
# @see ::Docker::Container.all
|
|
26
48
|
# @since 0.1.0
|
|
27
|
-
|
|
49
|
+
LIST_CONTAINERS_DEFINITION = ToolForge.define(:list_containers) do
|
|
28
50
|
description 'List Docker containers'
|
|
29
51
|
|
|
30
|
-
param :all,
|
|
31
|
-
|
|
52
|
+
param :all,
|
|
53
|
+
type: :boolean,
|
|
54
|
+
description: 'Show all containers (default shows all containers including stopped ones)',
|
|
55
|
+
required: false,
|
|
56
|
+
default: true
|
|
32
57
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# Retrieves information about all containers on the system, including:
|
|
36
|
-
# - Container names and IDs
|
|
37
|
-
# - Image information
|
|
38
|
-
# - Current state (running, stopped, etc.)
|
|
39
|
-
# - Port mappings
|
|
40
|
-
# - Network configuration
|
|
41
|
-
# - Volume mounts
|
|
42
|
-
# - Creation and status timestamps
|
|
43
|
-
#
|
|
44
|
-
# @param server_context [Object] the RubyLLM context (unused but required)
|
|
45
|
-
# @param all [Boolean] whether to show all containers (default: true)
|
|
46
|
-
# @return [RubyLLM::Tool::Response] response containing container information
|
|
47
|
-
#
|
|
48
|
-
# @example List all containers
|
|
49
|
-
# response = ListContainers.call(server_context: context)
|
|
50
|
-
# # Returns detailed info for all containers
|
|
51
|
-
#
|
|
52
|
-
# @see Docker::Container.all
|
|
53
|
-
def execute(all: true)
|
|
54
|
-
require 'docker'
|
|
55
|
-
::Docker::Container.all(all: all).map(&:info).to_s
|
|
58
|
+
execute do |all: true|
|
|
59
|
+
::Docker::Container.all(all: all).map(&:info)
|
|
56
60
|
end
|
|
57
61
|
end
|
|
62
|
+
|
|
63
|
+
ListContainers = LIST_CONTAINERS_DEFINITION.to_ruby_llm_tool
|
|
58
64
|
end
|
|
59
65
|
end
|
|
@@ -2,78 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyLLM
|
|
4
4
|
module Docker
|
|
5
|
-
#
|
|
5
|
+
# MCP tool for listing Docker images.
|
|
6
6
|
#
|
|
7
|
-
# This tool provides
|
|
8
|
-
# the local system. It returns
|
|
9
|
-
#
|
|
7
|
+
# This tool provides comprehensive information about all Docker images
|
|
8
|
+
# stored on the local system. It returns detailed metadata including
|
|
9
|
+
# image sizes, creation dates, tags, and usage statistics.
|
|
10
10
|
#
|
|
11
11
|
# == Features
|
|
12
12
|
#
|
|
13
|
-
# -
|
|
14
|
-
# -
|
|
15
|
-
# -
|
|
16
|
-
# -
|
|
17
|
-
# - Includes
|
|
13
|
+
# - Lists all locally stored Docker images
|
|
14
|
+
# - Provides detailed image metadata and statistics
|
|
15
|
+
# - Shows image sizes and storage usage
|
|
16
|
+
# - Displays repository tags and digests
|
|
17
|
+
# - Includes creation timestamps and labels
|
|
18
|
+
# - Reports container usage counts
|
|
18
19
|
#
|
|
19
|
-
# ==
|
|
20
|
+
# == Security Considerations
|
|
20
21
|
#
|
|
21
|
-
#
|
|
22
|
-
# - **
|
|
23
|
-
# - **
|
|
24
|
-
# - **
|
|
25
|
-
# - **Created**: Timestamp when image was created
|
|
26
|
-
# - **Parent ID**: Base image information
|
|
27
|
-
# - **RepoDigests**: Content-addressable identifiers
|
|
22
|
+
# This tool provides information that could be useful for:
|
|
23
|
+
# - **System Analysis**: Reveals installed software and versions
|
|
24
|
+
# - **Vulnerability Assessment**: Shows potential attack surfaces
|
|
25
|
+
# - **Resource Planning**: Exposes storage usage patterns
|
|
28
26
|
#
|
|
29
|
-
#
|
|
27
|
+
# Monitor access to this tool in production environments.
|
|
30
28
|
#
|
|
31
|
-
#
|
|
32
|
-
# - Exposes available images and versions
|
|
33
|
-
# - May reveal internal application details
|
|
34
|
-
# - Shows image sources and repositories
|
|
35
|
-
# - Could aid in reconnaissance activities
|
|
29
|
+
# == Return Format
|
|
36
30
|
#
|
|
37
|
-
#
|
|
38
|
-
# -
|
|
39
|
-
# -
|
|
40
|
-
# -
|
|
31
|
+
# Returns an array of image objects with comprehensive metadata:
|
|
32
|
+
# - Repository tags and digests
|
|
33
|
+
# - Image sizes and virtual sizes
|
|
34
|
+
# - Creation timestamps
|
|
35
|
+
# - Container usage counts
|
|
36
|
+
# - Labels and annotations
|
|
37
|
+
# - Parent-child relationships
|
|
41
38
|
#
|
|
42
39
|
# == Example Usage
|
|
43
40
|
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
41
|
+
# images = ListImages.call(server_context: context)
|
|
42
|
+
# images.each do |image|
|
|
43
|
+
# puts "#{image['RepoTags']}: #{image['Size']} bytes"
|
|
44
|
+
# end
|
|
46
45
|
#
|
|
47
|
-
# @
|
|
48
|
-
# # Get available images before container creation
|
|
49
|
-
# images_response = ListImages.call(server_context: context)
|
|
50
|
-
# # Use image information to select appropriate base images
|
|
51
|
-
#
|
|
52
|
-
# @see PullImage
|
|
53
|
-
# @see BuildImage
|
|
54
|
-
# @see Docker::Image.all
|
|
46
|
+
# @see ::Docker::Image.all
|
|
55
47
|
# @since 0.1.0
|
|
56
|
-
|
|
48
|
+
LIST_IMAGES_DEFINITION = ToolForge.define(:list_images) do
|
|
57
49
|
description 'List Docker images'
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# This method retrieves information about all Docker images stored
|
|
62
|
-
# locally, including both tagged and untagged images. The information
|
|
63
|
-
# includes comprehensive metadata for each image.
|
|
64
|
-
#
|
|
65
|
-
# @param args [Array] variable arguments (unused but accepted for compatibility)
|
|
66
|
-
#
|
|
67
|
-
# @return [RubyLLM::Tool::Response] comprehensive image information
|
|
68
|
-
#
|
|
69
|
-
# @example List all local images
|
|
70
|
-
# response = ListImages.call
|
|
71
|
-
# # Returns detailed info for all local Docker images
|
|
72
|
-
#
|
|
73
|
-
# @see Docker::Image.all
|
|
74
|
-
def execute
|
|
75
|
-
::Docker::Image.all.map(&:info).to_s
|
|
51
|
+
execute do
|
|
52
|
+
::Docker::Image.all.map(&:info)
|
|
76
53
|
end
|
|
77
54
|
end
|
|
55
|
+
|
|
56
|
+
ListImages = LIST_IMAGES_DEFINITION.to_ruby_llm_tool
|
|
78
57
|
end
|
|
79
58
|
end
|