diff --git a/config.edn b/config.edn index fd98ff5..90e2cc7 100644 --- a/config.edn +++ b/config.edn @@ -1,2 +1,2 @@ -;; {:backend-host "http://localhost:8080"} -{:backend-host "http://aemos:5008"} +{:backend-host "http://localhost:8080"} +;; {:backend-host "http://aemos:5008"} diff --git a/src/cli/mcp.clj b/src/cli/mcp.clj index 9186bcf..97e51d5 100644 --- a/src/cli/mcp.clj +++ b/src/cli/mcp.clj @@ -1,25 +1,56 @@ (ns cli.mcp (:require - [cli.view :as view] + [babashka.http-client :as http] + [cli.config :refer [config]] + [clojure.edn :as edn] [cheshire.core :as json])) ;; Tool definitions (def available-tools [{:name "list_snippets" - :description "List all available code snippets" + :description "List all available personal code snippets. Lists the id, title, slug, and tags of each snippet." :inputSchema {:type "object" :properties {} - :required []}}]) + :required []}} + {:name "get_snippet" + :description "Get a specific snippet by id, including body, tags, slug, title, and other details" + :inputSchema {:type "object" + :properties {:id {:type "string" + :description "The id of the snippet to retrieve"}} + :required ["id"]}}]) + +(defn fetch-snippets [] + (let [res (http/get (str (:backend-host config) "/api/snippets?limit=2000"))] + (json/parse-string (:body res) true))) + +(defn fetch-snippet [id] + (let [res (http/get (str (:backend-host config) "/api/snippet") + {:headers {"Accept" "application/edn"} + :query-params {:id id}})] + (edn/read-string (:body res)))) ;; Tool implementations (defn list-snippets-impl [] (try - (let [snippets (view/fetch-snippets)] - {:success true - :snippets (map #(select-keys % [:id :title :slug :tags]) snippets)}) + (let [snippets (fetch-snippets)] + {:content [{:type "text" + :text (json/encode {:success true + :snippets (map #(select-keys % [:id :title :slug :tags]) snippets)})}]}) (catch Exception e - {:success false - :error (.getMessage e)}))) + {:content [{:type "text" + :text (json/encode {:success false + :error (.getMessage e)})}]}))) + +(defn get-snippet-impl [id] + (try + (let [snippet (fetch-snippet id)] + {:content [{:type "text" + :text (json/encode {:success true + :snippet snippet})}]}) + (catch Exception e + {:content [{:type "text" + :text (json/encode {:success false + :error (.getMessage e)})}]}))) ;; Handle tools/list request (defn handle-tools-list [id] @@ -33,6 +64,7 @@ :id id :result (case tool-name "list_snippets" (list-snippets-impl) + "get_snippet" (get-snippet-impl (:id tool-input)) {:error (str "Unknown tool: " tool-name)})}) ;; Handle initialize request @@ -44,7 +76,9 @@ :resources {:listChanged true} :prompts {:listChanged true}} :serverInfo {:name "snippets-server" - :version "1.0.0"}}}) + :description "MCP server for managing and retrieving my personal code snippets. Provides access to a library of reusable code examples, templates, and + utilities both for terminal and code files." + :version "1.1.0"}}}) ;; Main request dispatcher (defn handle-request [request]