docker-tiny-mcp 0.2.0__tar.gz → 0.2.1__tar.gz

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.
Files changed (48) hide show
  1. docker_tiny_mcp-0.2.0/README.md → docker_tiny_mcp-0.2.1/PKG-INFO +37 -8
  2. docker_tiny_mcp-0.2.0/PKG-INFO → docker_tiny_mcp-0.2.1/README.md +23 -22
  3. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/__main__.py +7 -0
  4. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/models.py +29 -15
  5. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/prompts.py +2 -2
  6. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/__init__.py +4 -0
  7. docker_tiny_mcp-0.2.1/docker_tiny_mcp/resources/templates/file.py +77 -0
  8. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/server.py +19 -9
  9. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/__init__.py +0 -3
  10. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/container.py +4 -1
  11. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/containers.py +1 -1
  12. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/create.py +39 -8
  13. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/exec.py +1 -1
  14. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/pyproject.toml +2 -2
  15. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/pyproject.toml.orig +2 -2
  16. docker_tiny_mcp-0.2.0/docker_tiny_mcp/tools/read.py +0 -69
  17. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/LICENSE +0 -0
  18. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/__init__.py +0 -0
  19. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/consent.py +0 -0
  20. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/daemon.py +0 -0
  21. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/errors.py +0 -0
  22. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/events.py +0 -0
  23. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/__init__.py +0 -0
  24. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/containers.py +0 -0
  25. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/images.py +0 -0
  26. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/info.py +0 -0
  27. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/container.py +0 -0
  28. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/logs.py +0 -0
  29. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/safety.py +0 -0
  30. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/commit.py +0 -0
  31. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/create_volume.py +0 -0
  32. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/events.py +0 -0
  33. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/images.py +0 -0
  34. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/info.py +0 -0
  35. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/logs.py +0 -0
  36. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/networks.py +0 -0
  37. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/prune.py +0 -0
  38. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/pull.py +0 -0
  39. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/remove.py +0 -0
  40. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/remove_image.py +0 -0
  41. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/restart.py +0 -0
  42. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/results.py +0 -0
  43. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/start.py +0 -0
  44. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/stats.py +0 -0
  45. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/stop.py +0 -0
  46. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/volumes.py +0 -0
  47. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/wait.py +0 -0
  48. {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/write.py +0 -0
@@ -1,3 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: docker-tiny-mcp
3
+ Version: 0.2.1
4
+ Summary: An MCP server for Docker, over aiohttp-tiny-mcp.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Dist: aiodocker>=0.24
8
+ Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.9.1
9
+ Requires-Dist: argclass>=1.0
10
+ Requires-Python: >=3.10
11
+ Project-URL: Repository, https://github.com/mosquito/docker-tiny-mcp
12
+ Project-URL: Issues, https://github.com/mosquito/docker-tiny-mcp/issues
13
+ Description-Content-Type: text/markdown
14
+
1
15
  # docker-tiny-mcp
2
16
 
3
17
  An MCP server for Docker, built on
@@ -79,8 +93,8 @@ For example, call `create` with:
79
93
  {"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
80
94
  ```
81
95
 
82
- Before `read`, `write`, `exec`, `start` or `restart`, the server inspects the
83
- target container. It rejects host mounts, extra capabilities or devices,
96
+ Before reading a file resource or calling `write`, `exec`, `start` or `restart`,
97
+ the server inspects the target container. It rejects host mounts, extra capabilities or devices,
84
98
  shared host namespaces, custom runtimes and relaxed security settings.
85
99
  New containers use `no-new-privileges` and the default bridge network unless
86
100
  the operator selects another local bridge network or `none`.
@@ -205,14 +219,11 @@ start a new one.
205
219
  | Tool | Does |
206
220
  | --- | --- |
207
221
  | `containers` | List containers, filtered by name and by whether they run |
208
- | `container` | One container in full: health, exit code, restarts, mounts, Compose service |
209
222
  | `logs` | What it wrote, dated, with a cursor for reading only what is new |
210
- | `read` | One file out of it -- running or not, and with no shell in the image |
211
223
  | `images` | Images with sizes, and what still holds each one |
212
224
  | `networks`, `volumes` | What is attached, and what mounts what |
213
225
  | `events` | What the daemon did lately: started, died, removed |
214
226
  | `stats` | Processor, memory, network and disk, as rates |
215
- | `info` | Which daemon this is, its version, and how much it holds |
216
227
  | `create` | Make one and start it -- `docker run`, with the flags named |
217
228
  | `create_volume` | Create a local named volume with a description shown by `volumes` |
218
229
  | `commit` | Save a stopped container as a `localhost/` image with a description |
@@ -223,6 +234,24 @@ start a new one.
223
234
  | `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
224
235
  | `pull` | Download an image, reporting progress |
225
236
 
237
+ Read complete files through `docker://containers/{name}/files{+path}`, including
238
+ from stopped containers. Append the absolute path with its slashes. For example,
239
+ use `docker://containers/cache/files/tmp/screenshot.png` for `/tmp/screenshot.png`.
240
+ Percent-encode literal URI delimiters such as `#` and `?` in filenames. The
241
+ resource uses the file signature for PNG, JPEG, GIF, WebP, PDF, ZIP and gzip.
242
+ Other binary files use `application/octet-stream`.
243
+
244
+ By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
245
+ This helps when `sleep infinity` keeps the container running and `exec` starts
246
+ background services. Set `init=false` if the container command must run as
247
+ PID 1. The `docker://containers/{name}` resource reports the configured value.
248
+
249
+ Set `shm_size` on `create` to size `/dev/shm` in MiB. Docker normally uses
250
+ 64 MiB when the field is omitted. The server limits explicit sizes to 1024 MiB
251
+ by default. Set `--max-shm-size`, `DOCKER_TINY_MCP_MAX_SHM_SIZE`, or
252
+ `max_shm_size` in the config file to change that limit. The container details
253
+ resource reports the size in MiB.
254
+
226
255
  To reuse a prepared container, write `/AGENTS.md` at its root, stop the
227
256
  container and call `commit` with an image name such as `dev-env:v1` and a
228
257
  description. The image appears in `images` as `localhost/dev-env:v1`. Set
@@ -239,8 +268,8 @@ Resources: `docker://info`, `docker://containers`,
239
268
  `docker://images`.
240
269
 
241
270
  On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
242
- seconds and `docker://containers/{name}` for 5 seconds. To get current state
243
- immediately, call the `container` tool. Log reads have a cache lifetime of zero.
271
+ seconds and `docker://containers/{name}` for 5 seconds. File and log reads
272
+ have a cache lifetime of zero.
244
273
 
245
274
  Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
246
275
  space. Container and image names are suggested while either is filled in.
@@ -307,7 +336,7 @@ try:
307
336
  Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
308
337
  client,
309
338
  )
310
- assert {"containers", "logs", "read", "exec", "write", "create"} <= set(registry.tools)
339
+ assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
311
340
  finally:
312
341
  await client.close()
313
342
  ```
@@ -1,17 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: docker-tiny-mcp
3
- Version: 0.2.0
4
- Summary: An MCP server for Docker, over aiohttp-tiny-mcp.
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
- Requires-Dist: aiodocker>=0.24
8
- Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0
9
- Requires-Dist: argclass>=1.0
10
- Requires-Python: >=3.10
11
- Project-URL: Repository, https://github.com/mosquito/docker-tiny-mcp
12
- Project-URL: Issues, https://github.com/mosquito/docker-tiny-mcp/issues
13
- Description-Content-Type: text/markdown
14
-
15
1
  # docker-tiny-mcp
16
2
 
17
3
  An MCP server for Docker, built on
@@ -93,8 +79,8 @@ For example, call `create` with:
93
79
  {"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
94
80
  ```
95
81
 
96
- Before `read`, `write`, `exec`, `start` or `restart`, the server inspects the
97
- target container. It rejects host mounts, extra capabilities or devices,
82
+ Before reading a file resource or calling `write`, `exec`, `start` or `restart`,
83
+ the server inspects the target container. It rejects host mounts, extra capabilities or devices,
98
84
  shared host namespaces, custom runtimes and relaxed security settings.
99
85
  New containers use `no-new-privileges` and the default bridge network unless
100
86
  the operator selects another local bridge network or `none`.
@@ -219,14 +205,11 @@ start a new one.
219
205
  | Tool | Does |
220
206
  | --- | --- |
221
207
  | `containers` | List containers, filtered by name and by whether they run |
222
- | `container` | One container in full: health, exit code, restarts, mounts, Compose service |
223
208
  | `logs` | What it wrote, dated, with a cursor for reading only what is new |
224
- | `read` | One file out of it -- running or not, and with no shell in the image |
225
209
  | `images` | Images with sizes, and what still holds each one |
226
210
  | `networks`, `volumes` | What is attached, and what mounts what |
227
211
  | `events` | What the daemon did lately: started, died, removed |
228
212
  | `stats` | Processor, memory, network and disk, as rates |
229
- | `info` | Which daemon this is, its version, and how much it holds |
230
213
  | `create` | Make one and start it -- `docker run`, with the flags named |
231
214
  | `create_volume` | Create a local named volume with a description shown by `volumes` |
232
215
  | `commit` | Save a stopped container as a `localhost/` image with a description |
@@ -237,6 +220,24 @@ start a new one.
237
220
  | `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
238
221
  | `pull` | Download an image, reporting progress |
239
222
 
223
+ Read complete files through `docker://containers/{name}/files{+path}`, including
224
+ from stopped containers. Append the absolute path with its slashes. For example,
225
+ use `docker://containers/cache/files/tmp/screenshot.png` for `/tmp/screenshot.png`.
226
+ Percent-encode literal URI delimiters such as `#` and `?` in filenames. The
227
+ resource uses the file signature for PNG, JPEG, GIF, WebP, PDF, ZIP and gzip.
228
+ Other binary files use `application/octet-stream`.
229
+
230
+ By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
231
+ This helps when `sleep infinity` keeps the container running and `exec` starts
232
+ background services. Set `init=false` if the container command must run as
233
+ PID 1. The `docker://containers/{name}` resource reports the configured value.
234
+
235
+ Set `shm_size` on `create` to size `/dev/shm` in MiB. Docker normally uses
236
+ 64 MiB when the field is omitted. The server limits explicit sizes to 1024 MiB
237
+ by default. Set `--max-shm-size`, `DOCKER_TINY_MCP_MAX_SHM_SIZE`, or
238
+ `max_shm_size` in the config file to change that limit. The container details
239
+ resource reports the size in MiB.
240
+
240
241
  To reuse a prepared container, write `/AGENTS.md` at its root, stop the
241
242
  container and call `commit` with an image name such as `dev-env:v1` and a
242
243
  description. The image appears in `images` as `localhost/dev-env:v1`. Set
@@ -253,8 +254,8 @@ Resources: `docker://info`, `docker://containers`,
253
254
  `docker://images`.
254
255
 
255
256
  On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
256
- seconds and `docker://containers/{name}` for 5 seconds. To get current state
257
- immediately, call the `container` tool. Log reads have a cache lifetime of zero.
257
+ seconds and `docker://containers/{name}` for 5 seconds. File and log reads
258
+ have a cache lifetime of zero.
258
259
 
259
260
  Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
260
261
  space. Container and image names are suggested while either is filled in.
@@ -321,7 +322,7 @@ try:
321
322
  Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
322
323
  client,
323
324
  )
