get list_snippets and get_snippet mcp tools working
This commit is contained in:
parent
8ea0eee299
commit
f122acc72a
2 changed files with 45 additions and 11 deletions
|
|
@ -1,2 +1,2 @@
|
||||||
;; {:backend-host "http://localhost:8080"}
|
{:backend-host "http://localhost:8080"}
|
||||||
{:backend-host "http://aemos:5008"}
|
;; {:backend-host "http://aemos:5008"}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,56 @@
|
||||||
(ns cli.mcp
|
(ns cli.mcp
|
||||||
(:require
|
(:require
|
||||||
[cli.view :as view]
|
[babashka.http-client :as http]
|
||||||
|
[cli.config :refer [config]]
|
||||||
|
[clojure.edn :as edn]
|
||||||
[cheshire.core :as json]))
|
[cheshire.core :as json]))
|
||||||
|
|
||||||
;; Tool definitions
|
;; Tool definitions
|
||||||
(def available-tools
|
(def available-tools
|
||||||
[{:name "list_snippets"
|
[{: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"
|
:inputSchema {:type "object"
|
||||||
:properties {}
|
: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
|
;; Tool implementations
|
||||||
(defn list-snippets-impl []
|
(defn list-snippets-impl []
|
||||||
(try
|
(try
|
||||||
(let [snippets (view/fetch-snippets)]
|
(let [snippets (fetch-snippets)]
|
||||||
{:success true
|
{:content [{:type "text"
|
||||||
:snippets (map #(select-keys % [:id :title :slug :tags]) snippets)})
|
:text (json/encode {:success true
|
||||||
|
:snippets (map #(select-keys % [:id :title :slug :tags]) snippets)})}]})
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
{:success false
|
{:content [{:type "text"
|
||||||
:error (.getMessage e)})))
|
: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
|
;; Handle tools/list request
|
||||||
(defn handle-tools-list [id]
|
(defn handle-tools-list [id]
|
||||||
|
|
@ -33,6 +64,7 @@
|
||||||
:id id
|
:id id
|
||||||
: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))
|
||||||
{:error (str "Unknown tool: " tool-name)})})
|
{:error (str "Unknown tool: " tool-name)})})
|
||||||
|
|
||||||
;; Handle initialize request
|
;; Handle initialize request
|
||||||
|
|
@ -44,7 +76,9 @@
|
||||||
:resources {:listChanged true}
|
:resources {:listChanged true}
|
||||||
:prompts {:listChanged true}}
|
:prompts {:listChanged true}}
|
||||||
:serverInfo {:name "snippets-server"
|
: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
|
;; Main request dispatcher
|
||||||
(defn handle-request [request]
|
(defn handle-request [request]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue