Skip to content

Commit 4f6b300

Browse files
Add the socket server
1 parent 16ecfa5 commit 4f6b300

File tree

10 files changed

+291
-142
lines changed

10 files changed

+291
-142
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
/docs/public/
2323
/docs/.hugo_build.lock
2424
/functions/memory/memory.json
25+
/log/

compose.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
mcp_docker:
3+
image: mcp/docker
4+
ports:
5+
- 8811:8811
6+
volumes:
7+
- "/var/run/docker.sock:/var/run/docker.sock"
8+
- "docker-prompts:/prompts"
9+
command:
10+
- serve
11+
- --mcp
12+
- --port
13+
- "8811"
14+
- --register
15+
- github:docker/labs-ai-tools-for-devs?path=prompts/bootstrap.md
16+
volumes:
17+
docker-prompts:
18+
external: true

prompts/chrome.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ arguments:
55
- name: query
66
description: the question to answer
77
required: true
8+
parameter-values:
9+
query: "What is url of the logo for docker.com?"
810
tools:
911
- name: websocat
1012
description: A tool to send and receive messages over a websocket.
@@ -108,6 +110,6 @@ It is important that when you are done with your page, you close it. This is imp
108110

109111
The following is the question you are trying to answer:
110112

111-
what is the url of the logo for docker.com?
113+
{{query}}
112114

113115
(if there is no question, just confirm Chrome is running and ready to answer questions)

runbook.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```sh
2+
docker build -t mcp/docker .
3+
```
4+
5+
```sh
6+
docker extension rm vonwig/labs-ai-tools-for-devs
7+
```
8+
9+
```sh
10+
docker extension install vonwig/labs-ai-tools-for-devs:0.1.16
11+
```
12+
13+
```sh
14+
docker extension update docker/labs-ai-tools-for-devs:0.1.4
15+
```
16+
17+
```sh
18+
# docker:command=build-pre-release
19+
docker buildx build \
20+
--builder hydrobuild \
21+
--platform linux/amd64,linux/arm64 \
22+
--tag mcp/docker:prerelease \
23+
--file Dockerfile \
24+
--push .
25+
docker pull mcp/docker:prerelease
26+
```
27+
28+
```sh
29+
# docker:command=build-release
30+
docker buildx build \
31+
--builder hydrobuild \
32+
--platform linux/amd64,linux/arm64 \
33+
--tag mcp/docker:latest \
34+
--file Dockerfile \
35+
--push .
36+
docker pull mcp/docker:latest
37+
```
38+
39+
```sh
40+
docker run --rm -t --init -v docker-prompts:/prompts alpine:latest tail -f /prompts/log/docker-mcp-server.out
41+
```
42+
43+
```sh
44+
clj -M:main serve --mcp --port 8811 --register "github:docker/labs-ai-tools-for-devs?path=prompts/bootstrap.md"
45+
```
46+
47+
```sh
48+
docker run --rm -i --pull always -q --init \
49+
-v /var/run/docker.sock:/var/run/docker.sock \
50+
--mount type=volume,source=docker-prompts,target=/prompts \
51+
-p 8811:8811 \
52+
mcp/docker:latest \
53+
serve --mcp --port 8811 \
54+
--register "github:docker/labs-ai-tools-for-devs?path=prompts/bootstrap.md"
55+
```
56+
57+
```sh
58+
socat STDIO TCP:127.0.0.1:8811
59+
```

src/docker.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,19 +410,19 @@
410410
client))
411411

412412
(defn get-block [x-bytes start]
413-
(let [[type _ _ _ n1 n2 n3 n4] (Arrays/copyOfRange ^bytes x-bytes start (+ start 8))]
414-
(let [size (.getInt (ByteBuffer/wrap (Arrays/copyOfRange ^bytes x-bytes (+ start 4) (+ start 8))))]
415-
[(case type 0 :stdin 1 :stdout 2 :stderr)
413+
(let [[type _ _ _ n1 n2 n3 n4] (Arrays/copyOfRange ^bytes x-bytes ^int start ^int (+ start 8))]
414+
(let [size (.getInt (ByteBuffer/wrap (Arrays/copyOfRange ^bytes x-bytes ^int (+ start 4) ^int (+ start 8))))]
415+
[(case (int type) 0 :stdin 1 :stdout 2 :stderr)
416416
size
417-
(String. (Arrays/copyOfRange ^bytes x-bytes (+ start 8) (+ start 8 size)))])))
417+
(String. (Arrays/copyOfRange ^bytes x-bytes ^int (+ start 8) ^int (+ start 8 size)))])))
418418

419419
(defn process-bytes [x-bytes]
420420
(loop [agg {:stdout "" :stderr "" :stdin ""} start 0]
421421
(if (> (- (count x-bytes) start) 8)
422422
(let [[type size s] (get-block x-bytes start)]
423423
(recur
424424
(update agg type str s)
425-
(+ start size 8)))
425+
(long (+ start size 8))))
426426
agg)))
427427

428428
(defn docker-stream-format->stdout [bytes]

src/docker/main.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
:default []
7272
:update-fn conj]
7373
[nil "--mcp" "use the mcp jsonrpc protocol"]
74+
[nil "--port PORT" "run a socket server"
75+
:parse-fn #(Long/parseLong %)]
7476
[nil "--debug" "add debug logging"]
7577
[nil "--help" "print option summary"]])
7678

@@ -172,7 +174,10 @@
172174
{})))
173175
opts)))
174176
"serve" (fn []
175-
(let [[producer server-promise] (jsonrpc.server/run-server! opts)]
177+
(let [server-opts (jsonrpc.server/server-context opts)
178+
[producer server-promise] (if (:port opts)
179+
(jsonrpc.server/run-socket-server! opts server-opts)
180+
(jsonrpc.server/run-server! opts server-opts))]
176181
(alter-var-root
177182
#'jsonrpc/notify
178183
(constantly
@@ -208,6 +213,7 @@
208213
(try
209214
(cmd)
210215
(catch Throwable t
216+
(.printStackTrace t)
211217
(jsonrpc/notify :error {:content (str t)})
212218
(System/exit 1))))))))
213219
(catch Throwable t

0 commit comments

Comments
 (0)