324
- assert {"containers", "logs", "read", "exec", "write", "create"} <= set(registry.tools)
325
+ assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
325
326
  finally:
326
327
  await client.close()
327
328
  ```
@@ -22,6 +22,7 @@ from aiohttp_tiny_mcp.storage.sqlite import SqliteHub, SqliteSessionStore, Sqlit
22
22
 
23
23
  from .consent import LEVELS, Policy
24
24
  from .events import watch
25
+ from .models import DEFAULT_CREATE_LIMITS, CreateLimits
25
26
  from .server import build
26
27
 
27
28
  log = logging.getLogger("docker_tiny_mcp")
@@ -78,6 +79,10 @@ class Parser(argclass.Parser):
78
79
  default="",
79
80
  help="Fix the container network and disable network management tools.",
80
81
  )
82
+ max_shm_size: int = argclass.Argument(
83
+ default=DEFAULT_CREATE_LIMITS.max_shm_size,
84
+ help="Maximum explicit /dev/shm size in MiB for the create tool.",
85
+ )
81
86
  stdio: bool = argclass.Argument(
82
87
  default=False,
83
88
  help="Talk over standard input and output instead of listening on a port.",
@@ -160,6 +165,7 @@ def authentication(parser: Parser) -> Authorization | None:
160
165
 
161
166
  def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
162
167
  """Build the server from settings, independently of command-line parsing."""
168
+ create_limits = CreateLimits(max_shm_size=parser.max_shm_size)
163
169
  storage = SqliteStorage(parser.state)
164
170
  client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
165
171
  catalogue = CacheHint(cache_ttl=60, scope="private")
@@ -186,6 +192,7 @@ def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
186
192
  Policy(parser.confirm),
187
193
  unprivileged=parser.unprivileged,
188
194
  network=parser.network,
195
+ create_limits=create_limits,
189
196
  ),
190
197
  storage,
191
198
  client,
@@ -7,6 +7,7 @@ from typing import Annotated, Any, Literal
7
7
  from pydantic import BaseModel, ConfigDict, Field, StringConstraints
8
8
 
9
9
  Stream = Literal["stdout", "stderr"]
10
+ MIB = 1024**2
10
11
 
11
12
 
12
13
  class Nothing(BaseModel):
@@ -37,6 +38,11 @@ class ContainerName(BaseModel):
37
38
  name: str
38
39
 
39
40
 
41
+ class ContainerFile(ContainerName):
42
+ name: str = Field(pattern=r"^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
43
+ path: str = Field(description="Absolute path inside the container.")
44
+
45
+
40
46
  class StopRequest(ContainerRef):
41
47
  seconds: int = Field(10, ge=0, le=600, description="How long to wait before killing it.")
42
48
 
@@ -75,27 +81,12 @@ class ExecRequest(ContainerRef):
75
81
  user: str | None = Field(None, description='Who to run it as, such as "postgres".')
76
82
 
77
83
 
78
- class ReadRequest(ContainerRef):
79
- path: str = Field(description="Absolute path of the file inside the container.")
80
-
81
-
82
84
  class WriteRequest(ContainerRef):
83
85
  path: str = Field(description="Absolute path to write, inside the container.")
84
86
  content: str = Field(description="What the file is to hold. It replaces what is there.")
85
87
  mode: str = Field("644", description="Permission bits, as three or four octal digits.")
86
88
 
87
89
 
88
- class FileContent(BaseModel):
89
- """File bytes read through the archive API, including from stopped containers."""
90
-
91
- container: str
92
- path: str
93
- size_bytes: int
94
- text: str
95
- truncated: bool = Field(False, description="True where the file was too large to return.")
96
- binary: bool = Field(False, description="True where this is not text. `text` is then empty.")
97
-
98
-
99
90
  class Written(BaseModel):
100
91
  container: str
101
92
  path: str
@@ -103,6 +94,13 @@ class Written(BaseModel):
103
94
  note: str | None = None
104
95
 
105
96
 
97
+ class CreateLimits(BaseModel, frozen=True):
98
+ max_shm_size: int = Field(1024, ge=1, le=(2**63 - 1) // MIB, strict=True)
99
+
100
+
101
+ DEFAULT_CREATE_LIMITS = CreateLimits()
102
+
103
+
106
104
  class CreateOptions(BaseModel):
107
105
  """Container creation options; only image is required."""
108
106
 
@@ -126,6 +124,20 @@ class CreateOptions(BaseModel):
126
124
  restart: Literal["no", "on-failure", "always", "unless-stopped"] = Field(
127
125
  "no", description="Whether the daemon starts it again after it stops."
128
126
  )
127
+ init: bool = Field(
128
+ True,
129
+ description=(
130
+ "Run Docker's init as PID 1 to reap orphaned processes. Enable this when a "
131
+ "command such as sleep infinity will run daemons through exec. Set false "
132
+ "if the command must run as PID 1."
133
+ ),
134
+ )
135
+ shm_size: int | None = Field(
136
+ None,
137
+ gt=0,
138
+ strict=True,
139
+ description="Size of /dev/shm in MiB. Omit to use the Docker default.",
140
+ )
129
141
  workdir: str | None = Field(None, description="Directory its command starts in.")
130
142
  user: str | None = Field(None, description="Who its command runs as.")
131
143
  pull: Literal["missing", "always", "never"] = Field(
@@ -275,6 +287,8 @@ class ContainerDetail(BaseModel):
275
287
  command: str = Field(description="What it runs, quoted as a shell would.")
276
288
  restart_count: int
277
289
  restart_policy: str = Field("no", description="What the daemon does after it stops.")
290
+ init: bool | None = Field(None, description="Use Docker init. Null means the daemon default.")
291
+ shm_size: float | None = Field(None, description="Size of /dev/shm in MiB.")
278
292
  health: str | None = Field(None, description="healthy, unhealthy, starting, or absent.")
279
293
  exit_code: int | None = Field(None, description="Set once it has stopped.")
280
294
  error: str | None = None
@@ -14,11 +14,11 @@ async def diagnose(args: ContainerRef) -> str:
14
14
  """Work out why a container is unhealthy or keeps restarting."""
15
15
  return (
16
16
  f"Container {args.container} is not behaving. Work out why.\n\n"
17
- "Start with `container` for its state, exit code, health and restart "
17
+ "Read `docker://containers/{name}` for its state, exit code, health and restart "
18
18
  "count. Read `logs` for what it wrote before it stopped, and `events` "
