docker-tiny-mcp 0.2.0__tar.gz → 0.2.2__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.
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/PKG-INFO +50 -15
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/README.md +48 -13
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/__main__.py +83 -13
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/consent.py +67 -8
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/models.py +34 -13
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/prompts.py +4 -5
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/__init__.py +4 -0
- docker_tiny_mcp-0.2.2/docker_tiny_mcp/resources/templates/file.py +81 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/server.py +105 -30
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/__init__.py +2 -3
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/container.py +4 -1
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/containers.py +1 -1
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/create.py +39 -8
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/exec.py +10 -5
- docker_tiny_mcp-0.2.2/docker_tiny_mcp/tools/read.py +38 -0
- docker_tiny_mcp-0.2.2/docker_tiny_mcp/tools/remove_volume.py +22 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/pyproject.toml +2 -2
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/pyproject.toml.orig +2 -2
- docker_tiny_mcp-0.2.0/docker_tiny_mcp/tools/read.py +0 -69
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/LICENSE +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/__init__.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/daemon.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/errors.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/events.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/__init__.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/containers.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/images.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/info.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/container.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/logs.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/safety.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/commit.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/create_volume.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/events.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/images.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/info.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/logs.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/networks.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/prune.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/pull.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/remove.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/remove_image.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/restart.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/results.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/start.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/stats.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/stop.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/volumes.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/wait.py +0 -0
- {docker_tiny_mcp-0.2.0 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/write.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docker-tiny-mcp
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: An MCP server for Docker, over aiohttp-tiny-mcp.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Requires-Dist: aiodocker>=0.24
|
|
8
|
-
Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.9.
|
|
8
|
+
Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.9.1
|
|
9
9
|
Requires-Dist: argclass>=1.0
|
|
10
10
|
Requires-Python: >=3.10
|
|
11
11
|
Project-URL: Repository, https://github.com/mosquito/docker-tiny-mcp
|
|
@@ -93,8 +93,8 @@ For example, call `create` with:
|
|
|
93
93
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Before `read`, `write`, `exec`, `start` or `restart`,
|
|
97
|
-
target container. It rejects host mounts, extra capabilities or devices,
|
|
96
|
+
Before reading a file resource or calling `read`, `write`, `exec`, `start` or `restart`,
|
|
97
|
+
the server inspects the target container. It rejects host mounts, extra capabilities or devices,
|
|
98
98
|
shared host namespaces, custom runtimes and relaxed security settings.
|
|
99
99
|
New containers use `no-new-privileges` and the default bridge network unless
|
|
100
100
|
the operator selects another local bridge network or `none`.
|
|
@@ -219,24 +219,43 @@ start a new one.
|
|
|
219
219
|
| Tool | Does |
|
|
220
220
|
| --- | --- |
|
|
221
221
|
| `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
222
|
| `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
223
|
| `images` | Images with sizes, and what still holds each one |
|
|
226
224
|
| `networks`, `volumes` | What is attached, and what mounts what |
|
|
227
225
|
| `events` | What the daemon did lately: started, died, removed |
|
|
228
226
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
229
|
-
| `info` | Which daemon this is, its version, and how much it holds |
|
|
230
227
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
231
228
|
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
229
|
+
| `remove_volume` | Remove one volume and its data after confirmation. Docker refuses if a container uses it |
|
|
232
230
|
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
233
231
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
234
232
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
235
233
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
234
|
+
| `read` | Read a complete file from a running or stopped container |
|
|
236
235
|
| `write` | Put a file into it, running or not |
|
|
237
236
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
238
237
|
| `pull` | Download an image, reporting progress |
|
|
239
238
|
|
|
239
|
+
Call `read` with `container` and an absolute `path`. It returns UTF-8 text,
|
|
240
|
+
an image block, or an embedded resource with the binary file. The server
|
|
241
|
+
detects PNG, JPEG, GIF, WebP, PDF, ZIP and gzip by signature. Other binary
|
|
242
|
+
files use `application/octet-stream`.
|
|
243
|
+
|
|
244
|
+
You can also read the complete file through `docker://containers/{name}/files{+path}`.
|
|
245
|
+
For example, use `docker://containers/cache/files/tmp/screenshot.png` for
|
|
246
|
+
`/tmp/screenshot.png`. Percent-encode URI delimiters such as `#` and `?` in filenames.
|
|
247
|
+
|
|
248
|
+
By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
|
|
249
|
+
This helps when `sleep infinity` keeps the container running and `exec` starts
|
|
250
|
+
background services. Set `init=false` if the container command must run as
|
|
251
|
+
PID 1. The `docker://containers/{name}` resource reports the configured value.
|
|
252
|
+
|
|
253
|
+
Set `shm_size` on `create` to size `/dev/shm` in MiB. Docker normally uses
|
|
254
|
+
64 MiB when the field is omitted. The server limits explicit sizes to 1024 MiB
|
|
255
|
+
by default. Set `--max-shm-size`, `DOCKER_TINY_MCP_MAX_SHM_SIZE`, or
|
|
256
|
+
`max_shm_size` in the config file to change that limit. The container details
|
|
257
|
+
resource reports the size in MiB.
|
|
258
|
+
|
|
240
259
|
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
241
260
|
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
242
261
|
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
@@ -253,8 +272,8 @@ Resources: `docker://info`, `docker://containers`,
|
|
|
253
272
|
`docker://images`.
|
|
254
273
|
|
|
255
274
|
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
256
|
-
seconds and `docker://containers/{name}` for 5 seconds.
|
|
257
|
-
|
|
275
|
+
seconds and `docker://containers/{name}` for 5 seconds. File and log reads
|
|
276
|
+
have a cache lifetime of zero.
|
|
258
277
|
|
|
259
278
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
260
279
|
space. Container and image names are suggested while either is filled in.
|
|
@@ -321,7 +340,7 @@ try:
|
|
|
321
340
|
Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
|
|
322
341
|
client,
|
|
323
342
|
)
|
|
324
|
-
assert {"containers", "logs", "
|
|
343
|
+
assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
|
|
325
344
|
finally:
|
|
326
345
|
await client.close()
|
|
327
346
|
```
|
|
@@ -331,18 +350,18 @@ before everything is a server whose questions nobody reads -- and there is
|
|
|
331
350
|
usually a host in front of this one asking its own permission for every call,
|
|
332
351
|
so a second question buys only the habit of clicking through both. Four things
|
|
333
352
|
cut it down, in order: a policy decides which actions are worth a question at
|
|
334
|
-
all, a command that only reads
|
|
353
|
+
all, a command that only reads skips confirmation by default, an answer that said "do not ask
|
|
335
354
|
again" is honoured, and what is left asks once.
|
|
336
355
|
|
|
337
356
|
```bash
|
|
338
357
|
uv run docker-tiny-mcp # asks only before what cannot be undone
|
|
339
|
-
uv run docker-tiny-mcp --confirm never #
|
|
340
|
-
uv run docker-tiny-mcp --confirm changes # asks before
|
|
358
|
+
uv run docker-tiny-mcp --confirm never # disables default confirmations
|
|
359
|
+
uv run docker-tiny-mcp --confirm changes # also asks before create, write and non-overwriting commit
|
|
341
360
|
```
|
|
342
361
|
|
|
343
362
|
Under the default, `create` and `write` do not interrupt: creating is undone
|
|
344
363
|
by removing, and a file written into a container goes away with it. `remove`,
|
|
345
|
-
`remove_image`, `prune` and a command that is not merely reading do:
|
|
364
|
+
`remove_image`, `remove_volume`, `prune` and a command that is not merely reading do:
|
|
346
365
|
|
|
347
366
|
<!-- name: async test_readme_consent -->
|
|
348
367
|
```python
|
|
@@ -357,6 +376,22 @@ assert not Policy("never").asks("remove")
|
|
|
357
376
|
assert Policy("changes").asks("write")
|
|
358
377
|
```
|
|
359
378
|
|
|
379
|
+
Override the policy for any Docker tool in `[confirm]`. Set a tool to
|
|
380
|
+
`ask` to require approval or to `allow` to skip it. An omitted tool uses the
|
|
381
|
+
global mode. An explicit `exec = ask` also asks before read-only commands.
|
|
382
|
+
Confirmation can reuse a saved approval.
|
|
383
|
+
|
|
384
|
+
```ini
|
|
385
|
+
[confirm]
|
|
386
|
+
mode = destructive
|
|
387
|
+
remove_volume = ask
|
|
388
|
+
read = allow
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Use `--confirm-remove-volume ask` or set
|
|
392
|
+
`DOCKER_TINY_MCP_CONFIRM_REMOVE_VOLUME=ask` to set the same flag. Existing
|
|
393
|
+
`[DEFAULT]` keys named `confirm` still set the global mode.
|
|
394
|
+
|
|
360
395
|
What was allowed is kept in the session store the package already has, so a
|
|
361
396
|
second worker honours a permission the first one was given. `2026-07-28` keeps
|
|
362
397
|
no session of its own, so the answer is filed under the caller the revision
|
|
@@ -406,7 +441,7 @@ with the first:
|
|
|
406
441
|
|
|
407
442
|
```python
|
|
408
443
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
409
|
-
return build(registry, client,
|
|
444
|
+
return build(registry, client, parser.confirm.policy()), storage, client
|
|
410
445
|
```
|
|
411
446
|
|
|
412
447
|
**State is SQLite.** `aiohttp_tiny_mcp.storage.sqlite` holds the sessions and the
|
|
@@ -79,8 +79,8 @@ For example, call `create` with:
|
|
|
79
79
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
Before `read`, `write`, `exec`, `start` or `restart`,
|
|
83
|
-
target container. It rejects host mounts, extra capabilities or devices,
|
|
82
|
+
Before reading a file resource or calling `read`, `write`, `exec`, `start` or `restart`,
|
|
83
|
+
the server inspects the target container. It rejects host mounts, extra capabilities or devices,
|
|
84
84
|
shared host namespaces, custom runtimes and relaxed security settings.
|
|
85
85
|
New containers use `no-new-privileges` and the default bridge network unless
|
|
86
86
|
the operator selects another local bridge network or `none`.
|
|
@@ -205,24 +205,43 @@ start a new one.
|
|
|
205
205
|
| Tool | Does |
|
|
206
206
|
| --- | --- |
|
|
207
207
|
| `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
208
|
| `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
209
|
| `images` | Images with sizes, and what still holds each one |
|
|
212
210
|
| `networks`, `volumes` | What is attached, and what mounts what |
|
|
213
211
|
| `events` | What the daemon did lately: started, died, removed |
|
|
214
212
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
215
|
-
| `info` | Which daemon this is, its version, and how much it holds |
|
|
216
213
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
217
214
|
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
215
|
+
| `remove_volume` | Remove one volume and its data after confirmation. Docker refuses if a container uses it |
|
|
218
216
|
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
219
217
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
220
218
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
221
219
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
220
|
+
| `read` | Read a complete file from a running or stopped container |
|
|
222
221
|
| `write` | Put a file into it, running or not |
|
|
223
222
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
224
223
|
| `pull` | Download an image, reporting progress |
|
|
225
224
|
|
|
225
|
+
Call `read` with `container` and an absolute `path`. It returns UTF-8 text,
|
|
226
|
+
an image block, or an embedded resource with the binary file. The server
|
|
227
|
+
detects PNG, JPEG, GIF, WebP, PDF, ZIP and gzip by signature. Other binary
|
|
228
|
+
files use `application/octet-stream`.
|
|
229
|
+
|
|
230
|
+
You can also read the complete file through `docker://containers/{name}/files{+path}`.
|
|
231
|
+
For example, use `docker://containers/cache/files/tmp/screenshot.png` for
|
|
232
|
+
`/tmp/screenshot.png`. Percent-encode URI delimiters such as `#` and `?` in filenames.
|
|
233
|
+
|
|
234
|
+
By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
|
|
235
|
+
This helps when `sleep infinity` keeps the container running and `exec` starts
|
|
236
|
+
background services. Set `init=false` if the container command must run as
|
|
237
|
+
PID 1. The `docker://containers/{name}` resource reports the configured value.
|
|
238
|
+
|
|
239
|
+
Set `shm_size` on `create` to size `/dev/shm` in MiB. Docker normally uses
|
|
240
|
+
64 MiB when the field is omitted. The server limits explicit sizes to 1024 MiB
|
|
241
|
+
by default. Set `--max-shm-size`, `DOCKER_TINY_MCP_MAX_SHM_SIZE`, or
|
|
242
|
+
`max_shm_size` in the config file to change that limit. The container details
|
|
243
|
+
resource reports the size in MiB.
|
|
244
|
+
|
|
226
245
|
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
227
246
|
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
228
247
|
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
@@ -239,8 +258,8 @@ Resources: `docker://info`, `docker://containers`,
|
|
|
239
258
|
`docker://images`.
|
|
240
259
|
|
|
241
260
|
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
242
|
-
seconds and `docker://containers/{name}` for 5 seconds.
|
|
243
|
-
|
|
261
|
+
seconds and `docker://containers/{name}` for 5 seconds. File and log reads
|
|
262
|
+
have a cache lifetime of zero.
|
|
244
263
|
|
|
245
264
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
246
265
|
space. Container and image names are suggested while either is filled in.
|
|
@@ -307,7 +326,7 @@ try:
|
|
|
307
326
|
Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
|
|
308
327
|
client,
|
|
309
328
|
)
|
|
310
|
-
assert {"containers", "logs", "
|
|
329
|
+
assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
|
|
311
330
|
finally:
|
|
312
331
|
await client.close()
|
|
313
332
|
```
|
|
@@ -317,18 +336,18 @@ before everything is a server whose questions nobody reads -- and there is
|
|
|
317
336
|
usually a host in front of this one asking its own permission for every call,
|
|
318
337
|
so a second question buys only the habit of clicking through both. Four things
|
|
319
338
|
cut it down, in order: a policy decides which actions are worth a question at
|
|
320
|
-
all, a command that only reads
|
|
339
|
+
all, a command that only reads skips confirmation by default, an answer that said "do not ask
|
|
321
340
|
again" is honoured, and what is left asks once.
|
|
322
341
|
|
|
323
342
|
```bash
|
|
324
343
|
uv run docker-tiny-mcp # asks only before what cannot be undone
|
|
325
|
-
uv run docker-tiny-mcp --confirm never #
|
|
326
|
-
uv run docker-tiny-mcp --confirm changes # asks before
|
|
344
|
+
uv run docker-tiny-mcp --confirm never # disables default confirmations
|
|
345
|
+
uv run docker-tiny-mcp --confirm changes # also asks before create, write and non-overwriting commit
|
|
327
346
|
```
|
|
328
347
|
|
|
329
348
|
Under the default, `create` and `write` do not interrupt: creating is undone
|
|
330
349
|
by removing, and a file written into a container goes away with it. `remove`,
|
|
331
|
-
`remove_image`, `prune` and a command that is not merely reading do:
|
|
350
|
+
`remove_image`, `remove_volume`, `prune` and a command that is not merely reading do:
|
|
332
351
|
|
|
333
352
|
<!-- name: async test_readme_consent -->
|
|
334
353
|
```python
|
|
@@ -343,6 +362,22 @@ assert not Policy("never").asks("remove")
|
|
|
343
362
|
assert Policy("changes").asks("write")
|
|
344
363
|
```
|
|
345
364
|
|
|
365
|
+
Override the policy for any Docker tool in `[confirm]`. Set a tool to
|
|
366
|
+
`ask` to require approval or to `allow` to skip it. An omitted tool uses the
|
|
367
|
+
global mode. An explicit `exec = ask` also asks before read-only commands.
|
|
368
|
+
Confirmation can reuse a saved approval.
|
|
369
|
+
|
|
370
|
+
```ini
|
|
371
|
+
[confirm]
|
|
372
|
+
mode = destructive
|
|
373
|
+
remove_volume = ask
|
|
374
|
+
read = allow
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Use `--confirm-remove-volume ask` or set
|
|
378
|
+
`DOCKER_TINY_MCP_CONFIRM_REMOVE_VOLUME=ask` to set the same flag. Existing
|
|
379
|
+
`[DEFAULT]` keys named `confirm` still set the global mode.
|
|
380
|
+
|
|
346
381
|
What was allowed is kept in the session store the package already has, so a
|
|
347
382
|
second worker honours a permission the first one was given. `2026-07-28` keeps
|
|
348
383
|
no session of its own, so the answer is filed under the caller the revision
|
|
@@ -392,7 +427,7 @@ with the first:
|
|
|
392
427
|
|
|
393
428
|
```python
|
|
394
429
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
395
|
-
return build(registry, client,
|
|
430
|
+
return build(registry, client, parser.confirm.policy()), storage, client
|
|
396
431
|
```
|
|
397
432
|
|
|
398
433
|
**State is SQLite.** `aiohttp_tiny_mcp.storage.sqlite` holds the sessions and the
|
|
@@ -8,8 +8,11 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
import asyncio
|
|
10
10
|
import logging
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from configparser import ConfigParser
|
|
13
|
+
from importlib.metadata import version
|
|
11
14
|
from pathlib import Path
|
|
12
|
-
from typing import Literal
|
|
15
|
+
from typing import Any, Literal
|
|
13
16
|
|
|
14
17
|
import argclass
|
|
15
18
|
from aiodocker import Docker
|
|
@@ -20,8 +23,9 @@ from aiohttp_tiny_mcp.auth.jwt import HMACJWTVerifier
|
|
|
20
23
|
from aiohttp_tiny_mcp.console import Console
|
|
21
24
|
from aiohttp_tiny_mcp.storage.sqlite import SqliteHub, SqliteSessionStore, SqliteStorage
|
|
22
25
|
|
|
23
|
-
from .consent import LEVELS, Policy
|
|
26
|
+
from .consent import LEVELS, Confirmation, Policy
|
|
24
27
|
from .events import watch
|
|
28
|
+
from .models import DEFAULT_CREATE_LIMITS, CreateLimits
|
|
25
29
|
from .server import build
|
|
26
30
|
|
|
27
31
|
log = logging.getLogger("docker_tiny_mcp")
|
|
@@ -59,9 +63,75 @@ class JWT(argclass.Group):
|
|
|
59
63
|
)
|
|
60
64
|
|
|
61
65
|
|
|
66
|
+
CONFIRM_TOOL = argclass.EnumArgument(Confirmation, lowercase=True, required=False)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Confirm(argclass.Group):
|
|
70
|
+
mode: str = argclass.Argument(
|
|
71
|
+
"--confirm",
|
|
72
|
+
default="destructive",
|
|
73
|
+
env_var="DOCKER_TINY_MCP_CONFIRM",
|
|
74
|
+
choices=LEVELS,
|
|
75
|
+
help="Default confirmation policy for tools without an override.",
|
|
76
|
+
)
|
|
77
|
+
commit: Confirmation | None = CONFIRM_TOOL
|
|
78
|
+
containers: Confirmation | None = CONFIRM_TOOL
|
|
79
|
+
create: Confirmation | None = CONFIRM_TOOL
|
|
80
|
+
create_volume: Confirmation | None = CONFIRM_TOOL
|
|
81
|
+
events: Confirmation | None = CONFIRM_TOOL
|
|
82
|
+
exec: Confirmation | None = CONFIRM_TOOL
|
|
83
|
+
images: Confirmation | None = CONFIRM_TOOL
|
|
84
|
+
logs: Confirmation | None = CONFIRM_TOOL
|
|
85
|
+
networks: Confirmation | None = CONFIRM_TOOL
|
|
86
|
+
prune: Confirmation | None = CONFIRM_TOOL
|
|
87
|
+
pull: Confirmation | None = CONFIRM_TOOL
|
|
88
|
+
read: Confirmation | None = CONFIRM_TOOL
|
|
89
|
+
remove: Confirmation | None = CONFIRM_TOOL
|
|
90
|
+
remove_image: Confirmation | None = CONFIRM_TOOL
|
|
91
|
+
remove_volume: Confirmation | None = CONFIRM_TOOL
|
|
92
|
+
restart: Confirmation | None = CONFIRM_TOOL
|
|
93
|
+
start: Confirmation | None = CONFIRM_TOOL
|
|
94
|
+
stats: Confirmation | None = CONFIRM_TOOL
|
|
95
|
+
stop: Confirmation | None = CONFIRM_TOOL
|
|
96
|
+
volumes: Confirmation | None = CONFIRM_TOOL
|
|
97
|
+
wait: Confirmation | None = CONFIRM_TOOL
|
|
98
|
+
write: Confirmation | None = CONFIRM_TOOL
|
|
99
|
+
|
|
100
|
+
def policy(self) -> Policy:
|
|
101
|
+
return Policy(
|
|
102
|
+
self.mode,
|
|
103
|
+
overrides={
|
|
104
|
+
name: value
|
|
105
|
+
for name in self.__annotations__
|
|
106
|
+
if isinstance(value := getattr(self, name), Confirmation)
|
|
107
|
+
},
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class ConfigDefaults(argclass.INIDefaultsParser):
|
|
112
|
+
"""Map the old INI confirmation mode to the confirm group."""
|
|
113
|
+
|
|
114
|
+
def parse(self) -> Mapping[str, Any]:
|
|
115
|
+
values = super().parse()
|
|
116
|
+
confirm = values.get("confirm")
|
|
117
|
+
if isinstance(confirm, str):
|
|
118
|
+
self._values["confirm"] = {"mode": confirm}
|
|
119
|
+
elif isinstance(confirm, dict) and "mode" not in confirm:
|
|
120
|
+
# The confirm section replaces the same key from DEFAULT.
|
|
121
|
+
ini = ConfigParser(allow_no_value=True, strict=self._strict)
|
|
122
|
+
ini.read(self.loaded_files)
|
|
123
|
+
if (mode := ini.defaults().get("confirm")) is not None:
|
|
124
|
+
confirm["mode"] = mode
|
|
125
|
+
return self._values
|
|
126
|
+
|
|
127
|
+
|
|
62
128
|
class Parser(argclass.Parser):
|
|
63
129
|
"""docker-tiny-mcp -- an MCP server for Docker."""
|
|
64
130
|
|
|
131
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
132
|
+
kwargs.setdefault("config_parser_class", ConfigDefaults)
|
|
133
|
+
super().__init__(*args, **kwargs)
|
|
134
|
+
|
|
65
135
|
state: Path = argclass.Argument(
|
|
66
136
|
default=Path("docker-tiny-mcp.sqlite3"),
|
|
67
137
|
help="SQLite file holding sessions and events. Several workers may share one.",
|
|
@@ -78,6 +148,10 @@ class Parser(argclass.Parser):
|
|
|
78
148
|
default="",
|
|
79
149
|
help="Fix the container network and disable network management tools.",
|
|
80
150
|
)
|
|
151
|
+
max_shm_size: int = argclass.Argument(
|
|
152
|
+
default=DEFAULT_CREATE_LIMITS.max_shm_size,
|
|
153
|
+
help="Maximum explicit /dev/shm size in MiB for the create tool.",
|
|
154
|
+
)
|
|
81
155
|
stdio: bool = argclass.Argument(
|
|
82
156
|
default=False,
|
|
83
157
|
help="Talk over standard input and output instead of listening on a port.",
|
|
@@ -114,15 +188,9 @@ class Parser(argclass.Parser):
|
|
|
114
188
|
'as ["https://docker.example.com"].'
|
|
115
189
|
),
|
|
116
190
|
)
|
|
117
|
-
confirm
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
help=(
|
|
121
|
-
"What to ask a person about. 'destructive' asks only before what "
|
|
122
|
-
"cannot be undone; 'never' asks nothing, for a host that already "
|
|
123
|
-
"asks its own permission; 'changes' asks before anything that "
|
|
124
|
-
"changes anything."
|
|
125
|
-
),
|
|
191
|
+
confirm = Confirm(
|
|
192
|
+
title="Tool confirmations",
|
|
193
|
+
description="Set a tool to ask or allow. Omit it to use the default policy.",
|
|
126
194
|
)
|
|
127
195
|
session_ttl: int = argclass.Argument(default=3600, help="Seconds a session lives without use.")
|
|
128
196
|
generate_config = argclass.Argument(
|
|
@@ -160,12 +228,13 @@ def authentication(parser: Parser) -> Authorization | None:
|
|
|
160
228
|
|
|
161
229
|
def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
162
230
|
"""Build the server from settings, independently of command-line parsing."""
|
|
231
|
+
create_limits = CreateLimits(max_shm_size=parser.max_shm_size)
|
|
163
232
|
storage = SqliteStorage(parser.state)
|
|
164
233
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
165
234
|
catalogue = CacheHint(cache_ttl=60, scope="private")
|
|
166
235
|
registry = Registry(
|
|
167
236
|
"docker",
|
|
168
|
-
"
|
|
237
|
+
version("docker-tiny-mcp"),
|
|
169
238
|
icons=[Icons.BOX],
|
|
170
239
|
website_url="https://github.com/mosquito/docker-tiny-mcp",
|
|
171
240
|
hub=SqliteHub(storage),
|
|
@@ -183,9 +252,10 @@ def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
|
183
252
|
build(
|
|
184
253
|
registry,
|
|
185
254
|
client,
|
|
186
|
-
|
|
255
|
+
parser.confirm.policy(),
|
|
187
256
|
unprivileged=parser.unprivileged,
|
|
188
257
|
network=parser.network,
|
|
258
|
+
create_limits=create_limits,
|
|
189
259
|
),
|
|
190
260
|
storage,
|
|
191
261
|
client,
|
|
@@ -8,16 +8,24 @@ changes. Grants use shared session storage.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import hashlib
|
|
11
|
-
from
|
|
11
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
12
|
+
from enum import Enum
|
|
13
|
+
from functools import wraps
|
|
14
|
+
from inspect import Parameter, signature
|
|
15
|
+
from typing import Any, get_type_hints
|
|
12
16
|
|
|
13
17
|
from aiohttp_tiny_mcp import Exchange, elicit
|
|
14
18
|
from aiohttp_tiny_mcp.storage.namespaces import scoped
|
|
15
19
|
from aiohttp_tiny_mcp.storage.sessions import DATA_KEY, Session
|
|
20
|
+
from pydantic import BaseModel
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
from .errors import Conflict
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
CONSENT_KEY = "consent"
|
|
20
25
|
|
|
26
|
+
DESTROYS = frozenset(
|
|
27
|
+
{"exec", "overwrite_image", "prune", "remove", "remove_image", "remove_volume"}
|
|
28
|
+
)
|
|
21
29
|
LEVELS = ("never", "destructive", "changes")
|
|
22
30
|
|
|
23
31
|
CALLER_PREFIX = "consent-"
|
|
@@ -41,16 +49,60 @@ REMEMBER: dict[str, Any] = {
|
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
|
|
52
|
+
class Confirmation(Enum):
|
|
53
|
+
ASK = "ask"
|
|
54
|
+
ALLOW = "allow"
|
|
55
|
+
|
|
56
|
+
def wrap(
|
|
57
|
+
self, handler: Callable[..., Awaitable[Any]], *, title: str | None = None
|
|
58
|
+
) -> Callable[..., Awaitable[Any]]:
|
|
59
|
+
"""Add a confirmation before the handler when the setting is ASK."""
|
|
60
|
+
if self is Confirmation.ALLOW:
|
|
61
|
+
return handler
|
|
62
|
+
|
|
63
|
+
@wraps(handler)
|
|
64
|
+
async def guarded(args: BaseModel, *, confirmation_exchange: Exchange, **deps: Any) -> Any:
|
|
65
|
+
target = " ".join(
|
|
66
|
+
str(value)
|
|
67
|
+
for field in ("container", "image", "name", "path")
|
|
68
|
+
if (value := getattr(args, field, None))
|
|
69
|
+
)
|
|
70
|
+
name = confirmation_exchange.call.target or guarded.__name__
|
|
71
|
+
subject = title or f"Run {name}"
|
|
72
|
+
question = f"{subject} for {target}?" if target else f"{subject}?"
|
|
73
|
+
if not await ask_for_confirmation(confirmation_exchange, name, target, question):
|
|
74
|
+
raise Conflict(f"not run: {refusal(confirmation_exchange)}")
|
|
75
|
+
return await handler(args, **deps)
|
|
76
|
+
|
|
77
|
+
# The registry uses the signature to inject dependencies and build tool schemas.
|
|
78
|
+
original = signature(handler)
|
|
79
|
+
exchange = Parameter("confirmation_exchange", Parameter.KEYWORD_ONLY, annotation=Exchange)
|
|
80
|
+
guarded.__dict__["__signature__"] = original.replace(
|
|
81
|
+
parameters=[*original.parameters.values(), exchange]
|
|
82
|
+
)
|
|
83
|
+
guarded.__annotations__ = {**get_type_hints(handler), exchange.name: Exchange}
|
|
84
|
+
return guarded
|
|
85
|
+
|
|
86
|
+
|
|
44
87
|
class Policy:
|
|
45
88
|
"""Deployment-wide confirmation policy injected into handlers."""
|
|
46
89
|
|
|
47
|
-
def __init__(
|
|
90
|
+
def __init__(
|
|
91
|
+
self, level: str = "destructive", *, overrides: Mapping[str, Confirmation] | None = None
|
|
92
|
+
) -> None:
|
|
48
93
|
if level not in LEVELS:
|
|
49
94
|
raise ValueError(f"confirm must be one of {', '.join(LEVELS)}, not {level!r}")
|
|
50
95
|
self.level = level
|
|
96
|
+
self.overrides = dict(overrides or {})
|
|
97
|
+
|
|
98
|
+
def confirmation_for(self, name: str) -> Confirmation:
|
|
99
|
+
return self.overrides.get(name, Confirmation.ALLOW)
|
|
51
100
|
|
|
52
|
-
def asks(self, action: str) -> bool:
|
|
53
|
-
if
|
|
101
|
+
def asks(self, action: str, *, eligible: bool = True) -> bool:
|
|
102
|
+
tool = "commit" if action == "overwrite_image" else action
|
|
103
|
+
if (override := self.overrides.get(tool)) is not None:
|
|
104
|
+
return override is Confirmation.ASK
|
|
105
|
+
if not eligible or self.level == "never":
|
|
54
106
|
return False
|
|
55
107
|
if self.level == "changes":
|
|
56
108
|
return True
|
|
@@ -217,12 +269,18 @@ def refusal(ex: Exchange, key: str = "confirm") -> str:
|
|
|
217
269
|
return action.value if action is not None else "unanswered"
|
|
218
270
|
|
|
219
271
|
|
|
220
|
-
async def confirm(
|
|
272
|
+
async def confirm(
|
|
273
|
+
ex: Exchange, policy: Policy, action: str, target: str, text: str, *, eligible: bool = True
|
|
274
|
+
) -> bool:
|
|
221
275
|
"""Apply policy and remembered grants before asking. An accepted form with confirmed=false is
|
|
222
276
|
still a refusal.
|
|
223
277
|
"""
|
|
224
|
-
if not policy.asks(action):
|
|
278
|
+
if not policy.asks(action, eligible=eligible):
|
|
225
279
|
return True
|
|
280
|
+
return await ask_for_confirmation(ex, action, target, text)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
async def ask_for_confirmation(ex: Exchange, action: str, target: str, text: str) -> bool:
|
|
226
284
|
if await granted(ex, action, target):
|
|
227
285
|
return True
|
|
228
286
|
keepable = await remembering(ex) is not None
|
|
@@ -235,6 +293,7 @@ async def confirm(ex: Exchange, policy: Policy, action: str, target: str, text:
|
|
|
235
293
|
|
|
236
294
|
__all__ = [
|
|
237
295
|
"CONFIRM",
|
|
296
|
+
"Confirmation",
|
|
238
297
|
"CONSENT_KEY",
|
|
239
298
|
"DESTROYS",
|
|
240
299
|
"LEVELS",
|
|
@@ -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
|
|
|
@@ -76,7 +82,7 @@ class ExecRequest(ContainerRef):
|
|
|
76
82
|
|
|
77
83
|
|
|
78
84
|
class ReadRequest(ContainerRef):
|
|
79
|
-
path: str = Field(description="Absolute path
|
|
85
|
+
path: str = Field(description="Absolute path inside the container.")
|
|
80
86
|
|
|
81
87
|
|
|
82
88
|
class WriteRequest(ContainerRef):
|
|
@@ -85,17 +91,6 @@ class WriteRequest(ContainerRef):
|
|
|
85
91
|
mode: str = Field("644", description="Permission bits, as three or four octal digits.")
|
|
86
92
|
|
|
87
93
|
|
|
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
94
|
class Written(BaseModel):
|
|
100
95
|
container: str
|
|
101
96
|
path: str
|
|
@@ -103,6 +98,13 @@ class Written(BaseModel):
|
|
|
103
98
|
note: str | None = None
|
|
104
99
|
|
|
105
100
|
|
|
101
|
+
class CreateLimits(BaseModel, frozen=True):
|
|
102
|
+
max_shm_size: int = Field(1024, ge=1, le=(2**63 - 1) // MIB, strict=True)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
DEFAULT_CREATE_LIMITS = CreateLimits()
|
|
106
|
+
|
|
107
|
+
|
|
106
108
|
class CreateOptions(BaseModel):
|
|
107
109
|
"""Container creation options; only image is required."""
|
|
108
110
|
|
|
@@ -126,6 +128,20 @@ class CreateOptions(BaseModel):
|
|
|
126
128
|
restart: Literal["no", "on-failure", "always", "unless-stopped"] = Field(
|
|
127
129
|
"no", description="Whether the daemon starts it again after it stops."
|
|
128
130
|
)
|
|
131
|
+
init: bool = Field(
|
|
132
|
+
True,
|
|
133
|
+
description=(
|
|
134
|
+
"Run Docker's init as PID 1 to reap orphaned processes. Enable this when a "
|
|
135
|
+
"command such as sleep infinity will run daemons through exec. Set false "
|
|
136
|
+
"if the command must run as PID 1."
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
shm_size: int | None = Field(
|
|
140
|
+
None,
|
|
141
|
+
gt=0,
|
|
142
|
+
strict=True,
|
|
143
|
+
description="Size of /dev/shm in MiB. Omit to use the Docker default.",
|
|
144
|
+
)
|
|
129
145
|
workdir: str | None = Field(None, description="Directory its command starts in.")
|
|
130
146
|
user: str | None = Field(None, description="Who its command runs as.")
|
|
131
147
|
pull: Literal["missing", "always", "never"] = Field(
|
|
@@ -160,10 +176,13 @@ class UnprivilegedCreateRequest(FixedNetworkCreateRequest):
|
|
|
160
176
|
)
|
|
161
177
|
|
|
162
178
|
|
|
163
|
-
class
|
|
179
|
+
class VolumeRef(BaseModel):
|
|
164
180
|
model_config = ConfigDict(extra="forbid")
|
|
165
181
|
|
|
166
182
|
name: str = Field(pattern=rf"^{VOLUME_NAME}$", description="Name of the Docker volume.")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class CreateVolumeRequest(VolumeRef):
|
|
167
186
|
description: str = Field(min_length=1, description="What the volume holds or is for.")
|
|
168
187
|
|
|
169
188
|
|
|
@@ -275,6 +294,8 @@ class ContainerDetail(BaseModel):
|
|
|
275
294
|
command: str = Field(description="What it runs, quoted as a shell would.")
|
|
276
295
|
restart_count: int
|
|
277
296
|
restart_policy: str = Field("no", description="What the daemon does after it stops.")
|
|
297
|
+
init: bool | None = Field(None, description="Use Docker init. Null means the daemon default.")
|
|
298
|
+
shm_size: float | None = Field(None, description="Size of /dev/shm in MiB.")
|
|
278
299
|
health: str | None = Field(None, description="healthy, unhealthy, starting, or absent.")
|
|
279
300
|
exit_code: int | None = Field(None, description="Set once it has stopped.")
|
|
280
301
|
error: str | None = None
|