Browse Source

chore: remove unused write tools

Also revert related changes on api fns
Gabriel Horner 1 week ago
parent
commit
e5258c0708
2 changed files with 11 additions and 62 deletions
  1. 2 36
      deps/cli/src/logseq/cli/common/mcp/server.cljs
  2. 9 26
      src/main/logseq/api.cljs

+ 2 - 36
deps/cli/src/logseq/cli/common/mcp/server.cljs

@@ -85,14 +85,11 @@
 
 (defn- api-tool
   "Calls API method w/ args and returns a MCP response"
-  [api-fn api-method method-args & {:keys [write-tool?]}]
+  [api-fn api-method method-args]
   (-> (p/let [body (api-fn api-method method-args)]
         (if-let [error (and body (aget body "error"))]
           (mcp-error-response (str "API Error: " error))
-          (if write-tool?
-            ;; Writes that return have succeeded since writes fail fast if they don't write
-            (mcp-success-response {:ok true})
-            (mcp-success-response body))))
+          (mcp-success-response body)))
       (p/catch unexpected-api-error)))
 
 (defn- api-get-page
@@ -111,22 +108,6 @@
   [call-api-fn _args]
   (call-api-fn "logseq.cli.listProperties" []))
 
-(defn- api-add-to-page
-  [call-api-fn args]
-  (call-api-fn "logseq.editor.appendBlockInPage"
-               [(aget args "pageName")
-                (aget args "content")
-                #js {:mcp-options #js {:force (aget args "force")}}]
-               {:write-tool? true}))
-
-(defn- api-update-block
-  [call-api-fn args]
-  (call-api-fn "logseq.editor.updateBlock"
-               [(aget args "blockUUID")
-                (aget args "content")
-                #js {:mcp true}]
-               {:write-tool? true}))
-
 (defn- api-search-blocks
   [call-api-fn args]
   (call-api-fn "logseq.app.search" [(aget args "searchTerm") #js {:enable-snippet? false}]))
@@ -146,21 +127,6 @@
     :config #js {:title "Get Page"
                  :description "Get a page's content including its blocks. A property and a tag are pages."
                  :inputSchema #js {:pageName (-> (z/string) (.describe "The page's name or uuid"))}}}
-   :addToPage
-   {:fn api-add-to-page
-    :config #js {:title "Add to Page"
-                 :description "Add a block to a page"
-                 :inputSchema #js {:pageName (-> (z/string) (.describe "The page's name or uuid"))
-                                   :content (-> (z/string) (.describe "Block content"))
-                                   :force (-> (z/boolean)
-                                              (z/optional)
-                                              (.describe "Force given page to be created"))}}}
-   :updateBlock
-   {:fn api-update-block
-    :config #js {:title "Update Block"
-                 :description "Update block with new content"
-                 :inputSchema #js {:blockUUID (z/string)
-                                   :content (-> (z/string) (.describe "Block content"))}}}
    :upsertNodes
    {:fn api-upsert-nodes
     :config

+ 9 - 26
src/main/logseq/api.cljs

@@ -49,6 +49,7 @@
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             [logseq.api.block :as api-block]
+            [logseq.cli.common.mcp.tools :as cli-common-mcp-tools]
             [logseq.common.util :as common-util]
             [logseq.common.util.date-time :as date-time-util]
             [logseq.db :as ldb]
@@ -61,8 +62,7 @@
             [logseq.sdk.ui :as sdk-ui]
             [logseq.sdk.utils :as sdk-utils]
             [promesa.core :as p]
-            [reitit.frontend.easy :as rfe]
-            [logseq.cli.common.mcp.tools :as cli-common-mcp-tools]))
+            [reitit.frontend.easy :as rfe]))
 
 ;; Alert: this namespace shouldn't invoke any reactive queries
 
@@ -795,24 +795,18 @@
        {:block/uuid (sdk-utils/uuid-or-throw-error block-uuid) :repo repo}))))
 
 (def ^:export update_block
-  "Updates block with 3rd arg being a js map with following keys:
-   * :mcp - When set behaves as MCP tools expect
-   * :properties - A map of properties to update
-   * Remaining keys are passed to save-block!"
   (fn [block-uuid content ^js opts]
     (p/let [repo (state/get-current-repo)
             db-base? (config/db-based-graph? repo)
             block (<pull-block block-uuid)
             opts (bean/->clj opts)]
-      (if block
+      (when block
         (p/do!
          (when (and db-base? (seq (:properties opts)))
            (api-block/save-db-based-block-properties! block (:properties opts)))
          (editor-handler/save-block! repo
                                      (sdk-utils/uuid-or-throw-error block-uuid) content
-                                     (if db-base? (dissoc opts :properties) opts)))
-        (when (:mcp opts)
-          (throw (ex-info (str "Block " (pr-str block-uuid) " not found") {})))))))
+                                     (if db-base? (dissoc opts :properties) opts)))))))
 
 (def ^:export move_block
   (fn [src-block-uuid target-block-uuid ^js opts]
@@ -1084,16 +1078,10 @@
                       (insert_block target content (bean/->js opts)))))))))
 
 (defn ^:export append_block_in_page
-  "Append a block to a page and creates page if it does not exist.
-   If the 'mcp-options' opts key is set, this fn assumes MCP defaults by not creating a page unless explicitly
-   forced to. `opts` arg are options passed to `insert_block` except for
-   key the 'mcp-options', which has the following keys:
-   * :force - When set forces creation of nonexistent page"
   [uuid-or-page-name content ^js opts]
   (let [current-page? (or (and (nil? content) (nil? opts))
                           (and (nil? opts) (some->> content (instance? js/Object))))
         opts (if current-page? content opts)
-        mcp-options (some-> opts (aget "mcp-options") bean/->clj)
         content (if current-page? uuid-or-page-name content)
         uuid-or-page-name (if current-page?
                             (or (state/get-current-page) (date/today))
@@ -1101,17 +1089,12 @@
     (p/let [_ (<ensure-page-loaded uuid-or-page-name)
             page? (not (util/uuid-string? uuid-or-page-name))
             page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
-            _ (when (and page-not-exist?
-                         (or (nil? mcp-options)
-                             (:force mcp-options)))
-                (page-handler/<create! uuid-or-page-name
-                                       {:redirect? false
-                                        :format (state/get-preferred-format)}))]
-      (if-let [block (db-model/get-page uuid-or-page-name)]
+            _ (and page-not-exist? (page-handler/<create! uuid-or-page-name
+                                                          {:redirect? false
+                                                           :format (state/get-preferred-format)}))]
+      (when-let [block (db-model/get-page uuid-or-page-name)]
         (let [target (str (:block/uuid block))]
-          (insert_block target content opts))
-        (when mcp-options
-          (throw (ex-info (str "Page " (pr-str uuid-or-page-name) " not found") {})))))))
+          (insert_block target content opts))))))
 
 ;; plugins
 (defn ^:export validate_external_plugins [urls]