Skip to content

Commit 36de9d8

Browse files
Supporting clients with Roots
1 parent 84ec317 commit 36de9d8

File tree

6 files changed

+48
-17
lines changed

6 files changed

+48
-17
lines changed

prompts/catalog.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -2206,4 +2206,8 @@ registry:
22062206
icon: https://avatars.githubusercontent.com/u/182288589?s=200&v=4
22072207
secrets:
22082208
- name: perplexity-ask.api_key
2209-
2209+
bootstrap:
2210+
description: |
2211+
bootstrap new tools from your mcp client
2212+
ref: github:docker/labs-ai-tools-for-devs?path=prompts/bootstrap.md
2213+
icon: https://avatars.githubusercontent.com/u/182288589?s=200&v=4

runbook.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ docker pull mcp/docker:prerelease
2020

2121
```sh
2222
# docker:command=build-release
23-
VERSION="0.0.6"
23+
VERSION="0.0.7"
2424
docker buildx build \
2525
--builder hydrobuild \
2626
--platform linux/amd64,linux/arm64 \

src/extension/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE?=docker/labs-ai-tools-for-devs
2-
TAG?=0.2.17
2+
TAG?=0.2.25
33

44
BUILDER=buildx-multi-arch
55

src/extension/docker-compose.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
mcp_docker:
3-
image: mcp/docker:0.0.6
3+
image: mcp/docker:0.0.7
44
ports:
55
- 8811:8811
66
volumes:
@@ -11,8 +11,6 @@ services:
1111
- --mcp
1212
- --port
1313
- "8811"
14-
- --register
15-
- github:docker/labs-ai-tools-for-devs?path=prompts/bootstrap.md
1614
volumes:
1715
docker-prompts:
1816
name: docker-prompts

src/extension/runbook.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ Then, you can push the image to Docker Hub using the following command:
3636
docker push docker<image-name>
3737
```
3838

39-
That's it! With these commands, you should be able to build, run, and share your project with ease.
39+
That's it! With these commands, you should be able to build, run, and share your project with ease.
40+
41+
```sh
42+
make build-extension
43+
```
44+
45+
```sh
46+
docker extension update docker/labs-ai-tools-for-devs:0.2.25
47+
```

src/jsonrpc/server.clj

+31-10
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,37 @@
6868
(logger/info "ping")
6969
{})
7070

71-
(defmethod lsp.server/receive-request "initialize" [_ {:keys [db*]} params]
72-
(logger/info "Initializing " params)
71+
(defmethod lsp.server/receive-request "initialize" [_ {:keys [db* server-id]} params]
72+
(logger/info (format "Initializing server id %d %s" server-id params))
7373

7474
;; merges client-info capabilities and client protocol-version
75-
(swap! db* merge params)
75+
(swap! db* assoc-in [:servers server-id] params)
7676
{:protocol-version "2024-11-05"
7777
:capabilities {:prompts {:listChanged true}
7878
:tools {:listChanged true}
7979
:resources {}}
8080
:server-info {:name "docker-mcp-server"
8181
:version "0.0.1"}})
8282

83-
(defmethod lsp.server/receive-notification "notifications/initialized" [_ _ _]
84-
(logger/info "Initialized!"))
83+
(defmethod lsp.server/receive-notification "notifications/initialized" [_ {:keys [db* server server-id]} _]
84+
(logger/info "Initialized! " (-> @db* :servers (get server-id)))
85+
(lsp.server/discarding-stdout
86+
(when (get-in @db* [:servers server-id :capabilities :roots])
87+
(let [response (lsp.server/deref-or-cancel
88+
(lsp.server/send-request server "roots/list" {})
89+
10e3 ::timeout)]
90+
(cond
91+
;;
92+
(= ::timeout response)
93+
(logger/error "No response from client for workspace/inlayHint/refresh")
94+
;;
95+
(:roots response)
96+
(do
97+
(logger/info "client sent roots " (:roots response))
98+
(swap! db* update-in [:servers server-id] (fnil merge {}) response))
99+
;;
100+
:else
101+
(logger/warn "unexpected response " response))))))
85102

86103
; level is debug info notice warning error critical alert emergency
87104
(defmethod lsp.server/receive-request "logging/setLevel" [_ {:keys [db*]} {:keys [level]}]
@@ -216,7 +233,7 @@
216233
" params
217234
db* - uses mcp.prompts/registry and host-dir
218235
params - tools/call mcp params"
219-
[{:keys [db*] :as components} params]
236+
[{:keys [db* server-id] :as components} params]
220237
(volumes/with-volume
221238
(fn [thread-id]
222239
;; TODO non-mcp tool calls are maps of content, role tool_call_id
@@ -235,14 +252,15 @@
235252
:thread-id thread-id})
236253
;; tool calls are functions, which are arguments,name maps, and ids
237254
;; mcp tool call params are also maps of name, and arguments
238-
;; TODO add the config parameters for just the registry entry that defines the tool
239255
[{:function (update
240256
params :arguments
241257
(fn [arguments]
242258
(logger/trace
243-
(-> arguments
244-
(merge (db/parameter-values (:name params)))
245-
(json/generate-string)))))
259+
(-> arguments
260+
(merge
261+
(db/parameter-values (:name params))
262+
(select-keys (-> @db* :servers (get server-id)) [:roots]))
263+
(json/generate-string)))))
246264
:id "1"}])
247265
(async/reduce conj [])
248266
(async/<!!))]
@@ -328,6 +346,8 @@
328346
(when (fs/exists? (fs/file registry))
329347
(db/registry-refs registry)))))
330348

349+
(def server-counter (atom 0))
350+
331351
(defn server-context
332352
"create chan server options for any io chan server that we build"
333353
[{:keys [trace-level] :or {trace-level "off"} :as opts}]
@@ -361,6 +381,7 @@
361381
{:db* db*
362382
:logger timbre-logger
363383
:producer producer
384+
:server-id (swap! server-counter inc)
364385
:server server}))}
365386
(when (:mcp opts)
366387
{:in-chan-factory io-chan/mcp-input-stream->input-chan

0 commit comments

Comments
 (0)