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.
- checksums.yaml +4 -4
- data/lib/docker_mcp/build_image.rb +65 -84
- data/lib/docker_mcp/copy_to_container.rb +87 -161
- data/lib/docker_mcp/create_container.rb +63 -115
- data/lib/docker_mcp/create_network.rb +63 -102
- data/lib/docker_mcp/create_volume.rb +57 -100
- data/lib/docker_mcp/exec_container.rb +94 -147
- data/lib/docker_mcp/fetch_container_logs.rb +64 -117
- data/lib/docker_mcp/list_containers.rb +44 -47
- data/lib/docker_mcp/list_images.rb +32 -56
- data/lib/docker_mcp/list_networks.rb +33 -60
- data/lib/docker_mcp/list_volumes.rb +33 -67
- data/lib/docker_mcp/pull_image.rb +24 -68
- data/lib/docker_mcp/push_image.rb +61 -118
- data/lib/docker_mcp/recreate_container.rb +48 -99
- data/lib/docker_mcp/remove_container.rb +49 -101
- data/lib/docker_mcp/remove_image.rb +53 -119
- data/lib/docker_mcp/remove_network.rb +42 -96
- data/lib/docker_mcp/remove_volume.rb +52 -106
- data/lib/docker_mcp/run_container.rb +72 -82
- data/lib/docker_mcp/start_container.rb +36 -76
- data/lib/docker_mcp/stop_container.rb +41 -86
- data/lib/docker_mcp/tag_image.rb +67 -121
- data/lib/docker_mcp/version.rb +1 -1
- data/lib/docker_mcp.rb +2 -0
- metadata +15 -1
@@ -1,49 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DockerMCP
|
4
|
-
# MCP tool for creating Docker containers
|
4
|
+
# MCP tool for creating Docker containers.
|
5
5
|
#
|
6
|
-
# This tool
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
6
|
+
# This tool creates a new Docker container from a specified image without
|
7
|
+
# starting it. The container is created in a "created" state and can be
|
8
|
+
# started later using the start_container tool. This two-step process
|
9
|
+
# allows for container configuration before execution.
|
10
10
|
#
|
11
11
|
# == Features
|
12
12
|
#
|
13
|
-
# -
|
14
|
-
# -
|
15
|
-
# -
|
16
|
-
# -
|
17
|
-
# -
|
18
|
-
# -
|
19
|
-
# - Comprehensive error handling with specific error types
|
13
|
+
# - Creates containers from any available Docker image
|
14
|
+
# - Supports custom container naming
|
15
|
+
# - Configures command execution and environment variables
|
16
|
+
# - Sets up port exposure and network configuration
|
17
|
+
# - Applies advanced host configurations
|
18
|
+
# - Handles container labeling and metadata
|
20
19
|
#
|
21
20
|
# == Security Considerations
|
22
21
|
#
|
23
|
-
#
|
24
|
-
# -
|
25
|
-
# -
|
26
|
-
# -
|
27
|
-
# -
|
22
|
+
# Container creation is a powerful operation that can:
|
23
|
+
# - **Resource Allocation**: Consume system resources and storage
|
24
|
+
# - **Network Access**: Create network endpoints and bindings
|
25
|
+
# - **File System Access**: Mount host directories and volumes
|
26
|
+
# - **Security Context**: Run with elevated privileges if configured
|
28
27
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# -
|
34
|
-
# -
|
28
|
+
# Implement proper access controls and resource limits.
|
29
|
+
#
|
30
|
+
# == Parameters
|
31
|
+
#
|
32
|
+
# - **image**: Docker image to use (required)
|
33
|
+
# - **name**: Custom container name (optional)
|
34
|
+
# - **cmd**: Command to execute as space-separated string (optional)
|
35
|
+
# - **env**: Environment variables as comma-separated KEY=VALUE pairs (optional)
|
36
|
+
# - **exposed_ports**: Port exposure configuration as JSON object (optional)
|
37
|
+
# - **host_config**: Advanced host configuration as JSON object (optional)
|
35
38
|
#
|
36
39
|
# == Example Usage
|
37
40
|
#
|
38
41
|
# # Simple container creation
|
39
|
-
# CreateContainer.call(
|
42
|
+
# response = CreateContainer.call(
|
40
43
|
# server_context: context,
|
41
44
|
# image: "nginx:latest",
|
42
45
|
# name: "web-server"
|
43
46
|
# )
|
44
47
|
#
|
45
48
|
# # Advanced container with configuration
|
46
|
-
# CreateContainer.call(
|
49
|
+
# response = CreateContainer.call(
|
47
50
|
# server_context: context,
|
48
51
|
# image: "postgres:13",
|
49
52
|
# name: "database",
|
@@ -55,86 +58,41 @@ module DockerMCP
|
|
55
58
|
# }
|
56
59
|
# )
|
57
60
|
#
|
58
|
-
# @see RunContainer
|
59
|
-
# @see StartContainer
|
60
61
|
# @see Docker::Container.create
|
61
62
|
# @since 0.1.0
|
62
|
-
|
63
|
+
CREATE_CONTAINER_DEFINITION = ToolForge.define(:create_container) do
|
63
64
|
description 'Create a Docker container'
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
image: {
|
68
|
-
type: 'string',
|
66
|
+
param :image,
|
67
|
+
type: :string,
|
69
68
|
description: 'Image name to use (e.g., "ubuntu:22.04")'
|
70
|
-
},
|
71
|
-
name: {
|
72
|
-
type: 'string',
|
73
|
-
description: 'Container name (optional)'
|
74
|
-
},
|
75
|
-
cmd: {
|
76
|
-
type: 'string',
|
77
|
-
description: 'Command to run as space-separated string (optional, e.g., "npm start" or "python app.py")'
|
78
|
-
},
|
79
|
-
env: {
|
80
|
-
type: 'string',
|
81
|
-
description: 'Environment variables as comma-separated KEY=VALUE pairs (optional)'
|
82
|
-
},
|
83
|
-
exposed_ports: {
|
84
|
-
type: 'object',
|
85
|
-
description: 'Exposed ports as {"port/protocol": {}} (optional)'
|
86
|
-
},
|
87
|
-
host_config: {
|
88
|
-
type: 'object',
|
89
|
-
description: 'Host configuration including port bindings, volumes, etc. (optional)'
|
90
|
-
}
|
91
|
-
},
|
92
|
-
required: ['image']
|
93
|
-
)
|
94
69
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
# )
|
122
|
-
#
|
123
|
-
# @example Create container with full configuration
|
124
|
-
# response = CreateContainer.call(
|
125
|
-
# server_context: context,
|
126
|
-
# image: "redis:7-alpine",
|
127
|
-
# name: "redis-cache",
|
128
|
-
# env: "REDIS_PASSWORD=secret,REDIS_PORT=6379",
|
129
|
-
# exposed_ports: {"6379/tcp" => {}},
|
130
|
-
# host_config: {
|
131
|
-
# "PortBindings" => {"6379/tcp" => [{"HostPort" => "6379"}]},
|
132
|
-
# "RestartPolicy" => {"Name" => "unless-stopped"}
|
133
|
-
# }
|
134
|
-
# )
|
135
|
-
#
|
136
|
-
# @see Docker::Container.create
|
137
|
-
def self.call(image:, server_context:, name: nil, cmd: nil, env: nil, exposed_ports: nil, host_config: nil)
|
70
|
+
param :name,
|
71
|
+
type: :string,
|
72
|
+
description: 'Container name (optional)',
|
73
|
+
required: false
|
74
|
+
|
75
|
+
param :cmd,
|
76
|
+
type: :string,
|
77
|
+
description: 'Command to run as space-separated string (optional, e.g., "npm start" or "python app.py")',
|
78
|
+
required: false
|
79
|
+
|
80
|
+
param :env,
|
81
|
+
type: :string,
|
82
|
+
description: 'Environment variables as comma-separated KEY=VALUE pairs (optional)',
|
83
|
+
required: false
|
84
|
+
|
85
|
+
param :exposed_ports,
|
86
|
+
type: :object,
|
87
|
+
description: 'Exposed ports as {"port/protocol": {}} (optional)',
|
88
|
+
required: false
|
89
|
+
|
90
|
+
param :host_config,
|
91
|
+
type: :object,
|
92
|
+
description: 'Host configuration including port bindings, volumes, etc. (optional)',
|
93
|
+
required: false
|
94
|
+
|
95
|
+
execute do |image:, name: nil, cmd: nil, env: nil, exposed_ports: nil, host_config: nil|
|
138
96
|
config = { 'Image' => image }
|
139
97
|
config['name'] = name if name
|
140
98
|
|
@@ -150,25 +108,15 @@ module DockerMCP
|
|
150
108
|
container = Docker::Container.create(config)
|
151
109
|
container_name = container.info['Names']&.first&.delete_prefix('/')
|
152
110
|
|
153
|
-
|
154
|
-
type: 'text',
|
155
|
-
text: "Container created successfully. ID: #{container.id}, Name: #{container_name}"
|
156
|
-
}])
|
111
|
+
"Container created successfully. ID: #{container.id}, Name: #{container_name}"
|
157
112
|
rescue Docker::Error::NotFoundError
|
158
|
-
|
159
|
-
type: 'text',
|
160
|
-
text: "Image #{image} not found"
|
161
|
-
}])
|
113
|
+
"Image #{image} not found"
|
162
114
|
rescue Docker::Error::ConflictError
|
163
|
-
|
164
|
-
type: 'text',
|
165
|
-
text: "Container with name #{name} already exists"
|
166
|
-
}])
|
115
|
+
"Container with name #{name} already exists"
|
167
116
|
rescue StandardError => e
|
168
|
-
|
169
|
-
type: 'text',
|
170
|
-
text: "Error creating container: #{e.message}"
|
171
|
-
}])
|
117
|
+
"Error creating container: #{e.message}"
|
172
118
|
end
|
173
119
|
end
|
120
|
+
|
121
|
+
CreateContainer = CREATE_CONTAINER_DEFINITION.to_mcp_tool
|
174
122
|
end
|
@@ -3,128 +3,96 @@
|
|
3
3
|
module DockerMCP
|
4
4
|
# MCP tool for creating Docker networks.
|
5
5
|
#
|
6
|
-
# This tool provides the ability to create custom Docker networks
|
7
|
-
# container communication and isolation. Networks enable
|
8
|
-
#
|
9
|
-
# segments.
|
6
|
+
# This tool provides the ability to create custom Docker networks
|
7
|
+
# for container communication and isolation. Networks enable secure
|
8
|
+
# and controlled communication between containers and external systems.
|
10
9
|
#
|
11
10
|
# == Features
|
12
11
|
#
|
13
12
|
# - Create custom Docker networks
|
14
|
-
# - Support for
|
15
|
-
# - Duplicate name
|
13
|
+
# - Support for multiple network drivers (bridge, overlay, host, etc.)
|
14
|
+
# - Duplicate name checking and validation
|
15
|
+
# - Network configuration and options
|
16
16
|
# - Comprehensive error handling
|
17
|
-
# -
|
18
|
-
#
|
19
|
-
# == Network Drivers
|
20
|
-
#
|
21
|
-
# Docker supports various network drivers:
|
22
|
-
# - **bridge**: Default isolated network for single-host networking
|
23
|
-
# - **host**: Remove network isolation, use host networking directly
|
24
|
-
# - **overlay**: Multi-host networking for swarm services
|
25
|
-
# - **macvlan**: Assign MAC addresses to containers
|
26
|
-
# - **none**: Disable networking completely
|
27
|
-
# - **Custom**: Third-party network drivers
|
17
|
+
# - Network isolation and security controls
|
28
18
|
#
|
29
19
|
# == Security Considerations
|
30
20
|
#
|
31
|
-
# Network creation
|
32
|
-
# - **Network Isolation**:
|
33
|
-
# - **Traffic Control**:
|
34
|
-
# - **Access
|
35
|
-
# - **
|
21
|
+
# Network creation involves important security considerations:
|
22
|
+
# - **Network Isolation**: Improper networks can compromise container isolation
|
23
|
+
# - **Traffic Control**: Networks affect inter-container communication
|
24
|
+
# - **External Access**: Bridge networks may expose containers externally
|
25
|
+
# - **Resource Usage**: Networks consume system resources
|
26
|
+
# - **DNS Resolution**: Custom networks affect service discovery
|
27
|
+
# - **Firewall Bypass**: Networks can bypass host firewall rules
|
36
28
|
#
|
37
|
-
# Security
|
38
|
-
# -
|
39
|
-
# - Host networks expose containers to all host traffic
|
40
|
-
# - Custom networks should follow least-privilege principles
|
41
|
-
# - Network names may reveal infrastructure details
|
42
|
-
#
|
43
|
-
# Best practices:
|
44
|
-
# - Use descriptive but not sensitive network names
|
29
|
+
# **Security Recommendations**:
|
30
|
+
# - Use appropriate network drivers for use case
|
45
31
|
# - Implement network segmentation strategies
|
46
|
-
# -
|
47
|
-
# -
|
32
|
+
# - Monitor network traffic and usage
|
33
|
+
# - Avoid exposing internal networks externally
|
34
|
+
# - Use network policies for access control
|
48
35
|
# - Regular audit of network configurations
|
49
36
|
#
|
37
|
+
# == Parameters
|
38
|
+
#
|
39
|
+
# - **name**: Name of the network (required)
|
40
|
+
# - **driver**: Driver to use (optional, default: "bridge")
|
41
|
+
# - **check_duplicate**: Check for networks with duplicate names (optional, default: true)
|
42
|
+
#
|
43
|
+
# == Network Drivers
|
44
|
+
#
|
45
|
+
# - **bridge**: Default driver for single-host networking
|
46
|
+
# - **overlay**: Multi-host networking for Docker Swarm
|
47
|
+
# - **host**: Uses host's network stack directly
|
48
|
+
# - **none**: Disables networking for containers
|
49
|
+
# - **macvlan**: Assigns MAC addresses to containers
|
50
|
+
#
|
50
51
|
# == Example Usage
|
51
52
|
#
|
52
53
|
# # Create basic bridge network
|
53
|
-
# CreateNetwork.call(
|
54
|
+
# response = CreateNetwork.call(
|
54
55
|
# server_context: context,
|
55
56
|
# name: "app-network"
|
56
57
|
# )
|
57
58
|
#
|
58
|
-
# # Create network
|
59
|
-
# CreateNetwork.call(
|
59
|
+
# # Create overlay network for swarm
|
60
|
+
# response = CreateNetwork.call(
|
60
61
|
# server_context: context,
|
61
|
-
# name: "
|
62
|
-
# driver: "
|
62
|
+
# name: "swarm-network",
|
63
|
+
# driver: "overlay"
|
63
64
|
# )
|
64
65
|
#
|
65
|
-
# # Create
|
66
|
-
# CreateNetwork.call(
|
66
|
+
# # Create network allowing duplicates
|
67
|
+
# response = CreateNetwork.call(
|
67
68
|
# server_context: context,
|
68
|
-
# name: "
|
69
|
+
# name: "test-network",
|
70
|
+
# driver: "bridge",
|
69
71
|
# check_duplicate: false
|
70
72
|
# )
|
71
73
|
#
|
72
|
-
# @see ListNetworks
|
73
|
-
# @see RemoveNetwork
|
74
74
|
# @see Docker::Network.create
|
75
75
|
# @since 0.1.0
|
76
|
-
|
76
|
+
CREATE_NETWORK_DEFINITION = ToolForge.define(:create_network) do
|
77
77
|
description 'Create a Docker network'
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
name: {
|
82
|
-
type: 'string',
|
79
|
+
param :name,
|
80
|
+
type: :string,
|
83
81
|
description: 'Name of the network'
|
84
|
-
},
|
85
|
-
driver: {
|
86
|
-
type: 'string',
|
87
|
-
description: 'Driver to use (default: bridge)'
|
88
|
-
},
|
89
|
-
check_duplicate: {
|
90
|
-
type: 'boolean',
|
91
|
-
description: 'Check for networks with duplicate names (default: true)'
|
92
|
-
}
|
93
|
-
},
|
94
|
-
required: ['name']
|
95
|
-
)
|
96
82
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
# @raise [Docker::Error::ConflictError] if network name already exists
|
111
|
-
# @raise [StandardError] for other network creation failures
|
112
|
-
#
|
113
|
-
# @example Create application network
|
114
|
-
# response = CreateNetwork.call(
|
115
|
-
# server_context: context,
|
116
|
-
# name: "webapp-network"
|
117
|
-
# )
|
118
|
-
#
|
119
|
-
# @example Create host network
|
120
|
-
# response = CreateNetwork.call(
|
121
|
-
# server_context: context,
|
122
|
-
# name: "high-performance-net",
|
123
|
-
# driver: "host"
|
124
|
-
# )
|
125
|
-
#
|
126
|
-
# @see Docker::Network.create
|
127
|
-
def self.call(name:, server_context:, driver: 'bridge', check_duplicate: true)
|
83
|
+
param :driver,
|
84
|
+
type: :string,
|
85
|
+
description: 'Driver to use (default: bridge)',
|
86
|
+
required: false,
|
87
|
+
default: 'bridge'
|
88
|
+
|
89
|
+
param :check_duplicate,
|
90
|
+
type: :boolean,
|
91
|
+
description: 'Check for networks with duplicate names (default: true)',
|
92
|
+
required: false,
|
93
|
+
default: true
|
94
|
+
|
95
|
+
execute do |name:, driver: 'bridge', check_duplicate: true|
|
128
96
|
options = {
|
129
97
|
'Name' => name,
|
130
98
|
'Driver' => driver,
|
@@ -133,20 +101,13 @@ module DockerMCP
|
|
133
101
|
|
134
102
|
network = Docker::Network.create(name, options)
|
135
103
|
|
136
|
-
|
137
|
-
type: 'text',
|
138
|
-
text: "Network #{name} created successfully. ID: #{network.id}"
|
139
|
-
}])
|
104
|
+
"Network #{name} created successfully. ID: #{network.id}"
|
140
105
|
rescue Docker::Error::ConflictError
|
141
|
-
|
142
|
-
type: 'text',
|
143
|
-
text: "Network #{name} already exists"
|
144
|
-
}])
|
106
|
+
"Network #{name} already exists"
|
145
107
|
rescue StandardError => e
|
146
|
-
|
147
|
-
type: 'text',
|
148
|
-
text: "Error creating network: #{e.message}"
|
149
|
-
}])
|
108
|
+
"Error creating network: #{e.message}"
|
150
109
|
end
|
151
110
|
end
|
111
|
+
|
112
|
+
CreateNetwork = CREATE_NETWORK_DEFINITION.to_mcp_tool
|
152
113
|
end
|
@@ -3,125 +3,89 @@
|
|
3
3
|
module DockerMCP
|
4
4
|
# MCP tool for creating Docker volumes.
|
5
5
|
#
|
6
|
-
# This tool provides the ability to create
|
7
|
-
# data storage
|
8
|
-
#
|
9
|
-
# containers.
|
6
|
+
# This tool provides the ability to create Docker volumes for persistent
|
7
|
+
# data storage. Volumes are essential for maintaining data across container
|
8
|
+
# lifecycles and enabling data sharing between containers.
|
10
9
|
#
|
11
10
|
# == Features
|
12
11
|
#
|
13
|
-
# - Create named
|
14
|
-
# - Support for
|
12
|
+
# - Create named Docker volumes
|
13
|
+
# - Support for multiple volume drivers
|
14
|
+
# - Persistent data storage management
|
15
|
+
# - Volume driver configuration
|
15
16
|
# - Comprehensive error handling
|
16
|
-
# -
|
17
|
-
# - Flexible storage configuration
|
17
|
+
# - Volume lifecycle management
|
18
18
|
#
|
19
|
-
# ==
|
20
|
-
#
|
21
|
-
# Docker supports various volume drivers:
|
22
|
-
# - **local**: Default driver using host filesystem
|
23
|
-
# - **nfs**: Network File System for shared storage
|
24
|
-
# - **cifs**: Common Internet File System
|
25
|
-
# - **rexray**: External storage orchestration
|
26
|
-
# - **Custom**: Third-party volume drivers
|
19
|
+
# == Security Considerations
|
27
20
|
#
|
28
|
-
#
|
21
|
+
# Volume creation involves important security considerations:
|
22
|
+
# - **Data Persistence**: Volumes store data beyond container lifecycle
|
23
|
+
# - **Access Control**: Volume permissions affect data security
|
24
|
+
# - **Data Isolation**: Improper volumes can compromise data separation
|
25
|
+
# - **Storage Security**: Volume drivers may have security implications
|
26
|
+
# - **Resource Usage**: Volumes consume disk space and system resources
|
27
|
+
# - **Data Leakage**: Shared volumes can expose sensitive data
|
29
28
|
#
|
30
|
-
#
|
31
|
-
# -
|
32
|
-
# -
|
33
|
-
# -
|
34
|
-
# -
|
35
|
-
# -
|
36
|
-
# -
|
29
|
+
# **Security Recommendations**:
|
30
|
+
# - Use appropriate volume drivers for security requirements
|
31
|
+
# - Implement proper access controls and permissions
|
32
|
+
# - Monitor volume usage and capacity
|
33
|
+
# - Regular backup of critical volume data
|
34
|
+
# - Audit volume access patterns
|
35
|
+
# - Use encryption for sensitive data volumes
|
36
|
+
# - Implement volume lifecycle policies
|
37
37
|
#
|
38
|
-
# ==
|
38
|
+
# == Parameters
|
39
39
|
#
|
40
|
-
#
|
41
|
-
# - **
|
42
|
-
# - **Access Control**: Volume permissions affect data access
|
43
|
-
# - **Storage Location**: Local volumes stored on host filesystem
|
44
|
-
# - **Shared Access**: Multiple containers can access the same volume
|
40
|
+
# - **name**: Name of the volume (required)
|
41
|
+
# - **driver**: Driver to use (optional, default: "local")
|
45
42
|
#
|
46
|
-
#
|
47
|
-
# - Volumes persist data beyond container lifecycle
|
48
|
-
# - Volume names may reveal application details
|
49
|
-
# - Shared volumes can leak data between containers
|
50
|
-
# - Storage driver choice affects security properties
|
43
|
+
# == Volume Drivers
|
51
44
|
#
|
52
|
-
#
|
53
|
-
# -
|
54
|
-
# -
|
55
|
-
# -
|
56
|
-
# -
|
57
|
-
# - Choose appropriate drivers for security requirements
|
45
|
+
# - **local**: Default driver for local filesystem storage
|
46
|
+
# - **nfs**: Network File System driver for shared storage
|
47
|
+
# - **cifs**: Common Internet File System driver
|
48
|
+
# - **rexray**: REX-Ray driver for cloud storage integration
|
49
|
+
# - **convoy**: Convoy driver for snapshot management
|
58
50
|
#
|
59
51
|
# == Example Usage
|
60
52
|
#
|
61
53
|
# # Create basic local volume
|
62
|
-
# CreateVolume.call(
|
54
|
+
# response = CreateVolume.call(
|
63
55
|
# server_context: context,
|
64
56
|
# name: "app-data"
|
65
57
|
# )
|
66
58
|
#
|
67
59
|
# # Create volume with specific driver
|
68
|
-
# CreateVolume.call(
|
60
|
+
# response = CreateVolume.call(
|
69
61
|
# server_context: context,
|
70
62
|
# name: "shared-storage",
|
71
63
|
# driver: "nfs"
|
72
64
|
# )
|
73
65
|
#
|
74
|
-
#
|
75
|
-
#
|
66
|
+
# # Create database volume
|
67
|
+
# response = CreateVolume.call(
|
68
|
+
# server_context: context,
|
69
|
+
# name: "postgres-data",
|
70
|
+
# driver: "local"
|
71
|
+
# )
|
72
|
+
#
|
76
73
|
# @see Docker::Volume.create
|
77
74
|
# @since 0.1.0
|
78
|
-
|
75
|
+
CREATE_VOLUME_DEFINITION = ToolForge.define(:create_volume) do
|
79
76
|
description 'Create a Docker volume'
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
name: {
|
84
|
-
type: 'string',
|
78
|
+
param :name,
|
79
|
+
type: :string,
|
85
80
|
description: 'Name of the volume'
|
86
|
-
},
|
87
|
-
driver: {
|
88
|
-
type: 'string',
|
89
|
-
description: 'Driver to use (default: local)'
|
90
|
-
}
|
91
|
-
},
|
92
|
-
required: ['name']
|
93
|
-
)
|
94
81
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
# @param server_context [Object] MCP server context (unused but required)
|
103
|
-
# @param driver [String] volume driver to use (default: "local")
|
104
|
-
#
|
105
|
-
# @return [MCP::Tool::Response] volume creation results
|
106
|
-
#
|
107
|
-
# @raise [Docker::Error::ConflictError] if volume name already exists
|
108
|
-
# @raise [StandardError] for other volume creation failures
|
109
|
-
#
|
110
|
-
# @example Create application data volume
|
111
|
-
# response = CreateVolume.call(
|
112
|
-
# server_context: context,
|
113
|
-
# name: "webapp-data"
|
114
|
-
# )
|
115
|
-
#
|
116
|
-
# @example Create NFS volume
|
117
|
-
# response = CreateVolume.call(
|
118
|
-
# server_context: context,
|
119
|
-
# name: "shared-files",
|
120
|
-
# driver: "nfs"
|
121
|
-
# )
|
122
|
-
#
|
123
|
-
# @see Docker::Volume.create
|
124
|
-
def self.call(name:, server_context:, driver: 'local')
|
82
|
+
param :driver,
|
83
|
+
type: :string,
|
84
|
+
description: 'Driver to use (default: local)',
|
85
|
+
required: false,
|
86
|
+
default: 'local'
|
87
|
+
|
88
|
+
execute do |name:, driver: 'local'|
|
125
89
|
options = {
|
126
90
|
'Name' => name,
|
127
91
|
'Driver' => driver
|
@@ -129,20 +93,13 @@ module DockerMCP
|
|
129
93
|
|
130
94
|
Docker::Volume.create(name, options)
|
131
95
|
|
132
|
-
|
133
|
-
type: 'text',
|
134
|
-
text: "Volume #{name} created successfully"
|
135
|
-
}])
|
96
|
+
"Volume #{name} created successfully"
|
136
97
|
rescue Docker::Error::ConflictError
|
137
|
-
|
138
|
-
type: 'text',
|
139
|
-
text: "Volume #{name} already exists"
|
140
|
-
}])
|
98
|
+
"Volume #{name} already exists"
|
141
99
|
rescue StandardError => e
|
142
|
-
|
143
|
-
type: 'text',
|
144
|
-
text: "Error creating volume: #{e.message}"
|
145
|
-
}])
|
100
|
+
"Error creating volume: #{e.message}"
|
146
101
|
end
|
147
102
|
end
|
103
|
+
|
104
|
+
CreateVolume = CREATE_VOLUME_DEFINITION.to_mcp_tool
|
148
105
|
end
|