docker-tiny-mcp 0.1.1__tar.gz → 0.2.0__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/README.md → docker_tiny_mcp-0.2.0/PKG-INFO +45 -6
- docker_tiny_mcp-0.1.1/PKG-INFO → docker_tiny_mcp-0.2.0/README.md +31 -20
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/__main__.py +29 -34
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/consent.py +1 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/daemon.py +29 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/models.py +34 -1
- docker_tiny_mcp-0.2.0/docker_tiny_mcp/server.py +161 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/__init__.py +4 -0
- docker_tiny_mcp-0.2.0/docker_tiny_mcp/tools/commit.py +76 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/create.py +2 -1
- docker_tiny_mcp-0.2.0/docker_tiny_mcp/tools/create_volume.py +34 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/images.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/restart.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/start.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/volumes.py +3 -2
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/write.py +2 -1
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/pyproject.toml +2 -2
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/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-0.2.0}/LICENSE +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/__init__.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/errors.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/events.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/prompts.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/__init__.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/containers.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/images.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/info.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/templates/__init__.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/templates/container.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/templates/logs.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/safety.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/container.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/containers.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/events.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/exec.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/info.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/logs.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/networks.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/prune.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/pull.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/read.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/remove.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/remove_image.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/results.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/stats.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/stop.py +0 -0
- {docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/tools/wait.py +0 -0
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docker-tiny-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: An MCP server for Docker, over aiohttp-tiny-mcp.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: aiodocker>=0.24
|
|
8
|
+
Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0
|
|
9
|
+
Requires-Dist: argclass>=1.0
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Project-URL: Repository, https://github.com/mosquito/docker-tiny-mcp
|
|
12
|
+
Project-URL: Issues, https://github.com/mosquito/docker-tiny-mcp/issues
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
1
15
|
# docker-tiny-mcp
|
|
2
16
|
|
|
3
17
|
An MCP server for Docker, built on
|
|
@@ -47,6 +61,15 @@ allowed_origin = ["https://docker.example.com"]
|
|
|
47
61
|
DOCKER_TINY_MCP_ALLOWED_ORIGIN='["https://docker.example.com"]' uv run docker-tiny-mcp
|
|
48
62
|
```
|
|
49
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
|
+
|
|
50
73
|
## Unprivileged mode
|
|
51
74
|
|
|
52
75
|
Enable runtime checks for host access with `--unprivileged`:
|
|
@@ -166,17 +189,16 @@ token = jwt.encode(
|
|
|
166
189
|
assert (await auth.principal(f"Bearer {token}")).subject == "laptop"
|
|
167
190
|
```
|
|
168
191
|
|
|
169
|
-
`--jwt-query-token`
|
|
170
|
-
|
|
192
|
+
`--jwt-query-token` accepts the `token` query argument if the `Authorization`
|
|
193
|
+
header is empty or missing.
|
|
171
194
|
|
|
172
195
|
```
|
|
173
196
|
https://docker.example.com/mcp?token=<token>
|
|
174
197
|
```
|
|
175
198
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
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]`.
|
|
180
202
|
|
|
181
203
|
A token expires, and the server rejects one without `exp`. Revocation is
|
|
182
204
|
collective: replace the key and restart the server. This is a credential on
|
|
@@ -206,6 +228,8 @@ start a new one.
|
|
|
206
228
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
207
229
|
| `info` | Which daemon this is, its version, and how much it holds |
|
|
208
230
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
231
|
+
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
232
|
+
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
209
233
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
210
234
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
211
235
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
@@ -213,10 +237,25 @@ start a new one.
|
|
|
213
237
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
214
238
|
| `pull` | Download an image, reporting progress |
|
|
215
239
|
|
|
240
|
+
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
241
|
+
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
242
|
+
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
243
|
+
`overwrite=true` to replace an existing tag. Read `/AGENTS.md` from a new
|
|
244
|
+
container before using the image. The image keeps environment values and files
|
|
245
|
+
that may contain credentials. Mounted volume data is excluded.
|
|
246
|
+
|
|
247
|
+
The shared SQLite state file coordinates concurrent MCP operations on the same
|
|
248
|
+
container or image tag. A reservation can last up to one hour after a timeout
|
|
249
|
+
or interrupted request. Direct commands to the Docker daemon bypass these reservations.
|
|
250
|
+
|
|
216
251
|
Resources: `docker://info`, `docker://containers`,
|
|
217
252
|
`docker://containers/{name}`, `docker://containers/{name}/logs`,
|
|
218
253
|
`docker://images`.
|
|
219
254
|
|
|
255
|
+
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
256
|
+
seconds and `docker://containers/{name}` for 5 seconds. To get current state
|
|
257
|
+
immediately, call the `container` tool. Log reads have a cache lifetime of zero.
|
|
258
|
+
|
|
220
259
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
221
260
|
space. Container and image names are suggested while either is filled in.
|
|
222
261
|
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: docker-tiny-mcp
|
|
3
|
-
Version: 0.1.1
|
|
4
|
-
Summary: An MCP server for Docker, over aiohttp-tiny-mcp.
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Dist: aiodocker>=0.24
|
|
8
|
-
Requires-Dist: aiohttp-tiny-mcp[sqlite,jwt]>=0.8.2
|
|
9
|
-
Requires-Dist: argclass>=1.0
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Project-URL: Repository, https://github.com/mosquito/docker-tiny-mcp
|
|
12
|
-
Project-URL: Issues, https://github.com/mosquito/docker-tiny-mcp/issues
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
|
|
15
1
|
# docker-tiny-mcp
|
|
16
2
|
|
|
17
3
|
An MCP server for Docker, built on
|
|
@@ -61,6 +47,15 @@ allowed_origin = ["https://docker.example.com"]
|
|
|
61
47
|
DOCKER_TINY_MCP_ALLOWED_ORIGIN='["https://docker.example.com"]' uv run docker-tiny-mcp
|
|
62
48
|
```
|
|
63
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
|
+
|
|
64
59
|
## Unprivileged mode
|
|
65
60
|
|
|
66
61
|
Enable runtime checks for host access with `--unprivileged`:
|
|
@@ -180,17 +175,16 @@ token = jwt.encode(
|
|
|
180
175
|
assert (await auth.principal(f"Bearer {token}")).subject == "laptop"
|
|
181
176
|
```
|
|
182
177
|
|
|
183
|
-
`--jwt-query-token`
|
|
184
|
-
|
|
178
|
+
`--jwt-query-token` accepts the `token` query argument if the `Authorization`
|
|
179
|
+
header is empty or missing.
|
|
185
180
|
|
|
186
181
|
```
|
|
187
182
|
https://docker.example.com/mcp?token=<token>
|
|
188
183
|
```
|
|
189
184
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
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]`.
|
|
194
188
|
|
|
195
189
|
A token expires, and the server rejects one without `exp`. Revocation is
|
|
196
190
|
collective: replace the key and restart the server. This is a credential on
|
|
@@ -220,6 +214,8 @@ start a new one.
|
|
|
220
214
|
| `stats` | Processor, memory, network and disk, as rates |
|
|
221
215
|
| `info` | Which daemon this is, its version, and how much it holds |
|
|
222
216
|
| `create` | Make one and start it -- `docker run`, with the flags named |
|
|
217
|
+
| `create_volume` | Create a local named volume with a description shown by `volumes` |
|
|
218
|
+
| `commit` | Save a stopped container as a `localhost/` image with a description |
|
|
223
219
|
| `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
|
|
224
220
|
| `wait` | Hold until it is running, stopped, or healthy |
|
|
225
221
|
| `exec` | Run a command inside it -- **asks unless the command only reads** |
|
|
@@ -227,10 +223,25 @@ start a new one.
|
|
|
227
223
|
| `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
|
|
228
224
|
| `pull` | Download an image, reporting progress |
|
|
229
225
|
|
|
226
|
+
To reuse a prepared container, write `/AGENTS.md` at its root, stop the
|
|
227
|
+
container and call `commit` with an image name such as `dev-env:v1` and a
|
|
228
|
+
description. The image appears in `images` as `localhost/dev-env:v1`. Set
|
|
229
|
+
`overwrite=true` to replace an existing tag. Read `/AGENTS.md` from a new
|
|
230
|
+
container before using the image. The image keeps environment values and files
|
|
231
|
+
that may contain credentials. Mounted volume data is excluded.
|
|
232
|
+
|
|
233
|
+
The shared SQLite state file coordinates concurrent MCP operations on the same
|
|
234
|
+
container or image tag. A reservation can last up to one hour after a timeout
|
|
235
|
+
or interrupted request. Direct commands to the Docker daemon bypass these reservations.
|
|
236
|
+
|
|
230
237
|
Resources: `docker://info`, `docker://containers`,
|
|
231
238
|
`docker://containers/{name}`, `docker://containers/{name}/logs`,
|
|
232
239
|
`docker://images`.
|
|
233
240
|
|
|
241
|
+
On MCP `2026-07-28`, clients may privately cache catalogue listings for 60
|
|
242
|
+
seconds and `docker://containers/{name}` for 5 seconds. To get current state
|
|
243
|
+
immediately, call the `container` tool. Log reads have a cache lifetime of zero.
|
|
244
|
+
|
|
234
245
|
Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
|
|
235
246
|
space. Container and image names are suggested while either is filled in.
|
|
236
247
|
|
|
@@ -8,15 +8,14 @@ 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
|
|
@@ -28,26 +27,6 @@ from .server import build
|
|
|
28
27
|
log = logging.getLogger("docker_tiny_mcp")
|
|
29
28
|
|
|
30
29
|
|
|
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
30
|
class JWT(argclass.Group):
|
|
52
31
|
"""HS256 JWT authentication with a pre-shared key."""
|
|
53
32
|
|
|
@@ -73,9 +52,9 @@ class JWT(argclass.Group):
|
|
|
73
52
|
default=False,
|
|
74
53
|
action=argclass.Actions.STORE_TRUE,
|
|
75
54
|
help=(
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
55
|
+
"Read the 'token' query argument if the Authorization header is empty or missing. "
|
|
56
|
+
"The access log masks that argument. The URL still reaches browser history "
|
|
57
|
+
"and client settings."
|
|
79
58
|
),
|
|
80
59
|
)
|
|
81
60
|
|
|
@@ -103,6 +82,16 @@ class Parser(argclass.Parser):
|
|
|
103
82
|
default=False,
|
|
104
83
|
help="Talk over standard input and output instead of listening on a port.",
|
|
105
84
|
)
|
|
85
|
+
stdio_resources: Literal["native", "tool"] = argclass.Argument(
|
|
86
|
+
default="native",
|
|
87
|
+
choices=("native", "tool"),
|
|
88
|
+
help="Select native resources or resource tools for stdio clients.",
|
|
89
|
+
)
|
|
90
|
+
stdio_prompts: Literal["native", "resource"] = argclass.Argument(
|
|
91
|
+
default="native",
|
|
92
|
+
choices=("native", "resource"),
|
|
93
|
+
help="Add prompts to the resource catalogue for stdio clients.",
|
|
94
|
+
)
|
|
106
95
|
jwt = JWT(
|
|
107
96
|
title="JWT authentication",
|
|
108
97
|
description="Verify an HS256 JWT on every HTTP request. Without a key, nothing is asked.",
|
|
@@ -164,25 +153,31 @@ def authentication(parser: Parser) -> Authorization | None:
|
|
|
164
153
|
if not parser.jwt.audience:
|
|
165
154
|
raise SystemExit("--jwt-audience is required with a pre-shared key")
|
|
166
155
|
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
|
-
)
|
|
156
|
+
header = Header("Bearer")
|
|
157
|
+
sources = (header, Query("token")) if parser.jwt.query_token else (header,)
|
|
158
|
+
return Authorization(verifier, resource=parser.jwt.audience, sources=sources)
|
|
173
159
|
|
|
174
160
|
|
|
175
161
|
def assemble(parser: Parser) -> tuple[Registry, SqliteStorage, Docker]:
|
|
176
162
|
"""Build the server from settings, independently of command-line parsing."""
|
|
177
163
|
storage = SqliteStorage(parser.state)
|
|
178
164
|
client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
|
|
165
|
+
catalogue = CacheHint(cache_ttl=60, scope="private")
|
|
179
166
|
registry = Registry(
|
|
180
167
|
"docker",
|
|
181
168
|
"0.1.0",
|
|
169
|
+
icons=[Icons.BOX],
|
|
170
|
+
website_url="https://github.com/mosquito/docker-tiny-mcp",
|
|
182
171
|
hub=SqliteHub(storage),
|
|
183
172
|
session_store=SqliteSessionStore(storage),
|
|
184
173
|
session_ttl_seconds=parser.session_ttl,
|
|
185
174
|
auth=authentication(parser),
|
|
175
|
+
cache_hints={
|
|
176
|
+
"tools/list": catalogue,
|
|
177
|
+
"prompts/list": catalogue,
|
|
178
|
+
"resources/list": catalogue,
|
|
179
|
+
"resources/templates/list": catalogue,
|
|
180
|
+
},
|
|
186
181
|
)
|
|
187
182
|
return (
|
|
188
183
|
build(
|
|
@@ -254,7 +249,7 @@ async def stdio(parser: Parser) -> None:
|
|
|
254
249
|
log.warning("the pre-shared key authenticates HTTP requests only; stdio ignores it")
|
|
255
250
|
tasks = await background(registry, storage, client)
|
|
256
251
|
try:
|
|
257
|
-
await run_stdio(registry)
|
|
252
|
+
await run_stdio(registry, resources=parser.stdio_resources, prompts=parser.stdio_prompts)
|
|
258
253
|
finally:
|
|
259
254
|
for task in tasks:
|
|
260
255
|
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)
|
|
@@ -142,9 +142,11 @@ class FixedNetworkCreateRequest(CreateOptions):
|
|
|
142
142
|
model_config = ConfigDict(extra="forbid")
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
VOLUME_NAME = r"[a-zA-Z0-9][a-zA-Z0-9_.-]*"
|
|
146
|
+
|
|
145
147
|
NamedVolume = Annotated[
|
|
146
148
|
str,
|
|
147
|
-
StringConstraints(pattern=
|
|
149
|
+
StringConstraints(pattern=rf"^{VOLUME_NAME}:/[^:\x00\r\n]+(?::ro|:rw)?$"),
|
|
148
150
|
]
|
|
149
151
|
|
|
150
152
|
|
|
@@ -158,6 +160,13 @@ class UnprivilegedCreateRequest(FixedNetworkCreateRequest):
|
|
|
158
160
|
)
|
|
159
161
|
|
|
160
162
|
|
|
163
|
+
class CreateVolumeRequest(BaseModel):
|
|
164
|
+
model_config = ConfigDict(extra="forbid")
|
|
165
|
+
|
|
166
|
+
name: str = Field(pattern=rf"^{VOLUME_NAME}$", description="Name of the Docker volume.")
|
|
167
|
+
description: str = Field(min_length=1, description="What the volume holds or is for.")
|
|
168
|
+
|
|
169
|
+
|
|
161
170
|
class WaitRequest(ContainerRef):
|
|
162
171
|
state: Literal["running", "exited", "healthy"] = Field(
|
|
163
172
|
description="What to wait for it to become."
|
|
@@ -185,6 +194,23 @@ class PullRequest(BaseModel):
|
|
|
185
194
|
image: str = Field(description='Image to pull, such as "redis:7-alpine".')
|
|
186
195
|
|
|
187
196
|
|
|
197
|
+
class CommitRequest(ContainerRef):
|
|
198
|
+
model_config = ConfigDict(extra="forbid")
|
|
199
|
+
|
|
200
|
+
image: str = Field(
|
|
201
|
+
pattern=r"^[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*:[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$",
|
|
202
|
+
description='Repository and tag, such as "dev-env:v1". The server adds "localhost/".',
|
|
203
|
+
)
|
|
204
|
+
description: str = Field(min_length=1, description="What this image contains and is for.")
|
|
205
|
+
overwrite: bool = Field(False, description="Allow replacing an existing tag.")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class Committed(BaseModel):
|
|
209
|
+
id: str
|
|
210
|
+
image: str
|
|
211
|
+
note: str
|
|
212
|
+
|
|
213
|
+
|
|
188
214
|
class PruneRequest(BaseModel):
|
|
189
215
|
what: Literal["containers", "images", "volumes", "networks"] = Field(
|
|
190
216
|
description="Which kind of unused thing to remove."
|
|
@@ -268,6 +294,7 @@ class Image(BaseModel):
|
|
|
268
294
|
tags: list[str]
|
|
269
295
|
size_mb: float
|
|
270
296
|
created: str = Field(description="When it was built, ISO-8601.")
|
|
297
|
+
description: str = ""
|
|
271
298
|
used_by: list[str] = Field(
|
|
272
299
|
default_factory=list,
|
|
273
300
|
description="Containers holding it, running or not. Empty means safe to remove.",
|
|
@@ -299,6 +326,7 @@ class Volume(BaseModel):
|
|
|
299
326
|
driver: str
|
|
300
327
|
mountpoint: str
|
|
301
328
|
created: str | None = None
|
|
329
|
+
description: str = ""
|
|
302
330
|
used_by: list[str] = Field(
|
|
303
331
|
default_factory=list, description="Containers mounting it. Empty means safe to remove."
|
|
304
332
|
)
|
|
@@ -309,6 +337,11 @@ class Volumes(BaseModel):
|
|
|
309
337
|
total: int
|
|
310
338
|
|
|
311
339
|
|
|
340
|
+
class CreatedVolume(BaseModel):
|
|
341
|
+
name: str
|
|
342
|
+
description: str
|
|
343
|
+
|
|
344
|
+
|
|
312
345
|
class LogLine(BaseModel):
|
|
313
346
|
"""Internal timestamped stream line used to merge stdout and stderr."""
|
|
314
347
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""Register Docker handlers, descriptions, and annotations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from aiodocker import Docker
|
|
6
|
+
from aiohttp_tiny_mcp import Hint, Icons, Registry
|
|
7
|
+
|
|
8
|
+
from . import prompts, resources, tools
|
|
9
|
+
from .consent import Policy
|
|
10
|
+
from .resources import templates
|
|
11
|
+
from .tools.create import fixed_network_create, unprivileged_create
|
|
12
|
+
from .tools.prune import prune_fixed_network
|
|
13
|
+
|
|
14
|
+
INSTRUCTIONS = (
|
|
15
|
+
"Inspect and control Docker. Start with `containers` to find what to act "
|
|
16
|
+
"on; `container`, `logs`, `read` and `stats` to understand one; `events` "
|
|
17
|
+
"for what happened before now; and `info` to confirm the daemon is "
|
|
18
|
+
"reachable and is the one you meant.\n\n"
|
|
19
|
+
"To change something: `create` makes and starts a container, `start`, "
|
|
20
|
+
"`stop` and `restart` do the obvious, `wait` holds until a container is "
|
|
21
|
+
"running or healthy, `exec` runs a command inside one, and `write` puts a "
|
|
22
|
+
"file into one. `prune`, `remove` and `remove_image` reclaim space.\n\n"
|
|
23
|
+
"Use `create_volume` to make a named volume with a description. "
|
|
24
|
+
"Check `volumes` for its description and the containers that mount it.\n\n"
|
|
25
|
+
"To save a prepared container as a `localhost/` image, write `/AGENTS.md` "
|
|
26
|
+
"at its root, then use `stop`, then `commit`. Record its base image and what "
|
|
27
|
+
"you installed, its purpose, and how to reproduce it. Include the working "
|
|
28
|
+
"directory, commands, volume names and mount paths, and environment "
|
|
29
|
+
"variable names. Keep secrets out of the file and the container. To use a "
|
|
30
|
+
"saved image, find it in `images` and read `/AGENTS.md` from a container "
|
|
31
|
+
"created from that image.\n\n"
|
|
32
|
+
"Reading never asks, and neither does a command that only reads, such as "
|
|
33
|
+
"`ls` or `cat`. What cannot be undone -- `remove`, `remove_image`, "
|
|
34
|
+
"`prune`, and a command that is not merely reading -- asks once, and the "
|
|
35
|
+
"person answering may say not to ask again."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
READS = Hint.READ_ONLY | Hint.IDEMPOTENT
|
|
39
|
+
|
|
40
|
+
WATCHES = Hint.READ_ONLY
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def build(
|
|
44
|
+
registry: Registry,
|
|
45
|
+
client: Docker,
|
|
46
|
+
policy: Policy | None = None,
|
|
47
|
+
*,
|
|
48
|
+
unprivileged: bool = False,
|
|
49
|
+
network: str | None = None,
|
|
50
|
+
) -> Registry:
|
|
51
|
+
"""Register handlers and inject the Docker client and deployment confirmation policy."""
|
|
52
|
+
registry.instructions = INSTRUCTIONS
|
|
53
|
+
registry.provide_instance(client)
|
|
54
|
+
registry.provide_instance(policy or Policy())
|
|
55
|
+
if unprivileged:
|
|
56
|
+
registry.instructions += (
|
|
57
|
+
"\n\nUnprivileged mode: host mounts and privileged containers are forbidden. "
|
|
58
|
+
"Use named local volumes for persistent data. The server selects the network."
|
|
59
|
+
)
|
|
60
|
+
if network:
|
|
61
|
+
registry.instructions += (
|
|
62
|
+
"\n\nThe network is fixed by the server; network management is disabled."
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
registry.tool(tools.containers, annotations=READS, icons=[Icons.BOX])
|
|
66
|
+
registry.tool(tools.container, annotations=READS, icons=[Icons.BOX])
|
|
67
|
+
registry.tool(tools.images, annotations=READS, icons=[Icons.LAYER_GROUP])
|
|
68
|
+
if not network:
|
|
69
|
+
registry.tool(tools.networks, annotations=READS, icons=[Icons.NETWORK_WIRED])
|
|
70
|
+
registry.tool(tools.volumes, annotations=READS, icons=[Icons.HARD_DRIVE])
|
|
71
|
+
registry.tool(tools.info, annotations=READS, icons=[Icons.CIRCLE_INFO])
|
|
72
|
+
registry.tool(tools.logs, annotations=WATCHES, icons=[Icons.FILE_LINES])
|
|
73
|
+
registry.tool(tools.stats, annotations=WATCHES, icons=[Icons.CHART_LINE])
|
|
74
|
+
registry.tool(tools.events, annotations=WATCHES, icons=[Icons.CLOCK_ROTATE_LEFT])
|
|
75
|
+
registry.tool(tools.wait, annotations=WATCHES, icons=[Icons.HOURGLASS_HALF])
|
|
76
|
+
|
|
77
|
+
if unprivileged:
|
|
78
|
+
registry.tool(
|
|
79
|
+
unprivileged_create(network),
|
|
80
|
+
name="create",
|
|
81
|
+
annotations=Hint.OPEN_WORLD,
|
|
82
|
+
icons=[Icons.PLUS],
|
|
83
|
+
)
|
|
84
|
+
registry.tool(tools.read_unprivileged, name="read", annotations=READS, icons=[Icons.FILE])
|
|
85
|
+
registry.tool(
|
|
86
|
+
tools.start_unprivileged, name="start", annotations=Hint.IDEMPOTENT, icons=[Icons.PLAY]
|
|
87
|
+
)
|
|
88
|
+
registry.tool(tools.restart_unprivileged, name="restart", icons=[Icons.ARROWS_ROTATE])
|
|
89
|
+
registry.tool(
|
|
90
|
+
tools.write_unprivileged, name="write", annotations=Hint.DESTRUCTIVE, icons=[Icons.PEN]
|
|
91
|
+
)
|
|
92
|
+
registry.tool(
|
|
93
|
+
tools.exec_unprivileged,
|
|
94
|
+
name="exec",
|
|
95
|
+
annotations=Hint.DESTRUCTIVE | Hint.OPEN_WORLD,
|
|
96
|
+
icons=[Icons.TERMINAL],
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
if network:
|
|
100
|
+
registry.tool(
|
|
101
|
+
fixed_network_create(network),
|
|
102
|
+
name="create",
|
|
103
|
+
annotations=Hint.OPEN_WORLD,
|
|
104
|
+
icons=[Icons.PLUS],
|
|
105
|
+
)
|
|
106
|
+
else:
|
|
107
|
+
registry.tool(tools.create, annotations=Hint.OPEN_WORLD, icons=[Icons.PLUS])
|
|
108
|
+
registry.tool(tools.read, annotations=READS, icons=[Icons.FILE])
|
|
109
|
+
registry.tool(tools.start, annotations=Hint.IDEMPOTENT, icons=[Icons.PLAY])
|
|
110
|
+
registry.tool(tools.restart, icons=[Icons.ARROWS_ROTATE])
|
|
111
|
+
registry.tool(tools.write, annotations=Hint.DESTRUCTIVE, icons=[Icons.PEN])
|
|
112
|
+
registry.tool(
|
|
113
|
+
tools.exec, annotations=Hint.DESTRUCTIVE | Hint.OPEN_WORLD, icons=[Icons.TERMINAL]
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
registry.tool(tools.stop, annotations=Hint.IDEMPOTENT, icons=[Icons.STOP])
|
|
117
|
+
registry.tool(tools.commit, annotations=Hint.DESTRUCTIVE, icons=[Icons.FLOPPY_DISK])
|
|
118
|
+
registry.tool(tools.create_volume, annotations=Hint.IDEMPOTENT, icons=[Icons.HARD_DRIVE])
|
|
119
|
+
registry.tool(tools.remove, annotations=Hint.DESTRUCTIVE, icons=[Icons.TRASH_CAN])
|
|
120
|
+
registry.tool(tools.remove_image, annotations=Hint.DESTRUCTIVE, icons=[Icons.TRASH_CAN])
|
|
121
|
+
if network:
|
|
122
|
+
registry.tool(
|
|
123
|
+
prune_fixed_network, name="prune", annotations=Hint.DESTRUCTIVE, icons=[Icons.BROOM]
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
registry.tool(tools.prune, annotations=Hint.DESTRUCTIVE, icons=[Icons.BROOM])
|
|
127
|
+
registry.tool(tools.pull, streaming=True, annotations=Hint.OPEN_WORLD, icons=[Icons.DOWNLOAD])
|
|
128
|
+
|
|
129
|
+
registry.resource(
|
|
130
|
+
"docker://info", resources.info, mime_type="application/json", icons=[Icons.CIRCLE_INFO]
|
|
131
|
+
)
|
|
132
|
+
registry.resource(
|
|
133
|
+
"docker://containers", resources.containers, mime_type="application/json", icons=[Icons.BOX]
|
|
134
|
+
)
|
|
135
|
+
registry.resource(
|
|
136
|
+
"docker://containers/{name}",
|
|
137
|
+
templates.container,
|
|
138
|
+
name="container",
|
|
139
|
+
mime_type="application/json",
|
|
140
|
+
icons=[Icons.BOX],
|
|
141
|
+
cache_ttl=5,
|
|
142
|
+
cache_scope="private",
|
|
143
|
+
)
|
|
144
|
+
registry.resource(
|
|
145
|
+
"docker://containers/{name}/logs",
|
|
146
|
+
templates.logs,
|
|
147
|
+
name="container-logs",
|
|
148
|
+
icons=[Icons.FILE_LINES],
|
|
149
|
+
)
|
|
150
|
+
registry.resource(
|
|
151
|
+
"docker://images", resources.images, mime_type="application/json", icons=[Icons.LAYER_GROUP]
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
registry.prompt(prompts.diagnose, title="Diagnose a container", icons=[Icons.MAGNIFYING_GLASS])
|
|
155
|
+
registry.prompt(prompts.reclaim, title="Find space to reclaim", icons=[Icons.BROOM])
|
|
156
|
+
|
|
157
|
+
registry.completions(prompts.complete)
|
|
158
|
+
return registry
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
__all__ = ["INSTRUCTIONS", "build"]
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from .commit import commit
|
|
5
6
|
from .container import container
|
|
6
7
|
from .containers import containers
|
|
7
8
|
from .create import create
|
|
9
|
+
from .create_volume import create_volume
|
|
8
10
|
from .events import events
|
|
9
11
|
from .exec import exec, exec_unprivileged
|
|
10
12
|
from .images import images
|
|
@@ -26,9 +28,11 @@ from .wait import wait
|
|
|
26
28
|
from .write import write, write_unprivileged
|
|
27
29
|
|
|
28
30
|
__all__ = [
|
|
31
|
+
"commit",
|
|
29
32
|
"container",
|
|
30
33
|
"containers",
|
|
31
34
|
"create",
|
|
35
|
+
"create_volume",
|
|
32
36
|
"events",
|
|
33
37
|
"exec",
|
|
34
38
|
"exec_unprivileged",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Store a stopped container as a local image."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from aiodocker import Docker
|
|
8
|
+
from aiodocker.containers import DockerContainer
|
|
9
|
+
from aiodocker.exceptions import DockerError
|
|
10
|
+
from aiohttp_tiny_mcp import Exchange
|
|
11
|
+
|
|
12
|
+
from docker_tiny_mcp import daemon
|
|
13
|
+
from docker_tiny_mcp.consent import Policy, confirm, refusal
|
|
14
|
+
from docker_tiny_mcp.errors import Conflict, clear
|
|
15
|
+
from docker_tiny_mcp.events import publish
|
|
16
|
+
from docker_tiny_mcp.models import CommitRequest, Committed
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def stopped_config(container: DockerContainer, name: str) -> dict[str, Any]:
|
|
20
|
+
async with clear("checking the container", subject=name):
|
|
21
|
+
raw = await container.show()
|
|
22
|
+
state = raw.get("State") or {}
|
|
23
|
+
if (
|
|
24
|
+
state.get("Status") not in ("created", "exited")
|
|
25
|
+
or state.get("Running")
|
|
26
|
+
or state.get("Paused")
|
|
27
|
+
):
|
|
28
|
+
raise Conflict(f"container {name} must be stopped. Run stop before commit.")
|
|
29
|
+
return dict(raw.get("Config") or {})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def commit(args: CommitRequest, client: Docker, ex: Exchange, policy: Policy) -> Committed:
|
|
33
|
+
"""Save a stopped container as a `localhost/` image with a description.
|
|
34
|
+
|
|
35
|
+
Write `/AGENTS.md` in the container and stop it before committing. The image
|
|
36
|
+
keeps the container's environment values and files, including any credentials.
|
|
37
|
+
Mounted volume data is excluded. An existing tag requires `overwrite=true`.
|
|
38
|
+
"""
|
|
39
|
+
image = f"localhost/{args.image}"
|
|
40
|
+
repository, tag = image.rsplit(":", 1)
|
|
41
|
+
found = await daemon.find(client, args.container)
|
|
42
|
+
action = "overwrite_image" if args.overwrite else "commit"
|
|
43
|
+
prompt = f"Save {args.container} as {image}? The image can contain secrets."
|
|
44
|
+
if args.overwrite:
|
|
45
|
+
prompt += " This can replace the existing tag."
|
|
46
|
+
|
|
47
|
+
store = ex.registry.session_store
|
|
48
|
+
async with (
|
|
49
|
+
daemon.reserve(store, "image tag", image),
|
|
50
|
+
daemon.reserve(store, "container", found.id),
|
|
51
|
+
):
|
|
52
|
+
config = await stopped_config(found, args.container)
|
|
53
|
+
if policy.asks(action):
|
|
54
|
+
if not await confirm(ex, policy, action, image, prompt):
|
|
55
|
+
raise Conflict(f"image not committed: {refusal(ex)}")
|
|
56
|
+
config = await stopped_config(found, args.container)
|
|
57
|
+
|
|
58
|
+
if not args.overwrite:
|
|
59
|
+
async with clear("checking the image tag", subject=image):
|
|
60
|
+
try:
|
|
61
|
+
await client.images.inspect(image)
|
|
62
|
+
except DockerError as error:
|
|
63
|
+
if error.status != 404:
|
|
64
|
+
raise
|
|
65
|
+
else:
|
|
66
|
+
raise Conflict(
|
|
67
|
+
f"image {image} already exists. Set overwrite=true to replace it."
|
|
68
|
+
)
|
|
69
|
+
async with clear("committing the container", subject=args.container):
|
|
70
|
+
config["Labels"] = {**(config.get("Labels") or {}), "description": args.description}
|
|
71
|
+
result = await found.commit(repository=repository, tag=tag, config=config, pause=False)
|
|
72
|
+
|
|
73
|
+
await publish(ex.registry, "docker://images")
|
|
74
|
+
return Committed(
|
|
75
|
+
id=result["Id"], image=image, note="Mounted volume data is excluded from the image."
|
|
76
|
+
)
|
|
@@ -160,7 +160,8 @@ async def create_container(
|
|
|
160
160
|
) from error
|
|
161
161
|
note = None
|
|
162
162
|
if args.start:
|
|
163
|
-
|
|
163
|
+
async with daemon.reserve(ex.registry.session_store, "container", made.id):
|
|
164
|
+
await made.start()
|
|
164
165
|
state = await settled(made)
|
|
165
166
|
if str(state.get("Status")) != "running":
|
|
166
167
|
note = (
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Create a local named volume with a description."""
|
|
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 Conflict, clear
|
|
10
|
+
from docker_tiny_mcp.models import CreatedVolume, CreateVolumeRequest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def create_volume(
|
|
14
|
+
args: CreateVolumeRequest, client: Docker, ex: Exchange, policy: Policy
|
|
15
|
+
) -> CreatedVolume:
|
|
16
|
+
"""Create a named volume with a description that appears in `volumes`.
|
|
17
|
+
|
|
18
|
+
The volume uses the local driver without mount options. A volume with
|
|
19
|
+
the same name can be reused if its description and settings match.
|
|
20
|
+
"""
|
|
21
|
+
if not await confirm(ex, policy, "create_volume", args.name, f"Create volume {args.name}?"):
|
|
22
|
+
raise Conflict(f"volume not created: {refusal(ex)}")
|
|
23
|
+
|
|
24
|
+
labels = {"description": args.description}
|
|
25
|
+
async with clear("creating the volume", subject=args.name):
|
|
26
|
+
volume = await client.volumes.create(
|
|
27
|
+
{"Name": args.name, "Driver": "local", "Labels": labels}
|
|
28
|
+
)
|
|
29
|
+
found = await volume.show()
|
|
30
|
+
if found.get("Driver") != "local" or found.get("Options"):
|
|
31
|
+
raise Conflict(f"volume {args.name} exists with a different driver or mount options")
|
|
32
|
+
if (found.get("Labels") or {}).get("description") != args.description:
|
|
33
|
+
raise Conflict(f"volume {args.name} exists with a different description")
|
|
34
|
+
return CreatedVolume(name=args.name, description=args.description)
|
|
@@ -46,12 +46,13 @@ def image_of(raw: dict[str, Any], users: Mapping[str, list[str]] | None = None)
|
|
|
46
46
|
tags=tags,
|
|
47
47
|
size_mb=round(float(raw.get("Size", 0) or 0) / 1_000_000, 1),
|
|
48
48
|
created=daemon.when(raw.get("Created")) or "",
|
|
49
|
+
description=str((raw.get("Labels") or {}).get("description") or ""),
|
|
49
50
|
used_by=sorted({name for key in [identity, *tags] for name in holders.get(key, [])}),
|
|
50
51
|
)
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
async def images(args: ImageFilter, client: Docker) -> Images:
|
|
54
|
-
"""List images
|
|
55
|
+
"""List local images with their sizes, descriptions, and containers that use them.
|
|
55
56
|
|
|
56
57
|
`used_by` is empty exactly where an image can be removed, so ask with
|
|
57
58
|
`unused` when looking for space. Check here before pulling, too.
|
|
@@ -20,7 +20,8 @@ from .results import outcome, settled
|
|
|
20
20
|
async def restart(args: StopRequest, client: Docker, ex: Exchange) -> Done:
|
|
21
21
|
"""Stop and start a container. The usual first thing to try."""
|
|
22
22
|
found = await daemon.find(client, args.container)
|
|
23
|
-
|
|
23
|
+
async with daemon.reserve(ex.registry.session_store, "container", found.id):
|
|
24
|
+
await found.restart(timeout=args.seconds)
|
|
24
25
|
await publish(ex.registry, "docker://containers")
|
|
25
26
|
return outcome(args.container, "restart", await settled(found), "running")
|
|
26
27
|
|
|
@@ -25,7 +25,8 @@ async def start(args: ContainerRef, client: Docker, ex: Exchange) -> Done:
|
|
|
25
25
|
once is reported as dead rather than as started.
|
|
26
26
|
"""
|
|
27
27
|
found = await daemon.find(client, args.container)
|
|
28
|
-
|
|
28
|
+
async with daemon.reserve(ex.registry.session_store, "container", found.id):
|
|
29
|
+
await found.start()
|
|
29
30
|
await publish(ex.registry, "docker://containers")
|
|
30
31
|
return outcome(args.container, "start", await settled(found), "running")
|
|
31
32
|
|
|
@@ -35,16 +35,17 @@ def volume_of(raw: dict[str, Any], users: Mapping[str, list[str]] | None = None)
|
|
|
35
35
|
driver=str(raw.get("Driver", "")),
|
|
36
36
|
mountpoint=str(raw.get("Mountpoint", "")),
|
|
37
37
|
created=daemon.when(raw.get("CreatedAt")),
|
|
38
|
+
description=str((raw.get("Labels") or {}).get("description") or ""),
|
|
38
39
|
used_by=sorted((users or {}).get(name, [])),
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
async def volumes(args: NameFilter, client: Docker) -> Volumes:
|
|
43
|
-
"""List volumes
|
|
44
|
+
"""List volumes with their descriptions and the containers that mount them.
|
|
44
45
|
|
|
45
46
|
`used_by` is empty where a volume holds data nothing is reading -- which
|
|
46
47
|
is either space to reclaim or a service that lost its data, so read the
|
|
47
|
-
name before removing it.
|
|
48
|
+
name and description before removing it.
|
|
48
49
|
"""
|
|
49
50
|
users = mounters(await daemon.containers(client, all=True))
|
|
50
51
|
async with clear("listing volumes"):
|
|
@@ -60,7 +60,8 @@ async def write(args: WriteRequest, client: Docker, ex: Exchange, policy: Policy
|
|
|
60
60
|
):
|
|
61
61
|
raise Conflict(f"not written: {refusal(ex)}")
|
|
62
62
|
content = args.content.encode("utf-8")
|
|
63
|
-
|
|
63
|
+
async with daemon.reserve(ex.registry.session_store, "container", found.id):
|
|
64
|
+
await write_file(found, args.path, content, int(args.mode, 8))
|
|
64
65
|
state = await daemon.state_of(found)
|
|
65
66
|
note = None
|
|
66
67
|
if str(state.get("Status")) == "running":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "docker-tiny-mcp"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "An MCP server for Docker, over aiohttp-tiny-mcp."
|
|
5
5
|
requires-python = ">=3.10"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -8,7 +8,7 @@ license-files = ["LICENSE"]
|
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
dependencies = [
|
|
10
10
|
"aiodocker>=0.24",
|
|
11
|
-
"aiohttp-tiny-mcp[sqlite,jwt]>=0.
|
|
11
|
+
"aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0",
|
|
12
12
|
"argclass>=1.0",
|
|
13
13
|
]
|
|
14
14
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "docker-tiny-mcp"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "An MCP server for Docker, over aiohttp-tiny-mcp."
|
|
5
5
|
requires-python = ">=3.10"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -10,7 +10,7 @@ dependencies = [
|
|
|
10
10
|
"aiodocker>=0.24",
|
|
11
11
|
# The sessions and the events live in one SQLite file, and the JWT policy
|
|
12
12
|
# needs PyJWT; the extras bring both.
|
|
13
|
-
"aiohttp-tiny-mcp[sqlite,jwt]>=0.
|
|
13
|
+
"aiohttp-tiny-mcp[sqlite,jwt]>=0.9.0",
|
|
14
14
|
"argclass>=1.0",
|
|
15
15
|
]
|
|
16
16
|
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"""Register Docker handlers, descriptions, and annotations."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from aiodocker import Docker
|
|
6
|
-
from aiohttp_tiny_mcp import Hint, Registry
|
|
7
|
-
|
|
8
|
-
from . import prompts, resources, tools
|
|
9
|
-
from .consent import Policy
|
|
10
|
-
from .resources import templates
|
|
11
|
-
from .tools.create import fixed_network_create, unprivileged_create
|
|
12
|
-
from .tools.prune import prune_fixed_network
|
|
13
|
-
|
|
14
|
-
INSTRUCTIONS = (
|
|
15
|
-
"Inspect and control Docker. Start with `containers` to find what to act "
|
|
16
|
-
"on; `container`, `logs`, `read` and `stats` to understand one; `events` "
|
|
17
|
-
"for what happened before now; and `info` to confirm the daemon is "
|
|
18
|
-
"reachable and is the one you meant.\n\n"
|
|
19
|
-
"To change something: `create` makes and starts a container, `start`, "
|
|
20
|
-
"`stop` and `restart` do the obvious, `wait` holds until a container is "
|
|
21
|
-
"running or healthy, `exec` runs a command inside one, and `write` puts a "
|
|
22
|
-
"file into one. `prune`, `remove` and `remove_image` reclaim space.\n\n"
|
|
23
|
-
"Reading never asks, and neither does a command that only reads, such as "
|
|
24
|
-
"`ls` or `cat`. What cannot be undone -- `remove`, `remove_image`, "
|
|
25
|
-
"`prune`, and a command that is not merely reading -- asks once, and the "
|
|
26
|
-
"person answering may say not to ask again."
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
READS = Hint.READ_ONLY | Hint.IDEMPOTENT
|
|
30
|
-
|
|
31
|
-
WATCHES = Hint.READ_ONLY
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def build(
|
|
35
|
-
registry: Registry,
|
|
36
|
-
client: Docker,
|
|
37
|
-
policy: Policy | None = None,
|
|
38
|
-
*,
|
|
39
|
-
unprivileged: bool = False,
|
|
40
|
-
network: str | None = None,
|
|
41
|
-
) -> Registry:
|
|
42
|
-
"""Register handlers and inject the Docker client and deployment confirmation policy."""
|
|
43
|
-
registry.instructions = INSTRUCTIONS
|
|
44
|
-
registry.provide_instance(client)
|
|
45
|
-
registry.provide_instance(policy or Policy())
|
|
46
|
-
if unprivileged:
|
|
47
|
-
registry.instructions += (
|
|
48
|
-
"\n\nUnprivileged mode: host mounts and privileged containers are forbidden. "
|
|
49
|
-
"Use named local volumes for persistent data. The server selects the network."
|
|
50
|
-
)
|
|
51
|
-
if network:
|
|
52
|
-
registry.instructions += (
|
|
53
|
-
"\n\nThe network is fixed by the server; network management is disabled."
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
registry.tool(tools.containers, annotations=READS)
|
|
57
|
-
registry.tool(tools.container, annotations=READS)
|
|
58
|
-
registry.tool(tools.images, annotations=READS)
|
|
59
|
-
if not network:
|
|
60
|
-
registry.tool(tools.networks, annotations=READS)
|
|
61
|
-
registry.tool(tools.volumes, annotations=READS)
|
|
62
|
-
registry.tool(tools.info, annotations=READS)
|
|
63
|
-
registry.tool(tools.logs, annotations=WATCHES)
|
|
64
|
-
registry.tool(tools.stats, annotations=WATCHES)
|
|
65
|
-
registry.tool(tools.events, annotations=WATCHES)
|
|
66
|
-
registry.tool(tools.wait, annotations=WATCHES)
|
|
67
|
-
|
|
68
|
-
if unprivileged:
|
|
69
|
-
registry.tool(unprivileged_create(network), name="create", annotations=Hint.OPEN_WORLD)
|
|
70
|
-
registry.tool(tools.read_unprivileged, name="read", annotations=READS)
|
|
71
|
-
registry.tool(tools.start_unprivileged, name="start", annotations=Hint.IDEMPOTENT)
|
|
72
|
-
registry.tool(tools.restart_unprivileged, name="restart")
|
|
73
|
-
registry.tool(tools.write_unprivileged, name="write", annotations=Hint.DESTRUCTIVE)
|
|
74
|
-
registry.tool(
|
|
75
|
-
tools.exec_unprivileged, name="exec", annotations=Hint.DESTRUCTIVE | Hint.OPEN_WORLD
|
|
76
|
-
)
|
|
77
|
-
else:
|
|
78
|
-
if network:
|
|
79
|
-
registry.tool(fixed_network_create(network), name="create", annotations=Hint.OPEN_WORLD)
|
|
80
|
-
else:
|
|
81
|
-
registry.tool(tools.create, annotations=Hint.OPEN_WORLD)
|
|
82
|
-
registry.tool(tools.read, annotations=READS)
|
|
83
|
-
registry.tool(tools.start, annotations=Hint.IDEMPOTENT)
|
|
84
|
-
registry.tool(tools.restart)
|
|
85
|
-
registry.tool(tools.write, annotations=Hint.DESTRUCTIVE)
|
|
86
|
-
registry.tool(tools.exec, annotations=Hint.DESTRUCTIVE | Hint.OPEN_WORLD)
|
|
87
|
-
|
|
88
|
-
registry.tool(tools.stop, annotations=Hint.IDEMPOTENT)
|
|
89
|
-
registry.tool(tools.remove, annotations=Hint.DESTRUCTIVE)
|
|
90
|
-
registry.tool(tools.remove_image, annotations=Hint.DESTRUCTIVE)
|
|
91
|
-
if network:
|
|
92
|
-
registry.tool(prune_fixed_network, name="prune", annotations=Hint.DESTRUCTIVE)
|
|
93
|
-
else:
|
|
94
|
-
registry.tool(tools.prune, annotations=Hint.DESTRUCTIVE)
|
|
95
|
-
registry.tool(tools.pull, streaming=True, annotations=Hint.OPEN_WORLD)
|
|
96
|
-
|
|
97
|
-
registry.resource("docker://info", resources.info, mime_type="application/json")
|
|
98
|
-
registry.resource("docker://containers", resources.containers, mime_type="application/json")
|
|
99
|
-
registry.resource(
|
|
100
|
-
"docker://containers/{name}",
|
|
101
|
-
templates.container,
|
|
102
|
-
name="container",
|
|
103
|
-
mime_type="application/json",
|
|
104
|
-
)
|
|
105
|
-
registry.resource("docker://containers/{name}/logs", templates.logs, name="container-logs")
|
|
106
|
-
registry.resource("docker://images", resources.images, mime_type="application/json")
|
|
107
|
-
|
|
108
|
-
registry.prompt(prompts.diagnose, title="Diagnose a container")
|
|
109
|
-
registry.prompt(prompts.reclaim, title="Find space to reclaim")
|
|
110
|
-
|
|
111
|
-
registry.completions(prompts.complete)
|
|
112
|
-
return registry
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
__all__ = ["INSTRUCTIONS", "build"]
|
|
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.1.1 → docker_tiny_mcp-0.2.0}/docker_tiny_mcp/resources/templates/__init__.py
RENAMED
|
File without changes
|
{docker_tiny_mcp-0.1.1 → docker_tiny_mcp-0.2.0}/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
|