19
19
  "for whether this has happened before and how often. Where it is a "
20
20
  "resource problem, `stats` says so; where it is a configuration "
21
- "problem, `read` shows the file the program actually has. Check "
21
+ "problem, read the file resource `docker://containers/{name}/files{+path}`. Check "
22
22
  "whether the exit code and the last lines agree about the cause.\n\n"
23
23
  "Report the cause, the evidence for it, and the smallest change that "
24
24
  "would fix it. Say so plainly if the evidence does not settle it."
@@ -3,9 +3,13 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from .container import container
6
+ from .file import FILE_URI, file, file_unprivileged
6
7
  from .logs import logs
7
8
 
8
9
  __all__ = [
10
+ "FILE_URI",
9
11
  "container",
12
+ "file",
13
+ "file_unprivileged",
10
14
  "logs",
11
15
  ]
@@ -0,0 +1,77 @@
1
+ """Read a file from a container through Docker's archive endpoint."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from base64 import b64encode
6
+ from urllib.parse import quote
7
+
8
+ from aiodocker import Docker
9
+ from aiodocker.containers import DockerContainer
10
+ from aiohttp_tiny_mcp import BlobResourceContents
11
+
12
+ from docker_tiny_mcp import daemon
13
+ from docker_tiny_mcp.errors import Conflict, clear
14
+ from docker_tiny_mcp.models import ContainerFile
15
+ from docker_tiny_mcp.safety import checked_container
16
+
17
+ FILE_URI = "docker://containers/{name}/files{+path}"
18
+
19
+ FILE_SIGNATURES = (
20
+ (b"\x89PNG\r\n\x1a\n", "image/png"),
21
+ (b"\xff\xd8\xff", "image/jpeg"),
22
+ (b"GIF87a", "image/gif"),
23
+ (b"GIF89a", "image/gif"),
24
+ (b"%PDF-", "application/pdf"),
25
+ (b"PK\x03\x04", "application/zip"),
26
+ (b"PK\x05\x06", "application/zip"),
27
+ (b"\x1f\x8b", "application/gzip"),
28
+ )
29
+
30
+
31
+ async def file_contents(
32
+ args: ContainerFile, container: DockerContainer
33
+ ) -> str | bytes | BlobResourceContents:
34
+ path = args.path
35
+ if not path.startswith("/") or "\0" in path:
36
+ raise Conflict("Use an absolute file path inside the container.")
37
+
38
+ async with clear("reading the file", subject=path):
39
+ archive = await container.get_archive(path)
40
+ with archive:
41
+ members = archive.getmembers()
42
+ if len(members) != 1 or not members[0].isfile():
43
+ raise Conflict(f"{path} is a directory. Name a file inside it.")
44
+ handle = archive.extractfile(members[0])
45
+ assert handle is not None
46
+ with handle:
47
+ content = handle.read()
48
+
49
+ mime_type = next((mime for prefix, mime in FILE_SIGNATURES if content.startswith(prefix)), None)
50
+ if content.startswith(b"RIFF") and content[8:12] == b"WEBP":
51
+ mime_type = "image/webp"
52
+ if mime_type is not None:
53
+ return BlobResourceContents(
54
+ uri=f"docker://containers/{args.name}/files{quote(path)}",
55
+ blob=b64encode(content).decode("ascii"),
56
+ mime_type=mime_type,
57
+ )
58
+ if b"\0" not in content:
59
+ try:
60
+ return content.decode("utf-8")
61
+ except UnicodeDecodeError:
62
+ pass
63
+ return content
64
+
65
+
66
+ async def file(args: ContainerFile, client: Docker) -> str | bytes | BlobResourceContents:
67
+ """Read a file by container name or ID."""
68
+ found = await daemon.find(client, args.name)
69
+ return await file_contents(args, found)
70
+
71
+
72
+ async def file_unprivileged(
73
+ args: ContainerFile, client: Docker
74
+ ) -> str | bytes | BlobResourceContents:
75
+ """Read a file after checking container isolation."""
76
+ identity = await checked_container(client, args.name)
77
+ return await file_contents(args, client.containers.container(identity))
@@ -7,15 +7,17 @@ from aiohttp_tiny_mcp import Hint, Icons, Registry
7
7
 
8
8
  from . import prompts, resources, tools
9
9
  from .consent import Policy
10
+ from .models import DEFAULT_CREATE_LIMITS, CreateLimits
10
11
  from .resources import templates
11
12
  from .tools.create import fixed_network_create, unprivileged_create
12
13
  from .tools.prune import prune_fixed_network
13
14
 
14
15
  INSTRUCTIONS = (
15
- "Inspect and control Docker. Start with `containers` to find what to act "
16
- "on; `container`, `logs`, `read` and `stats` to understand one; `events` "
17
- "for what happened before now; and `info` to confirm the daemon is "
18
- "reachable and is the one you meant.\n\n"
16
+ "Inspect and control Docker. Start with `containers` to find a target. "
17
+ "Read `docker://containers/{name}` for details, and use `logs`, `stats` "
18
+ "and `events` to investigate. Read `docker://info` to identify the daemon.\n\n"
19
+ "Append an absolute path to `docker://containers/{name}/files` to read a file, "
20
+ "for example `docker://containers/cache/files/tmp/note.txt`.\n\n"
19
21
  "To change something: `create` makes and starts a container, `start`, "
20
22
  "`stop` and `restart` do the obvious, `wait` holds until a container is "
21
23
  "running or healthy, `exec` runs a command inside one, and `write` puts a "
@@ -47,11 +49,13 @@ def build(
47
49
  *,
48
50
  unprivileged: bool = False,
49
51
  network: str | None = None,
52
+ create_limits: CreateLimits = DEFAULT_CREATE_LIMITS,
50
53
  ) -> Registry:
51
- """Register handlers and inject the Docker client and deployment confirmation policy."""
54
+ """Register handlers and provide the Docker client and deployment settings."""
52
55
  registry.instructions = INSTRUCTIONS
53
56
  registry.provide_instance(client)
54
57
  registry.provide_instance(policy or Policy())
58
+ registry.provide_instance(create_limits)
55
59
  if unprivileged:
56
60
  registry.instructions += (
57
61
  "\n\nUnprivileged mode: host mounts and privileged containers are forbidden. "
@@ -63,12 +67,10 @@ def build(
63
67
  )
64
68
 
65
69
  registry.tool(tools.containers, annotations=READS, icons=[Icons.BOX])
66
- registry.tool(tools.container, annotations=READS, icons=[Icons.BOX])
67
70
  registry.tool(tools.images, annotations=READS, icons=[Icons.LAYER_GROUP])
68
71
  if not network:
69
72
  registry.tool(tools.networks, annotations=READS, icons=[Icons.NETWORK_WIRED])
70
73
  registry.tool(tools.volumes, annotations=READS, icons=[Icons.HARD_DRIVE])
71
- registry.tool(tools.info, annotations=READS, icons=[Icons.CIRCLE_INFO])
72
74
  registry.tool(tools.logs, annotations=WATCHES, icons=[Icons.FILE_LINES])
73
75
  registry.tool(tools.stats, annotations=WATCHES, icons=[Icons.CHART_LINE])
74
76
  registry.tool(tools.events, annotations=WATCHES, icons=[Icons.CLOCK_ROTATE_LEFT])
@@ -81,7 +83,6 @@ def build(
81
83
  annotations=Hint.OPEN_WORLD,
82
84
  icons=[Icons.PLUS],
83
85
  )
84
- registry.tool(tools.read_unprivileged, name="read", annotations=READS, icons=[Icons.FILE])
85
86
  registry.tool(
86
87
  tools.start_unprivileged, name="start", annotations=Hint.IDEMPOTENT, icons=[Icons.PLAY]
87
88
  )
@@ -105,7 +106,6 @@ def build(
105
106
  )
106
107
  else:
107
108
  registry.tool(tools.create, annotations=Hint.OPEN_WORLD, icons=[Icons.PLUS])
108
- registry.tool(tools.read, annotations=READS, icons=[Icons.FILE])
109
109
  registry.tool(tools.start, annotations=Hint.IDEMPOTENT, icons=[Icons.PLAY])
110
110
  registry.tool(tools.restart, icons=[Icons.ARROWS_ROTATE])
111
111
  registry.tool(tools.write, annotations=Hint.DESTRUCTIVE, icons=[Icons.PEN])
@@ -147,6 +147,16 @@ def build(
147
147
  name="container-logs",
148
148
  icons=[Icons.FILE_LINES],
149
149
  )
150
+ registry.resource(
151
+ templates.FILE_URI,
152
+ templates.file_unprivileged if unprivileged else templates.file,
153
+ name="container-file",
154
+ description=(
155
+ "Read a complete file, including from a stopped container. "
156
+ "Append the absolute path as it appears inside the container."
157
+ ),
158
+ icons=[Icons.FILE],
159
+ )
150
160
  registry.resource(
151
161
  "docker://images", resources.images, mime_type="application/json", icons=[Icons.LAYER_GROUP]
152
162
  )
@@ -15,7 +15,6 @@ from .logs import logs
15
15
  from .networks import networks
16
16
  from .prune import prune
17
17
  from .pull import pull
18
- from .read import read, read_unprivileged
19
18
  from .remove import remove
20
19
  from .remove_image import remove_image
21
20
  from .restart import restart, restart_unprivileged
@@ -43,8 +42,6 @@ __all__ = [
43
42
  "outcome",
44
43
  "prune",
45
44
  "pull",
46
- "read",
47
- "read_unprivileged",
48
45
  "remove",
49
46
  "remove_image",
50
47
  "restart",
@@ -14,7 +14,7 @@ from aiodocker import Docker
14
14
 
15
15
  from docker_tiny_mcp import daemon
16
16
  from docker_tiny_mcp.errors import clear
17
- from docker_tiny_mcp.models import ContainerDetail, ContainerRef, short
17
+ from docker_tiny_mcp.models import MIB, ContainerDetail, ContainerRef, short
18
18
 
19
19
  PROJECT_LABEL = "com.docker.compose.project"
20
20
  SERVICE_LABEL = "com.docker.compose.service"
@@ -65,6 +65,7 @@ def detail(raw: dict[str, Any]) -> ContainerDetail:
65
65
  networks = (raw.get("NetworkSettings") or {}).get("Networks") or {}
66
66
  health = (state.get("Health") or {}).get("Status")
67
67
  exit_code = state.get("ExitCode")
68
+ shm_bytes = host.get("ShmSize")
68
69
  return ContainerDetail(
69
70
  id=short(str(raw.get("Id", ""))),
70
71
  name=str(raw.get("Name", "")).lstrip("/"),
@@ -77,6 +78,8 @@ def detail(raw: dict[str, Any]) -> ContainerDetail:
77
78
  command=command_of(config, raw),
78
79
  restart_count=int(raw.get("RestartCount", 0) or 0),
79
80
  restart_policy=str((host.get("RestartPolicy") or {}).get("Name") or "no"),
81
+ init=host.get("Init"),
82
+ shm_size=shm_bytes / MIB if shm_bytes is not None else None,
80
83
  health=str(health) if health else None,
81
84
  exit_code=int(exit_code)
82
85
  if exit_code is not None and state.get("Status") != "running"
@@ -30,7 +30,7 @@ async def containers(args: ContainerFilter, client: Docker) -> Containers:
30
30
  """List containers. Use this first to find what to act on.
