docker-tiny-mcp 0.1.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.
Files changed (45) hide show
  1. docker_tiny_mcp-0.1.0/LICENSE +202 -0
  2. docker_tiny_mcp-0.1.0/PKG-INFO +424 -0
  3. docker_tiny_mcp-0.1.0/README.md +410 -0
  4. docker_tiny_mcp-0.1.0/docker_tiny_mcp/__init__.py +1 -0
  5. docker_tiny_mcp-0.1.0/docker_tiny_mcp/__main__.py +280 -0
  6. docker_tiny_mcp-0.1.0/docker_tiny_mcp/consent.py +252 -0
  7. docker_tiny_mcp-0.1.0/docker_tiny_mcp/daemon.py +71 -0
  8. docker_tiny_mcp-0.1.0/docker_tiny_mcp/errors.py +89 -0
  9. docker_tiny_mcp-0.1.0/docker_tiny_mcp/events.py +51 -0
  10. docker_tiny_mcp-0.1.0/docker_tiny_mcp/models.py +444 -0
  11. docker_tiny_mcp-0.1.0/docker_tiny_mcp/prompts.py +58 -0
  12. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/__init__.py +15 -0
  13. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/containers.py +13 -0
  14. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/images.py +13 -0
  15. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/info.py +13 -0
  16. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/templates/__init__.py +11 -0
  17. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/templates/container.py +13 -0
  18. docker_tiny_mcp-0.1.0/docker_tiny_mcp/resources/templates/logs.py +14 -0
  19. docker_tiny_mcp-0.1.0/docker_tiny_mcp/safety.py +156 -0
  20. docker_tiny_mcp-0.1.0/docker_tiny_mcp/server.py +115 -0
  21. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/__init__.py +57 -0
  22. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/container.py +104 -0
  23. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/containers.py +44 -0
  24. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/create.py +210 -0
  25. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/events.py +65 -0
  26. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/exec.py +99 -0
  27. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/images.py +71 -0
  28. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/info.py +51 -0
  29. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/logs.py +101 -0
  30. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/networks.py +59 -0
  31. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/prune.py +60 -0
  32. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/pull.py +36 -0
  33. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/read.py +69 -0
  34. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/remove.py +36 -0
  35. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/remove_image.py +37 -0
  36. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/restart.py +31 -0
  37. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/results.py +50 -0
  38. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/start.py +36 -0
  39. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/stats.py +124 -0
  40. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/stop.py +28 -0
  41. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/volumes.py +56 -0
  42. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/wait.py +57 -0
  43. docker_tiny_mcp-0.1.0/docker_tiny_mcp/tools/write.py +76 -0
  44. docker_tiny_mcp-0.1.0/pyproject.toml +65 -0
  45. docker_tiny_mcp-0.1.0/pyproject.toml.orig +60 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: docker-tiny-mcp
