Skip to content

Commit eb35536

Browse files
add hooks
1 parent b06b65c commit eb35536

File tree

7 files changed

+121
-51
lines changed

7 files changed

+121
-51
lines changed

dev/catalog.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
prompts))
88

99
(prompts/get-prompts {:prompts (fs/file "prompts/examples/mcp-memory.md")})
10-
(yaml/parse-string (slurp "prompts/examples/mcp-memory.md"))
1110

1211
(defn f->prompt [f]
1312
(prompts/get-prompts {:prompts f}))

prompts/catalog.yaml

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ registry:
107107
- type: function
108108
function:
109109
name: hello-docker
110-
description: print a secret message
110+
description: send a greeting from docker
111111
parameters:
112112
type: object
113113
properties:
114114
greeting: {type: string, description: the greeting to send}
115+
required: [greeting]
115116
container:
116117
image: busybox:latest
117118
command: [echo, '{{greeting}}']
@@ -227,21 +228,24 @@ registry:
227228
type: object
228229
properties:
229230
host-dir: {type: string}
231+
name: {type: string}
230232
container:
231-
image: vonwig/speculative:latest
232-
mounts: ['{{host-dir|safe}}:/repo']
233-
commands: [sandbox, source, /repo]
233+
image: lorax:latest
234+
entrypoint: lorax
235+
command: [sandbox, source, -n, '{{name}}', '{{host-dir}}']
236+
background: true
234237
- type: function
235238
function:
236239
name: sandbox-clone
237-
description: create a sandbox for a host repo and respond with the id of the new sandbox
240+
description: create a sandbox and respond with the id of the new sandbox
238241
parameters:
239242
type: object
240243
properties:
241244
sandbox-name: {type: string}
242245
container:
243-
image: vonwig/speculative:latest
244-
commands: [sandbox, clone, user-source, --name, '{{sandbox-name}}']
246+
image: lorax:latest
247+
entrypoint: lorax
248+
command: [sandbox, clone, '{{sandbox-name}}']
245249
- type: function
246250
function:
247251
name: sandbox-snapshot
@@ -251,8 +255,9 @@ registry:
251255
properties:
252256
sandbox-id: {type: string}
253257
container:
254-
image: vonwig/speculative:latest
255-
commands: [sandbox, snapshot, '{{sandbox-id}}']
258+
image: lorax:latest
259+
entrypoint: lorax
260+
command: [sandbox, snapshot, '{{sandbox-id}}']
256261
- type: function
257262
function:
258263
name: sandbox-restore
@@ -263,8 +268,9 @@ registry:
263268
sandbox-id: {type: string}
264269
tree-id: {type: string}
265270
container:
266-
image: vonwig/speculative:latest
267-
commands: [sandbox, restore, '{{sandbox-id}}', '{{tree-id}}']
271+
image: lorax:latest
272+
entrypoint: lorax
273+
command: [sandbox, restore, '{{sandbox-id}}', '{{tree-id}}']
268274
- type: function
269275
function:
270276
name: sandbox-exec
@@ -275,8 +281,9 @@ registry:
275281
sandbox-id: {type: string}
276282
image: {type: string}
277283
container:
278-
image: vonwig/speculative:latest
279-
commands: [sandbox, exec, --mount-image, '{{image}}', '{{sandbox-id}}']
284+
image: lorax:latest
285+
entrypoint: lorax
286+
command: [sandbox, exec, --mount-image, '{{image}}', '{{sandbox-id}}']
280287
- type: function
281288
function:
282289
name: sandbox-delete-file
@@ -287,8 +294,9 @@ registry:
287294
sandbox-id: {type: string}
288295
path: {type: string}
289296
container:
290-
image: vonwig/speculative:latest
291-
commands: [sandbox, delete, '{{sandbox-id}}', '{{path}}']
297+
image: lorax:latest
298+
entrypoint: lorax
299+
command: [sandbox, delete, '{{sandbox-id}}', '{{path}}']
292300
- type: function
293301
function:
294302
name: sandbox-rm
@@ -299,8 +307,9 @@ registry:
299307
sandbox-id: {type: string}
300308
path: {type: string}
301309
container:
302-
image: vonwig/speculative:latest
303-
commands: [sandbox, rm, '{{sandbox-id}}']
310+
image: lorax:latest
311+
entrypoint: lorax
312+
command: [sandbox, rm, '{{sandbox-id}}']
304313
- type: function
305314
function:
306315
name: sandbox-diff
@@ -311,8 +320,9 @@ registry:
311320
sandbox-id: {type: string}
312321
tree-id: {type: string}
313322
container:
314-
image: vonwig/speculative:latest
315-
commands: [sandbox, diff, '{{sandbox-id}}', '{{tree-id}}']
323+
image: lorax:latest
324+
entrypoint: lorax
325+
command: [sandbox, diff, '{{sandbox-id}}', '{{tree-id}}']
316326
- type: function
317327
function:
318328
name: sandbox-apply
@@ -322,8 +332,9 @@ registry:
322332
properties:
323333
diff: {type: string}
324334
container:
325-
image: vonwig/speculative:latest
326-
commands: [sandbox, apply, user-source, '{{diff}}']
335+
image: lorax:latest
336+
entrypoint: lorax
337+
command: [sandbox, apply, user-source, '{{diff}}']
327338
prompts: 1
328339
resources: {}
329340
memory:
@@ -354,7 +365,7 @@ registry:
354365
container:
355366
image: vonwig/memory:latest
356367
volumes: ['mcp-memory:/memory']
357-
command: [create-entities, '{{raw}}']
368+
command: [create-entities, '{{raw|safe}}']
358369
- type: function
359370
function:
360371
name: create_relations
@@ -375,7 +386,7 @@ registry:
375386
container:
376387
image: vonwig/memory:latest
377388
volumes: ['mcp-memory:/memory']
378-
command: [create-relations, '{{raw}}']
389+
command: [create-relations, '{{raw|safe}}']
379390
- type: function
380391
function:
381392
name: add_observations
@@ -398,7 +409,7 @@ registry:
398409
container:
399410
image: vonwig/memory:latest
400411
volumes: ['mcp-memory:/memory']
401-
command: [add-observations, '{{raw}}']
412+
command: [add-observations, '{{raw|safe}}']
402413
- type: function
403414
function:
404415
name: delete_entities
@@ -414,7 +425,7 @@ registry:
414425
container:
415426
image: vonwig/memory:latest
416427
volumes: ['mcp-memory:/memory']
417-
command: [delete-entities, '{{raw}}']
428+
command: [delete-entities, '{{raw|safe}}']
418429
- type: function
419430
function:
420431
name: delete_observations
@@ -437,7 +448,7 @@ registry:
437448
container:
438449
image: vonwig/memory:latest
439450
volumes: ['mcp-memory:/memory']
440-
command: [delete-observations, '{{raw}}']
451+
command: [delete-observations, '{{raw|safe}}']
441452
- type: function
442453
function:
443454
name: delete_relations
@@ -459,16 +470,18 @@ registry:
459470
container:
460471
image: vonwig/memory:latest
461472
volumes: ['mcp-memory:/memory']
462-
command: [delete-releations, '{{raw}}']
473+
command: [delete-relations, '{{raw|safe}}']
463474
- type: function
464475
function:
465476
name: read_graph
466477
description: Read the entire knowledge graph
467-
parameters: {type: object, properties: null}
478+
parameters:
479+
type: object
480+
properties: {}
468481
container:
469482
image: vonwig/memory:latest
470483
volumes: ['mcp-memory:/memory']
471-
command: [read-graph, '{{raw}}']
484+
command: [read-graph, '{{raw|safe}}']
472485
- type: function
473486
function:
474487
name: search_nodes
@@ -481,7 +494,7 @@ registry:
481494
container:
482495
image: vonwig/memory:latest
483496
volumes: ['mcp-memory:/memory']
484-
command: [search-nodes, '{{raw}}']
497+
command: [search-nodes, '{{raw|safe}}']
485498
- type: function
486499
function:
487500
name: open_nodes
@@ -497,10 +510,49 @@ registry:
497510
container:
498511
image: vonwig/memory:latest
499512
volumes: ['mcp-memory:/memory']
500-
command: [open-nodes, '{{raw}}']
501-
prompts: 1
513+
command: [open-nodes, '{{raw|safe}}']
514+
prompts: 0
502515
resources: {}
503516
chrome:
504517
description: Drive a headless Chrome browser to interact with web pages
505518
ref: github:docker/labs-ai-tools-for-devs?path=prompts/chrome.md
506519
icon: https://cdn.jsdelivr.net/npm/simple-icons@v7/icons/googlechrome.svg
520+
tools:
521+
- type: function
522+
function:
523+
name: websocat
524+
description: A tool to send and receive messages over a websocket.
525+
parameters:
526+
type: object
527+
properties:
528+
url: {type: string, description: The url of the websocket endpoint.}
529+
message: {type: string, description: The message to send to websocat on stdin.}
530+
websocat_args:
531+
type: array
532+
items: {type: string}
533+
description: The arguments to pass to websocat.
534+
required: [url, message, websocat_args]
535+
container:
536+
image: vonwig/websocat:latest
537+
stdin: {content: '{{message|safe}}'}
538+
command: ['{{websocat_args|into}}', '{{url|safe}}']
539+
- type: function
540+
function:
541+
name: curl-manual
542+
description: Run the man page for curl
543+
container:
544+
image: vonwig/curl:latest
545+
command: ['{{raw|safe}}', man]
546+
- type: function
547+
function:
548+
description: Run a curl command.
549+
parameters:
550+
type: object
551+
properties:
552+
args: {type: string, description: The arguments to pass to curl}
553+
container:
554+
image: vonwig/curl:latest
555+
command: ['{{raw|safe}}']
556+
name: curl
557+
prompts: 2
558+
resources: {}

