adjust to work with datomic backend that does not use ids

This commit is contained in:
Travis Shears 2026-03-11 09:46:15 +01:00
parent ea4e78a737
commit f7d5762b77
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
5 changed files with 16 additions and 16 deletions

View file

@ -14,15 +14,15 @@
(let [params (if limit {:limit limit} {})]
(get-request "/api/snippets" params)))
(defn fetch-snippet [id]
(get-request "/api/snippet" {:id id}))
(defn fetch-snippet [slug]
(get-request "/api/snippet-by-slug" {:slug slug}))
(defn delete-snippet [id]
(http/delete (str (:backend-host config) "/api/snippet") {:query-params {"id" id}}))
(defn delete-snippet [slug]
(http/delete (str (:backend-host config) "/api/snippet") {:query-params {"slug" slug}}))
(defn update-snippet [id patch]
(defn update-snippet [slug patch]
(http/patch (str (:backend-host config) "/api/snippet")
{:query-params {:id id}
{:query-params {:slug slug}
:headers {:accept "application/edn"
:content-type "application/edn"}
:body (pr-str patch)}))

View file

@ -15,9 +15,9 @@
{: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"]}}
:properties {:slug {:type "string"
:description "The slug of the snippet to retrieve"}}
:required ["slug"]}}
{:name "create_snippet"
:description "Create a new code snippet with title, slug, markdown content, and tags"
:inputSchema {:type "object"
@ -47,8 +47,8 @@
(let [snippets (fetch-snippets)]
{:snippets (map #(select-keys % [:id :title :slug :tags]) snippets)}))
(defn get-snippet-impl [id]
(let [snippet (fetch-snippet id)]
(defn get-snippet-impl [slug]
(let [snippet (fetch-snippet slug)]
{:snippet snippet}))
(defn create-snippet-impl [{:keys [title slug markdown tags]}]
@ -68,7 +68,7 @@
:id id
:result (case tool-name
"list_snippets" (mcp-res list-snippets-impl [])
"get_snippet" (mcp-res get-snippet-impl [(:id tool-input)])
"get_snippet" (mcp-res get-snippet-impl [(:slug tool-input)])
"create_snippet" (mcp-res create-snippet-impl [tool-input])
{:error (str "Unknown tool: " tool-name)})})

View file

@ -5,4 +5,4 @@
(defn run []
(let [selected-snippet (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
(delete-snippet (:id selected-snippet))))
(delete-snippet (:slug selected-snippet))))

View file

@ -29,6 +29,6 @@
(defn run []
(let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
(update-snippet (:id snippet-to-edit) (edit snippet-to-edit))
(update-snippet (:slug snippet-to-edit) (edit snippet-to-edit))
(println "Snippet updated successfully")
(view/view (fetch-snippet (:id snippet-to-edit)))))
(view/view (fetch-snippet (:slug snippet-to-edit)))))

View file

@ -13,4 +13,4 @@
(defn run []
(let [snippet-to-view (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets 25)))]
(view (fetch-snippet (:id snippet-to-view)))))
(view (fetch-snippet (:slug snippet-to-view)))))