From 42f853a91f9a478e1006dfee2723fd8a28359004 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Sun, 8 Mar 2026 17:59:31 +0100 Subject: [PATCH] add create_snippet mcp tool --- src/cli/mcp.clj | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/cli/mcp.clj b/src/cli/mcp.clj index 97e51d5..5b420fa 100644 --- a/src/cli/mcp.clj +++ b/src/cli/mcp.clj @@ -17,7 +17,20 @@ :inputSchema {:type "object" :properties {:id {:type "string" :description "The id of the snippet to retrieve"}} - :required ["id"]}}]) + :required ["id"]}} + {:name "create_snippet" + :description "Create a new code snippet with title, slug, markdown content, and tags" + :inputSchema {:type "object" + :properties {:title {:type "string" + :description "The title of the snippet"} + :slug {:type "string" + :description "A URL-friendly slug for the snippet"} + :markdown {:type "string" + :description "The markdown content of the snippet"} + :tags {:type "array" + :items {:type "string"} + :description "Array of tags for categorizing the snippet"}} + :required ["title" "slug" "markdown" "tags"]}}]) (defn fetch-snippets [] (let [res (http/get (str (:backend-host config) "/api/snippets?limit=2000"))] @@ -29,6 +42,11 @@ :query-params {:id id}})] (edn/read-string (:body res)))) +(defn create-snippet [{:keys [title slug markdown tags]}] + (http/post (str (:backend-host config) "/api/snippet") + {:headers {:content-type "application/edn"} + :body (pr-str {:title title :slug slug :markdown markdown :tags tags})})) + ;; Tool implementations (defn list-snippets-impl [] (try @@ -52,6 +70,18 @@ :text (json/encode {:success false :error (.getMessage e)})}]}))) +(defn create-snippet-impl [{:keys [title slug markdown tags]}] + (try + (let [response (create-snippet {:title title :slug slug :markdown markdown :tags tags})] + {:content [{:type "text" + :text (json/encode {:success true + :message "Snippet created successfully" + :status (:status response)})}]}) + (catch Exception e + {:content [{:type "text" + :text (json/encode {:success false + :error (.getMessage e)})}]}))) + ;; Handle tools/list request (defn handle-tools-list [id] {:jsonrpc "2.0" @@ -65,6 +95,7 @@ :result (case tool-name "list_snippets" (list-snippets-impl) "get_snippet" (get-snippet-impl (:id tool-input)) + "create_snippet" (create-snippet-impl tool-input) {:error (str "Unknown tool: " tool-name)})}) ;; Handle initialize request