prompts/examples/mcp-memory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: mcp-memory
33
description: Create a memory system for conversational agents
44
model: claude-3-5-sonnet-20241022
55
defs:
6-
- lorax: &memory
6+
- memory: &memory
77
image: vonwig/memory:latest
88
volumes:
99
- "mcp-memory:/memory"

src/docker.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
jsonrpc
1010
[jsonrpc.logger :as logger]
1111
logging
12-
schema)
12+
schema
13+
shutdown)
1314
(:import
1415
[java.net UnixDomainSocketAddress]
1516
[java.nio ByteBuffer]
@@ -300,7 +301,10 @@
300301
(-pull m))
301302
(let [x (create m)]
302303
(start x)
303-
;; TODO schedule shutdown hook
304+
(shutdown/schedule-container-shutdown
305+
(fn []
306+
(kill-container x)
307+
(delete x)))
304308
{:done :running}))
305309

306310
(defn run-function

src/jsonrpc/db.clj

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
(def db* (atom {}))
1111

12-
(defn get-prompt-data
13-
"register is a coll of prompt file ref maps"
12+
(defn- get-prompt-data
13+
"get map of prompt data from a set of prompt files
14+
params
15+
register is a coll of prompt file ref maps"
1416
[{:keys [register] :as opts}]
1517
(->> register
1618
(map (fn [{:keys [cached-path ref-string]}]
1719
(let [m (prompts/get-prompts (assoc opts :prompts cached-path))]
1820
[(or (-> m :metadata :name) ref-string) m])))
1921
(into {})))
2022

21-
(defn extract-resources [m]
23+
(defn- extract-resources
24+
"extract resource map from a prompt"
25+
[m]
2226
(->> (vals m)
2327
(map (comp :resources :metadata))
2428
(filter identity)
@@ -29,31 +33,32 @@
2933
{:text (-> entry :default :text)}))]))
3034
(into {})))
3135

