docker-tiny-mcp 0.1.1__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.
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/PKG-INFO +54 -14
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/README.md +52 -12
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/__main__.py +36 -34
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/consent.py +1 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/daemon.py +29 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/models.py +63 -16
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/prompts.py +2 -2
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/__init__.py +4 -0
- docker_tiny_mcp-0.2.1/docker_tiny_mcp/resources/templates/file.py +77 -0
- docker_tiny_mcp-0.2.1/docker_tiny_mcp/server.py +171 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/__init__.py +4 -3
- docker_tiny_mcp-0.2.1/docker_tiny_mcp/tools/commit.py +76 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/container.py +4 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/containers.py +1 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/create.py +41 -9
- docker_tiny_mcp-0.2.1/docker_tiny_mcp/tools/create_volume.py +34 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/exec.py +1 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/images.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/restart.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/start.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/volumes.py +3 -2
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/write.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/pyproject.toml +2 -2
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/pyproject.toml.orig +2 -2
- docker_tiny_mcp-0.1.1/docker_tiny_mcp/server.py +0 -115
- docker_tiny_mcp-0.1.1/docker_tiny_mcp/tools/read.py +0 -69
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/LICENSE +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/__init__.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/errors.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/events.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/__init__.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/containers.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/images.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/info.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/container.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/resources/templates/logs.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/safety.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/events.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/info.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/logs.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/networks.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/prune.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/pull.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/remove.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/remove_image.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/results.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/stats.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/stop.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.1}/docker_tiny_mcp/tools/wait.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docker-tiny-mcp
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.1
|
|
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.
|
|
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
|
|
@@ -61,6 +61,15 @@ allowed_origin = ["https://docker.example.com"]
|
|
|
61
61
|
DOCKER_TINY_MCP_ALLOWED_ORIGIN='["https://docker.example.com"]' uv run docker-tiny-mcp
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
Open `/console` to browse the MCP catalogue. Clients on MCP `2025-11-25` or
|
|
65
|
+
`2026-07-28` receive light and dark icons for the server and its catalogue entries.
|
|
66
|
+
|
|
67
|
+
For an HTTP client that lacks native prompts, add `prompts=resource` to the
|
|
68
|
+
endpoint URL. For a client that can only call tools, add `resources=tool` to
|
|
69
|
+
list and read resources and prompts with `mcp_resources_list` and
|
|
70
|
+
`mcp_resources_read`. Over stdio, use `--stdio-prompts resource` or
|
|
71
|
+
`--stdio-resources tool` respectively.
|
|
72
|
+
|
|
64
73
|
## Unprivileged mode
|
|
65
74
|
|
|
66
75
|
Enable runtime checks for host access with `--unprivileged`:
|
|
@@ -84,8 +93,8 @@ For example, call `create` with:
|
|
|
84
93
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
85
94
|
```
|
|
86
95
|
|
|
87
|
-
Before
|
|
88
|
-
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,
|
|
89
98
|
shared host namespaces, custom runtimes and relaxed security settings.
|
|
90
99
|
New containers use `no-new-privileges` and the default bridge network unless
|
|
91
100
|
the operator selects another local bridge network or `none`.
|
|
@@ -180,17 +189,16 @@ token = jwt.encode(
|
|
|
180
189
|
assert (await auth.principal(f"Bearer {token}")).subject == "laptop"
|
|
181
190
|
```
|
|
182
191
|
|
|
183
|
-
`--jwt-query-token`
|
|
184
|
-
|
|
192
|
+
`--jwt-query-token` accepts the `token` query argument if the `Authorization`
|
|
193
|
+
header is empty or missing.
|
|
185
194
|
|
|
186
195
|
```
|
|
187
196
|
https://docker.example.com/mcp?token=<token>
|
|
188
197
|
```
|
|
189
198
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
argument in the aiohttp access log, which writes `token=[REDACTED]`.
|
|
199
|
+
A nonempty header takes precedence. The option is off by default because
|
|
200
|
+
the URL can carry credentials into browser history, saved client settings,
|
|
201
|
+
and logs that keep the query. The aiohttp access log writes `token=[REDACTED]`.
|
|
194
202
|
|
|
195
203
|
A token expires, and the server rejects one without `exp`. Revocation is
|
|
196
204
|
collective: replace the key and restart the server. This is a credential on
|
|
@@ -211,15 +219,14 @@ start a new one.
|
|
|
211
219
|
| Tool | Does |
|
|
212
220
|
| --- | --- |
|
|
213
221
|
| `containers` | List containers, filtered by name and by whether they run |
|
|
214
|
-
| `container` | One container in full: health, exit code, restarts, mounts, Compose service |
|
|
215
222
|
| `logs` | What it wrote, dated, with a cursor for reading only what is new |
|
|
216
|
-
| `read` | One file out of it -- running or not, and with no shell in the image |
|
|
217
223
|
| `images` | Images with sizes, and what still holds each one |
|
|
218
224
|
| `networks`, `volumes` | What is attached, and what mounts what |
|
|
219
225
|
| `events` | What the daemon did lately: started, died, removed |
|
|
220
226
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
221
|
-
| `info` | Which daemon this is, its version, and how much it holds |
|
|
222
227
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
228
|
+
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
229
|
+
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
223
230
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
224
231
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
225
232
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
@@ -227,10 +234,43 @@ start a new one.
|
|
|
227
234
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
228
235
|
| `pull` | Download an image, reporting progress |
|
|
229
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
|
+
|
|
255
|
+
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
256
|
+
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
257
|
+
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
258
|
+
`overwrite=true` to replace an existing tag. Read `/AGENTS.md` from a new
|
|
259
|
+
container before using the image. The image keeps environment values and files
|
|
260
|
+
that may contain credentials. Mounted volume data is excluded.
|
|
261
|
+
|
|
262
|
+
The shared SQLite state file coordinates concurrent MCP operations on the same
|
|
263
|
+
container or image tag. A reservation can last up to one hour after a timeout
|
|
264
|
+
or interrupted request. Direct commands to the Docker daemon bypass these reservations.
|
|
265
|
+
|
|
230
266
|
Resources: `docker://info`, `docker://containers`,
|
|
231
267
|
`docker://containers/{name}`, `docker://containers/{name}/logs`,
|
|
232
268
|
`docker://images`.
|
|
233
269
|
|
|
270
|
+
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
271
|
+
seconds and `docker://containers/{name}` for 5 seconds. File and log reads
|
|
272
|
+
have a cache lifetime of zero.
|
|
273
|
+
|
|
234
274
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
235
275
|
space. Container and image names are suggested while either is filled in.
|
|
236
276
|
|
|
@@ -296,7 +336,7 @@ try:
|
|
|
296
336
|
Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
|
|
297
337
|
client,
|
|
298
338
|
)
|
|
299
|
-
assert {"containers", "logs", "
|
|
339
|
+
assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
|
|
300
340
|
finally:
|
|
301
341
|
await client.close()
|
|
302
342
|
```
|
|
@@ -47,6 +47,15 @@ allowed_origin = ["https://docker.example.com"]
|
|
|
47
47
|
DOCKER_TINY_MCP_ALLOWED_ORIGIN='["https://docker.example.com"]' uv run docker-tiny-mcp
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
Open `/console` to browse the MCP catalogue. Clients on MCP `2025-11-25` or
|
|
51
|
+
`2026-07-28` receive light and dark icons for the server and its catalogue entries.
|
|
52
|
+
|
|
53
|
+
For an HTTP client that lacks native prompts, add `prompts=resource` to the
|
|
54
|
+
endpoint URL. For a client that can only call tools, add `resources=tool` to
|
|
55
|
+
list and read resources and prompts with `mcp_resources_list` and
|
|
56
|
+
`mcp_resources_read`. Over stdio, use `--stdio-prompts resource` or
|
|
57
|
+
`--stdio-resources tool` respectively.
|
|
58
|
+
|
|
50
59
|
## Unprivileged mode
|
|
51
60
|
|
|
52
61
|
Enable runtime checks for host access with `--unprivileged`:
|
|
@@ -70,8 +79,8 @@ For example, call `create` with:
|
|
|
70
79
|
{"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
|
|
71
80
|
```
|
|
72
81
|
|
|
73
|
-
Before
|
|
74
|
-
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,
|
|
75
84
|
shared host namespaces, custom runtimes and relaxed security settings.
|
|
76
85
|
New containers use `no-new-privileges` and the default bridge network unless
|
|
77
86
|
the operator selects another local bridge network or `none`.
|
|
@@ -166,17 +175,16 @@ token = jwt.encode(
|
|
|
166
175
|
assert (await auth.principal(f"Bearer {token}")).subject == "laptop"
|
|
167
176
|
```
|
|
168
177
|
|
|
169
|
-
`--jwt-query-token`
|
|
170
|
-
|
|
178
|
+
`--jwt-query-token` accepts the `token` query argument if the `Authorization`
|
|
179
|
+
header is empty or missing.
|
|
171
180
|
|
|
172
181
|
```
|
|
173
182
|
https://docker.example.com/mcp?token=<token>
|
|
174
183
|
```
|
|
175
184
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
argument in the aiohttp access log, which writes `token=[REDACTED]`.
|
|
185
|
+
A nonempty header takes precedence. The option is off by default because
|
|
186
|
+
the URL can carry credentials into browser history, saved client settings,
|
|
187
|
+
and logs that keep the query. The aiohttp access log writes `token=[REDACTED]`.
|
|
180
188
|
|
|
181
189
|
A token expires, and the server rejects one without `exp`. Revocation is
|
|
182
190
|
collective: replace the key and restart the server. This is a credential on
|
|
@@ -197,15 +205,14 @@ start a new one.
|
|
|
197
205
|
| Tool | Does |
|
|
198
206
|
| --- | --- |
|
|
199
207
|
| `containers` | List containers, filtered by name and by whether they run |
|
|
200
|
-
| `container` | One container in full: health, exit code, restarts, mounts, Compose service |
|
|
201
208
|
| `logs` | What it wrote, dated, with a cursor for reading only what is new |
|
|
202
|
-
| `read` | One file out of it -- running or not, and with no shell in the image |
|
|
203
209
|
| `images` | Images with sizes, and what still holds each one |
|
|
204
210
|
| `networks`, `volumes` | What is attached, and what mounts what |
|
|
205
211
|
| `events` | What the daemon did lately: started, died, removed |
|
|
206
212
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
207
|
-
| `info` | Which daemon this is, its version, and how much it holds |
|
|
208
213
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
214
|
+
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
215
|
+
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
209
216
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
210
217
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
211
218
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
@@ -213,10 +220,43 @@ start a new one.
|
|
|
213
220
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
214
221
|
| `pull` | Download an image, reporting progress |
|
|
215
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
|
+
|
|
241
|
+
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
242
|
+
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
243
|
+
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
244
|
+
`overwrite=true` to replace an existing tag. Read `/AGENTS.md` from a new
|
|
245
|
+
container before using the image. The image keeps environment values and files
|
|
246
|
+
that may contain credentials. Mounted volume data is excluded.
|
|
247
|
+
|
|
248
|
+
The shared SQLite state file coordinates concurrent MCP operations on the same
|
|
249
|
+
container or image tag. A reservation can last up to one hour after a timeout
|
|
250
|
+
or interrupted request. Direct commands to the Docker daemon bypass these reservations.
|
|
251
|
+
|
|
216
252
|
Resources: `docker://info`, `docker://containers`,
|
|
217
253
|
`docker://containers/{name}`, `docker://containers/{name}/logs`,
|
|
218
254
|
`docker://images`.
|
|
219
255
|
|
|
256
|
+
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
257
|
+
seconds and `docker://containers/{name}` for 5 seconds. File and log reads
|
|
258
|
+
have a cache lifetime of zero.
|
|
259
|
+
|
|
220
260
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
221
261
|
space. Container and image names are suggested while either is filled in.
|
|
222
262
|
|
|
@@ -282,7 +322,7 @@ try:
|
|
|
282
322
|
Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
|
|
283
323
|
client,
|
|
284
324
|
)
|
|
285
|
-
assert {"containers", "logs", "
|
|
325
|
+
assert {"containers", "logs", "exec", "write", "create"} <= set(registry.tools)
|
|
286
326
|
finally:
|
|
287
327
|
await client.close()
|
|
288
328
|
```
|
|
@@ -8,46 +8,26 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
import asyncio
|
|
10
10
|
import logging
|
|
11
|
-
from dataclasses import dataclass
|
|
12
11
|
from pathlib import Path
|
|
13
|
-
from typing import
|
|
12
|
+
from typing import Literal
|
|
14
13
|
|
|
15
14
|
import argclass
|
|
16
15
|
from aiodocker import Docker
|
|
17
16
|
from aiohttp import web
|
|
18
|
-
from aiohttp_tiny_mcp import Endpoint,
|
|
19
|
-
from aiohttp_tiny_mcp.auth import Authorization,
|
|
17
|
+
from aiohttp_tiny_mcp import CacheHint, Endpoint, Icons, Registry, run_stdio
|
|
18
|
+
from aiohttp_tiny_mcp.auth import Authorization, Header, Query
|
|
20
19
|
from aiohttp_tiny_mcp.auth.jwt import HMACJWTVerifier
|
|
21
20
|
from aiohttp_tiny_mcp.console import Console
|
|
22
21
|
from aiohttp_tiny_mcp.storage.sqlite import SqliteHub, SqliteSessionStore, SqliteStorage
|
|
23
22
|
|
|
24
23
|
from .consent import LEVELS, Policy
|
|
25
24
|
from .events import watch
|
|
25
|
+
from .models import DEFAULT_CREATE_LIMITS, CreateLimits
|
|
26
26
|
from .server import build
|
|
27
27
|
|
|
28
28
|
log = logging.getLogger("docker_tiny_mcp")
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
@dataclass(frozen=True)
|
|
32
|
-
class QueryToken(Authorization):
|
|
33
|
-
"""Bearer authentication that also reads the `token` query argument.
|
|
34
|
-
|
|
35
|
-
A client that cannot send a header sends the token in the URL instead. The
|
|
36
|
-
URL is then a credential: it reaches browser history, the client's saved
|
|
37
|
-
settings and every log that keeps the query. The header wins where both
|
|
38
|
-
are present.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
query: bool = False
|
|
42
|
-
|
|
43
|
-
async def authenticate(self, request: web.Request) -> Principal:
|
|
44
|
-
if self.query and "Authorization" not in request.headers:
|
|
45
|
-
supplied = request.query.get("token", "")
|
|
46
|
-
if supplied:
|
|
47
|
-
return await self.principal(f"Bearer {supplied}")
|
|
48
|
-
return await super().authenticate(request)
|
|
49
|
-
|
|
50
|
-
|
|
51
31
|
class JWT(argclass.Group):
|
|
52
32
|
"""HS256 JWT authentication with a pre-shared key."""
|
|
53
33
|
|
|
@@ -73,9 +53,9 @@ class JWT(argclass.Group):
|
|
|
73
53
|
default=False,
|
|
74
54
|
action=argclass.Actions.STORE_TRUE,
|
|
75
55
|
help=(
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
56
|
+
"Read the 'token' query argument if the Authorization header is empty or missing. "
|
|
57
|
+
"The access log masks that argument. The URL still reaches browser history "
|
|
58
|
+
"and client settings."
|
|
79
59
|
),
|
|
80
60
|
)
|
|
81
61
|
|
|
@@ -99,10 +79,24 @@ class Parser(argclass.Parser):
|
|
|
99
79
|
default="",
|
|
100
80
|
help="Fix the container network and disable network management tools.",
|
|
101
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
|
+
)
|
|
102
86
|
stdio: bool = argclass.Argument(
|
|
103
87
|
default=False,
|
|
104
88
|
help="Talk over standard input and output instead of listening on a port.",
|
|
105
89
|
)
|
|
90
|
+
stdio_resources: Literal["native", "tool"] = argclass.Argument(
|
|
91
|
+
default="native",
|
|
92
|
+
choices=("native", "tool"),
|
|
93
|
+
help="Select native resources or resource tools for stdio clients.",
|
|
94
|
+
)
|
|
95
|
+
stdio_prompts: Literal["native", "resource"] = argclass.Argument(
|
|
96
|
+
default="native",
|
|
97
|
+
choices=("native", "resource"),
|
|
98
|
+
help="Add prompts to the resource catalogue for stdio clients.",
|
|
99
|
+
)
|
|
106
100
|
jwt = JWT(
|
|
107
101
|
title="JWT authentication",
|
|
108
102
|
description="Verify an HS256 JWT on every HTTP request. Without a key, nothing is asked.",
|
|
@@ -164,25 +158,32 @@ def authentication(parser: Parser) -> Authorization | None:
|
|
|
164
158
|
if not parser.jwt.audience:
|
|
165
159
|
raise SystemExit("--jwt-audience is required with a pre-shared key")
|
|
166
160
|
verifier = HMACJWTVerifier(key, issuer=parser.jwt.issuer, audience=parser.jwt.audience)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return QueryToken(
|
|
171
|
-
cast(TokenVerifier, verifier), resource=parser.jwt.audience, query=parser.jwt.query_token
|
|
172
|
-
)
|
|
161
|
+
header = Header("Bearer")
|
|
162
|
+
sources = (header, Query("token")) if parser.jwt.query_token else (header,)
|
|
163
|
+
return Authorization(verifier, resource=parser.jwt.audience, sources=sources)
|
|
173
164
|
|
|
174
165
|
|
|
175
166
|
def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
176
167
|
"""Build the server from settings, independently of command-line parsing."""
|
|
168
|
+
create_limits = CreateLimits(max_shm_size=parser.max_shm_size)
|
|
177
169
|
storage = SqliteStorage(parser.state)
|
|
178
170
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
171
|
+
catalogue = CacheHint(cache_ttl=60, scope="private")
|
|
179
172
|
registry = Registry(
|
|
180
173
|
"docker",
|
|
181
174
|
"0.1.0",
|
|
175
|
+
icons=[Icons.BOX],
|
|
176
|
+
website_url="https://github.com/mosquito/docker-tiny-mcp",
|
|
182
177
|
hub=SqliteHub(storage),
|
|
183
178
|
session_store=SqliteSessionStore(storage),
|
|
184
179
|
session_ttl_seconds=parser.session_ttl,
|
|
185
180
|
auth=authentication(parser),
|
|
181
|
+
cache_hints={
|
|
182
|
+
"tools/list": catalogue,
|
|
183
|
+
"prompts/list": catalogue,
|
|
184
|
+
"resources/list": catalogue,
|
|
185
|
+
"resources/templates/list": catalogue,
|
|
186
|
+
},
|
|
186
187
|
)
|
|
187
188
|
return (
|
|
188
189
|
build(
|
|
@@ -191,6 +192,7 @@ def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
|
191
192
|
Policy(parser.confirm),
|
|
192
193
|
unprivileged=parser.unprivileged,
|
|
193
194
|
network=parser.network,
|
|
195
|
+
create_limits=create_limits,
|
|
194
196
|
),
|
|
195
197
|
storage,
|
|
196
198
|
client,
|
|
@@ -254,7 +256,7 @@ async def stdio(parser: Parser) -> None:
|
|
|
254
256
|
log.warning("the pre-shared key authenticates HTTP requests only; stdio ignores it")
|
|
255
257
|
tasks = await background(registry, storage, client)
|
|
256
258
|
try:
|
|
257
|
-
await run_stdio(registry)
|
|
259
|
+
await run_stdio(registry, resources=parser.stdio_resources, prompts=parser.stdio_prompts)
|
|
258
260
|
finally:
|
|
259
261
|
for task in tasks:
|
|
260
262
|
task.cancel()
|
|
@@ -16,7 +16,7 @@ from aiohttp_tiny_mcp.storage.sessions import DATA_KEY, Session
|
|
|
16
16
|
|
|
17
17
|
CONSENT_KEY = "consent"
|
|
18
18
|
|
|
19
|
-
DESTROYS = frozenset({"exec", "prune", "remove", "remove_image"})
|
|
19
|
+
DESTROYS = frozenset({"exec", "overwrite_image", "prune", "remove", "remove_image"})
|
|
20
20
|
|
|
21
21
|
LEVELS = ("never", "destructive", "changes")
|
|
22
22
|
|
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from asyncio import CancelledError, TimeoutError
|
|
6
|
+
from collections.abc import AsyncIterator
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
5
8
|
from datetime import datetime, timezone
|
|
9
|
+
from time import monotonic
|
|
6
10
|
from typing import Any
|
|
7
11
|
|
|
8
12
|
from aiodocker import Docker
|
|
9
13
|
from aiodocker.containers import DockerContainer
|
|
10
14
|
from aiodocker.exceptions import DockerError
|
|
15
|
+
from aiohttp_tiny_mcp.storage.sessions import SessionStore
|
|
11
16
|
|
|
12
|
-
from docker_tiny_mcp.errors import NotFound, clear
|
|
17
|
+
from docker_tiny_mcp.errors import Conflict, NotFound, Unreachable, clear
|
|
13
18
|
from docker_tiny_mcp.models import short
|
|
14
19
|
|
|
20
|
+
# shortcut: Reservations expire after one hour. Renew them for longer operations.
|
|
21
|
+
RESERVATION_TTL_SECONDS = 3600
|
|
22
|
+
|
|
15
23
|
|
|
16
24
|
def name_of(raw: Any) -> str:
|
|
17
25
|
names = raw.get("Names") or []
|
|
@@ -69,3 +77,23 @@ async def state_of(container: DockerContainer) -> dict[str, Any]:
|
|
|
69
77
|
async def images(client: Docker) -> list[dict[str, Any]]:
|
|
70
78
|
async with clear("listing images"):
|
|
71
79
|
return [dict(item) for item in await client.images.list()]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@asynccontextmanager
|
|
83
|
+
async def reserve(store: SessionStore, kind: str, name: str) -> AsyncIterator[None]:
|
|
84
|
+
"""Exclude concurrent writes across workers that share a session store."""
|
|
85
|
+
# A line break keeps this key out of MCP session headers.
|
|
86
|
+
key = f"docker-tiny-mcp\n{kind}:{name}"
|
|
87
|
+
expires = monotonic() + RESERVATION_TTL_SECONDS
|
|
88
|
+
if not await store.create(key, {}, ttl_seconds=RESERVATION_TTL_SECONDS):
|
|
89
|
+
raise Conflict(f"another operation is in progress for {kind} {name}")
|
|
90
|
+
release = True
|
|
91
|
+
try:
|
|
92
|
+
yield
|
|
93
|
+
except (CancelledError, TimeoutError, Unreachable):
|
|
94
|
+
# Keep the reservation if the daemon can still finish the operation.
|
|
95
|
+
release = False
|
|
96
|
+
raise
|
|
97
|
+
finally:
|
|
98
|
+
if release and monotonic() < expires:
|
|
99
|
+
await store.delete(key)
|
|
@@ -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(
|
|
@@ -142,9 +154,11 @@ class FixedNetworkCreateRequest(CreateOptions):
|
|
|
142
154
|
model_config = ConfigDict(extra="forbid")
|
|
143
155
|
|
|
144
156
|
|
|
157
|
+
VOLUME_NAME = r"[a-zA-Z0-9][a-zA-Z0-9_.-]*"
|
|
158
|
+
|
|
145
159
|
NamedVolume = Annotated[
|
|
146
160
|
str,
|
|
147
|
-
StringConstraints(pattern=
|
|
161
|
+
StringConstraints(pattern=rf"^{VOLUME_NAME}:/[^:\x00\r\n]+(?::ro|:rw)?$"),
|
|
148
162
|
]
|
|
149
163
|
|
|
150
164
|
|
|
@@ -158,6 +172,13 @@ class UnprivilegedCreateRequest(FixedNetworkCreateRequest):
|
|
|
158
172
|
)
|
|
159
173
|
|
|
160
174
|
|
|
175
|
+
class CreateVolumeRequest(BaseModel):
|
|
176
|
+
model_config = ConfigDict(extra="forbid")
|
|
177
|
+
|
|
178
|
+
name: str = Field(pattern=rf"^{VOLUME_NAME}$", description="Name of the Docker volume.")
|
|
179
|
+
description: str = Field(min_length=1, description="What the volume holds or is for.")
|
|
180
|
+
|
|
181
|
+
|
|
161
182
|
class WaitRequest(ContainerRef):
|
|
162
183
|
state: Literal["running", "exited", "healthy"] = Field(
|
|
163
184
|
description="What to wait for it to become."
|
|
@@ -185,6 +206,23 @@ class PullRequest(BaseModel):
|
|
|
185
206
|
image: str = Field(description='Image to pull, such as "redis:7-alpine".')
|
|
186
207
|
|
|
187
208
|
|
|
209
|
+
class CommitRequest(ContainerRef):
|
|
210
|
+
model_config = ConfigDict(extra="forbid")
|
|
211
|
+
|
|
212
|
+
image: str = Field(
|
|
213
|
+
pattern=r"^[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*:[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$",
|
|
214
|
+
description='Repository and tag, such as "dev-env:v1". The server adds "localhost/".',
|
|
215
|
+
)
|
|
216
|
+
description: str = Field(min_length=1, description="What this image contains and is for.")
|
|
217
|
+
overwrite: bool = Field(False, description="Allow replacing an existing tag.")
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class Committed(BaseModel):
|
|
221
|
+
id: str
|
|
222
|
+
image: str
|
|
223
|
+
note: str
|
|
224
|
+
|
|
225
|
+
|
|
188
226
|
class PruneRequest(BaseModel):
|
|
189
227
|
what: Literal["containers", "images", "volumes", "networks"] = Field(
|
|
190
228
|
description="Which kind of unused thing to remove."
|
|
@@ -249,6 +287,8 @@ class ContainerDetail(BaseModel):
|
|
|
249
287
|
command: str = Field(description="What it runs, quoted as a shell would.")
|
|
250
288
|
restart_count: int
|
|
251
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.")
|
|
252
292
|
health: str | None = Field(None, description="healthy, unhealthy, starting, or absent.")
|
|
253
293
|
exit_code: int | None = Field(None, description="Set once it has stopped.")
|
|
254
294
|
error: str | None = None
|
|
@@ -268,6 +308,7 @@ class Image(BaseModel):
|
|
|
268
308
|
tags: list[str]
|
|
269
309
|
size_mb: float
|
|
270
310
|
created: str = Field(description="When it was built, ISO-8601.")
|
|
311
|
+
description: str = ""
|
|
271
312
|
used_by: list[str] = Field(
|
|
272
313
|
default_factory=list,
|
|
273
314
|
description="Containers holding it, running or not. Empty means safe to remove.",
|
|
@@ -299,6 +340,7 @@ class Volume(BaseModel):
|
|
|
299
340
|
driver: str
|
|
300
341
|
mountpoint: str
|
|
301
342
|
created: str | None = None
|
|
343
|
+
description: str = ""
|
|
302
344
|
used_by: list[str] = Field(
|
|
303
345
|
default_factory=list, description="Containers mounting it. Empty means safe to remove."
|
|
304
346
|
)
|
|
@@ -309,6 +351,11 @@ class Volumes(BaseModel):
|
|
|
309
351
|
total: int
|
|
310
352
|
|
|
311
353
|
|
|
354
|
+
class CreatedVolume(BaseModel):
|
|
355
|
+
name: str
|
|
356
|
+
description: str
|
|
357
|
+
|
|
358
|
+
|
|
312
359
|
class LogLine(BaseModel):
|
|
313
360
|
"""Internal timestamped stream line used to merge stdout and stderr."""
|
|
314
361
|
|
|
@@ -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
|
-
"
|
|
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,
|
|
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."
|