Skip to content

Commit

Permalink
repl testing of mcp server
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Dec 5, 2024
1 parent 4a3504c commit 0b88534
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/docker/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[git.registry :as registry]
graph
jsonrpc
[jsonrpc.db :as db]
[jsonrpc.logger :as logger]
jsonrpc.producer
jsonrpc.server
[logging :refer [warn]]
Expand Down Expand Up @@ -169,6 +171,11 @@
(constantly
(fn [method params]
(jsonrpc.producer/publish-docker-notify producer method params))))
(when (:prompts opts)
(try
(db/add opts)
(catch Throwable t
(logger/error t))))
(let [finished @server-promise]
{:result-code (if (= :done finished) 0 1)})))
(fn []
Expand Down
28 changes: 26 additions & 2 deletions src/jsonrpc.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns jsonrpc
(:require
[babashka.process :as process]
[cheshire.core :as json]
[clojure.core.async :as async]
[clojure.java.io :as io]
Expand Down Expand Up @@ -143,6 +144,30 @@
(comment
(notify :message {:content "message"}))

(comment
(def mcp
(process/process {:err :string}
"docker"
"run"
"-i"
"-v" "/var/run/docker.sock:/var/run/docker.sock"
"--mount" "type=volume,source=docker-prompts,target=/prompts"
"vonwig/prompts:local"
"serve"
"--host-dir" "/Users/slim/docker/labs-ai-tools-for-devs"
"--prompts" "github:docker/labs-ai-tools-for-devs?path=prompts/examples/explain_dockerfile.md"))
(async/thread
(with-open [rdr (io/reader (:out mcp))]
(binding [*in* rdr]
(loop []
(when-let [line (read-line)]
(println :mcp line)
(recur))))))
(write-message (:in mcp) (request "ping" {} (constantly 1)))
(-> @mcp :err)
(-> @mcp :out slurp)
)

(comment
"tool module
:start for container runs or failures
Expand All @@ -163,5 +188,4 @@
:message :debug when entering a new node of the state machine
main
:messsage :content for the final output
"
)
")
4 changes: 3 additions & 1 deletion src/jsonrpc/db.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
(ns jsonrpc.db
(:require
git
[jsonrpc.logger :as logger]
prompts))

(def db* (atom {}))

(defn get-prompt-data [{:keys [prompts] :as opts}]
(let [f (git/prompt-file prompts)
(let [f (if (string? prompts) (git/prompt-file prompts) prompts)
{:keys [messages metadata functions] :as entry} (prompts/get-prompts (assoc opts :prompts f))]
entry))

(defn add [opts]
(logger/info "adding prompts" (:prompts opts))
(swap! db* update-in [:mcp.prompts/registry] (fnil assoc {}) (:prompts opts) (get-prompt-data opts)))

(comment
Expand Down

0 comments on commit 0b88534

Please sign in to comment.