32-
(defn add-static-prompts [db m]
36+
(defn- add-static-prompts
37+
[db m]
3338
(-> db
3439
(update :mcp.prompts/registry (fnil merge {}) m)
3540
(assoc :mcp.prompts/static m)
3641
(update :mcp.prompts/resources (fnil merge {}) (extract-resources m))))
3742

38-
(defn add-dynamic-prompts [db m]
43+
(defn- add-dynamic-prompts [db m]
3944
(logger/info "dynamic keys" (keys (:mcp.prompts/registry db)))
4045
(logger/info "static keys" (keys (:mcp.prompts/static db)))
4146
(-> db
4247
(assoc :mcp.prompts/registry (merge m (:mcp.prompts/static db)))
4348
(update :mcp.prompts/resources (fnil merge {}) (extract-resources m))))
4449

45-
(defn update-dynamic [coll]
50+
(defn- update-dynamic [coll]
4651
(swap! db* add-dynamic-prompts (get-prompt-data {:register coll})))
47-
(defn update-static [coll]
52+
(defn- update-static [coll]
4853
(swap! db* add-static-prompts (get-prompt-data {:register coll})))
4954

50-
(defn missing-cached-prompt-file? [m]
55+
(defn- missing-cached-prompt-file? [m]
5156
(when (not (contains? m :cached-path))
5257
(logger/warn "missing cached path: %s" (:ref-string m))
5358
m))
5459

5560
(defn add-refs
56-
"update the db with new refs
61+
"update the db with new refs after rereshing the cache from git
5762
params
5863
refs - coll of [type ref] type is static or dynamic"
5964
[refs]
@@ -86,7 +91,9 @@
8691
(constantly (or (:mcp.prompts/static db) {})))))))
8792
(logger/info "resources are " (:mcp.prompts/resources @db*)))
8893

89-
(defn update-prompt [opts s content]
94+
(defn update-prompt
95+
"update the db with new markdown prompt content being dynamically registered"
96+
[opts s content]
9097
(logger/info (format "update prompt %s with content %s" s content))
9198
(let [m (prompts/get-prompts
9299
(assoc opts :prompt-content content))]
@@ -101,6 +108,7 @@
101108
(-> @db* :mcp.prompts/registry (get "github-issues"))
102109
(update-prompt {} "github-issues" (slurp "prompts/examples/github_issues.md")))
103110

111+
;; the registry.yaml file is a list of refs selected from our catalog
104112
(defn registry-refs
105113
"parse refs from the registry.yaml file - these are dynamic"
106114
[f]

src/jsonrpc/server.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
:producer producer
377377
:server server}]
378378
(swap! db* merge {:log-path log-path} (dissoc opts :in))
379+
(shutdown/init)
379380
;; register static prompts
380381
(doseq [[s content] (->> (fs/list-dir "/prompts")
381382
(filter (fn [f] (= "md" (fs/extension f))))

0 commit comments

Comments
 (0)