3
+ Version: 0.1.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.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
+ # docker-tiny-mcp
16
+
17
+ An MCP server for Docker, built on
18
+ [aiohttp-tiny-mcp](https://github.com/mosquito/aiohttp-tiny-mcp).
19
+
20
+ It began as the worked example of a complete server in that repository: a real
21
+ client library underneath, a real store and event source, a command line, and
22
+ tests that run where Docker is not installed. Every protocol revision the
23
+ package speaks is served by the same handlers.
24
+
25
+ ## Running it
26
+
27
+ ```bash
28
+ uvx --from docker-tiny-mcp docker-tiny-mcp # http://127.0.0.1:8080/mcp
29
+ uv run docker-tiny-mcp --stdio # for a locally-installed client
30
+ uv run docker-tiny-mcp --port 9000 --state /var/lib/docker-tiny-mcp/state.sqlite3
31
+ ```
32
+
33
+ Every setting can also come from the environment or a config file. Three files
34
+ are read where they exist: `/etc/docker/mcp.ini`, then `~/.config/docker/mcp.ini`,
35
+ then `.docker-tiny-mcp.ini` in this directory, each overriding the one before.
36
+ `--config FILE` overrides all three. The order of precedence is defaults, then
37
+ those files, then `DOCKER_TINY_MCP_*`, then the command line:
38
+
39
+ ```bash
40
+ DOCKER_TINY_MCP_PORT=9000 DOCKER_TINY_MCP_STATE=/tmp/state.sqlite3 uv run docker-tiny-mcp
41
+ ```
42
+
43
+ `--help` lists everything, including which environment variable each setting
44
+ reads. `--generate-config` writes every setting, its help and its default to a
45
+ config file, so a deployment edits that file instead of a command line:
46
+
47
+ ```bash
48
+ uv run docker-tiny-mcp --generate-config /etc/docker/mcp.ini
49
+ uv run docker-tiny-mcp --generate-config - # to standard output
50
+ ```
51
+
52
+ Top-level settings go under `[DEFAULT]`, and a group of settings has its own
53
+ section, such as `[jwt]`. A list is written as a Python literal, in the config
54
+ file and in the environment alike:
55
+
56
+ ```ini
57
+ allowed_origin = ["https://docker.example.com"]
58
+ ```
59
+
60
+ ```bash
61
+ DOCKER_TINY_MCP_ALLOWED_ORIGIN='["https://docker.example.com"]' uv run docker-tiny-mcp
62
+ ```
63
+
64
+ ## Unprivileged mode
65
+
66
+ Enable runtime checks for host access with `--unprivileged`:
67
+
68
+ ```bash
69
+ uv run docker-tiny-mcp --unprivileged
70
+ uv run docker-tiny-mcp --unprivileged --network sandbox
71
+ ```
72
+
73
+ The `create` tool hides and rejects `network`. Its `volumes` argument accepts
74
+ only named volumes, such as `data:/data`, `data:/data:rw` or `data:/data:ro`.
75
+ Host paths, Docker socket mounts, extra mount flags and unknown creation
76
+ arguments are rejected. Missing named volumes are created with the `local`
77
+ driver. Existing volumes must use `local` without driver options, because
78
+ [volume options can mount host paths](https://docs.docker.com/engine/storage/volumes/).
79
+ Named volumes persist after their containers are removed.
80
+
81
+ For example, call `create` with:
82
+
83
+ ```json
84
+ {"image": "redis:7-alpine", "name": "cache", "volumes": ["cache-data:/data"]}
85
+ ```
86
+
87
+ Before `read`, `write`, `exec`, `start` or `restart`, the server inspects the
88
+ target container. It rejects host mounts, extra capabilities or devices,
89
+ shared host namespaces, custom runtimes and relaxed security settings.
90
+ New containers use `no-new-privileges` and the default bridge network unless
91
+ the operator selects another local bridge network or `none`.
92
+ Published ports remain available.
93
+
94
+ Equivalent settings are `DOCKER_TINY_MCP_UNPRIVILEGED=true` or `unprivileged=true`
95
+ in the config file. Python callers can use `build(registry, client, unprivileged=True)`.
96
+
97
+ This mode restricts Docker configuration exposed through MCP. It does not
98
+ filter container network traffic, provide per-user volume isolation or
99
+ protect against Docker/kernel vulnerabilities and concurrent changes by
100
+ another Docker administrator. Use a dedicated daemon for untrusted workloads.
101
+
102
+ ## Fixed network
103
+
104
+ `--network NAME` works independently of `--unprivileged`:
105
+
106
+ ```bash
107
+ uv run docker-tiny-mcp --network sandbox
108
+ ```
109
+
110
+ The network must already exist. The server uses it for new containers,
111
+ hides and rejects `create.network`, omits the `networks` tool and removes
112
+ `networks` from `prune.what`. This option does not enable unprivileged mode.
113
+
114
+ Equivalent settings are `DOCKER_TINY_MCP_NETWORK=sandbox` or `network=sandbox`
115
+ in the config file. Python callers can use `build(registry, client, network="sandbox")`.
116
+ Add `--unprivileged` separately when both restrictions are needed.
117
+
118
+ ## Authentication
119
+
120
+ `--jwt-psk` verifies an HS256 JWT on every HTTP request. The audience is this
121
+ endpoint's public URL: a token must name it, and the endpoint publishes it as
122
+ its protected resource.
123
+
124
+ ```bash
125
+ uv run docker-tiny-mcp --jwt-psk "$KEY" \
126
+ --jwt-audience https://docker.example.com/mcp \
127
+ --jwt-issuer https://docker.example.com
128
+ ```
129
+
130
+ The key needs at least 32 bytes. It is a secret argument: its `repr` is
131
+ `******`, so a log of the settings does not hold it. The config file or
132
+ `DOCKER_TINY_MCP_JWT_PSK` keeps it out of the command line, which another user on
133
+ the machine can read. `--jwt-issuer` is optional; an empty issuer accepts a
134
+ token from any issuer.
135
+
136
+ These three settings are one group, and the config file holds them in one
137
+ section:
138
+
139
+ ```ini
140
+ [jwt]
141
+ psk = a-key-of-at-least-32-random-bytes
142
+ audience = https://docker.example.com/mcp
143
+ issuer = https://docker.example.com
144
+ ```
145
+
146
+ Mint a token with the same key, and send it as `Authorization: Bearer <token>`:
147
+
148
+ <!-- name: async test_readme_jwt -->
149
+ ```python
150
+ import time
151
+
152
+ import jwt
153
+
154
+ from docker_tiny_mcp.__main__ import Parser, authentication
155
+
156
+ key = "replace-this-example-key-with-32-random-bytes"
157
+ parser = Parser()
158
+ parser.parse_args(
159
+ [
160
+ "--jwt-psk",
161
+ key,
162
+ "--jwt-audience",
163
+ "https://docker.example.com/mcp",
164
+ "--jwt-issuer",
165
+ "https://docker.example.com",
166
+ ]
167
+ )
168
+ auth = authentication(parser)
169
+
170
+ token = jwt.encode(
171
+ {
172
+ "sub": "laptop",
173
+ "iss": "https://docker.example.com",
174
+ "aud": "https://docker.example.com/mcp",
175
+ "exp": time.time() + 86400,
176
+ },
177
+ key,
178
+ algorithm="HS256",
179
+ )
180
+ assert (await auth.principal(f"Bearer {token}")).subject == "laptop"
181
+ ```
182
+
183
+ `--jwt-query-token` also accepts the token as the `token` query argument, for
184
+ a client that sends no header:
185
+
186
+ ```
187
+ https://docker.example.com/mcp?token=<token>
188
+ ```
189
+
190
+ The header wins where both are present. The URL is then a credential: it
191
+ reaches browser history, the client's saved settings and every log that keeps
192
+ the query, so the option is off by default. The endpoint already masks the
193
+ argument in the aiohttp access log, which writes `token=[REDACTED]`.
194
+
195
+ A token expires, and the server rejects one without `exp`. Revocation is
196
+ collective: replace the key and restart the server. This is a credential on
197
+ the wire, so terminate TLS in front of the server. The policy protects the MCP
198
+ route; the console page itself stays public and asks for the token in its
199
+ dialog. `--stdio` ignores the key, because one process serves one caller.
200
+
201
+ Other deployments need other identity: `Registry(auth=...)` also takes Basic
202
+ authentication, an OAuth protected resource, or a policy of your own. See
203
+ [authentication](https://mosquito.github.io/aiohttp-tiny-mcp/guide/auth.html).
204
+
205
+ ## What it offers
206
+
207
+ Enough on its own. An agent given this server and nothing else can find a
208
+ container, read its files and its log, run a command in it, change it, and
209
+ start a new one.
210
+
211
+ | Tool | Does |
212
+ | --- | --- |
213
+ | `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
+ | `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
+ | `images` | Images with sizes, and what still holds each one |
218
+ | `networks`, `volumes` | What is attached, and what mounts what |
219
+ | `events` | What the daemon did lately: started, died, removed |
220
+ | `stats` | Processor, memory, network and disk, as rates |
221
+ | `info` | Which daemon this is, its version, and how much it holds |
222
+ | `create` | Make one and start it -- `docker run`, with the flags named |
223
+ | `start`, `stop`, `restart` | The obvious things, reporting the state that followed |
224
+ | `wait` | Hold until it is running, stopped, or healthy |
225
+ | `exec` | Run a command inside it -- **asks unless the command only reads** |
226
+ | `write` | Put a file into it, running or not |
227
+ | `remove`, `remove_image`, `prune` | Reclaim space -- **each asks first** |
228
+ | `pull` | Download an image, reporting progress |
229
+
230
+ Resources: `docker://info`, `docker://containers`,
231
+ `docker://containers/{name}`, `docker://containers/{name}/logs`,
232
+ `docker://images`.
233
+
234
+ Prompts: `diagnose` for a container that misbehaves, `reclaim` for finding
235
+ space. Container and image names are suggested while either is filled in.
236
+
237
+ ## The parts worth copying
238
+
239
+ **Handlers are plain functions.** Nothing in `tools/` knows about a registry.
240
+ Each is a coroutine over a connected `aiodocker.Docker`, so a test calls it
241
+ directly:
242
+
243
+ <!-- name: async test_readme_direct -->
244
+ ```python
245
+ from docker_tiny_mcp import tools
246
+ from docker_tiny_mcp.models import ContainerFilter
247
+
248
+
249
+ async def show(client):
250
+ listed = await tools.containers(ContainerFilter(all=True), client)
251
+ return [item.name for item in listed.containers]
252
+ ```
253
+
254
+ **One file per tool, holding the whole tool.** `tools/stats.py` has the two
255
+ samples, the arithmetic between them, and the handler -- open it and there is
256
+ nothing else to find. Nothing was factored out for its own sake: a helper
257
+ moves to `daemon.py` only where a second tool calls it, which is true of six
258
+ functions in all.
259
+
260
+ ```
261
+ daemon.py what more than one tool asks the daemon
262
+ tools/ one file per tool, plus results.py
263
+ resources/ addressed rather than called
264
+ resources/templates/ the ones whose address a client fills in
265
+ ```
266
+
267
+ What a tool may do is read from its signature, not from where its file sits. A
268
+ handler taking only `(args, client)` changes nothing and can ask nobody; one
269
+ taking `ex: Exchange` may put a question; one taking `policy: Policy` may
270
+ destroy something. That is one place to look, and it is in the file already.
271
+
272
+ There is no wrapper around the daemon. `aiodocker.Docker` is the connection,
273
+ the application opens one and hands it to the registry, and a handler takes it
274
+ as `client: Docker`. Several functions in `daemon.py` never see it at all -- a
275
+ container reads its own log -- which a wrapper hid.
276
+
277
+ `templates/` is apart because a fixed resource can be listed and subscribed
278
+ to, a template cannot be listed at all, and a client only discovers that
279
+ difference by failing.
280
+
281
+ `server.py` registers handlers and selects deployment restrictions.
282
+ `safety.py` checks Docker configuration at runtime in unprivileged mode:
283
+
284
+ <!-- name: async test_readme_inventory -->
285
+ ```python
286
+ from aiodocker import Docker
287
+ from aiohttp_tiny_mcp import MemoryHub, MemorySessionStore, Registry
288
+
289
+ from docker_tiny_mcp.server import build
290
+
291
+ # `build` says what is offered and nothing else. Reading it is reading the
292
+ # whole surface -- the daemon is never asked anything until a tool is called.
293
+ client = Docker()
294
+ try:
295
+ registry = build(
296
+ Registry("docker", "0.1.0", hub=MemoryHub(), session_store=MemorySessionStore()),
297
+ client,
298
+ )
299
+ assert {"containers", "logs", "read", "exec", "write", "create"} <= set(registry.tools)
300
+ finally:
301
+ await client.close()
302
+ ```
303
+
304
+ **Asking is rationed, and the deployment sets the rate.** A server that asks
305
+ before everything is a server whose questions nobody reads -- and there is
306
+ usually a host in front of this one asking its own permission for every call,
307
+ so a second question buys only the habit of clicking through both. Four things
308
+ cut it down, in order: a policy decides which actions are worth a question at
309
+ all, a command that only reads never asks, an answer that said "do not ask
310
+ again" is honoured, and what is left asks once.
311
+
312
+ ```bash
313
+ uv run docker-tiny-mcp # asks only before what cannot be undone
314
+ uv run docker-tiny-mcp --confirm never # asks nothing; the host in front already does
315
+ uv run docker-tiny-mcp --confirm changes # asks before anything that changes anything
316
+ ```
317
+
318
+ Under the default, `create` and `write` do not interrupt: creating is undone
319
+ by removing, and a file written into a container goes away with it. `remove`,
320
+ `remove_image`, `prune` and a command that is not merely reading do:
321
+
322
+ <!-- name: async test_readme_consent -->
323
+ ```python
324
+ from docker_tiny_mcp.consent import Policy, only_reads
325
+
326
+ assert only_reads(["cat", "/etc/hosts"])
327
+ assert not only_reads(["sh", "-c", "rm -rf /"])
328
+ assert not only_reads(["find", "/app", "-delete"])
329
+
330
+ assert Policy().asks("remove") and not Policy().asks("write")
331
+ assert not Policy("never").asks("remove")
332
+ assert Policy("changes").asks("write")
333
+ ```
334
+
335
+ What was allowed is kept in the session store the package already has, so a
336
+ second worker honours a permission the first one was given. `2026-07-28` keeps
337
+ no session of its own, so the answer is filed under the caller the revision
338
+ states on every request -- otherwise "do not ask again in this session" would
339
+ be forgotten before the next call, which is worse than never offering it.
340
+ `ex.ask` reaches a client through MRTR on `2026-07-28`, a pushed request on
341
+ `2025-11-25` and `2025-06-18`, and the tool call itself on `2025-03-26`. The
342
+ handler says one line and knows none of that.
343
+
344
+ **Failures are said in words, not status numbers.** `errors.py` translates
345
+ Docker failures. A command sent to a stopped container came
346
+ back as `DockerError: [409] container 3156cbe0b5f6... is not running`, which
347
+ names an id nobody typed and does not say what to do:
348
+
349
+ <!-- name: async test_readme_errors -->
350
+ ```python
351
+ import pytest
352
+ from aiodocker.exceptions import DockerError
353
+
354
+ from docker_tiny_mcp.errors import NotRunning, clear
355
+
356
+
357
+ async def check():
358
+ with pytest.raises(NotRunning, match="Start it first"):
359
+ async with clear("running a command", subject="cache"):
360
+ raise DockerError(409, "container 3156cbe0b5f6 is not running")
361
+ ```
362
+
363
+ **A change reports the state that followed it.** Docker answers `start`
364
+ before the process is up, so a container that starts and dies at once would
365
+ be reported as started. Every changing tool reads the state a moment later,
366
+ and says what went differently:
367
+
368
+ <!-- name: async test_readme_outcome -->
369
+ ```python
370
+ from docker_tiny_mcp import tools
371
+
372
+ done = tools.outcome("web", "start", {"Status": "exited", "ExitCode": 3}, "running")
373
+ assert done.exit_code == 3
374
+ assert "did not stay running" in done.note
375
+ ```
376
+
377
+ **The application owns the connection.** `__main__.py` opens one
378
+ `aiodocker.Docker`, hands it over with `registry.provide_instance(client)`, and
379
+ closes it on the way out. No lazy opening, no second lifetime to keep in step
380
+ with the first:
381
+
382
+ ```python
383
+ client = Docker(url=parser.docker_url) if parser.docker_url else Docker()
384
+ return build(registry, client, Policy(parser.confirm)), storage, client
385
+ ```
386
+
387
+ **State is SQLite.** `aiohttp_tiny_mcp.storage.sqlite` holds the sessions and the
388
+ events in one file, which is what several workers on one machine share. This
389
+ example used to carry its own copy of that; the package ships it now, and
390
+ `aiohttp-tiny-mcp[sqlite]` is what brings it. Across machines the same two
391
+ contracts are served by `aiohttp_tiny_mcp.storage.redis` or `.postgres`.
392
+
393
+ **The daemon's own events become notifications.** A container that dies is
394
+ published to the hub, and whoever subscribed hears about it.
395
+
396
+ ## Tests
397
+
398
+ ```bash
399
+ uv sync --all-groups
400
+ uv run pytest
401
+ ```
402
+
403
+ They need no Docker. `tests/fake_docker.py` is an aiohttp application
404
+ answering the endpoints these tools use, so the real `aiodocker`, the real
405
+ SQLite store, the real endpoint and a real MCP client are all exercised --
406
+ only the daemon is a stand-in.
407
+
408
+ Two layers, deliberately:
409
+
410
+ - `test_functions.py` calls the handlers directly. Fast, and it says what
411
+ broke.
412
+ - `test_reading.py`, `test_changing.py` and `test_events.py` drive a real
413
+ client over HTTP, once per protocol revision where the revision matters.
414
+ - `test_real_daemon.py` lives one container end to end against a real daemon:
415
+ create, wait, exec, write, read, logs, stats, events, stop, remove. It is
416
+ skipped where Docker is not reachable, and it is what caught `since` on the
417
+ log endpoint taking a Unix timestamp while every line it returns is dated
418
+ RFC 3339.
419
+
420
+ To run against a real daemon instead, point the tests at it:
421
+
422
+ ```bash
423
+ DOCKER_TINY_MCP_DOCKER_URL=unix:///var/run/docker.sock uv run pytest -k real
424
+ ```