31
31
 
32
32
  Reports name, image, state and published ports. Running only unless `all`
33
- is true. Ask for `container` when one of these needs explaining.
33
+ is true. Read `docker://containers/{name}` for details about one container.
34
34
  """
35
35
  found = await daemon.containers(client, all=args.all)
36
36
  if args.name:
@@ -22,7 +22,10 @@ from docker_tiny_mcp.consent import Policy, confirm, refusal
22
22
  from docker_tiny_mcp.errors import Conflict, clear
23
23
  from docker_tiny_mcp.events import publish
24
24
  from docker_tiny_mcp.models import (
25
+ DEFAULT_CREATE_LIMITS,
26
+ MIB,
25
27
  Created,
28
+ CreateLimits,
26
29
  CreateRequest,
27
30
  FixedNetworkCreateRequest,
28
31
  PullRequest,
@@ -66,6 +69,8 @@ def configuration(
66
69
  restart: str,
67
70
  workdir: str | None,
68
71
  user: str | None,
72
+ init: bool = True,
73
+ shm_size: int | None = None,
69
74
  ) -> dict[str, Any]:
70
75
  """What `containers/create` takes, built from named arguments.
71
76
 
@@ -79,7 +84,9 @@ def configuration(
79
84
  key, _, binding = port_binding(spec)
80
85
  exposed[key] = {}
81
86
  bindings.setdefault(key, []).append(binding)
82
- host: dict[str, Any] = {"RestartPolicy": {"Name": restart}}
87
+ host: dict[str, Any] = {"RestartPolicy": {"Name": restart}, "Init": init}
88
+ if shm_size is not None:
89
+ host["ShmSize"] = shm_size * MIB
83
90
  if bindings:
84
91
  host["PortBindings"] = bindings
85
92
  if volumes:
@@ -110,7 +117,13 @@ def creation(args: CreateRequest) -> str:
110
117
  return said + "?"
111
118
 
112
119
 
113
- async def create(args: CreateRequest, client: Docker, ex: Exchange, policy: Policy) -> Created:
120
+ async def create(
121
+ args: CreateRequest,
122
+ client: Docker,
123
+ ex: Exchange,
124
+ policy: Policy,
125
+ limits: CreateLimits = DEFAULT_CREATE_LIMITS,
126
+ ) -> Created:
114
127
  """Create a container, and start it unless told not to.
115
128
 
116
129
  This is `docker run`, with the flags named rather than written into one
@@ -120,13 +133,21 @@ async def create(args: CreateRequest, client: Docker, ex: Exchange, policy: Poli
120
133
  Asks first only where the policy says to: creating something is undone
121
134
  by removing it, so the default does not interrupt for this.
122
135
  """
123
- return await create_container(args, client, ex, policy)
136
+ return await create_container(args, client, ex, policy, limits)
124
137
 
125
138
 
126
139
  async def create_container(
127
- args: CreateRequest, client: Docker, ex: Exchange, policy: Policy, *, unprivileged: bool = False
140
+ args: CreateRequest,
141
+ client: Docker,
142
+ ex: Exchange,
143
+ policy: Policy,
144
+ limits: CreateLimits,
145
+ *,
146
+ unprivileged: bool = False,
128
147
  ) -> Created:
129
148
  """Create a container after checking deployment restrictions."""
149
+ if args.shm_size is not None and args.shm_size > limits.max_shm_size:
150
+ raise Conflict(f"shm_size exceeds the server limit of {limits.max_shm_size} MiB")
130
151
  if not await confirm(ex, policy, "create", args.image, creation(args)):
131
152
  raise Conflict(f"not created: {refusal(ex)}")
132
153
 
@@ -140,6 +161,8 @@ async def create_container(
140
161
  restart=args.restart,
141
162
  workdir=args.workdir,
142
163
  user=args.user,
164
+ init=args.init,
165
+ shm_size=args.shm_size,
143
166
  )
144
167
  if unprivileged:
145
168
  await configure_unprivileged(client, args, config)
@@ -185,11 +208,15 @@ def fixed_network_create(network: str) -> Callable[..., Awaitable[Created]]:
185
208
  """Bind operator settings without exposing them as tool arguments."""
186
209
 
187
210
  async def create_fixed_network(
188
- args: FixedNetworkCreateRequest, client: Docker, ex: Exchange, policy: Policy
211
+ args: FixedNetworkCreateRequest,
212
+ client: Docker,
213
+ ex: Exchange,
214
+ policy: Policy,
215
+ limits: CreateLimits,
189
216
  ) -> Created:
190
217
  """Create a container on the server's fixed network; callers cannot change the network."""
191
218
  request = CreateRequest(**args.model_dump(), network=network)
192
- return await create_container(request, client, ex, policy)
219
+ return await create_container(request, client, ex, policy, limits)
193
220
 
194
221
  return create_fixed_network
195
222
 
@@ -198,7 +225,11 @@ def unprivileged_create(network: str | None) -> Callable[..., Awaitable[Created]
198
225
  """Bind the operator's network for unprivileged container creation."""
199
226
 
200
227
  async def create_unprivileged(
201
- args: UnprivilegedCreateRequest, client: Docker, ex: Exchange, policy: Policy
228
+ args: UnprivilegedCreateRequest,
229
+ client: Docker,
230
+ ex: Exchange,
231
+ policy: Policy,
232
+ limits: CreateLimits,
202
233
  ) -> Created:
203
234
  """Create an isolated container with optional persistent named volumes.
204
235
 
@@ -206,6 +237,6 @@ def unprivileged_create(network: str | None) -> Callable[..., Awaitable[Created]
206
237
  Missing volumes use the local driver without mount options.
207
238
  """
208
239
  request = CreateRequest(**args.model_dump(), network=network)
209
- return await create_container(request, client, ex, policy, unprivileged=True)
240
+ return await create_container(request, client, ex, policy, limits, unprivileged=True)
210
241
 
211
242
  return create_unprivileged
@@ -51,7 +51,7 @@ async def exec(args: ExecRequest, client: Docker, ex: Exchange, policy: Policy)
51
51
  if str(state.get("Status")) != "running":
52
52
  raise Conflict(
53
53
  f"{args.container} is {state.get('Status')}, and a command needs it running. "
54
- "Start it first, or use `read` to see a file without running anything."
54
+ "Start it first, or read the file through its Docker resource."
55
55
  )
56
56
 
57
57
  session = await found.exec(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "docker-tiny-mcp"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "An MCP server for Docker, over aiohttp-tiny-mcp."
5
5
  requires-python = ">=3.10"
6
6
  license = "Apache-2.0"
@@ -8,7 +8,7 @@ license-files = ["LICENSE"]
8
8
  readme = "README.md"
9
9
  dependencies = [
10
10
  "aiodocker>=0.24",
11
- "aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0",
11
+ "aiohttp-tiny-mcp[sqlite,jwt]>=0.9.1",
12
12
  "argclass>=1.0",
13
13
  ]
14
14
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "docker-tiny-mcp"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "An MCP server for Docker, over aiohttp-tiny-mcp."
5
5
  requires-python = ">=3.10"
6
6
  license = "Apache-2.0"
@@ -10,7 +10,7 @@ dependencies = [
10
10
  "aiodocker>=0.24",
11
11
  # The sessions and the events live in one SQLite file, and the JWT policy
12
12
  # needs PyJWT; the extras bring both.
13
- "aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0",
13
+ "aiohttp-tiny-mcp[sqlite,jwt]>=0.9.1",
14
14
  "argclass>=1.0",
15
15
  ]
16
16
 
@@ -1,69 +0,0 @@
1
- """One file out of a container, through the archive endpoint.
2
-
3
- Not `cat`. The archive works on a stopped container, which is when a
4
- configuration file is most worth reading, and it needs no shell inside the
5
- image, which a slim image does not have.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- from aiodocker import Docker
11
- from aiodocker.containers import DockerContainer
12
-
13
- from docker_tiny_mcp import daemon
14
- from docker_tiny_mcp.errors import Conflict, clear
15
- from docker_tiny_mcp.models import FileContent, ReadRequest
16
- from docker_tiny_mcp.safety import checked_container
17
-
18
- MAX_FILE_BYTES = 256_000
19
-
20
-
21
- async def read_file(container: DockerContainer, path: str) -> tuple[bytes, int, bool]:
22
- """Read one file as an archive: bytes, size, and whether it was cut.
23
-
24
- The archive endpoint works on a stopped container and needs no shell in the image.
25
- """
26
- async with clear("reading the file", subject=path):
27
- archive = await container.get_archive(path)
28
- members = archive.getmembers()
29
- if len(members) != 1 or not members[0].isfile():
30
- raise Conflict(f"{path} is a directory, not a file. Name a file inside it.")
31
- handle = archive.extractfile(members[0])
32
- content = handle.read(MAX_FILE_BYTES + 1) if handle is not None else b""
33
- size = int(members[0].size)
34
- return content[:MAX_FILE_BYTES], size, len(content) > MAX_FILE_BYTES
35
-
36
-
37
- async def read(args: ReadRequest, client: Docker) -> FileContent:
38
- """Read one file out of a container.
39
-
40
- Works whether or not the container runs, and needs no shell inside it.
41
- Use it for configuration the environment does not show, and for a log the
42
- program wrote to a file instead of to its output.
43
- """
44
- found = await daemon.find(client, args.container)
45
- content, size, cut = await read_file(found, args.path)
46
- try:
47
- text = content.decode("utf-8")
48
- except UnicodeDecodeError:
49
- return FileContent(
50
- container=args.container,
51
- path=args.path,
52
- size_bytes=size,
53
- text="",
54
- truncated=cut,
55
- binary=True,
56
- )
57
- return FileContent(
58
- container=args.container,
59
- path=args.path,
60
- size_bytes=size,
61
- text=text,
62
- truncated=cut,
63
- )
64
-
65
-
66
- async def read_unprivileged(args: ReadRequest, client: Docker) -> FileContent:
67
- """Read a file after checking that the container has no host access."""
68
- identity = await checked_container(client, args.container)
69
- return await read(args.model_copy(update={"container": identity}), client)
File without changes