add create_snippet mcp tool
This commit is contained in:
parent
f122acc72a
commit
42f853a91f
1 changed files with 32 additions and 1 deletions
|
|
@ -17,7 +17,20 @@
|
||||||
:inputSchema {:type "object"
|
:inputSchema {:type "object"
|
||||||
:properties {:id {:type "string"
|
:properties {:id {:type "string"
|
||||||
:description "The id of the snippet to retrieve"}}
|
: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 []
|
(defn fetch-snippets []
|
||||||
(let [res (http/get (str (:backend-host config) "/api/snippets?limit=2000"))]
|
(let [res (http/get (str (:backend-host config) "/api/snippets?limit=2000"))]
|
||||||
|
|
@ -29,6 +42,11 @@
|
||||||
:query-params {:id id}})]
|
:query-params {:id id}})]
|
||||||
(edn/read-string (:body res))))
|
(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
|
;; Tool implementations
|
||||||
(defn list-snippets-impl []
|
(defn list-snippets-impl []
|
||||||
(try
|
(try
|
||||||
|
|
@ -52,6 +70,18 @@
|
||||||
:text (json/encode {:success false
|
:text (json/encode {:success false
|
||||||
:error (.getMessage e)})}]})))
|
: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
|
;; Handle tools/list request
|
||||||
(defn handle-tools-list [id]
|
(defn handle-tools-list [id]
|
||||||
{:jsonrpc "2.0"
|
{:jsonrpc "2.0"
|
||||||
|
|
@ -65,6 +95,7 @@
|
||||||
:result (case tool-name
|
:result (case tool-name
|
||||||
"list_snippets" (list-snippets-impl)
|
"list_snippets" (list-snippets-impl)
|
||||||
"get_snippet" (get-snippet-impl (:id tool-input))
|
"get_snippet" (get-snippet-impl (:id tool-input))
|
||||||
|
"create_snippet" (create-snippet-impl tool-input)
|
||||||
{:error (str "Unknown tool: " tool-name)})})
|
{:error (str "Unknown tool: " tool-name)})})
|
||||||
|
|
||||||
;; Handle initialize request
|
;; Handle initialize request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue