浏览代码

fix: fixes related to getPage tool

Fix getPage returning successful when no page found. Also make pageName
arg consistent with other tools. Also fix api server error where
a nil response fails the 500 check
Gabriel Horner 1 月之前
父节点
当前提交
d83641b08c

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

@@ -141,7 +141,7 @@
    {:fn api-get-page
     :config #js {:title "Get Page"
                  :description "Get a page's content including its blocks"
-                 :inputSchema #js {:pageName (z/string)}}}
+                 :inputSchema #js {:pageName (-> (z/string) (.describe "The page's name or uuid"))}}}
    :addToPage
    {:fn api-add-to-page
     :config #js {:title "Add to Page"

+ 2 - 3
deps/cli/src/logseq/cli/common/mcp/tools.cljs

@@ -3,7 +3,6 @@
   (:require [datascript.core :as d]
             [logseq.db :as ldb]
             [logseq.db.frontend.entity-util :as entity-util]
-            [logseq.db.common.initial-data :as common-initial-data]
             [logseq.db.frontend.property :as db-property]
             [logseq.outliner.tree :as otree]))
 
@@ -48,8 +47,8 @@
 
 (defn get-page-blocks
   "Get page blocks for GetPage tool"
-  [db page-title]
-  (when-let [page-id (common-initial-data/get-first-page-by-title db page-title)]
+  [db page-name-or-uuid]
+  (when-let [page-id (:db/id (ldb/get-page db page-name-or-uuid))]
     (let [blocks (ldb/get-page-blocks db page-id)]
       ;; Use repo stub since this is a DB only tool
       (->> (otree/blocks->vec-tree "logseq_db_repo_stub" db blocks page-id)

+ 3 - 2
src/main/logseq/api.cljs

@@ -1187,10 +1187,11 @@
 (defn ^:export get_page_data
   "Like get_page_blocks_tree but for MCP tools"
   [page-title]
-  (when-let [tools (cli-common-mcp-tools/get-page-blocks (db/get-db) page-title)]
+  (if-let [tools (cli-common-mcp-tools/get-page-blocks (db/get-db) page-title)]
     (->> tools
          (map #(dissoc % :block.temp/has-children? :block.temp/load-status))
-         clj->js)))
+         clj->js)
+    #js {:error (str "Page " (pr-str page-title) " not found")}))
 
 (defn ^:export list_pages
   []