Merge pull request #12111 from logseq/feat/mcp-server

Feat: Add MCP server
This commit is contained in:
Gabriel Horner
2025-10-29 15:59:32 -04:00
committed by GitHub
30 changed files with 1924 additions and 74 deletions

View File

@@ -38,6 +38,7 @@
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[lambdaisland.glogi.console :as glogi-console]
[logseq.cli.common.mcp.tools :as cli-common-mcp-tools]
[logseq.common.util :as common-util]
[logseq.db :as ldb]
[logseq.db.common.entity-plus :as entity-plus]
@@ -491,18 +492,18 @@
(def-thread-api :thread-api/block-refs-check
[repo id {:keys [unlinked?]}]
(m/sp
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [db @conn
block (d/entity db id)]
(if unlinked?
(let [title (string/lower-case (:block/title block))
result (m/? (search-blocks repo title {:limit 100}))]
(boolean (some (fn [b]
(let [block (d/entity db (:db/id b))]
(and (not= id (:db/id block))
(not ((set (map :db/id (:block/refs block))) id))
(string/includes? (string/lower-case (:block/title block)) title)))) result)))
(some? (first (common-initial-data/get-block-refs db (:db/id block)))))))))
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [db @conn
block (d/entity db id)]
(if unlinked?
(let [title (string/lower-case (:block/title block))
result (m/? (search-blocks repo title {:limit 100}))]
(boolean (some (fn [b]
(let [block (d/entity db (:db/id b))]
(and (not= id (:db/id block))
(not ((set (map :db/id (:block/refs block))) id))
(string/includes? (string/lower-case (:block/title block)) title)))) result)))
(some? (first (common-initial-data/get-block-refs db (:db/id block)))))))))
(def-thread-api :thread-api/get-block-parents
[repo id depth]
@@ -802,6 +803,31 @@
(when-let [conn (worker-state/get-datascript-conn repo)]
(ldb/get-graph-rtc-uuid @conn)))
(def-thread-api :thread-api/api-get-page-data
[repo page-title]
(let [conn (worker-state/get-datascript-conn repo)]
(cli-common-mcp-tools/get-page-data @conn page-title)))
(def-thread-api :thread-api/api-list-properties
[repo options]
(let [conn (worker-state/get-datascript-conn repo)]
(cli-common-mcp-tools/list-properties @conn options)))
(def-thread-api :thread-api/api-list-tags
[repo options]
(let [conn (worker-state/get-datascript-conn repo)]
(cli-common-mcp-tools/list-tags @conn options)))
(def-thread-api :thread-api/api-list-pages
[repo options]
(let [conn (worker-state/get-datascript-conn repo)]
(cli-common-mcp-tools/list-pages @conn options)))
(def-thread-api :thread-api/api-build-upsert-nodes-edn
[repo ops]
(let [conn (worker-state/get-datascript-conn repo)]
(cli-common-mcp-tools/build-upsert-nodes-edn @conn ops)))
(comment
(def-thread-api :general/dangerousRemoveAllDbs
[]
@@ -855,14 +881,14 @@
[repo start-opts]
(js/Promise.
(m/sp
(c.m/<? (init-sqlite-module!))
(when-not (:import-type start-opts)
(c.m/<? (start-db! repo start-opts))
(assert (some? (worker-state/get-datascript-conn repo))))
(c.m/<? (init-sqlite-module!))
(when-not (:import-type start-opts)
(c.m/<? (start-db! repo start-opts))
(assert (some? (worker-state/get-datascript-conn repo))))
;; Don't wait for rtc started because the app will be slow to be ready
;; for users.
(when @worker-state/*rtc-ws-url
(rtc.core/new-task--rtc-start true)))))
(when @worker-state/*rtc-ws-url
(rtc.core/new-task--rtc-start true)))))
(def broadcast-data-types
(set (map