docker-tiny-mcp 0.2.1__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.1 → docker_tiny_mcp-0.2.2}/PKG-INFO +33 -13
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/README.md +32 -12
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/__main__.py +76 -13
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/consent.py +67 -8
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/models.py +8 -1
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/prompts.py +3 -4
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/file.py +9 -5
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/server.py +88 -23
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/__init__.py +2 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/exec.py +9 -4
- 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.1 → docker_tiny_mcp-0.2.2}/pyproject.toml +1 -1
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/pyproject.toml.orig +1 -1
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/LICENSE +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/__init__.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/daemon.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/errors.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/events.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/__init__.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/containers.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/images.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/info.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/__init__.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/container.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/logs.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/safety.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/commit.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/container.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/containers.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/create.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/create_volume.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/events.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/images.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/info.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/logs.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/networks.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/prune.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/pull.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/remove.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/remove_image.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/restart.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/results.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/start.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/stats.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/stop.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/volumes.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/wait.py +0 -0
- {docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/tools/write.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
@@ -93,7 +93,7 @@ For example, call `create` with:
|
|
|
93
93
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Before reading a file resource or calling `write`, `exec`, `start` or `restart`,
|
|
96
|
+
Before reading a file resource or calling `read`, `write`, `exec`, `start` or `restart`,
|
|
97
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
|
|
@@ -226,20 +226,24 @@ start a new one.
|
|
|
226
226
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
227
227
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
228
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 |
|
|
229
230
|
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
230
231
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
231
232
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
232
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 |
|
|
233
235
|
| `write` | Put a file into it, running or not |
|
|
234
236
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
235
237
|
| `pull` | Download an image, reporting progress |
|
|
236
238
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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.
|
|
243
247
|
|
|
244
248
|
By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
|
|
245
249
|
This helps when `sleep infinity` keeps the container running and `exec` starts
|
|
@@ -346,18 +350,18 @@ before everything is a server whose questions nobody reads -- and there is
|
|
|
346
350
|
usually a host in front of this one asking its own permission for every call,
|
|
347
351
|
so a second question buys only the habit of clicking through both. Four things
|
|
348
352
|
cut it down, in order: a policy decides which actions are worth a question at
|
|
349
|
-
all, a command that only reads
|
|
353
|
+
all, a command that only reads skips confirmation by default, an answer that said "do not ask
|
|
350
354
|
again" is honoured, and what is left asks once.
|
|
351
355
|
|
|
352
356
|
```bash
|
|
353
357
|
uv run docker-tiny-mcp # asks only before what cannot be undone
|
|
354
|
-
uv run docker-tiny-mcp --confirm never #
|
|
355
|
-
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
|
|
356
360
|
```
|
|
357
361
|
|
|
358
362
|
Under the default, `create` and `write` do not interrupt: creating is undone
|
|
359
363
|
by removing, and a file written into a container goes away with it. `remove`,
|
|
360
|
-
`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:
|
|
361
365
|
|
|
362
366
|
<!-- name: async test_readme_consent -->
|
|
363
367
|
```python
|
|
@@ -372,6 +376,22 @@ assert not Policy("never").asks("remove")
|
|
|
372
376
|
assert Policy("changes").asks("write")
|
|
373
377
|
```
|
|
374
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
|
+
|
|
375
395
|
What was allowed is kept in the session store the package already has, so a
|
|
376
396
|
second worker honours a permission the first one was given. `2026-07-28` keeps
|
|
377
397
|
no session of its own, so the answer is filed under the caller the revision
|
|
@@ -421,7 +441,7 @@ with the first:
|
|
|
421
441
|
|
|
422
442
|
```python
|
|
423
443
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
424
|
-
return build(registry, client,
|
|
444
|
+
return build(registry, client, parser.confirm.policy()), storage, client
|
|
425
445
|
```
|
|
426
446
|
|
|
427
447
|
**State is SQLite.** `aiohttp_tiny_mcp.storage.sqlite` holds the sessions and the
|
|
@@ -79,7 +79,7 @@ For example, call `create` with:
|
|
|
79
79
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
Before reading a file resource or calling `write`, `exec`, `start` or `restart`,
|
|
82
|
+
Before reading a file resource or calling `read`, `write`, `exec`, `start` or `restart`,
|
|
83
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
|
|
@@ -212,20 +212,24 @@ start a new one.
|
|
|
212
212
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
213
213
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
214
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 |
|
|
215
216
|
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
216
217
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
217
218
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
218
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 |
|
|
219
221
|
| `write` | Put a file into it, running or not |
|
|
220
222
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
221
223
|
| `pull` | Download an image, reporting progress |
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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.
|
|
229
233
|
|
|
230
234
|
By default, `create` runs Docker's init as PID 1 to reap orphaned processes.
|
|
231
235
|
This helps when `sleep infinity` keeps the container running and `exec` starts
|
|
@@ -332,18 +336,18 @@ before everything is a server whose questions nobody reads -- and there is
|
|
|
332
336
|
usually a host in front of this one asking its own permission for every call,
|
|
333
337
|
so a second question buys only the habit of clicking through both. Four things
|
|
334
338
|
cut it down, in order: a policy decides which actions are worth a question at
|
|
335
|
-
all, a command that only reads
|
|
339
|
+
all, a command that only reads skips confirmation by default, an answer that said "do not ask
|
|
336
340
|
again" is honoured, and what is left asks once.
|
|
337
341
|
|
|
338
342
|
```bash
|
|
339
343
|
uv run docker-tiny-mcp # asks only before what cannot be undone
|
|
340
|
-
uv run docker-tiny-mcp --confirm never #
|
|
341
|
-
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
|
|
342
346
|
```
|
|
343
347
|
|
|
344
348
|
Under the default, `create` and `write` do not interrupt: creating is undone
|
|
345
349
|
by removing, and a file written into a container goes away with it. `remove`,
|
|
346
|
-
`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:
|
|
347
351
|
|
|
348
352
|
<!-- name: async test_readme_consent -->
|
|
349
353
|
```python
|
|
@@ -358,6 +362,22 @@ assert not Policy("never").asks("remove")
|
|
|
358
362
|
assert Policy("changes").asks("write")
|
|
359
363
|
```
|
|
360
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
|
+
|
|
361
381
|
What was allowed is kept in the session store the package already has, so a
|
|
362
382
|
second worker honours a permission the first one was given. `2026-07-28` keeps
|
|
363
383
|
no session of its own, so the answer is filed under the caller the revision
|
|
@@ -407,7 +427,7 @@ with the first:
|
|
|
407
427
|
|
|
408
428
|
```python
|
|
409
429
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
410
|
-
return build(registry, client,
|
|
430
|
+
return build(registry, client, parser.confirm.policy()), storage, client
|
|
411
431
|
```
|
|
412
432
|
|
|
413
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,7 +23,7 @@ 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
|
|
25
28
|
from .models import DEFAULT_CREATE_LIMITS, CreateLimits
|
|
26
29
|
from .server import build
|
|
@@ -60,9 +63,75 @@ class JWT(argclass.Group):
|
|
|
60
63
|
)
|
|
61
64
|
|
|
62
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
|
+
|
|
63
128
|
class Parser(argclass.Parser):
|
|
64
129
|
"""docker-tiny-mcp -- an MCP server for Docker."""
|
|
65
130
|
|
|
131
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
132
|
+
kwargs.setdefault("config_parser_class", ConfigDefaults)
|
|
133
|
+
super().__init__(*args, **kwargs)
|
|
134
|
+
|
|
66
135
|
state: Path = argclass.Argument(
|
|
67
136
|
default=Path("docker-tiny-mcp.sqlite3"),
|
|
68
137
|
help="SQLite file holding sessions and events. Several workers may share one.",
|
|
@@ -119,15 +188,9 @@ class Parser(argclass.Parser):
|
|
|
119
188
|
'as ["https://docker.example.com"].'
|
|
120
189
|
),
|
|
121
190
|
)
|
|
122
|
-
confirm
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
help=(
|
|
126
|
-
"What to ask a person about. 'destructive' asks only before what "
|
|
127
|
-
"cannot be undone; 'never' asks nothing, for a host that already "
|
|
128
|
-
"asks its own permission; 'changes' asks before anything that "
|
|
129
|
-
"changes anything."
|
|
130
|
-
),
|
|
191
|
+
confirm = Confirm(
|
|
192
|
+
title="Tool confirmations",
|
|
193
|
+
description="Set a tool to ask or allow. Omit it to use the default policy.",
|
|
131
194
|
)
|
|
132
195
|
session_ttl: int = argclass.Argument(default=3600, help="Seconds a session lives without use.")
|
|
133
196
|
generate_config = argclass.Argument(
|
|
@@ -171,7 +234,7 @@ def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
|
171
234
|
catalogue = CacheHint(cache_ttl=60, scope="private")
|
|
172
235
|
registry = Registry(
|
|
173
236
|
"docker",
|
|
174
|
-
"
|
|
237
|
+
version("docker-tiny-mcp"),
|
|
175
238
|
icons=[Icons.BOX],
|
|
176
239
|
website_url="https://github.com/mosquito/docker-tiny-mcp",
|
|
177
240
|
hub=SqliteHub(storage),
|
|
@@ -189,7 +252,7 @@ def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
|
189
252
|
build(
|
|
190
253
|
registry,
|
|
191
254
|
client,
|
|
192
|
-
|
|
255
|
+
parser.confirm.policy(),
|
|
193
256
|
unprivileged=parser.unprivileged,
|
|
194
257
|
network=parser.network,
|
|
195
258
|
create_limits=create_limits,
|
|
@@ -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",
|
|
@@ -81,6 +81,10 @@ class ExecRequest(ContainerRef):
|
|
|
81
81
|
user: str | None = Field(None, description='Who to run it as, such as "postgres".')
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
class ReadRequest(ContainerRef):
|
|
85
|
+
path: str = Field(description="Absolute path inside the container.")
|
|
86
|
+
|
|
87
|
+
|
|
84
88
|
class WriteRequest(ContainerRef):
|
|
85
89
|
path: str = Field(description="Absolute path to write, inside the container.")
|
|
86
90
|
content: str = Field(description="What the file is to hold. It replaces what is there.")
|
|
@@ -172,10 +176,13 @@ class UnprivilegedCreateRequest(FixedNetworkCreateRequest):
|
|
|
172
176
|
)
|
|
173
177
|
|
|
174
178
|
|
|
175
|
-
class
|
|
179
|
+
class VolumeRef(BaseModel):
|
|
176
180
|
model_config = ConfigDict(extra="forbid")
|
|
177
181
|
|
|
178
182
|
name: str = Field(pattern=rf"^{VOLUME_NAME}$", description="Name of the Docker volume.")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class CreateVolumeRequest(VolumeRef):
|
|
179
186
|
description: str = Field(min_length=1, description="What the volume holds or is for.")
|
|
180
187
|
|
|
181
188
|
|
|
@@ -18,7 +18,7 @@ async def diagnose(args: ContainerRef) -> str:
|
|
|
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 the file
|
|
21
|
+
"problem, use `read` to check the configuration file. 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."
|
|
@@ -36,9 +36,8 @@ async def reclaim(args: Nothing) -> str:
|
|
|
36
36
|
"proposing it, because it may be a database whose container is "
|
|
37
37
|
"gone.\n\n"
|
|
38
38
|
"Propose what to remove and why, largest first, and name the tool for "
|
|
39
|
-
"each: `prune` for a whole kind at once, `remove_image` for one
|
|
40
|
-
"
|
|
41
|
-
"decide."
|
|
39
|
+
"each: `prune` for a whole kind at once, `remove_image` for one image, "
|
|
40
|
+
"or `remove_volume` for one volume. Do not remove anything. Wait for the person to decide."
|
|
42
41
|
)
|
|
43
42
|
|
|
44
43
|
|
|
@@ -28,6 +28,14 @@ FILE_SIGNATURES = (
|
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def file_blob(args: ContainerFile, content: bytes, mime_type: str) -> BlobResourceContents:
|
|
32
|
+
return BlobResourceContents(
|
|
33
|
+
uri=f"docker://containers/{args.name}/files{quote(args.path)}",
|
|
34
|
+
blob=b64encode(content).decode("ascii"),
|
|
35
|
+
mime_type=mime_type,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
31
39
|
async def file_contents(
|
|
32
40
|
args: ContainerFile, container: DockerContainer
|
|
33
41
|
) -> str | bytes | BlobResourceContents:
|
|
@@ -50,11 +58,7 @@ async def file_contents(
|
|
|
50
58
|
if content.startswith(b"RIFF") and content[8:12] == b"WEBP":
|
|
51
59
|
mime_type = "image/webp"
|
|
52
60
|
if mime_type is not None:
|
|
53
|
-
return
|
|
54
|
-
uri=f"docker://containers/{args.name}/files{quote(path)}",
|
|
55
|
-
blob=b64encode(content).decode("ascii"),
|
|
56
|
-
mime_type=mime_type,
|
|
57
|
-
)
|
|
61
|
+
return file_blob(args, content, mime_type)
|
|
58
62
|
if b"\0" not in content:
|
|
59
63
|
try:
|
|
60
64
|
return content.decode("utf-8")
|
|
@@ -11,30 +11,32 @@ from .models import DEFAULT_CREATE_LIMITS, CreateLimits
|
|
|
11
11
|
from .resources import templates
|
|
12
12
|
from .tools.create import fixed_network_create, unprivileged_create
|
|
13
13
|
from .tools.prune import prune_fixed_network
|
|
14
|
+
from .tools.read import read, read_unprivileged
|
|
14
15
|
|
|
15
16
|
INSTRUCTIONS = (
|
|
16
17
|
"Inspect and control Docker. Start with `containers` to find a target. "
|
|
17
18
|
"Read `docker://containers/{name}` for details, and use `logs`, `stats` "
|
|
18
19
|
"and `events` to investigate. Read `docker://info` to identify the daemon.\n\n"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
20
|
+
"Use `read` with a container name and an absolute path to read a complete file. "
|
|
21
|
+
"You can also read it through `docker://containers/{name}/files{+path}`.\n\n"
|
|
21
22
|
"To change something: `create` makes and starts a container, `start`, "
|
|
22
23
|
"`stop` and `restart` do the obvious, `wait` holds until a container is "
|
|
23
24
|
"running or healthy, `exec` runs a command inside one, and `write` puts a "
|
|
24
25
|
"file into one. `prune`, `remove` and `remove_image` reclaim space.\n\n"
|
|
25
26
|
"Use `create_volume` to make a named volume with a description. "
|
|
26
|
-
"Check `volumes` for its description and the containers that mount it
|
|
27
|
+
"Check `volumes` for its description and the containers that mount it. "
|
|
28
|
+
"Use `remove_volume` to delete one volume and its data.\n\n"
|
|
27
29
|
"To save a prepared container as a `localhost/` image, write `/AGENTS.md` "
|
|
28
30
|
"at its root, then use `stop`, then `commit`. Record its base image and what "
|
|
29
31
|
"you installed, its purpose, and how to reproduce it. Include the working "
|
|
30
32
|
"directory, commands, volume names and mount paths, and environment "
|
|
31
33
|
"variable names. Keep secrets out of the file and the container. To use a "
|
|
32
|
-
"saved image, find it in `images` and read `/AGENTS.md`
|
|
34
|
+
"saved image, find it in `images` and use `read` on `/AGENTS.md` in a container "
|
|
33
35
|
"created from that image.\n\n"
|
|
34
|
-
"
|
|
35
|
-
"`ls`
|
|
36
|
-
"`
|
|
37
|
-
"person
|
|
36
|
+
"The default policy skips confirmation for reads and read-only commands such as "
|
|
37
|
+
"`ls` and `cat`. It asks before `remove`, `remove_image`, `remove_volume`, `prune`, "
|
|
38
|
+
"overwriting an image with `commit`, or running a command that can change the container. "
|
|
39
|
+
"A person who approves an action can save the approval."
|
|
38
40
|
)
|
|
39
41
|
|
|
40
42
|
READS = Hint.READ_ONLY | Hint.IDEMPOTENT
|
|
@@ -54,8 +56,10 @@ def build(
|
|
|
54
56
|
"""Register handlers and provide the Docker client and deployment settings."""
|
|
55
57
|
registry.instructions = INSTRUCTIONS
|
|
56
58
|
registry.provide_instance(client)
|
|
57
|
-
|
|
59
|
+
policy = policy or Policy()
|
|
60
|
+
registry.provide_instance(policy)
|
|
58
61
|
registry.provide_instance(create_limits)
|
|
62
|
+
|
|
59
63
|
if unprivileged:
|
|
60
64
|
registry.instructions += (
|
|
61
65
|
"\n\nUnprivileged mode: host mounts and privileged containers are forbidden. "
|
|
@@ -66,15 +70,53 @@ def build(
|
|
|
66
70
|
"\n\nThe network is fixed by the server; network management is disabled."
|
|
67
71
|
)
|
|
68
72
|
|
|
69
|
-
registry.tool(
|
|
70
|
-
|
|
73
|
+
registry.tool(
|
|
74
|
+
policy.confirmation_for("containers").wrap(tools.containers),
|
|
75
|
+
annotations=READS,
|
|
76
|
+
icons=[Icons.BOX],
|
|
77
|
+
)
|
|
78
|
+
registry.tool(
|
|
79
|
+
policy.confirmation_for("images").wrap(tools.images),
|
|
80
|
+
annotations=READS,
|
|
81
|
+
icons=[Icons.LAYER_GROUP],
|
|
82
|
+
)
|
|
71
83
|
if not network:
|
|
72
|
-
registry.tool(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
registry.tool(
|
|
84
|
+
registry.tool(
|
|
85
|
+
policy.confirmation_for("networks").wrap(tools.networks),
|
|
86
|
+
annotations=READS,
|
|
87
|
+
icons=[Icons.NETWORK_WIRED],
|
|
88
|
+
)
|
|
89
|
+
registry.tool(
|
|
90
|
+
policy.confirmation_for("volumes").wrap(tools.volumes),
|
|
91
|
+
annotations=READS,
|
|
92
|
+
icons=[Icons.HARD_DRIVE],
|
|
93
|
+
)
|
|
94
|
+
registry.tool(
|
|
95
|
+
policy.confirmation_for("logs").wrap(tools.logs),
|
|
96
|
+
annotations=WATCHES,
|
|
97
|
+
icons=[Icons.FILE_LINES],
|
|
98
|
+
)
|
|
99
|
+
registry.tool(
|
|
100
|
+
policy.confirmation_for("stats").wrap(tools.stats),
|
|
101
|
+
annotations=WATCHES,
|
|
102
|
+
icons=[Icons.CHART_LINE],
|
|
103
|
+
)
|
|
104
|
+
registry.tool(
|
|
105
|
+
policy.confirmation_for("events").wrap(tools.events),
|
|
106
|
+
annotations=WATCHES,
|
|
107
|
+
icons=[Icons.CLOCK_ROTATE_LEFT],
|
|
108
|
+
)
|
|
109
|
+
registry.tool(
|
|
110
|
+
policy.confirmation_for("wait").wrap(tools.wait),
|
|
111
|
+
annotations=WATCHES,
|
|
112
|
+
icons=[Icons.HOURGLASS_HALF],
|
|
113
|
+
)
|
|
114
|
+
registry.tool(
|
|
115
|
+
policy.confirmation_for("read").wrap(read_unprivileged if unprivileged else read),
|
|
116
|
+
name="read",
|
|
117
|
+
annotations=READS,
|
|
118
|
+
icons=[Icons.FILE],
|
|
119
|
+
)
|
|
78
120
|
|
|
79
121
|
if unprivileged:
|
|
80
122
|
registry.tool(
|
|
@@ -84,9 +126,16 @@ def build(
|
|
|
84
126
|
icons=[Icons.PLUS],
|
|
85
127
|
)
|
|
86
128
|
registry.tool(
|
|
87
|
-
|
|
129
|
+
policy.confirmation_for("start").wrap(tools.start_unprivileged),
|
|
130
|
+
name="start",
|
|
131
|
+
annotations=Hint.IDEMPOTENT,
|
|
132
|
+
icons=[Icons.PLAY],
|
|
133
|
+
)
|
|
134
|
+
registry.tool(
|
|
135
|
+
policy.confirmation_for("restart").wrap(tools.restart_unprivileged),
|
|
136
|
+
name="restart",
|
|
137
|
+
icons=[Icons.ARROWS_ROTATE],
|
|
88
138
|
)
|
|
89
|
-
registry.tool(tools.restart_unprivileged, name="restart", icons=[Icons.ARROWS_ROTATE])
|
|
90
139
|
registry.tool(
|
|
91
140
|
tools.write_unprivileged, name="write", annotations=Hint.DESTRUCTIVE, icons=[Icons.PEN]
|
|
92
141
|
)
|
|
@@ -106,25 +155,41 @@ def build(
|
|
|
106
155
|
)
|
|
107
156
|
else:
|
|
108
157
|
registry.tool(tools.create, annotations=Hint.OPEN_WORLD, icons=[Icons.PLUS])
|
|
109
|
-
registry.tool(
|
|
110
|
-
|
|
158
|
+
registry.tool(
|
|
159
|
+
policy.confirmation_for("start").wrap(tools.start),
|
|
160
|
+
annotations=Hint.IDEMPOTENT,
|
|
161
|
+
icons=[Icons.PLAY],
|
|
162
|
+
)
|
|
163
|
+
registry.tool(
|
|
164
|
+
policy.confirmation_for("restart").wrap(tools.restart), icons=[Icons.ARROWS_ROTATE]
|
|
165
|
+
)
|
|
111
166
|
registry.tool(tools.write, annotations=Hint.DESTRUCTIVE, icons=[Icons.PEN])
|
|
112
167
|
registry.tool(
|
|
113
168
|
tools.exec, annotations=Hint.DESTRUCTIVE | Hint.OPEN_WORLD, icons=[Icons.TERMINAL]
|
|
114
169
|
)
|
|
115
170
|
|
|
116
|
-
registry.tool(
|
|
171
|
+
registry.tool(
|
|
172
|
+
policy.confirmation_for("stop").wrap(tools.stop),
|
|
173
|
+
annotations=Hint.IDEMPOTENT,
|
|
174
|
+
icons=[Icons.STOP],
|
|
175
|
+
)
|
|
117
176
|
registry.tool(tools.commit, annotations=Hint.DESTRUCTIVE, icons=[Icons.FLOPPY_DISK])
|
|
118
177
|
registry.tool(tools.create_volume, annotations=Hint.IDEMPOTENT, icons=[Icons.HARD_DRIVE])
|
|
119
178
|
registry.tool(tools.remove, annotations=Hint.DESTRUCTIVE, icons=[Icons.TRASH_CAN])
|
|
120
179
|
registry.tool(tools.remove_image, annotations=Hint.DESTRUCTIVE, icons=[Icons.TRASH_CAN])
|
|
180
|
+
registry.tool(tools.remove_volume, annotations=Hint.DESTRUCTIVE, icons=[Icons.TRASH_CAN])
|
|
121
181
|
if network:
|
|
122
182
|
registry.tool(
|
|
123
183
|
prune_fixed_network, name="prune", annotations=Hint.DESTRUCTIVE, icons=[Icons.BROOM]
|
|
124
184
|
)
|
|
125
185
|
else:
|
|
126
186
|
registry.tool(tools.prune, annotations=Hint.DESTRUCTIVE, icons=[Icons.BROOM])
|
|
127
|
-
registry.tool(
|
|
187
|
+
registry.tool(
|
|
188
|
+
policy.confirmation_for("pull").wrap(tools.pull),
|
|
189
|
+
streaming=True,
|
|
190
|
+
annotations=Hint.OPEN_WORLD,
|
|
191
|
+
icons=[Icons.DOWNLOAD],
|
|
192
|
+
)
|
|
128
193
|
|
|
129
194
|
registry.resource(
|
|
130
195
|
"docker://info", resources.info, mime_type="application/json", icons=[Icons.CIRCLE_INFO]
|
|
@@ -17,6 +17,7 @@ from .prune import prune
|
|
|
17
17
|
from .pull import pull
|
|
18
18
|
from .remove import remove
|
|
19
19
|
from .remove_image import remove_image
|
|
20
|
+
from .remove_volume import remove_volume
|
|
20
21
|
from .restart import restart, restart_unprivileged
|
|
21
22
|
from .results import outcome, settled
|
|
22
23
|
from .start import start, start_unprivileged
|
|
@@ -44,6 +45,7 @@ __all__ = [
|
|
|
44
45
|
"pull",
|
|
45
46
|
"remove",
|
|
46
47
|
"remove_image",
|
|
48
|
+
"remove_volume",
|
|
47
49
|
"restart",
|
|
48
50
|
"restart_unprivileged",
|
|
49
51
|
"settled",
|
|
@@ -29,15 +29,20 @@ async def exec(args: ExecRequest, client: Docker, ex: Exchange, policy: Policy)
|
|
|
29
29
|
This is `docker exec`, not `docker run`: it needs a container that is
|
|
30
30
|
already running. Use `create` to start a new one.
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
By default, read-only commands such as `ls`, `cat`, `ps` and `df` run
|
|
33
|
+
without confirmation. Other commands may ask first, because a command
|
|
34
34
|
can do whatever the container can. It is given `seconds` to finish, and is
|
|
35
35
|
reported as timed out after that.
|
|
36
36
|
"""
|
|
37
37
|
found = await daemon.find(client, args.container)
|
|
38
38
|
printable = " ".join(args.command)
|
|
39
|
-
if not
|
|
40
|
-
ex,
|
|
39
|
+
if not await confirm(
|
|
40
|
+
ex,
|
|
41
|
+
policy,
|
|
42
|
+
"exec",
|
|
43
|
+
args.container,
|
|
44
|
+
f"Run `{printable}` inside {args.container}?",
|
|
45
|
+
eligible=not only_reads(args.command),
|
|
41
46
|
):
|
|
42
47
|
return Executed(
|
|
43
48
|
container=args.container,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Read a complete file as tool content."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from aiodocker import Docker
|
|
6
|
+
from aiohttp_tiny_mcp import (
|
|
7
|
+
BlobResourceContents,
|
|
8
|
+
CallToolResult,
|
|
9
|
+
EmbeddedResource,
|
|
10
|
+
ImageContent,
|
|
11
|
+
TextContent,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from docker_tiny_mcp.models import ContainerFile, ReadRequest
|
|
15
|
+
from docker_tiny_mcp.resources.templates.file import file, file_blob, file_unprivileged
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def file_result(args: ContainerFile, content: str | bytes | BlobResourceContents) -> CallToolResult:
|
|
19
|
+
if isinstance(content, str):
|
|
20
|
+
return CallToolResult(content=[TextContent(text=content)])
|
|
21
|
+
if isinstance(content, bytes):
|
|
22
|
+
content = file_blob(args, content, "application/octet-stream")
|
|
23
|
+
mime_type = content.mime_type
|
|
24
|
+
if mime_type and mime_type.startswith("image/"):
|
|
25
|
+
return CallToolResult(content=[ImageContent(data=content.blob, mime_type=mime_type)])
|
|
26
|
+
return CallToolResult(content=[EmbeddedResource(resource=content)])
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def read(args: ReadRequest, client: Docker) -> CallToolResult:
|
|
30
|
+
"""Read a complete file from a running or stopped container. Returns text or binary data."""
|
|
31
|
+
target = ContainerFile(name=args.container.lstrip("/"), path=args.path)
|
|
32
|
+
return file_result(target, await file(target, client))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def read_unprivileged(args: ReadRequest, client: Docker) -> CallToolResult:
|
|
36
|
+
"""Read a complete file from an isolated container. Returns text or binary data."""
|
|
37
|
+
target = ContainerFile(name=args.container.lstrip("/"), path=args.path)
|
|
38
|
+
return file_result(target, await file_unprivileged(target, client))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Remove one named Docker volume."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from aiodocker import Docker
|
|
6
|
+
from aiohttp_tiny_mcp import Exchange
|
|
7
|
+
|
|
8
|
+
from docker_tiny_mcp.consent import Policy, confirm, refusal
|
|
9
|
+
from docker_tiny_mcp.errors import clear
|
|
10
|
+
from docker_tiny_mcp.models import VolumeRef
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def remove_volume(args: VolumeRef, client: Docker, ex: Exchange, policy: Policy) -> str:
|
|
14
|
+
"""Remove a named volume and its data. Docker refuses if any container uses it."""
|
|
15
|
+
if not await confirm(
|
|
16
|
+
ex, policy, "remove_volume", args.name, f"Remove volume {args.name} and all its data?"
|
|
17
|
+
):
|
|
18
|
+
return f"not removed: {refusal(ex)}"
|
|
19
|
+
async with clear("removing the volume", subject=args.name):
|
|
20
|
+
volume = await client.volumes.get(args.name)
|
|
21
|
+
await volume.delete()
|
|
22
|
+
return f"removed {args.name}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/__init__.py
RENAMED
|
File without changes
|
{docker_tiny_mcp-0.2.1 → docker_tiny_mcp-0.2.2}/docker_tiny_mcp/resources/templates/container.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|